logo

Expression of type Forall

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 ExprRange, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult, Unitary
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, IntervalCO, Mod, Mult, NaturalPos, Real, Round, e, four, frac, greater, i, one, pi, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, normalized_var_ket_u, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, s_ket_domain, two_pow_s, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, one)
sub_expr3 = Add(t, s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Forall(instance_param_or_params = [s, t], instance_expr = Forall(instance_param_or_params = [U], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [phase], instance_expr = greater(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)], [ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(Mod(Round(Mult(two_pow_t, phase)), two_pow_t), t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)]))), frac(four, Exp(pi, two))), domain = Real, conditions = [InSet(phase, IntervalCO(zero, one)), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), var_ket_u))]).with_wrapping(), domain = s_ket_domain, condition = normalized_var_ket_u).with_wrapping(), domain = Unitary(two_pow_s)).with_wrapping(), domain = NaturalPos).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_{s, t \in \mathbb{N}^+}~\\
\left[\begin{array}{l}\forall_{U \in \textrm{U}\left(2^{s}\right)}~\\
\left[\begin{array}{l}\forall_{\lvert u \rangle \in \mathbb{C}^{2^{s}}~|~\left \|\lvert u \rangle\right \| = 1}~\\
\left[\begin{array}{l}\forall_{\varphi \in \mathbb{R}~|~\varphi \in \left[0,1\right), \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\\
\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) > \frac{4}{\pi^{2}}\right)\end{array}\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: 28
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple166, 180
4Conditionalvalue: 5
condition: 6
5Operationoperator: 28
operand: 9
6Operationoperator: 44
operands: 8
7ExprTuple9
8ExprTuple10, 11
9Lambdaparameter: 163
body: 13
10Operationoperator: 62
operands: 14
11Operationoperator: 62
operands: 15
12ExprTuple163
13Conditionalvalue: 16
condition: 17
14ExprTuple166, 18
15ExprTuple180, 18
16Operationoperator: 28
operand: 21
17Operationoperator: 62
operands: 20
18Literal
19ExprTuple21
20ExprTuple163, 22
21Lambdaparameter: 152
body: 23
22Operationoperator: 24
operand: 56
23Conditionalvalue: 26
condition: 27
24Literal
25ExprTuple56
26Operationoperator: 28
operand: 31
27Operationoperator: 44
operands: 30
28Literal
29ExprTuple31
30ExprTuple32, 33
31Lambdaparameter: 176
body: 35
32Operationoperator: 62
operands: 36
33Operationoperator: 64
operands: 37
34ExprTuple176
35Conditionalvalue: 38
condition: 39
36ExprTuple152, 40
37ExprTuple41, 165
38Operationoperator: 42
operands: 43
39Operationoperator: 44
operands: 45
40Operationoperator: 46
operands: 47
41Operationoperator: 48
operand: 152
42Literal
43ExprTuple50, 51
44Literal
45ExprTuple52, 53, 54
46Literal
47ExprTuple55, 56
48Literal
49ExprTuple152
50Operationoperator: 57
operands: 58
51Operationoperator: 59
operand: 69
52Operationoperator: 62
operands: 61
53Operationoperator: 62
operands: 63
54Operationoperator: 64
operands: 65
55Literal
56Operationoperator: 177
operands: 66
57Literal
58ExprTuple67, 68
59Literal
60ExprTuple69
61ExprTuple176, 70
62Literal
63ExprTuple176, 71
64Literal
65ExprTuple72, 73
66ExprTuple179, 166
67Literal
68Operationoperator: 177
operands: 74
69Operationoperator: 75
operands: 76
70Literal
71Operationoperator: 77
operands: 78
72Operationoperator: 79
operands: 80
73Operationoperator: 81
operands: 82
74ExprTuple125, 179
75Literal
76ExprTuple83, 84, 85, 86
77Literal
78ExprTuple87, 165
79Literal
80ExprTuple163, 152
81Literal
82ExprTuple88, 152
83ExprTuple89, 90
84ExprTuple91, 92
85ExprTuple93, 94
86ExprTuple95, 96
87Literal
88Operationoperator: 177
operands: 97
89ExprRangelambda_map: 98
start_index: 165
end_index: 180
90ExprRangelambda_map: 99
start_index: 165
end_index: 166
91ExprRangelambda_map: 100
start_index: 165
end_index: 180
92ExprRangelambda_map: 100
start_index: 154
end_index: 155
93ExprRangelambda_map: 101
start_index: 165
end_index: 180
94ExprRangelambda_map: 102
start_index: 165
end_index: 166
95ExprRangelambda_map: 103
start_index: 165
end_index: 180
96ExprRangelambda_map: 104
start_index: 165
end_index: 166
97ExprTuple105, 106
98Lambdaparameter: 153
body: 107
99Lambdaparameter: 153
body: 108
100Lambdaparameter: 153
body: 109
101Lambdaparameter: 153
body: 110
102Lambdaparameter: 153
body: 111
103Lambdaparameter: 153
body: 112
104Lambdaparameter: 153
body: 114
105Literal
106Operationoperator: 173
operands: 115
107Operationoperator: 139
operands: 116
108Operationoperator: 123
operands: 117
109Operationoperator: 123
operands: 118
110Operationoperator: 119
operands: 120
111Operationoperator: 140
operands: 121
112Operationoperator: 123
operands: 122
113ExprTuple153
114Operationoperator: 123
operands: 124
115ExprTuple179, 125, 126, 176
116NamedExprsstate: 127
117NamedExprselement: 128
targets: 136
118NamedExprselement: 129
targets: 130
119Literal
120NamedExprsbasis: 131
121NamedExprsoperation: 132
122NamedExprselement: 133
targets: 134
123Literal
124NamedExprselement: 135
targets: 136
125Literal
126Literal
127Operationoperator: 137
operand: 149
128Operationoperator: 139
operands: 146
129Operationoperator: 140
operands: 141
130Operationoperator: 147
operands: 142
131Literal
132Literal
133Operationoperator: 145
operands: 143
134Operationoperator: 147
operands: 144
135Operationoperator: 145
operands: 146
136Operationoperator: 147
operands: 148
137Literal
138ExprTuple149
139Literal
140Literal
141NamedExprsoperation: 150
part: 153
142ExprTuple165, 155
143NamedExprsstate: 151
part: 153
144ExprTuple165, 180
145Literal
146NamedExprsstate: 152
part: 153
147Literal
148ExprTuple154, 155
149Literal
150Operationoperator: 156
operands: 157
151Operationoperator: 158
operands: 159
152Variable
153Variable
154Operationoperator: 161
operands: 160
155Operationoperator: 161
operands: 162
156Literal
157ExprTuple163, 180
158Literal
159ExprTuple164, 180
160ExprTuple180, 165
161Literal
162ExprTuple180, 166
163Variable
164Operationoperator: 167
operands: 168
165Literal
166Variable
167Literal
168ExprTuple169, 175
169Operationoperator: 170
operand: 172
170Literal
171ExprTuple172
172Operationoperator: 173
operands: 174
173Literal
174ExprTuple175, 176
175Operationoperator: 177
operands: 178
176Variable
177Literal
178ExprTuple179, 180
179Literal
180Variable