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 Abs, Add, Exp, Interval, Mod, Mult, Round, one, two
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import QPE, SubIndexed, _U, _alpha, _ket_u, _phase, _s, _s_wire, _t, _two_pow_t
from proveit.physics.quantum.circuits import Gate, 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 = Add(_t, one)
sub_expr3 = Add(_t, _s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(_U, _t), part = sub_expr1), targets = Interval(one, sub_expr3))
sub_expr6 = Mod(Round(Mult(_two_pow_t, _phase)), _two_pow_t)
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_expr4), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, _t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, _t), _s_wire], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(sub_expr6, _t), part = sub_expr1), targets = Interval(one, _t)), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)]))), Exp(Abs(SubIndexed(_alpha, [sub_expr6])), two))
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}\left(U, t\right)} & \meter & \multiqout{3}{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = \left|\alpha_{round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t}}\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: 8
4Operationoperator: 103
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 105
8Operationoperator: 10
operands: 11
9Operationoperator: 12
operand: 18
10Literal
11ExprTuple14, 15, 16, 17
12Literal
13ExprTuple18
14ExprTuple19, 20
15ExprTuple21, 22
16ExprTuple23, 24
17ExprTuple25, 26
18Operationoperator: 27
operand: 90
19ExprRangelambda_map: 29
start_index: 91
end_index: 106
20ExprRangelambda_map: 30
start_index: 91
end_index: 92
21ExprRangelambda_map: 31
start_index: 91
end_index: 106
22ExprRangelambda_map: 31
start_index: 80
end_index: 81
23ExprRangelambda_map: 32
start_index: 91
end_index: 106
24ExprRangelambda_map: 33
start_index: 91
end_index: 92
25ExprRangelambda_map: 34
start_index: 91
end_index: 106
26ExprRangelambda_map: 35
start_index: 91
end_index: 92
27Literal
28ExprTuple90
29Lambdaparameter: 79
body: 36
30Lambdaparameter: 79
body: 37
31Lambdaparameter: 79
body: 38
32Lambdaparameter: 79
body: 39
33Lambdaparameter: 79
body: 40
34Lambdaparameter: 79
body: 41
35Lambdaparameter: 79
body: 43
36Operationoperator: 65
operands: 44
37Operationoperator: 51
operands: 45
38Operationoperator: 51
operands: 46
39Operationoperator: 47
operands: 48
40Operationoperator: 66
operands: 49
41Operationoperator: 51
operands: 50
42ExprTuple79
43Operationoperator: 51
operands: 52
44NamedExprsstate: 53
45NamedExprselement: 54
targets: 62
46NamedExprselement: 55
targets: 56
47Literal
48NamedExprsbasis: 57
49NamedExprsoperation: 58
50NamedExprselement: 59
targets: 60
51Literal
52NamedExprselement: 61
targets: 62
53Operationoperator: 63
operand: 75
54Operationoperator: 65
operands: 72
55Operationoperator: 66
operands: 67
56Operationoperator: 73
operands: 68
57Literal
58Literal
59Operationoperator: 71
operands: 69
60Operationoperator: 73
operands: 70
61Operationoperator: 71
operands: 72
62Operationoperator: 73
operands: 74
63Literal
64ExprTuple75
65Literal
66Literal
67NamedExprsoperation: 76
part: 79
68ExprTuple91, 81
69NamedExprsstate: 77
part: 79
70ExprTuple91, 106
71Literal
72NamedExprsstate: 78
part: 79
73Literal
74ExprTuple80, 81
75Literal
76Operationoperator: 82
operands: 83
77Operationoperator: 84
operands: 85
78Literal
79Variable
80Operationoperator: 87
operands: 86
81Operationoperator: 87
operands: 88
82Literal
83ExprTuple89, 106
84Literal
85ExprTuple90, 106
86ExprTuple106, 91
87Literal
88ExprTuple106, 92
89Literal
90Operationoperator: 93
operands: 94
91Literal
92Literal
93Literal
94ExprTuple95, 101
95Operationoperator: 96
operand: 98
96Literal
97ExprTuple98
98Operationoperator: 99
operands: 100
99Literal
100ExprTuple101, 102
101Operationoperator: 103
operands: 104
102Literal
103Literal
104ExprTuple105, 106
105Literal
106Literal