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
from proveit.logic import And, 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_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(var_ket_u, Conditional(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(), And(InSet(var_ket_u, s_ket_domain), normalized_var_ket_u))))
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(\lvert u \rangle \mapsto \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} \textrm{ if } \lvert u \rangle \in \mathbb{C}^{2^{s}} ,  \left \|\lvert u \rangle\right \| = 1\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: 129
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 21
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameter: 153
body: 12
9Operationoperator: 39
operands: 13
10Operationoperator: 41
operands: 14
11ExprTuple153
12Conditionalvalue: 15
condition: 16
13ExprTuple129, 17
14ExprTuple18, 142
15Operationoperator: 19
operands: 20
16Operationoperator: 21
operands: 22
17Operationoperator: 23
operands: 24
18Operationoperator: 25
operand: 129
19Literal
20ExprTuple27, 28
21Literal
22ExprTuple29, 30, 31
23Literal
24ExprTuple32, 33
25Literal
26ExprTuple129
27Operationoperator: 34
operands: 35
28Operationoperator: 36
operand: 46
29Operationoperator: 39
operands: 38
30Operationoperator: 39
operands: 40
31Operationoperator: 41
operands: 42
32Literal
33Operationoperator: 154
operands: 43
34Literal
35ExprTuple44, 45
36Literal
37ExprTuple46
38ExprTuple153, 47
39Literal
40ExprTuple153, 48
41Literal
42ExprTuple49, 50
43ExprTuple156, 143
44Literal
45Operationoperator: 154
operands: 51
46Operationoperator: 52
operands: 53
47Literal
48Operationoperator: 54
operands: 55
49Operationoperator: 56
operands: 57
50Operationoperator: 58
operands: 59
51ExprTuple102, 156
52Literal
53ExprTuple60, 61, 62, 63
54Literal
55ExprTuple64, 142
56Literal
57ExprTuple140, 129
58Literal
59ExprTuple65, 129
60ExprTuple66, 67
61ExprTuple68, 69
62ExprTuple70, 71
63ExprTuple72, 73
64Literal
65Operationoperator: 154
operands: 74
66ExprRangelambda_map: 75
start_index: 142
end_index: 157
67ExprRangelambda_map: 76
start_index: 142
end_index: 143
68ExprRangelambda_map: 77
start_index: 142
end_index: 157
69ExprRangelambda_map: 77
start_index: 131
end_index: 132
70ExprRangelambda_map: 78
start_index: 142
end_index: 157
71ExprRangelambda_map: 79
start_index: 142
end_index: 143
72ExprRangelambda_map: 80
start_index: 142
end_index: 157
73ExprRangelambda_map: 81
start_index: 142
end_index: 143
74ExprTuple82, 83
75Lambdaparameter: 130
body: 84
76Lambdaparameter: 130
body: 85
77Lambdaparameter: 130
body: 86
78Lambdaparameter: 130
body: 87
79Lambdaparameter: 130
body: 88
80Lambdaparameter: 130
body: 89
81Lambdaparameter: 130
body: 91
82Literal
83Operationoperator: 150
operands: 92
84Operationoperator: 116
operands: 93
85Operationoperator: 100
operands: 94
86Operationoperator: 100
operands: 95
87Operationoperator: 96
operands: 97
88Operationoperator: 117
operands: 98
89Operationoperator: 100
operands: 99
90ExprTuple130
91Operationoperator: 100
operands: 101
92ExprTuple156, 102, 103, 153
93NamedExprsstate: 104
94NamedExprselement: 105
targets: 113
95NamedExprselement: 106
targets: 107
96Literal
97NamedExprsbasis: 108
98NamedExprsoperation: 109
99NamedExprselement: 110
targets: 111
100Literal
101NamedExprselement: 112
targets: 113
102Literal
103Literal
104Operationoperator: 114
operand: 126
105Operationoperator: 116
operands: 123
106Operationoperator: 117
operands: 118
107Operationoperator: 124
operands: 119
108Literal
109Literal
110Operationoperator: 122
operands: 120
111Operationoperator: 124
operands: 121
112Operationoperator: 122
operands: 123
113Operationoperator: 124
operands: 125
114Literal
115ExprTuple126
116Literal
117Literal
118NamedExprsoperation: 127
part: 130
119ExprTuple142, 132
120NamedExprsstate: 128
part: 130
121ExprTuple142, 157
122Literal
123NamedExprsstate: 129
part: 130
124Literal
125ExprTuple131, 132
126Literal
127Operationoperator: 133
operands: 134
128Operationoperator: 135
operands: 136
129Variable
130Variable
131Operationoperator: 138
operands: 137
132Operationoperator: 138
operands: 139
133Literal
134ExprTuple140, 157
135Literal
136ExprTuple141, 157
137ExprTuple157, 142
138Literal
139ExprTuple157, 143
140Variable
141Operationoperator: 144
operands: 145
142Literal
143Variable
144Literal
145ExprTuple146, 152
146Operationoperator: 147
operand: 149
147Literal
148ExprTuple149
149Operationoperator: 150
operands: 151
150Literal
151ExprTuple152, 153
152Operationoperator: 154
operands: 155
153Variable
154Literal
155ExprTuple156, 157
156Literal
157Variable