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))
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_expr3), one, _s)], [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)], [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_expr3), 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 \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) = 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, 69
3Operationoperator: 4
operand: 6
4Literal
5ExprTuple6
6Operationoperator: 7
operands: 8
7Literal
8ExprTuple9, 10, 11
9ExprTuple12, 13
10ExprTuple14, 15
11ExprTuple16, 17
12ExprRangelambda_map: 18
start_index: 69
end_index: 70
13ExprRangelambda_map: 19
start_index: 69
end_index: 71
14ExprRangelambda_map: 20
start_index: 69
end_index: 70
15ExprRangelambda_map: 21
start_index: 69
end_index: 71
16ExprRangelambda_map: 22
start_index: 69
end_index: 70
17ExprRangelambda_map: 23
start_index: 69
end_index: 71
18Lambdaparameter: 60
body: 24
19Lambdaparameter: 60
body: 25
20Lambdaparameter: 60
body: 26
21Lambdaparameter: 60
body: 27
22Lambdaparameter: 60
body: 28
23Lambdaparameter: 60
body: 30
24Operationoperator: 36
operands: 31
25Operationoperator: 36
operands: 32
26Operationoperator: 36
operands: 33
27Operationoperator: 48
operands: 34
28Operationoperator: 36
operands: 35
29ExprTuple60
30Operationoperator: 36
operands: 37
31NamedExprselement: 38
targets: 43
32NamedExprselement: 39
targets: 45
33NamedExprselement: 40
targets: 43
34NamedExprsoperation: 41
35NamedExprselement: 42
targets: 43
36Literal
37NamedExprselement: 44
targets: 45
38Operationoperator: 47
operands: 46
39Operationoperator: 47
operands: 53
40Operationoperator: 48
operands: 49
41Literal
42Operationoperator: 52
operands: 50
43Operationoperator: 54
operands: 51
44Operationoperator: 52
operands: 53
45Operationoperator: 54
operands: 55
46NamedExprsstate: 56
part: 60
47Literal
48Literal
49NamedExprsoperation: 57
part: 60
50NamedExprsstate: 58
part: 60
51ExprTuple69, 70
52Literal
53NamedExprsstate: 59
part: 60
54Literal
55ExprTuple61, 62
56Operationoperator: 63
operand: 70
57Operationoperator: 64
operand: 70
58Literal
59Literal
60Variable
61Operationoperator: 67
operands: 66
62Operationoperator: 67
operands: 68
63Literal
64Literal
65ExprTuple70
66ExprTuple70, 69
67Literal
68ExprTuple70, 71
69Literal
70Literal
71Literal