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 And, Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, Mult, NaturalPos, Real, e, i, one, pi, subtract, 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 = Mult(two_pow_t, phase)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = ExprTuple(Lambda([s, t], 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 = Equals(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_expr6, one, t), ExprRange(sub_expr1, sub_expr6, 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(sub_expr5, 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)]))), one), domain = Real, conditions = [InSet(sub_expr5, Interval(zero, subtract(two_pow_t, 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(\left(s, t\right) \mapsto \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}~|~\left(2^{t} \cdot \varphi\right) \in \{0~\ldotp \ldotp~2^{t} - 1\}, \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = 1\right)\end{array}\right]\end{array}\right]\end{array} \textrm{ if } s \in \mathbb{N}^+ ,  t \in \mathbb{N}^+\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
1Lambdaparameters: 2
body: 3
2ExprTuple162, 170
3Conditionalvalue: 4
condition: 5
4Operationoperator: 27
operand: 8
5Operationoperator: 42
operands: 7
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameter: 159
body: 12
9Operationoperator: 57
operands: 13
10Operationoperator: 57
operands: 14
11ExprTuple159
12Conditionalvalue: 15
condition: 16
13ExprTuple162, 17
14ExprTuple170, 17
15Operationoperator: 27
operand: 20
16Operationoperator: 57
operands: 19
17Literal
18ExprTuple20
19ExprTuple159, 21
20Lambdaparameter: 148
body: 22
21Operationoperator: 23
operand: 53
22Conditionalvalue: 25
condition: 26
23Literal
24ExprTuple53
25Operationoperator: 27
operand: 30
26Operationoperator: 42
operands: 29
27Literal
28ExprTuple30
29ExprTuple31, 32
30Lambdaparameter: 166
body: 34
31Operationoperator: 57
operands: 35
32Operationoperator: 59
operands: 36
33ExprTuple166
34Conditionalvalue: 37
condition: 38
35ExprTuple148, 39
36ExprTuple40, 161
37Operationoperator: 59
operands: 41
38Operationoperator: 42
operands: 43
39Operationoperator: 44
operands: 45
40Operationoperator: 46
operand: 148
41ExprTuple48, 161
42Literal
43ExprTuple49, 50, 51
44Literal
45ExprTuple52, 53
46Literal
47ExprTuple148
48Operationoperator: 54
operand: 62
49Operationoperator: 57
operands: 56
50Operationoperator: 57
operands: 58
51Operationoperator: 59
operands: 60
52Literal
53Operationoperator: 167
operands: 61
54Literal
55ExprTuple62
56ExprTuple166, 63
57Literal
58ExprTuple160, 64
59Literal
60ExprTuple65, 66
61ExprTuple169, 162
62Operationoperator: 67
operands: 68
63Literal
64Operationoperator: 143
operands: 69
65Operationoperator: 70
operands: 71
66Operationoperator: 72
operands: 73
67Literal
68ExprTuple74, 75, 76, 77
69ExprTuple78, 79
70Literal
71ExprTuple159, 148
72Literal
73ExprTuple80, 148
74ExprTuple81, 82
75ExprTuple83, 84
76ExprTuple85, 86
77ExprTuple87, 88
78Literal
79Operationoperator: 157
operands: 89
80Operationoperator: 167
operands: 90
81ExprRangelambda_map: 91
start_index: 161
end_index: 170
82ExprRangelambda_map: 92
start_index: 161
end_index: 162
83ExprRangelambda_map: 93
start_index: 161
end_index: 170
84ExprRangelambda_map: 93
start_index: 150
end_index: 151
85ExprRangelambda_map: 94
start_index: 161
end_index: 170
86ExprRangelambda_map: 95
start_index: 161
end_index: 162
87ExprRangelambda_map: 96
start_index: 161
end_index: 170
88ExprRangelambda_map: 97
start_index: 161
end_index: 162
89ExprTuple165, 98
90ExprTuple99, 100
91Lambdaparameter: 149
body: 101
92Lambdaparameter: 149
body: 102
93Lambdaparameter: 149
body: 103
94Lambdaparameter: 149
body: 104
95Lambdaparameter: 149
body: 105
96Lambdaparameter: 149
body: 106
97Lambdaparameter: 149
body: 108
98Operationoperator: 109
operand: 161
99Literal
100Operationoperator: 163
operands: 111
101Operationoperator: 135
operands: 112
102Operationoperator: 119
operands: 113
103Operationoperator: 119
operands: 114
104Operationoperator: 115
operands: 116
105Operationoperator: 136
operands: 117
106Operationoperator: 119
operands: 118
107ExprTuple149
108Operationoperator: 119
operands: 120
109Literal
110ExprTuple161
111ExprTuple169, 121, 122, 166
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, 170
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, 170
154Literal
155ExprTuple160, 170
156ExprTuple170, 161
157Literal
158ExprTuple170, 162
159Variable
160Operationoperator: 163
operands: 164
161Literal
162Variable
163Literal
164ExprTuple165, 166
165Operationoperator: 167
operands: 168
166Variable
167Literal
168ExprTuple169, 170
169Literal
170Variable