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