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, U, Variable, VertExprArray, s, t
from proveit.logic import Equals
from proveit.numbers import Add, Interval, Mult, one
from proveit.physics.quantum import I, NumKet, Z, ket_plus, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, 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))
expr = Equals(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_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), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(Mult(two_pow_t, phase), t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), 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}\left(U, t\right)} & \meter & \multiqout{3}{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\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: 92
14ExprRangelambda_map: 22
start_index: 83
end_index: 84
15ExprRangelambda_map: 23
start_index: 83
end_index: 92
16ExprRangelambda_map: 23
start_index: 72
end_index: 73
17ExprRangelambda_map: 24
start_index: 83
end_index: 92
18ExprRangelambda_map: 25
start_index: 83
end_index: 84
19ExprRangelambda_map: 26
start_index: 83
end_index: 92
20ExprRangelambda_map: 27
start_index: 83
end_index: 84
21Lambdaparameter: 71
body: 28
22Lambdaparameter: 71
body: 29
23Lambdaparameter: 71
body: 30
24Lambdaparameter: 71
body: 31
25Lambdaparameter: 71
body: 32
26Lambdaparameter: 71
body: 33
27Lambdaparameter: 71
body: 35
28Operationoperator: 57
operands: 36
29Operationoperator: 43
operands: 37
30Operationoperator: 43
operands: 38
31Operationoperator: 39
operands: 40
32Operationoperator: 58
operands: 41
33Operationoperator: 43
operands: 42
34ExprTuple71
35Operationoperator: 43
operands: 44
36NamedExprsstate: 45
37NamedExprselement: 46
targets: 54
38NamedExprselement: 47
targets: 48
39Literal
40NamedExprsbasis: 49
41NamedExprsoperation: 50
42NamedExprselement: 51
targets: 52
43Literal
44NamedExprselement: 53
targets: 54
45Operationoperator: 55
operand: 67
46Operationoperator: 57
operands: 64
47Operationoperator: 58
operands: 59
48Operationoperator: 65
operands: 60
49Literal
50Literal
51Operationoperator: 63
operands: 61
52Operationoperator: 65
operands: 62
53Operationoperator: 63
operands: 64
54Operationoperator: 65
operands: 66
55Literal
56ExprTuple67
57Literal
58Literal
59NamedExprsoperation: 68
part: 71
60ExprTuple83, 73
61NamedExprsstate: 69
part: 71
62ExprTuple83, 92
63Literal
64NamedExprsstate: 70
part: 71
65Literal
66ExprTuple72, 73
67Literal
68Operationoperator: 74
operands: 75
69Operationoperator: 76
operands: 77
70Variable
71Variable
72Operationoperator: 79
operands: 78
73Operationoperator: 79
operands: 80
74Literal
75ExprTuple81, 92
76Literal
77ExprTuple82, 92
78ExprTuple92, 83
79Literal
80ExprTuple92, 84
81Variable
82Operationoperator: 85
operands: 86
83Literal
84Variable
85Literal
86ExprTuple87, 88
87Operationoperator: 89
operands: 90
88Variable
89Literal
90ExprTuple91, 92
91Literal
92Variable