logo

Expression of type Conditional

from the theory of proveit.physics.quantum.QPE

In [1]:
import proveit
# Automation is not needed when building an expression:
proveit.defaults.automation = False # This will speed things up.
proveit.defaults.inline_pngs = False # Makes files smaller.
%load_expr # Load the stored expression as 'stored_expr'
# import Expression classes needed to build the expression
from proveit import Conditional, ExprRange, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import Unitary
from proveit.logic import And, Forall, InSet
from proveit.numbers import Add, Exp, Interval, NaturalPos, one, two
from proveit.physics.quantum.QPE import QPE1, QPE1_U_t_circuit
from proveit.physics.quantum.circuits import Gate, MultiQubitElem, Qcircuit, QcircuitEquiv
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, s)
sub_expr3 = MultiQubitElem(element = Gate(operation = QPE1(U, t), part = sub_expr1), targets = Interval(one, sub_expr2))
expr = Conditional(Forall(instance_param_or_params = [U], instance_expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr3, one, t), ExprRange(sub_expr1, sub_expr3, Add(t, one), sub_expr2)])), QPE1_U_t_circuit), domain = Unitary(Exp(two, s))), And(InSet(s, NaturalPos), InSet(t, NaturalPos)))
expr:
In [3]:
# check that the built expression is the same as the stored expression
assert expr == stored_expr
assert expr._style_id == stored_expr._style_id
print("Passed sanity check: expr matches stored_expr")
Passed sanity check: expr matches stored_expr
In [4]:
# Show the LaTeX representation of the expression for convenience if you need it.
print(stored_expr.latex())
\left\{\forall_{U \in \textrm{U}\left(2^{s}\right)}~\left(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multigate{1}{\textrm{QPE}_1\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qw \\
& \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qw \\
& \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & { /^{s} } \qw
} \end{array}\right)\right) \textrm{ if } s \in \mathbb{N}^+ ,  t \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operand: 7
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7
5Literal
6ExprTuple8, 9
7Lambdaparameter: 93
body: 11
8Operationoperator: 19
operands: 12
9Operationoperator: 19
operands: 13
10ExprTuple93
11Conditionalvalue: 14
condition: 15
12ExprTuple95, 16
13ExprTuple103, 16
14Operationoperator: 17
operands: 18
15Operationoperator: 19
operands: 20
16Literal
17Literal
18ExprTuple21, 22
19Literal
20ExprTuple93, 23
21Operationoperator: 25
operand: 29
22Operationoperator: 25
operands: 26
23Operationoperator: 27
operand: 31
24ExprTuple29
25Literal
26ExprTuple30
27Literal
28ExprTuple31
29ExprTuple32, 33
30ExprRangelambda_map: 34
start_index: 35
end_index: 36
31Operationoperator: 97
operands: 37
32ExprRangelambda_map: 38
start_index: 104
end_index: 103
33ExprRangelambda_map: 38
start_index: 96
end_index: 81
34Lambdaparameter: 107
body: 39
35Operationoperator: 99
operands: 40
36Literal
37ExprTuple101, 95
38Lambdaparameter: 86
body: 41
39ExprTuple42, 43
40ExprTuple44, 104
41Operationoperator: 73
operands: 45
42ExprRangelambda_map: 46
start_index: 104
end_index: 103
43ExprRangelambda_map: 47
start_index: 104
end_index: 95
44Operationoperator: 105
operand: 103
45NamedExprselement: 49
targets: 50
46Lambdaparameter: 86
body: 51
47Lambdaparameter: 86
body: 53
48ExprTuple103
49Operationoperator: 76
operands: 54
50Operationoperator: 71
operands: 55
51Operationoperator: 56
operands: 57
52ExprTuple86
53Operationoperator: 73
operands: 58
54NamedExprsoperation: 59
part: 86
55ExprTuple104, 81
56Literal
57ExprTuple60, 61
58NamedExprselement: 62
targets: 63
59Operationoperator: 64
operands: 65
60Conditionalvalue: 66
condition: 67
61Conditionalvalue: 68
condition: 69
62Operationoperator: 76
operands: 70
63Operationoperator: 71
operands: 72
64Literal
65ExprTuple93, 103
66Operationoperator: 73
operands: 74
67Operationoperator: 75
operands: 79
68Operationoperator: 76
operands: 77
69Operationoperator: 78
operands: 79
70NamedExprsoperation: 80
part: 86
71Literal
72ExprTuple96, 81
73Literal
74NamedExprselement: 82
targets: 83
75Literal
76Literal
77NamedExprsoperation: 84
78Literal
79ExprTuple85, 86
80Operationoperator: 87
operands: 88
81Operationoperator: 99
operands: 89
82Literal
83Operationoperator: 90
operand: 96
84Literal
85Operationoperator: 99
operands: 92
86Variable
87Literal
88ExprTuple93, 94
89ExprTuple103, 95
90Literal
91ExprTuple96
92ExprTuple107, 103
93Variable
94Operationoperator: 97
operands: 98
95Variable
96Operationoperator: 99
operands: 100
97Literal
98ExprTuple101, 102
99Literal
100ExprTuple103, 104
101Literal
102Operationoperator: 105
operand: 107
103Variable
104Literal
105Literal
106ExprTuple107
107Variable