logo

Expression of type Equals

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, Variable, VertExprArray, m
from proveit.logic import Equals
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 = Equals(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())
\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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 5
operand: 9
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9
7Literal
8ExprTuple10, 11
9Operationoperator: 12
operands: 13
10Operationoperator: 14
operand: 19
11Literal
12Literal
13ExprTuple16, 17, 18
14Literal
15ExprTuple19
16ExprTuple20, 21
17ExprTuple22, 23
18ExprTuple24, 25
19Operationoperator: 26
operand: 77
20ExprRangelambda_map: 28
start_index: 78
end_index: 79
21ExprRangelambda_map: 29
start_index: 78
end_index: 80
22ExprRangelambda_map: 30
start_index: 78
end_index: 79
23ExprRangelambda_map: 31
start_index: 78
end_index: 80
24ExprRangelambda_map: 32
start_index: 78
end_index: 79
25ExprRangelambda_map: 33
start_index: 78
end_index: 80
26Literal
27ExprTuple77
28Lambdaparameter: 69
body: 34
29Lambdaparameter: 69
body: 35
30Lambdaparameter: 69
body: 36
31Lambdaparameter: 69
body: 37
32Lambdaparameter: 69
body: 38
33Lambdaparameter: 69
body: 40
34Operationoperator: 48
operands: 41
35Operationoperator: 48
operands: 42
36Operationoperator: 43
operands: 44
37Operationoperator: 45
operands: 46
38Operationoperator: 48
operands: 47
39ExprTuple69
40Operationoperator: 48
operands: 49
41NamedExprselement: 50
targets: 55
42NamedExprselement: 51
targets: 57
43Literal
44NamedExprsbasis: 52
45Literal
46NamedExprsoperation: 53
47NamedExprselement: 54
targets: 55
48Literal
49NamedExprselement: 56
targets: 57
50Operationoperator: 59
operands: 58
51Operationoperator: 59
operands: 63
52Literal
53Literal
54Operationoperator: 62
operands: 60
55Operationoperator: 64
operands: 61
56Operationoperator: 62
operands: 63
57Operationoperator: 64
operands: 65
58NamedExprsstate: 66
part: 69
59Literal
60NamedExprsstate: 67
part: 69
61ExprTuple78, 79
62Literal
63NamedExprsstate: 68
part: 69
64Literal
65ExprTuple70, 71
66Literal
67Operationoperator: 72
operands: 73
68Literal
69Variable
70Operationoperator: 75
operands: 74
71Operationoperator: 75
operands: 76
72Literal
73ExprTuple77, 79
74ExprTuple79, 78
75Literal
76ExprTuple79, 80
77Variable
78Literal
79Literal
80Literal