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, Mult, 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(U, Conditional(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(), 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}~|~\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} \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: 147
body: 3
2ExprTuple147
3Conditionalvalue: 4
condition: 5
4Operationoperator: 15
operand: 8
5Operationoperator: 45
operands: 7
6ExprTuple8
7ExprTuple147, 9
8Lambdaparameter: 136
body: 10
9Operationoperator: 11
operand: 41
10Conditionalvalue: 13
condition: 14
11Literal
12ExprTuple41
13Operationoperator: 15
operand: 18
14Operationoperator: 30
operands: 17
15Literal
16ExprTuple18
17ExprTuple19, 20
18Lambdaparameter: 154
body: 22
19Operationoperator: 45
operands: 23
20Operationoperator: 47
operands: 24
21ExprTuple154
22Conditionalvalue: 25
condition: 26
23ExprTuple136, 27
24ExprTuple28, 149
25Operationoperator: 47
operands: 29
26Operationoperator: 30
operands: 31
27Operationoperator: 32
operands: 33
28Operationoperator: 34
operand: 136
29ExprTuple36, 149
30Literal
31ExprTuple37, 38, 39
32Literal
33ExprTuple40, 41
34Literal
35ExprTuple136
36Operationoperator: 42
operand: 50
37Operationoperator: 45
operands: 44
38Operationoperator: 45
operands: 46
39Operationoperator: 47
operands: 48
40Literal
41Operationoperator: 155
operands: 49
42Literal
43ExprTuple50
44ExprTuple154, 51
45Literal
46ExprTuple148, 52
47Literal
48ExprTuple53, 54
49ExprTuple157, 150
50Operationoperator: 55
operands: 56
51Literal
52Operationoperator: 131
operands: 57
53Operationoperator: 58
operands: 59
54Operationoperator: 60
operands: 61
55Literal
56ExprTuple62, 63, 64, 65
57ExprTuple66, 67
58Literal
59ExprTuple147, 136
60Literal
61ExprTuple68, 136
62ExprTuple69, 70
63ExprTuple71, 72
64ExprTuple73, 74
65ExprTuple75, 76
66Literal
67Operationoperator: 145
operands: 77
68Operationoperator: 155
operands: 78
69ExprRangelambda_map: 79
start_index: 149
end_index: 158
70ExprRangelambda_map: 80
start_index: 149
end_index: 150
71ExprRangelambda_map: 81
start_index: 149
end_index: 158
72ExprRangelambda_map: 81
start_index: 138
end_index: 139
73ExprRangelambda_map: 82
start_index: 149
end_index: 158
74ExprRangelambda_map: 83
start_index: 149
end_index: 150
75ExprRangelambda_map: 84
start_index: 149
end_index: 158
76ExprRangelambda_map: 85
start_index: 149
end_index: 150
77ExprTuple153, 86
78ExprTuple87, 88
79Lambdaparameter: 137
body: 89
80Lambdaparameter: 137
body: 90
81Lambdaparameter: 137
body: 91
82Lambdaparameter: 137
body: 92
83Lambdaparameter: 137
body: 93
84Lambdaparameter: 137
body: 94
85Lambdaparameter: 137
body: 96
86Operationoperator: 97
operand: 149
87Literal
88Operationoperator: 151
operands: 99
89Operationoperator: 123
operands: 100
90Operationoperator: 107
operands: 101
91Operationoperator: 107
operands: 102
92Operationoperator: 103
operands: 104
93Operationoperator: 124
operands: 105
94Operationoperator: 107
operands: 106
95ExprTuple137
96Operationoperator: 107
operands: 108
97Literal
98ExprTuple149
99ExprTuple157, 109, 110, 154
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, 158
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, 158
142Literal
143ExprTuple148, 158
144ExprTuple158, 149
145Literal
146ExprTuple158, 150
147Variable
148Operationoperator: 151
operands: 152
149Literal
150Variable
151Literal
152ExprTuple153, 154
153Operationoperator: 155
operands: 156
154Variable
155Literal
156ExprTuple157, 158
157Literal
158Variable