logo

Expression of type Conditional

from the theory of proveit.physics.quantum.circuits

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, IndexedVar, U, Variable, m, t
from proveit.linear_algebra import MatrixMult, ScalarMult, Unitary
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import Exp, Mult, NaturalPos, e, i, one, pi, two
from proveit.physics.quantum import m_ket_domain, normalized_var_ket_u, var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_on_register_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(U, sub_expr1)
sub_expr3 = IndexedVar(varphi, sub_expr1)
expr = Conditional(Forall(instance_param_or_params = [ExprRange(sub_expr1, sub_expr2, one, t)], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [ExprRange(sub_expr1, sub_expr3, one, t)], instance_expr = Equals(Prob(phase_kickback_on_register_circuit), one), condition = ExprRange(sub_expr1, Equals(MatrixMult(sub_expr2, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, sub_expr3)), var_ket_u)), one, t)).with_wrapping(), domain = m_ket_domain, condition = normalized_var_ket_u).with_wrapping(), domain = Unitary(Exp(two, m))).with_wrapping(), And(InSet(m, 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\{\begin{array}{l}\forall_{U_{1}, U_{2}, \ldots, U_{t} \in \textrm{U}\left(2^{m}\right)}~\\
\left[\begin{array}{l}\forall_{\lvert u \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert u \rangle\right \| = 1}~\\
\left[\begin{array}{l}\forall_{\varphi_{1}, \varphi_{2}, \ldots, \varphi_{t}~|~\left(\left(U_{1} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert u \rangle\right)\right), \left(\left(U_{2} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert u \rangle\right)\right), \ldots, \left(\left(U_{t} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert u \rangle\right)\right)}~\\
\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U_{1}} & \gate{U_{2}} & \gate{\cdots} & \gate{U_{t}} & \qout{\lvert u \rangle}
} \end{array}\right) = 1\right)\end{array}\right]\end{array}\right]\end{array} \textrm{ if } m \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: 26
operand: 5
2Operationoperator: 48
operands: 4
3ExprTuple5
4ExprTuple6, 7
5Lambdaparameters: 8
body: 9
6Operationoperator: 36
operands: 10
7Operationoperator: 36
operands: 11
8ExprTuple12
9Conditionalvalue: 13
condition: 14
10ExprTuple155, 15
11ExprTuple171, 15
12ExprRangelambda_map: 16
start_index: 172
end_index: 171
13Operationoperator: 26
operand: 19
14Operationoperator: 48
operands: 18
15Literal
16Lambdaparameter: 181
body: 85
17ExprTuple19
18ExprTuple20
19Lambdaparameter: 119
body: 21
20ExprRangelambda_map: 22
start_index: 172
end_index: 171
21Conditionalvalue: 23
condition: 24
22Lambdaparameter: 181
body: 25
23Operationoperator: 26
operand: 30
24Operationoperator: 48
operands: 28
25Operationoperator: 36
operands: 29
26Literal
27ExprTuple30
28ExprTuple31, 32
29ExprTuple85, 33
30Lambdaparameters: 34
body: 35
31Operationoperator: 36
operands: 37
32Operationoperator: 132
operands: 38
33Operationoperator: 39
operand: 57
34ExprTuple41
35Conditionalvalue: 42
condition: 43
36Literal
37ExprTuple119, 44
38ExprTuple45, 172
39Literal
40ExprTuple57
41ExprRangelambda_map: 46
start_index: 172
end_index: 171
42Operationoperator: 132
operands: 47
43Operationoperator: 48
operands: 49
44Operationoperator: 50
operands: 51
45Operationoperator: 52
operand: 119
46Lambdaparameter: 181
body: 178
47ExprTuple54, 172
48Literal
49ExprTuple55
50Literal
51ExprTuple56, 57
52Literal
53ExprTuple119
54Operationoperator: 58
operand: 62
55ExprRangelambda_map: 60
start_index: 172
end_index: 171
56Literal
57Operationoperator: 163
operands: 61
58Literal
59ExprTuple62
60Lambdaparameter: 181
body: 63
61ExprTuple175, 155
62Operationoperator: 64
operands: 65
63Operationoperator: 132
operands: 66
64Literal
65ExprTuple67, 68, 69
66ExprTuple70, 71
67ExprTuple72, 73
68ExprRangelambda_map: 74
start_index: 172
end_index: 171
69ExprTuple75, 76
70Operationoperator: 77
operands: 78
71Operationoperator: 150
operands: 79
72ExprRangelambda_map: 80
start_index: 172
end_index: 171
73ExprRangelambda_map: 81
start_index: 172
end_index: 155
74Lambdaparameter: 154
body: 82
75ExprRangelambda_map: 83
start_index: 172
end_index: 171
76ExprRangelambda_map: 84
start_index: 172
end_index: 155
77Literal
78ExprTuple85, 119
79ExprTuple158, 119
80Lambdaparameter: 181
body: 86
81Lambdaparameter: 181
body: 87
82ExprTuple88, 89
83Lambdaparameter: 181
body: 90
84Lambdaparameter: 181
body: 91
85IndexedVarvariable: 145
index: 181
86Operationoperator: 105
operands: 92
87Operationoperator: 130
operands: 93
88ExprRangelambda_map: 94
start_index: 172
end_index: 171
89ExprRangelambda_map: 95
start_index: 172
end_index: 155
90Operationoperator: 110
operands: 96
91Operationoperator: 130
operands: 97
92NamedExprsstate: 98
93NamedExprselement: 99
targets: 116
94Lambdaparameter: 181
body: 100
95Lambdaparameter: 181
body: 101
96NamedExprsstate: 102
97NamedExprselement: 103
targets: 116
98Operationoperator: 165
operand: 112
99Operationoperator: 105
operands: 111
100Operationoperator: 106
operands: 107
101Operationoperator: 130
operands: 108
102Operationoperator: 150
operands: 109
103Operationoperator: 110
operands: 111
104ExprTuple112
105Literal
106Literal
107ExprTuple113, 114
108NamedExprselement: 115
targets: 116
109ExprTuple117, 118
110Literal
111NamedExprsstate: 119
part: 181
112Literal
113Conditionalvalue: 120
condition: 121
114Conditionalvalue: 122
condition: 123
115Operationoperator: 133
operands: 124
116Operationoperator: 125
operands: 126
117Operationoperator: 161
operands: 127
118Operationoperator: 128
operands: 129
119Variable
120Operationoperator: 130
operands: 131
121Operationoperator: 132
operands: 136
122Operationoperator: 133
operands: 134
123Operationoperator: 135
operands: 136
124NamedExprsoperation: 137
part: 181
125Literal
126ExprTuple160, 138
127ExprTuple172, 139
128Literal
129ExprTuple140, 141
130Literal
131NamedExprselement: 142
targets: 143
132Literal
133Literal
134NamedExprsoperation: 144
135Literal
136ExprTuple154, 181
137IndexedVarvariable: 145
index: 154
138Operationoperator: 167
operands: 147
139Operationoperator: 163
operands: 148
140Operationoperator: 165
operand: 157
141Operationoperator: 150
operands: 151
142Literal
143Operationoperator: 152
operand: 160
144Literal
145Variable
146ExprTuple154
147ExprTuple171, 155
148ExprTuple175, 156
149ExprTuple157
150Literal
151ExprTuple158, 159
152Literal
153ExprTuple160
154Variable
155Variable
156Operationoperator: 161
operands: 162
157Literal
158Operationoperator: 163
operands: 164
159Operationoperator: 165
operand: 172
160Operationoperator: 167
operands: 168
161Literal
162ExprTuple172, 175
163Literal
164ExprTuple169, 170
165Literal
166ExprTuple172
167Literal
168ExprTuple171, 172
169Literal
170Operationoperator: 173
operands: 174
171Variable
172Literal
173Literal
174ExprTuple175, 176, 177, 178
175Literal
176Literal
177Literal
178IndexedVarvariable: 179
index: 181
179Variable
180ExprTuple181
181Variable