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, s, t
from proveit.numbers import Add, Exp, Interval, Mod, Mult, Round, four, frac, one, pi, two
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(frac(four, Exp(pi, two)), 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)]))))
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(\frac{4}{\pi^{2}}, \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)\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: 3
operands: 4
2Operationoperator: 5
operand: 9
3Literal
4ExprTuple7, 8
5Literal
6ExprTuple9
7Literal
8Operationoperator: 100
operands: 10
9Operationoperator: 11
operands: 12
10ExprTuple13, 102
11Literal
12ExprTuple14, 15, 16, 17
13Literal
14ExprTuple18, 19
15ExprTuple20, 21
16ExprTuple22, 23
17ExprTuple24, 25
18ExprRangelambda_map: 26
start_index: 88
end_index: 103
19ExprRangelambda_map: 27
start_index: 88
end_index: 89
20ExprRangelambda_map: 28
start_index: 88
end_index: 103
21ExprRangelambda_map: 28
start_index: 77
end_index: 78
22ExprRangelambda_map: 29
start_index: 88
end_index: 103
23ExprRangelambda_map: 30
start_index: 88
end_index: 89
24ExprRangelambda_map: 31
start_index: 88
end_index: 103
25ExprRangelambda_map: 32
start_index: 88
end_index: 89
26Lambdaparameter: 76
body: 33
27Lambdaparameter: 76
body: 34
28Lambdaparameter: 76
body: 35
29Lambdaparameter: 76
body: 36
30Lambdaparameter: 76
body: 37
31Lambdaparameter: 76
body: 38
32Lambdaparameter: 76
body: 40
33Operationoperator: 62
operands: 41
34Operationoperator: 48
operands: 42
35Operationoperator: 48
operands: 43
36Operationoperator: 44
operands: 45
37Operationoperator: 63
operands: 46
38Operationoperator: 48
operands: 47
39ExprTuple76
40Operationoperator: 48
operands: 49
41NamedExprsstate: 50
42NamedExprselement: 51
targets: 59
43NamedExprselement: 52
targets: 53
44Literal
45NamedExprsbasis: 54
46NamedExprsoperation: 55
47NamedExprselement: 56
targets: 57
48Literal
49NamedExprselement: 58
targets: 59
50Operationoperator: 60
operand: 72
51Operationoperator: 62
operands: 69
52Operationoperator: 63
operands: 64
53Operationoperator: 70
operands: 65
54Literal
55Literal
56Operationoperator: 68
operands: 66
57Operationoperator: 70
operands: 67
58Operationoperator: 68
operands: 69
59Operationoperator: 70
operands: 71
60Literal
61ExprTuple72
62Literal
63Literal
64NamedExprsoperation: 73
part: 76
65ExprTuple88, 78
66NamedExprsstate: 74
part: 76
67ExprTuple88, 103
68Literal
69NamedExprsstate: 75
part: 76
70Literal
71ExprTuple77, 78
72Literal
73Operationoperator: 79
operands: 80
74Operationoperator: 81
operands: 82
75Variable
76Variable
77Operationoperator: 84
operands: 83
78Operationoperator: 84
operands: 85
79Literal
80ExprTuple86, 103
81Literal
82ExprTuple87, 103
83ExprTuple103, 88
84Literal
85ExprTuple103, 89
86Variable
87Operationoperator: 90
operands: 91
88Literal
89Variable
90Literal
91ExprTuple92, 98
92Operationoperator: 93
operand: 95
93Literal
94ExprTuple95
95Operationoperator: 96
operands: 97
96Literal
97ExprTuple98, 99
98Operationoperator: 100
operands: 101
99Variable
100Literal
101ExprTuple102, 103
102Literal
103Variable