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 ExprRange, ExprTuple, U, Variable, VertExprArray, eps, m, n, s, t
from proveit.numbers import Add, Exp, Interval, LessEq, ModAbs, Neg, frac, one, subtract, 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 ProbOfAll
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(subtract(one, eps), ProbOfAll(instance_param_or_params = [m], instance_element = 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(m, 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)])), domain = Interval(zero, subtract(two_pow_t, one)), condition = LessEq(ModAbs(subtract(frac(m, two_pow_t), phase), one), Exp(two, Neg(n)))).with_wrapping())
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(1 - \epsilon, \begin{array}{l}\textrm{Prob}_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}~|~\left|\frac{m}{2^{t}} - \varphi\right|_{\textup{mod}\thinspace 1} \leq 2^{-n}}~\\
\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \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 m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right)\end{array}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Operationoperator: 117
operands: 3
2Operationoperator: 4
operand: 7
3ExprTuple123, 6
4Literal
5ExprTuple7
6Operationoperator: 110
operand: 11
7Lambdaparameter: 122
body: 10
8ExprTuple11
9ExprTuple122
10Conditionalvalue: 12
condition: 13
11Variable
12Operationoperator: 14
operands: 15
13Operationoperator: 16
operands: 17
14Literal
15ExprTuple18, 19, 20, 21
16Literal
17ExprTuple22, 23
18ExprTuple24, 25
19ExprTuple26, 27
20ExprTuple28, 29
21ExprTuple30, 31
22Operationoperator: 32
operands: 33
23Operationoperator: 34
operands: 35
24ExprRangelambda_map: 36
start_index: 123
end_index: 128
25ExprRangelambda_map: 37
start_index: 123
end_index: 124
26ExprRangelambda_map: 38
start_index: 123
end_index: 128
27ExprRangelambda_map: 38
start_index: 105
end_index: 106
28ExprRangelambda_map: 39
start_index: 123
end_index: 128
29ExprRangelambda_map: 40
start_index: 123
end_index: 124
30ExprRangelambda_map: 41
start_index: 123
end_index: 128
31ExprRangelambda_map: 42
start_index: 123
end_index: 124
32Literal
33ExprTuple122, 43
34Literal
35ExprTuple44, 45
36Lambdaparameter: 104
body: 46
37Lambdaparameter: 104
body: 47
38Lambdaparameter: 104
body: 48
39Lambdaparameter: 104
body: 49
40Lambdaparameter: 104
body: 50
41Lambdaparameter: 104
body: 51
42Lambdaparameter: 104
body: 53
43Operationoperator: 94
operands: 54
44Operationoperator: 55
operands: 56
45Operationoperator: 125
operands: 57
46Operationoperator: 86
operands: 58
47Operationoperator: 65
operands: 59
48Operationoperator: 65
operands: 60
49Operationoperator: 61
operands: 62
50Operationoperator: 87
operands: 63
51Operationoperator: 65
operands: 64
52ExprTuple104
53Operationoperator: 65
operands: 66
54ExprTuple67, 68
55Literal
56ExprTuple69, 123
57ExprTuple127, 70
58NamedExprsstate: 71
59NamedExprselement: 72
targets: 80
60NamedExprselement: 73
targets: 74
61Literal
62NamedExprsbasis: 75
63NamedExprsoperation: 76
64NamedExprselement: 77
targets: 78
65Literal
66NamedExprselement: 79
targets: 80
67Literal
68Operationoperator: 117
operands: 81
69Operationoperator: 117
operands: 82
70Operationoperator: 110
operand: 99
71Operationoperator: 84
operand: 100
72Operationoperator: 86
operands: 93
73Operationoperator: 87
operands: 88
74Operationoperator: 94
operands: 89
75Literal
76Literal
77Operationoperator: 92
operands: 90
78Operationoperator: 94
operands: 91
79Operationoperator: 92
operands: 93
80Operationoperator: 94
operands: 95
81ExprTuple119, 96
82ExprTuple97, 98
83ExprTuple99
84Literal
85ExprTuple100
86Literal
87Literal
88NamedExprsoperation: 101
part: 104
89ExprTuple123, 106
90NamedExprsstate: 102
part: 104
91ExprTuple123, 128
92Literal
93NamedExprsstate: 103
part: 104
94Literal
95ExprTuple105, 106
96Operationoperator: 110
operand: 123
97Operationoperator: 108
operands: 109
98Operationoperator: 110
operand: 120
99Variable
100Literal
101Operationoperator: 112
operands: 113
102Operationoperator: 114
operands: 115
103Variable
104Variable
105Operationoperator: 117
operands: 116
106Operationoperator: 117
operands: 118
107ExprTuple123
108Literal
109ExprTuple122, 119
110Literal
111ExprTuple120
112Literal
113ExprTuple121, 128
114Literal
115ExprTuple122, 128
116ExprTuple128, 123
117Literal
118ExprTuple128, 124
119Operationoperator: 125
operands: 126
120Variable
121Variable
122Variable
123Literal
124Variable
125Literal
126ExprTuple127, 128
127Literal
128Variable