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, 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, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, 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(phase, Conditional(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))), And(InSet(phase, Real), InSet(phase, IntervalCO(zero, one)), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), 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(\varphi \mapsto \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}} \textrm{ if } \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)\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: 133
body: 3
2ExprTuple133
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operands: 7
5Operationoperator: 8
operands: 9
6Literal
7ExprTuple10, 11
8Literal
9ExprTuple12, 13, 14
10Operationoperator: 15
operands: 16
11Operationoperator: 17
operand: 26
12Operationoperator: 20
operands: 19
13Operationoperator: 20
operands: 21
14Operationoperator: 22
operands: 23
15Literal
16ExprTuple24, 25
17Literal
18ExprTuple26
19ExprTuple133, 27
20Literal
21ExprTuple133, 28
22Literal
23ExprTuple29, 30
24Literal
25Operationoperator: 134
operands: 31
26Operationoperator: 32
operands: 33
27Literal
28Operationoperator: 34
operands: 35
29Operationoperator: 36
operands: 37
30Operationoperator: 38
operands: 39
31ExprTuple82, 136
32Literal
33ExprTuple40, 41, 42, 43
34Literal
35ExprTuple44, 122
36Literal
37ExprTuple120, 109
38Literal
39ExprTuple45, 109
40ExprTuple46, 47
41ExprTuple48, 49
42ExprTuple50, 51
43ExprTuple52, 53
44Literal
45Operationoperator: 134
operands: 54
46ExprRangelambda_map: 55
start_index: 122
end_index: 137
47ExprRangelambda_map: 56
start_index: 122
end_index: 123
48ExprRangelambda_map: 57
start_index: 122
end_index: 137
49ExprRangelambda_map: 57
start_index: 111
end_index: 112
50ExprRangelambda_map: 58
start_index: 122
end_index: 137
51ExprRangelambda_map: 59
start_index: 122
end_index: 123
52ExprRangelambda_map: 60
start_index: 122
end_index: 137
53ExprRangelambda_map: 61
start_index: 122
end_index: 123
54ExprTuple62, 63
55Lambdaparameter: 110
body: 64
56Lambdaparameter: 110
body: 65
57Lambdaparameter: 110
body: 66
58Lambdaparameter: 110
body: 67
59Lambdaparameter: 110
body: 68
60Lambdaparameter: 110
body: 69
61Lambdaparameter: 110
body: 71
62Literal
63Operationoperator: 130
operands: 72
64Operationoperator: 96
operands: 73
65Operationoperator: 80
operands: 74
66Operationoperator: 80
operands: 75
67Operationoperator: 76
operands: 77
68Operationoperator: 97
operands: 78
69Operationoperator: 80
operands: 79
70ExprTuple110
71Operationoperator: 80
operands: 81
72ExprTuple136, 82, 83, 133
73NamedExprsstate: 84
74NamedExprselement: 85
targets: 93
75NamedExprselement: 86
targets: 87
76Literal
77NamedExprsbasis: 88
78NamedExprsoperation: 89
79NamedExprselement: 90
targets: 91
80Literal
81NamedExprselement: 92
targets: 93
82Literal
83Literal
84Operationoperator: 94
operand: 106
85Operationoperator: 96
operands: 103
86Operationoperator: 97
operands: 98
87Operationoperator: 104
operands: 99
88Literal
89Literal
90Operationoperator: 102
operands: 100
91Operationoperator: 104
operands: 101
92Operationoperator: 102
operands: 103
93Operationoperator: 104
operands: 105
94Literal
95ExprTuple106
96Literal
97Literal
98NamedExprsoperation: 107
part: 110
99ExprTuple122, 112
100NamedExprsstate: 108
part: 110
101ExprTuple122, 137
102Literal
103NamedExprsstate: 109
part: 110
104Literal
105ExprTuple111, 112
106Literal
107Operationoperator: 113
operands: 114
108Operationoperator: 115
operands: 116
109Variable
110Variable
111Operationoperator: 118
operands: 117
112Operationoperator: 118
operands: 119
113Literal
114ExprTuple120, 137
115Literal
116ExprTuple121, 137
117ExprTuple137, 122
118Literal
119ExprTuple137, 123
120Variable
121Operationoperator: 124
operands: 125
122Literal
123Variable
124Literal
125ExprTuple126, 132
126Operationoperator: 127
operand: 129
127Literal
128ExprTuple129
129Operationoperator: 130
operands: 131
130Literal
131ExprTuple132, 133
132Operationoperator: 134
operands: 135
133Variable
134Literal
135ExprTuple136, 137
136Literal
137Variable