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 Interval, one
from proveit.physics.quantum import NumKet, Z
from proveit.physics.quantum.QPE import _Psi_ket, _alpha_m_sqrd, _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)
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, Measure(basis = Z), one, _t)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, _t), part = sub_expr1), targets = sub_expr2), one, _t)]))), _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}}
} \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
17ExprTuple21
18ExprTuple22
19Operationoperator: 23
operand: 53
20ExprRangelambda_map: 25
start_index: 50
end_index: 54
21ExprRangelambda_map: 26
start_index: 50
end_index: 54
22ExprRangelambda_map: 27
start_index: 50
end_index: 54
23Literal
24ExprTuple53
25Lambdaparameter: 49
body: 28
26Lambdaparameter: 49
body: 29
27Lambdaparameter: 49
body: 31
28Operationoperator: 35
operands: 32
29Operationoperator: 33
operands: 34
30ExprTuple49
31Operationoperator: 35
operands: 36
32NamedExprselement: 37
targets: 40
33Literal
34NamedExprsbasis: 38
35Literal
36NamedExprselement: 39
targets: 40
37Operationoperator: 41
operands: 42
38Literal
39Operationoperator: 43
operands: 44
40Operationoperator: 45
operands: 46
41Literal
42NamedExprsstate: 47
part: 49
43Literal
44NamedExprsstate: 48
part: 49
45Literal
46ExprTuple50, 54
47Literal
48Operationoperator: 51
operands: 52
49Variable
50Literal
51Literal
52ExprTuple53, 54
53Variable
54Literal