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, 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(varphi, sub_expr1)
sub_expr3 = IndexedVar(U, sub_expr1)
expr = Conditional(Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [ExprRange(sub_expr1, sub_expr2, one, t)], instance_expr = Equals(Prob(phase_kickback_on_register_circuit), one), condition = ExprRange(sub_expr1, Equals(MatrixMult(sub_expr3, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, sub_expr2)), var_ket_u)), one, t)).with_wrapping(), domain = m_ket_domain, condition = normalized_var_ket_u).with_wrapping(), And(ExprRange(sub_expr1, InSet(sub_expr3, Unitary(Exp(two, m))), one, t)))
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_{\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} \textrm{ if } \left(U_{1} \in \textrm{U}\left(2^{m}\right)\right) \land  \left(U_{2} \in \textrm{U}\left(2^{m}\right)\right) \land  \ldots \land  \left(U_{t} \in \textrm{U}\left(2^{m}\right)\right)\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: 12
operand: 5
2Operationoperator: 34
operands: 4
3ExprTuple5
4ExprTuple6
5Lambdaparameter: 105
body: 7
6ExprRangelambda_map: 8
start_index: 158
end_index: 157
7Conditionalvalue: 9
condition: 10
8Lambdaparameter: 167
body: 11
9Operationoperator: 12
operand: 16
10Operationoperator: 34
operands: 14
11Operationoperator: 22
operands: 15
12Literal
13ExprTuple16
14ExprTuple17, 18
15ExprTuple71, 19
16Lambdaparameters: 20
body: 21
17Operationoperator: 22
operands: 23
18Operationoperator: 118
operands: 24
19Operationoperator: 25
operand: 43
20ExprTuple27
21Conditionalvalue: 28
condition: 29
22Literal
23ExprTuple105, 30
24ExprTuple31, 158
25Literal
26ExprTuple43
27ExprRangelambda_map: 32
start_index: 158
end_index: 157
28Operationoperator: 118
operands: 33
29Operationoperator: 34
operands: 35
30Operationoperator: 36
operands: 37
31Operationoperator: 38
operand: 105
32Lambdaparameter: 167
body: 164
33ExprTuple40, 158
34Literal
35ExprTuple41
36Literal
37ExprTuple42, 43
38Literal
39ExprTuple105
40Operationoperator: 44
operand: 48
41ExprRangelambda_map: 46
start_index: 158
end_index: 157
42Literal
43Operationoperator: 149
operands: 47
44Literal
45ExprTuple48
46Lambdaparameter: 167
body: 49
47ExprTuple161, 141
48Operationoperator: 50
operands: 51
49Operationoperator: 118
operands: 52
50Literal
51ExprTuple53, 54, 55
52ExprTuple56, 57
53ExprTuple58, 59
54ExprRangelambda_map: 60
start_index: 158
end_index: 157
55ExprTuple61, 62
56Operationoperator: 63
operands: 64
57Operationoperator: 136
operands: 65
58ExprRangelambda_map: 66
start_index: 158
end_index: 157
59ExprRangelambda_map: 67
start_index: 158
end_index: 141
60Lambdaparameter: 140
body: 68
61ExprRangelambda_map: 69
start_index: 158
end_index: 157
62ExprRangelambda_map: 70
start_index: 158
end_index: 141
63Literal
64ExprTuple71, 105
65ExprTuple144, 105
66Lambdaparameter: 167
body: 72
67Lambdaparameter: 167
body: 73
68ExprTuple74, 75
69Lambdaparameter: 167
body: 76
70Lambdaparameter: 167
body: 77
71IndexedVarvariable: 131
index: 167
72Operationoperator: 91
operands: 78
73Operationoperator: 116
operands: 79
74ExprRangelambda_map: 80
start_index: 158
end_index: 157
75ExprRangelambda_map: 81
start_index: 158
end_index: 141
76Operationoperator: 96
operands: 82
77Operationoperator: 116
operands: 83
78NamedExprsstate: 84
79NamedExprselement: 85
targets: 102
80Lambdaparameter: 167
body: 86
81Lambdaparameter: 167
body: 87
82NamedExprsstate: 88
83NamedExprselement: 89
targets: 102
84Operationoperator: 151
operand: 98
85Operationoperator: 91
operands: 97
86Operationoperator: 92
operands: 93
87Operationoperator: 116
operands: 94
88Operationoperator: 136
operands: 95
89Operationoperator: 96
operands: 97
90ExprTuple98
91Literal
92Literal
93ExprTuple99, 100
94NamedExprselement: 101
targets: 102
95ExprTuple103, 104
96Literal
97NamedExprsstate: 105
part: 167
98Literal
99Conditionalvalue: 106
condition: 107
100Conditionalvalue: 108
condition: 109
101Operationoperator: 119
operands: 110
102Operationoperator: 111
operands: 112
103Operationoperator: 147
operands: 113
104Operationoperator: 114
operands: 115
105Variable
106Operationoperator: 116
operands: 117
107Operationoperator: 118
operands: 122
108Operationoperator: 119
operands: 120
109Operationoperator: 121
operands: 122
110NamedExprsoperation: 123
part: 167
111Literal
112ExprTuple146, 124
113ExprTuple158, 125
114Literal
115ExprTuple126, 127
116Literal
117NamedExprselement: 128
targets: 129
118Literal
119Literal
120NamedExprsoperation: 130
121Literal
122ExprTuple140, 167
123IndexedVarvariable: 131
index: 140
124Operationoperator: 153
operands: 133
125Operationoperator: 149
operands: 134
126Operationoperator: 151
operand: 143
127Operationoperator: 136
operands: 137
128Literal
129Operationoperator: 138
operand: 146
130Literal
131Variable
132ExprTuple140
133ExprTuple157, 141
134ExprTuple161, 142
135ExprTuple143
136Literal
137ExprTuple144, 145
138Literal
139ExprTuple146
140Variable
141Variable
142Operationoperator: 147
operands: 148
143Literal
144Operationoperator: 149
operands: 150
145Operationoperator: 151
operand: 158
146Operationoperator: 153
operands: 154
147Literal
148ExprTuple158, 161
149Literal
150ExprTuple155, 156
151Literal
152ExprTuple158
153Literal
154ExprTuple157, 158
155Literal
156Operationoperator: 159
operands: 160
157Variable
158Literal
159Literal
160ExprTuple161, 162, 163, 164
161Literal
162Literal
163Literal
164IndexedVarvariable: 165
index: 167
165Variable
166ExprTuple167
167Variable