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 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 = Conditional(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(), InSet(U, Unitary(two_pow_s)))
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^{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} \textrm{ if } U \in \textrm{U}\left(2^{s}\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: 46
operands: 4
3ExprTuple5
4ExprTuple147, 6
5Lambdaparameter: 136
body: 7
6Operationoperator: 8
operand: 40
7Conditionalvalue: 10
condition: 11
8Literal
9ExprTuple40
10Operationoperator: 12
operand: 15
11Operationoperator: 28
operands: 14
12Literal
13ExprTuple15
14ExprTuple16, 17
15Lambdaparameter: 160
body: 19
16Operationoperator: 46
operands: 20
17Operationoperator: 48
operands: 21
18ExprTuple160
19Conditionalvalue: 22
condition: 23
20ExprTuple136, 24
21ExprTuple25, 149
22Operationoperator: 26
operands: 27
23Operationoperator: 28
operands: 29
24Operationoperator: 30
operands: 31
25Operationoperator: 32
operand: 136
26Literal
27ExprTuple34, 35
28Literal
29ExprTuple36, 37, 38
30Literal
31ExprTuple39, 40
32Literal
33ExprTuple136
34Operationoperator: 41
operands: 42
35Operationoperator: 43
operand: 53
36Operationoperator: 46
operands: 45
37Operationoperator: 46
operands: 47
38Operationoperator: 48
operands: 49
39Literal
40Operationoperator: 161
operands: 50
41Literal
42ExprTuple51, 52
43Literal
44ExprTuple53
45ExprTuple160, 54
46Literal
47ExprTuple160, 55
48Literal
49ExprTuple56, 57
50ExprTuple163, 150
51Literal
52Operationoperator: 161
operands: 58
53Operationoperator: 59
operands: 60
54Literal
55Operationoperator: 61
operands: 62
56Operationoperator: 63
operands: 64
57Operationoperator: 65
operands: 66
58ExprTuple109, 163
59Literal
60ExprTuple67, 68, 69, 70
61Literal
62ExprTuple71, 149
63Literal
64ExprTuple147, 136
65Literal
66ExprTuple72, 136
67ExprTuple73, 74
68ExprTuple75, 76
69ExprTuple77, 78
70ExprTuple79, 80
71Literal
72Operationoperator: 161
operands: 81
73ExprRangelambda_map: 82
start_index: 149
end_index: 164
74ExprRangelambda_map: 83
start_index: 149
end_index: 150
75ExprRangelambda_map: 84
start_index: 149
end_index: 164
76ExprRangelambda_map: 84
start_index: 138
end_index: 139
77ExprRangelambda_map: 85
start_index: 149
end_index: 164
78ExprRangelambda_map: 86
start_index: 149
end_index: 150
79ExprRangelambda_map: 87
start_index: 149
end_index: 164
80ExprRangelambda_map: 88
start_index: 149
end_index: 150
81ExprTuple89, 90
82Lambdaparameter: 137
body: 91
83Lambdaparameter: 137
body: 92
84Lambdaparameter: 137
body: 93
85Lambdaparameter: 137
body: 94
86Lambdaparameter: 137
body: 95
87Lambdaparameter: 137
body: 96
88Lambdaparameter: 137
body: 98
89Literal
90Operationoperator: 157
operands: 99
91Operationoperator: 123
operands: 100
92Operationoperator: 107
operands: 101
93Operationoperator: 107
operands: 102
94Operationoperator: 103
operands: 104
95Operationoperator: 124
operands: 105
96Operationoperator: 107
operands: 106
97ExprTuple137
98Operationoperator: 107
operands: 108
99ExprTuple163, 109, 110, 160
100NamedExprsstate: 111
101NamedExprselement: 112
targets: 120
102NamedExprselement: 113
targets: 114
103Literal
104NamedExprsbasis: 115
105NamedExprsoperation: 116
106NamedExprselement: 117
targets: 118
107Literal
108NamedExprselement: 119
targets: 120
109Literal
110Literal
111Operationoperator: 121
operand: 133
112Operationoperator: 123
operands: 130
113Operationoperator: 124
operands: 125
114Operationoperator: 131
operands: 126
115Literal
116Literal
117Operationoperator: 129
operands: 127
118Operationoperator: 131
operands: 128
119Operationoperator: 129
operands: 130
120Operationoperator: 131
operands: 132
121Literal
122ExprTuple133
123Literal
124Literal
125NamedExprsoperation: 134
part: 137
126ExprTuple149, 139
127NamedExprsstate: 135
part: 137
128ExprTuple149, 164
129Literal
130NamedExprsstate: 136
part: 137
131Literal
132ExprTuple138, 139
133Literal
134Operationoperator: 140
operands: 141
135Operationoperator: 142
operands: 143
136Variable
137Variable
138Operationoperator: 145
operands: 144
139Operationoperator: 145
operands: 146
140Literal
141ExprTuple147, 164
142Literal
143ExprTuple148, 164
144ExprTuple164, 149
145Literal
146ExprTuple164, 150
147Variable
148Operationoperator: 151
operands: 152
149Literal
150Variable
151Literal
152ExprTuple153, 159
153Operationoperator: 154
operand: 156
154Literal
155ExprTuple156
156Operationoperator: 157
operands: 158
157Literal
158ExprTuple159, 160
159Operationoperator: 161
operands: 162
160Variable
161Literal
162ExprTuple163, 164
163Literal
164Variable