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, 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 = [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()
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 \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}
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: 16
operand: 2
1ExprTuple2
2Lambdaparameter: 151
body: 4
3ExprTuple151
4Conditionalvalue: 5
condition: 6
5Operationoperator: 16
operand: 9
6Operationoperator: 50
operands: 8
7ExprTuple9
8ExprTuple151, 10
9Lambdaparameter: 140
body: 11
10Operationoperator: 12
operand: 44
11Conditionalvalue: 14
condition: 15
12Literal
13ExprTuple44
14Operationoperator: 16
operand: 19
15Operationoperator: 32
operands: 18
16Literal
17ExprTuple19
18ExprTuple20, 21
19Lambdaparameter: 164
body: 23
20Operationoperator: 50
operands: 24
21Operationoperator: 52
operands: 25
22ExprTuple164
23Conditionalvalue: 26
condition: 27
24ExprTuple140, 28
25ExprTuple29, 153
26Operationoperator: 30
operands: 31
27Operationoperator: 32
operands: 33
28Operationoperator: 34
operands: 35
29Operationoperator: 36
operand: 140
30Literal
31ExprTuple38, 39
32Literal
33ExprTuple40, 41, 42
34Literal
35ExprTuple43, 44
36Literal
37ExprTuple140
38Operationoperator: 45
operands: 46
39Operationoperator: 47
operand: 57
40Operationoperator: 50
operands: 49
41Operationoperator: 50
operands: 51
42Operationoperator: 52
operands: 53
43Literal
44Operationoperator: 165
operands: 54
45Literal
46ExprTuple55, 56
47Literal
48ExprTuple57
49ExprTuple164, 58
50Literal
51ExprTuple164, 59
52Literal
53ExprTuple60, 61
54ExprTuple167, 154
55Literal
56Operationoperator: 165
operands: 62
57Operationoperator: 63
operands: 64
58Literal
59Operationoperator: 65
operands: 66
60Operationoperator: 67
operands: 68
61Operationoperator: 69
operands: 70
62ExprTuple113, 167
63Literal
64ExprTuple71, 72, 73, 74
65Literal
66ExprTuple75, 153
67Literal
68ExprTuple151, 140
69Literal
70ExprTuple76, 140
71ExprTuple77, 78
72ExprTuple79, 80
73ExprTuple81, 82
74ExprTuple83, 84
75Literal
76Operationoperator: 165
operands: 85
77ExprRangelambda_map: 86
start_index: 153
end_index: 168
78ExprRangelambda_map: 87
start_index: 153
end_index: 154
79ExprRangelambda_map: 88
start_index: 153
end_index: 168
80ExprRangelambda_map: 88
start_index: 142
end_index: 143
81ExprRangelambda_map: 89
start_index: 153
end_index: 168
82ExprRangelambda_map: 90
start_index: 153
end_index: 154
83ExprRangelambda_map: 91
start_index: 153
end_index: 168
84ExprRangelambda_map: 92
start_index: 153
end_index: 154
85ExprTuple93, 94
86Lambdaparameter: 141
body: 95
87Lambdaparameter: 141
body: 96
88Lambdaparameter: 141
body: 97
89Lambdaparameter: 141
body: 98
90Lambdaparameter: 141
body: 99
91Lambdaparameter: 141
body: 100
92Lambdaparameter: 141
body: 102
93Literal
94Operationoperator: 161
operands: 103
95Operationoperator: 127
operands: 104
96Operationoperator: 111
operands: 105
97Operationoperator: 111
operands: 106
98Operationoperator: 107
operands: 108
99Operationoperator: 128
operands: 109
100Operationoperator: 111
operands: 110
101ExprTuple141
102Operationoperator: 111
operands: 112
103ExprTuple167, 113, 114, 164
104NamedExprsstate: 115
105NamedExprselement: 116
targets: 124
106NamedExprselement: 117
targets: 118
107Literal
108NamedExprsbasis: 119
109NamedExprsoperation: 120
110NamedExprselement: 121
targets: 122
111Literal
112NamedExprselement: 123
targets: 124
113Literal
114Literal
115Operationoperator: 125
operand: 137
116Operationoperator: 127
operands: 134
117Operationoperator: 128
operands: 129
118Operationoperator: 135
operands: 130
119Literal
120Literal
121Operationoperator: 133
operands: 131
122Operationoperator: 135
operands: 132
123Operationoperator: 133
operands: 134
124Operationoperator: 135
operands: 136
125Literal
126ExprTuple137
127Literal
128Literal
129NamedExprsoperation: 138
part: 141
130ExprTuple153, 143
131NamedExprsstate: 139
part: 141
132ExprTuple153, 168
133Literal
134NamedExprsstate: 140
part: 141
135Literal
136ExprTuple142, 143
137Literal
138Operationoperator: 144
operands: 145
139Operationoperator: 146
operands: 147
140Variable
141Variable
142Operationoperator: 149
operands: 148
143Operationoperator: 149
operands: 150
144Literal
145ExprTuple151, 168
146Literal
147ExprTuple152, 168
148ExprTuple168, 153
149Literal
150ExprTuple168, 154
151Variable
152Operationoperator: 155
operands: 156
153Literal
154Variable
155Literal
156ExprTuple157, 163
157Operationoperator: 158
operand: 160
158Literal
159ExprTuple160
160Operationoperator: 161
operands: 162
161Literal
162ExprTuple163, 164
163Operationoperator: 165
operands: 166
164Variable
165Literal
166ExprTuple167, 168
167Literal
168Variable