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, Variable, VertExprArray, m
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import NumKet, Z
from proveit.physics.quantum.QPE import _Psi_ket, _alpha_m_sqrd, _ket_u, _s, _s_wire, _t
from proveit.physics.quantum.circuits import 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 = Interval(one, _t)
sub_expr3 = Interval(Add(_t, one), Add(_t, _s))
expr = ExprTuple(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _Psi_ket, part = sub_expr1), targets = sub_expr2), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr3), one, _s)], [ExprRange(sub_expr1, Measure(basis = Z), one, _t), _s_wire], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, _t), part = sub_expr1), targets = sub_expr2), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr3), one, _s)]))), _alpha_m_sqrd)
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(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{3}{\lvert \Psi \rangle} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right), \left|\alpha_{m}\right|^{2}\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
operand: 7
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7
5Literal
6ExprTuple8, 9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operand: 17
9Literal
10Literal
11ExprTuple14, 15, 16
12Literal
13ExprTuple17
14ExprTuple18, 19
15ExprTuple20, 21
16ExprTuple22, 23
17Operationoperator: 24
operand: 75
18ExprRangelambda_map: 26
start_index: 76
end_index: 77
19ExprRangelambda_map: 27
start_index: 76
end_index: 78
20ExprRangelambda_map: 28
start_index: 76
end_index: 77
21ExprRangelambda_map: 29
start_index: 76
end_index: 78
22ExprRangelambda_map: 30
start_index: 76
end_index: 77
23ExprRangelambda_map: 31
start_index: 76
end_index: 78
24Literal
25ExprTuple75
26Lambdaparameter: 67
body: 32
27Lambdaparameter: 67
body: 33
28Lambdaparameter: 67
body: 34
29Lambdaparameter: 67
body: 35
30Lambdaparameter: 67
body: 36
31Lambdaparameter: 67
body: 38
32Operationoperator: 46
operands: 39
33Operationoperator: 46
operands: 40
34Operationoperator: 41
operands: 42
35Operationoperator: 43
operands: 44
36Operationoperator: 46
operands: 45
37ExprTuple67
38Operationoperator: 46
operands: 47
39NamedExprselement: 48
targets: 53
40NamedExprselement: 49
targets: 55
41Literal
42NamedExprsbasis: 50
43Literal
44NamedExprsoperation: 51
45NamedExprselement: 52
targets: 53
46Literal
47NamedExprselement: 54
targets: 55
48Operationoperator: 57
operands: 56
49Operationoperator: 57
operands: 61
50Literal
51Literal
52Operationoperator: 60
operands: 58
53Operationoperator: 62
operands: 59
54Operationoperator: 60
operands: 61
55Operationoperator: 62
operands: 63
56NamedExprsstate: 64
part: 67
57Literal
58NamedExprsstate: 65
part: 67
59ExprTuple76, 77
60Literal
61NamedExprsstate: 66
part: 67
62Literal
63ExprTuple68, 69
64Literal
65Operationoperator: 70
operands: 71
66Literal
67Variable
68Operationoperator: 73
operands: 72
69Operationoperator: 73
operands: 74
70Literal
71ExprTuple75, 77
72ExprTuple77, 76
73Literal
74ExprTuple77, 78
75Variable
76Literal
77Literal
78Literal