logo

Expression of type ExprTuple

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, ExprTuple, Lambda, 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 = ExprTuple(Lambda(U, 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(U \mapsto \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..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 150
body: 3
2ExprTuple150
3Conditionalvalue: 4
condition: 5
4Operationoperator: 15
operand: 8
5Operationoperator: 49
operands: 7
6ExprTuple8
7ExprTuple150, 9
8Lambdaparameter: 139
body: 10
9Operationoperator: 11
operand: 43
10Conditionalvalue: 13
condition: 14
11Literal
12ExprTuple43
13Operationoperator: 15
operand: 18
14Operationoperator: 31
operands: 17
15Literal
16ExprTuple18
17ExprTuple19, 20
18Lambdaparameter: 163
body: 22
19Operationoperator: 49
operands: 23
20Operationoperator: 51
operands: 24
21ExprTuple163
22Conditionalvalue: 25
condition: 26
23ExprTuple139, 27
24ExprTuple28, 152
25Operationoperator: 29
operands: 30
26Operationoperator: 31
operands: 32
27Operationoperator: 33
operands: 34
28Operationoperator: 35
operand: 139
29Literal
30ExprTuple37, 38
31Literal
32ExprTuple39, 40, 41
33Literal
34ExprTuple42, 43
35Literal
36ExprTuple139
37Operationoperator: 44
operands: 45
38Operationoperator: 46
operand: 56
39Operationoperator: 49
operands: 48
40Operationoperator: 49
operands: 50
41Operationoperator: 51
operands: 52
42Literal
43Operationoperator: 164
operands: 53
44Literal
45ExprTuple54, 55
46Literal
47ExprTuple56
48ExprTuple163, 57
49Literal
50ExprTuple163, 58
51Literal
52ExprTuple59, 60
53ExprTuple166, 153
54Literal
55Operationoperator: 164
operands: 61
56Operationoperator: 62
operands: 63
57Literal
58Operationoperator: 64
operands: 65
59Operationoperator: 66
operands: 67
60Operationoperator: 68
operands: 69
61ExprTuple112, 166
62Literal
63ExprTuple70, 71, 72, 73
64Literal
65ExprTuple74, 152
66Literal
67ExprTuple150, 139
68Literal
69ExprTuple75, 139
70ExprTuple76, 77
71ExprTuple78, 79
72ExprTuple80, 81
73ExprTuple82, 83
74Literal
75Operationoperator: 164
operands: 84
76ExprRangelambda_map: 85
start_index: 152
end_index: 167
77ExprRangelambda_map: 86
start_index: 152
end_index: 153
78ExprRangelambda_map: 87
start_index: 152
end_index: 167
79ExprRangelambda_map: 87
start_index: 141
end_index: 142
80ExprRangelambda_map: 88
start_index: 152
end_index: 167
81ExprRangelambda_map: 89
start_index: 152
end_index: 153
82ExprRangelambda_map: 90
start_index: 152
end_index: 167
83ExprRangelambda_map: 91
start_index: 152
end_index: 153
84ExprTuple92, 93
85Lambdaparameter: 140
body: 94
86Lambdaparameter: 140
body: 95
87Lambdaparameter: 140
body: 96
88Lambdaparameter: 140
body: 97
89Lambdaparameter: 140
body: 98
90Lambdaparameter: 140
body: 99
91Lambdaparameter: 140
body: 101
92Literal
93Operationoperator: 160
operands: 102
94Operationoperator: 126
operands: 103
95Operationoperator: 110
operands: 104
96Operationoperator: 110
operands: 105
97Operationoperator: 106
operands: 107
98Operationoperator: 127
operands: 108
99Operationoperator: 110
operands: 109
100ExprTuple140
101Operationoperator: 110
operands: 111
102ExprTuple166, 112, 113, 163
103NamedExprsstate: 114
104NamedExprselement: 115
targets: 123
105NamedExprselement: 116
targets: 117
106Literal
107NamedExprsbasis: 118
108NamedExprsoperation: 119
109NamedExprselement: 120
targets: 121
110Literal
111NamedExprselement: 122
targets: 123
112Literal
113Literal
114Operationoperator: 124
operand: 136
115Operationoperator: 126
operands: 133
116Operationoperator: 127
operands: 128
117Operationoperator: 134
operands: 129
118Literal
119Literal
120Operationoperator: 132
operands: 130
121Operationoperator: 134
operands: 131
122Operationoperator: 132
operands: 133
123Operationoperator: 134
operands: 135
124Literal
125ExprTuple136
126Literal
127Literal
128NamedExprsoperation: 137
part: 140
129ExprTuple152, 142
130NamedExprsstate: 138
part: 140
131ExprTuple152, 167
132Literal
133NamedExprsstate: 139
part: 140
134Literal
135ExprTuple141, 142
136Literal
137Operationoperator: 143
operands: 144
138Operationoperator: 145
operands: 146
139Variable
140Variable
141Operationoperator: 148
operands: 147
142Operationoperator: 148
operands: 149
143Literal
144ExprTuple150, 167
145Literal
146ExprTuple151, 167
147ExprTuple167, 152
148Literal
149ExprTuple167, 153
150Variable
151Operationoperator: 154
operands: 155
152Literal
153Variable
154Literal
155ExprTuple156, 162
156Operationoperator: 157
operand: 159
157Literal
158ExprTuple159
159Operationoperator: 160
operands: 161
160Literal
161ExprTuple162, 163
162Operationoperator: 164
operands: 165
163Variable
164Literal
165ExprTuple166, 167
166Literal
167Variable