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
from proveit.logic import Equals
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import I
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import _Psi_ket, _ket_u, _psi__t_ket, _s, _t
from proveit.physics.quantum.circuits import Gate, Input, 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))
sub_expr4 = ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_ket, part = sub_expr1), targets = sub_expr2), one, _t)
sub_expr5 = ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _psi__t_ket, part = sub_expr1), targets = sub_expr2), one, _t)
sub_expr6 = ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(_t), part = sub_expr1), targets = sub_expr2), one, _t)
expr = Equals(Prob(Qcircuit(vert_expr_array = VertExprArray([sub_expr5], [sub_expr6], [sub_expr4]))), Prob(Qcircuit(vert_expr_array = VertExprArray([sub_expr5, ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr3), one, _s)], [sub_expr6, ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, _s)], [sub_expr4, ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr3), one, _s)])))).with_wrapping_at(2)
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())
\begin{array}{c} \begin{array}{l} \textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi_{t} \rangle} & \gate{{\mathrm {FT}}^{\dag}_{t}} & \qout{\lvert \Psi \rangle}
} \end{array}\right) =  \\ \textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi_{t} \rangle} & \gate{{\mathrm {FT}}^{\dag}_{t}} & \qout{\lvert \Psi \rangle} \\
\qin{\lvert u \rangle} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) \end{array} \end{array}
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.()(2)('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: 6
operand: 8
4Operationoperator: 6
operand: 9
5ExprTuple8
6Literal
7ExprTuple9
8Operationoperator: 11
operands: 10
9Operationoperator: 11
operands: 12
10ExprTuple13, 14, 15
11Literal
12ExprTuple16, 17, 18
13ExprTuple19
14ExprTuple21
15ExprTuple23
16ExprTuple19, 20
17ExprTuple21, 22
18ExprTuple23, 24
19ExprRangelambda_map: 25
start_index: 76
end_index: 77
20ExprRangelambda_map: 26
start_index: 76
end_index: 78
21ExprRangelambda_map: 27
start_index: 76
end_index: 77
22ExprRangelambda_map: 28
start_index: 76
end_index: 78
23ExprRangelambda_map: 29
start_index: 76
end_index: 77
24ExprRangelambda_map: 30
start_index: 76
end_index: 78
25Lambdaparameter: 67
body: 31
26Lambdaparameter: 67
body: 32
27Lambdaparameter: 67
body: 33
28Lambdaparameter: 67
body: 34
29Lambdaparameter: 67
body: 35
30Lambdaparameter: 67
body: 37
31Operationoperator: 43
operands: 38
32Operationoperator: 43
operands: 39
33Operationoperator: 43
operands: 40
34Operationoperator: 55
operands: 41
35Operationoperator: 43
operands: 42
36ExprTuple67
37Operationoperator: 43
operands: 44
38NamedExprselement: 45
targets: 50
39NamedExprselement: 46
targets: 52
40NamedExprselement: 47
targets: 50
41NamedExprsoperation: 48
42NamedExprselement: 49
targets: 50
43Literal
44NamedExprselement: 51
targets: 52
45Operationoperator: 54
operands: 53
46Operationoperator: 54
operands: 60
47Operationoperator: 55
operands: 56
48Literal
49Operationoperator: 59
operands: 57
50Operationoperator: 61
operands: 58
51Operationoperator: 59
operands: 60
52Operationoperator: 61
operands: 62
53NamedExprsstate: 63
part: 67
54Literal
55Literal
56NamedExprsoperation: 64
part: 67
57NamedExprsstate: 65
part: 67
58ExprTuple76, 77
59Literal
60NamedExprsstate: 66
part: 67
61Literal
62ExprTuple68, 69
63Operationoperator: 70
operand: 77
64Operationoperator: 71
operand: 77
65Literal
66Literal
67Variable
68Operationoperator: 74
operands: 73
69Operationoperator: 74
operands: 75
70Literal
71Literal
72ExprTuple77
73ExprTuple77, 76
74Literal
75ExprTuple77, 78
76Literal
77Literal
78Literal