logo

Expression of type Conditional

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 Conditional, ExprRange, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult, Unitary
from proveit.logic import And, 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 = Conditional(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(), And(InSet(s, 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 \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} \textrm{ if } s \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: 24
operand: 5
2Operationoperator: 40
operands: 4
3ExprTuple5
4ExprTuple6, 7
5Lambdaparameter: 159
body: 9
6Operationoperator: 58
operands: 10
7Operationoperator: 58
operands: 11
8ExprTuple159
9Conditionalvalue: 12
condition: 13
10ExprTuple162, 14
11ExprTuple176, 14
12Operationoperator: 24
operand: 17
13Operationoperator: 58
operands: 16
14Literal
15ExprTuple17
16ExprTuple159, 18
17Lambdaparameter: 148
body: 19
18Operationoperator: 20
operand: 52
19Conditionalvalue: 22
condition: 23
20Literal
21ExprTuple52
22Operationoperator: 24
operand: 27
23Operationoperator: 40
operands: 26
24Literal
25ExprTuple27
26ExprTuple28, 29
27Lambdaparameter: 172
body: 31
28Operationoperator: 58
operands: 32
29Operationoperator: 60
operands: 33
30ExprTuple172
31Conditionalvalue: 34
condition: 35
32ExprTuple148, 36
33ExprTuple37, 161
34Operationoperator: 38
operands: 39
35Operationoperator: 40
operands: 41
36Operationoperator: 42
operands: 43
37Operationoperator: 44
operand: 148
38Literal
39ExprTuple46, 47
40Literal
41ExprTuple48, 49, 50
42Literal
43ExprTuple51, 52
44Literal
45ExprTuple148
46Operationoperator: 53
operands: 54
47Operationoperator: 55
operand: 65
48Operationoperator: 58
operands: 57
49Operationoperator: 58
operands: 59
50Operationoperator: 60
operands: 61
51Literal
52Operationoperator: 173
operands: 62
53Literal
54ExprTuple63, 64
55Literal
56ExprTuple65
57ExprTuple172, 66
58Literal
59ExprTuple172, 67
60Literal
61ExprTuple68, 69
62ExprTuple175, 162
63Literal
64Operationoperator: 173
operands: 70
65Operationoperator: 71
operands: 72
66Literal
67Operationoperator: 73
operands: 74
68Operationoperator: 75
operands: 76
69Operationoperator: 77
operands: 78
70ExprTuple121, 175
71Literal
72ExprTuple79, 80, 81, 82
73Literal
74ExprTuple83, 161
75Literal
76ExprTuple159, 148
77Literal
78ExprTuple84, 148
79ExprTuple85, 86
80ExprTuple87, 88
81ExprTuple89, 90
82ExprTuple91, 92
83Literal
84Operationoperator: 173
operands: 93
85ExprRangelambda_map: 94
start_index: 161
end_index: 176
86ExprRangelambda_map: 95
start_index: 161
end_index: 162
87ExprRangelambda_map: 96
start_index: 161
end_index: 176
88ExprRangelambda_map: 96
start_index: 150
end_index: 151
89ExprRangelambda_map: 97
start_index: 161
end_index: 176
90ExprRangelambda_map: 98
start_index: 161
end_index: 162
91ExprRangelambda_map: 99
start_index: 161
end_index: 176
92ExprRangelambda_map: 100
start_index: 161
end_index: 162
93ExprTuple101, 102
94Lambdaparameter: 149
body: 103
95Lambdaparameter: 149
body: 104
96Lambdaparameter: 149
body: 105
97Lambdaparameter: 149
body: 106
98Lambdaparameter: 149
body: 107
99Lambdaparameter: 149
body: 108
100Lambdaparameter: 149
body: 110
101Literal
102Operationoperator: 169
operands: 111
103Operationoperator: 135
operands: 112
104Operationoperator: 119
operands: 113
105Operationoperator: 119
operands: 114
106Operationoperator: 115
operands: 116
107Operationoperator: 136
operands: 117
108Operationoperator: 119
operands: 118
109ExprTuple149
110Operationoperator: 119
operands: 120
111ExprTuple175, 121, 122, 172
112NamedExprsstate: 123
113NamedExprselement: 124
targets: 132
114NamedExprselement: 125
targets: 126
115Literal
116NamedExprsbasis: 127
117NamedExprsoperation: 128
118NamedExprselement: 129
targets: 130
119Literal
120NamedExprselement: 131
targets: 132
121Literal
122Literal
123Operationoperator: 133
operand: 145
124Operationoperator: 135
operands: 142
125Operationoperator: 136
operands: 137
126Operationoperator: 143
operands: 138
127Literal
128Literal
129Operationoperator: 141
operands: 139
130Operationoperator: 143
operands: 140
131Operationoperator: 141
operands: 142
132Operationoperator: 143
operands: 144
133Literal
134ExprTuple145
135Literal
136Literal
137NamedExprsoperation: 146
part: 149
138ExprTuple161, 151
139NamedExprsstate: 147
part: 149
140ExprTuple161, 176
141Literal
142NamedExprsstate: 148
part: 149
143Literal
144ExprTuple150, 151
145Literal
146Operationoperator: 152
operands: 153
147Operationoperator: 154
operands: 155
148Variable
149Variable
150Operationoperator: 157
operands: 156
151Operationoperator: 157
operands: 158
152Literal
153ExprTuple159, 176
154Literal
155ExprTuple160, 176
156ExprTuple176, 161
157Literal
158ExprTuple176, 162
159Variable
160Operationoperator: 163
operands: 164
161Literal
162Variable
163Literal
164ExprTuple165, 171
165Operationoperator: 166
operand: 168
166Literal
167ExprTuple168
168Operationoperator: 169
operands: 170
169Literal
170ExprTuple171, 172
171Operationoperator: 173
operands: 174
172Variable
173Literal
174ExprTuple175, 176
175Literal
176Variable