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, ket_plus
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import QPE1, _Psi_ket, _U, _ket_u, _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 = Add(_t, one)
sub_expr3 = Add(_t, _s)
sub_expr4 = Interval(one, _t)
sub_expr5 = Interval(sub_expr2, sub_expr3)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE1(_U, _t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Equals(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr5), one, _s)], [ExprRange(sub_expr1, sub_expr6, one, _t), ExprRange(sub_expr1, sub_expr6, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(_t), part = sub_expr1), targets = sub_expr4), one, _t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, _s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_ket, part = sub_expr1), targets = sub_expr4), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr5), one, _s)]))), one)
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 + \rangle} & \multigate{4}{\textrm{QPE}_1\left(U, t\right)} & \multigate{3}{{\mathrm {FT}}^{\dag}_{t}} & \multiqout{3}{\lvert \Psi \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghost{{\mathrm {FT}}^{\dag}_{t}} & \ghostqout{\lvert \Psi \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghost{{\mathrm {FT}}^{\dag}_{t}} & \ghostqout{\lvert \Psi \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghost{{\mathrm {FT}}^{\dag}_{t}} & \ghostqout{\lvert \Psi \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = 1
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, 83
3Operationoperator: 4
operand: 6
4Literal
5ExprTuple6
6Operationoperator: 7
operands: 8
7Literal
8ExprTuple9, 10, 11, 12
9ExprTuple13, 14
10ExprTuple15, 16
11ExprTuple17, 18
12ExprTuple19, 20
13ExprRangelambda_map: 21
start_index: 83
end_index: 84
14ExprRangelambda_map: 22
start_index: 83
end_index: 85
15ExprRangelambda_map: 23
start_index: 83
end_index: 84
16ExprRangelambda_map: 23
start_index: 73
end_index: 74
17ExprRangelambda_map: 24
start_index: 83
end_index: 84
18ExprRangelambda_map: 25
start_index: 83
end_index: 85
19ExprRangelambda_map: 26
start_index: 83
end_index: 84
20ExprRangelambda_map: 27
start_index: 83
end_index: 85
21Lambdaparameter: 72
body: 28
22Lambdaparameter: 72
body: 29
23Lambdaparameter: 72
body: 30
24Lambdaparameter: 72
body: 31
25Lambdaparameter: 72
body: 32
26Lambdaparameter: 72
body: 33
27Lambdaparameter: 72
body: 35
28Operationoperator: 56
operands: 36
29Operationoperator: 42
operands: 37
30Operationoperator: 42
operands: 38
31Operationoperator: 42
operands: 39
32Operationoperator: 59
operands: 40
33Operationoperator: 42
operands: 41
34ExprTuple72
35Operationoperator: 42
operands: 43
36NamedExprsstate: 44
37NamedExprselement: 45
targets: 53
38NamedExprselement: 46
targets: 47
39NamedExprselement: 48
targets: 51
40NamedExprsoperation: 49
41NamedExprselement: 50
targets: 51
42Literal
43NamedExprselement: 52
targets: 53
44Operationoperator: 54
operand: 67
45Operationoperator: 56
operands: 64
46Operationoperator: 59
operands: 57
47Operationoperator: 65
operands: 58
48Operationoperator: 59
operands: 60
49Literal
50Operationoperator: 63
operands: 61
51Operationoperator: 65
operands: 62
52Operationoperator: 63
operands: 64
53Operationoperator: 65
operands: 66
54Literal
55ExprTuple67
56Literal
57NamedExprsoperation: 68
part: 72
58ExprTuple83, 74
59Literal
60NamedExprsoperation: 69
part: 72
61NamedExprsstate: 70
part: 72
62ExprTuple83, 84
63Literal
64NamedExprsstate: 71
part: 72
65Literal
66ExprTuple73, 74
67Literal
68Operationoperator: 75
operands: 76
69Operationoperator: 77
operand: 84
70Literal
71Literal
72Variable
73Operationoperator: 80
operands: 79
74Operationoperator: 80
operands: 81
75Literal
76ExprTuple82, 84
77Literal
78ExprTuple84
79ExprTuple84, 83
80Literal
81ExprTuple84, 85
82Literal
83Literal
84Literal
85Literal