logo

Expression of type Forall

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 ExprRange, IndexedVar, U, Variable, m, t
from proveit.linear_algebra import MatrixMult, ScalarMult, Unitary
from proveit.logic import Equals, Forall
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(U, sub_expr1)
sub_expr3 = IndexedVar(varphi, sub_expr1)
expr = 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()
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())
\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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 18
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple5
4Conditionalvalue: 6
condition: 7
5ExprRangelambda_map: 8
start_index: 164
end_index: 163
6Operationoperator: 18
operand: 11
7Operationoperator: 40
operands: 10
8Lambdaparameter: 173
body: 77
9ExprTuple11
10ExprTuple12
11Lambdaparameter: 111
body: 13
12ExprRangelambda_map: 14
start_index: 164
end_index: 163
13Conditionalvalue: 15
condition: 16
14Lambdaparameter: 173
body: 17
15Operationoperator: 18
operand: 22
16Operationoperator: 40
operands: 20
17Operationoperator: 28
operands: 21
18Literal
19ExprTuple22
20ExprTuple23, 24
21ExprTuple77, 25
22Lambdaparameters: 26
body: 27
23Operationoperator: 28
operands: 29
24Operationoperator: 124
operands: 30
25Operationoperator: 31
operand: 49
26ExprTuple33
27Conditionalvalue: 34
condition: 35
28Literal
29ExprTuple111, 36
30ExprTuple37, 164
31Literal
32ExprTuple49
33ExprRangelambda_map: 38
start_index: 164
end_index: 163
34Operationoperator: 124
operands: 39
35Operationoperator: 40
operands: 41
36Operationoperator: 42
operands: 43
37Operationoperator: 44
operand: 111
38Lambdaparameter: 173
body: 170
39ExprTuple46, 164
40Literal
41ExprTuple47
42Literal
43ExprTuple48, 49
44Literal
45ExprTuple111
46Operationoperator: 50
operand: 54
47ExprRangelambda_map: 52
start_index: 164
end_index: 163
48Literal
49Operationoperator: 155
operands: 53
50Literal
51ExprTuple54
52Lambdaparameter: 173
body: 55
53ExprTuple167, 147
54Operationoperator: 56
operands: 57
55Operationoperator: 124
operands: 58
56Literal
57ExprTuple59, 60, 61
58ExprTuple62, 63
59ExprTuple64, 65
60ExprRangelambda_map: 66
start_index: 164
end_index: 163
61ExprTuple67, 68
62Operationoperator: 69
operands: 70
63Operationoperator: 142
operands: 71
64ExprRangelambda_map: 72
start_index: 164
end_index: 163
65ExprRangelambda_map: 73
start_index: 164
end_index: 147
66Lambdaparameter: 146
body: 74
67ExprRangelambda_map: 75
start_index: 164
end_index: 163
68ExprRangelambda_map: 76
start_index: 164
end_index: 147
69Literal
70ExprTuple77, 111
71ExprTuple150, 111
72Lambdaparameter: 173
body: 78
73Lambdaparameter: 173
body: 79
74ExprTuple80, 81
75Lambdaparameter: 173
body: 82
76Lambdaparameter: 173
body: 83
77IndexedVarvariable: 137
index: 173
78Operationoperator: 97
operands: 84
79Operationoperator: 122
operands: 85
80ExprRangelambda_map: 86
start_index: 164
end_index: 163
81ExprRangelambda_map: 87
start_index: 164
end_index: 147
82Operationoperator: 102
operands: 88
83Operationoperator: 122
operands: 89
84NamedExprsstate: 90
85NamedExprselement: 91
targets: 108
86Lambdaparameter: 173
body: 92
87Lambdaparameter: 173
body: 93
88NamedExprsstate: 94
89NamedExprselement: 95
targets: 108
90Operationoperator: 157
operand: 104
91Operationoperator: 97
operands: 103
92Operationoperator: 98
operands: 99
93Operationoperator: 122
operands: 100
94Operationoperator: 142
operands: 101
95Operationoperator: 102
operands: 103
96ExprTuple104
97Literal
98Literal
99ExprTuple105, 106
100NamedExprselement: 107
targets: 108
101ExprTuple109, 110
102Literal
103NamedExprsstate: 111
part: 173
104Literal
105Conditionalvalue: 112
condition: 113
106Conditionalvalue: 114
condition: 115
107Operationoperator: 125
operands: 116
108Operationoperator: 117
operands: 118
109Operationoperator: 153
operands: 119
110Operationoperator: 120
operands: 121
111Variable
112Operationoperator: 122
operands: 123
113Operationoperator: 124
operands: 128
114Operationoperator: 125
operands: 126
115Operationoperator: 127
operands: 128
116NamedExprsoperation: 129
part: 173
117Literal
118ExprTuple152, 130
119ExprTuple164, 131
120Literal
121ExprTuple132, 133
122Literal
123NamedExprselement: 134
targets: 135
124Literal
125Literal
126NamedExprsoperation: 136
127Literal
128ExprTuple146, 173
129IndexedVarvariable: 137
index: 146
130Operationoperator: 159
operands: 139
131Operationoperator: 155
operands: 140
132Operationoperator: 157
operand: 149
133Operationoperator: 142
operands: 143
134Literal
135Operationoperator: 144
operand: 152
136Literal
137Variable
138ExprTuple146
139ExprTuple163, 147
140ExprTuple167, 148
141ExprTuple149
142Literal
143ExprTuple150, 151
144Literal
145ExprTuple152
146Variable
147Variable
148Operationoperator: 153
operands: 154
149Literal
150Operationoperator: 155
operands: 156
151Operationoperator: 157
operand: 164
152Operationoperator: 159
operands: 160
153Literal
154ExprTuple164, 167
155Literal
156ExprTuple161, 162
157Literal
158ExprTuple164
159Literal
160ExprTuple163, 164
161Literal
162Operationoperator: 165
operands: 166
163Variable
164Literal
165Literal
166ExprTuple167, 168, 169, 170
167Literal
168Literal
169Literal
170IndexedVarvariable: 171
index: 173
171Variable
172ExprTuple173
173Variable