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 = Add(_t, _s)
sub_expr3 = Interval(one, _t)
sub_expr4 = Interval(Add(_t, one), sub_expr2)
sub_expr5 = [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(_t), part = sub_expr1), targets = sub_expr3), one, _t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, _s)]
sub_expr6 = [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_ket, part = sub_expr1), targets = sub_expr3), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)]
expr = Equals(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = TensorProd(_psi__t_ket, _ket_u), part = sub_expr1), targets = Interval(one, sub_expr2)), one, sub_expr2)], sub_expr5, sub_expr6))), Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _psi__t_ket, part = sub_expr1), targets = sub_expr3), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)], sub_expr5, sub_expr6))))
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(QCIRCUIT\left(VertExprArray\left(\begin{array}{c} \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + s~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}\right),  \\ \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{{\mathrm {FT}}^{\dag}_{t}~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{{\mathrm {FT}}^{\dag}_{t}~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{{\mathrm {FT}}^{\dag}_{t}~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t\}} & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, ..\left(s - 3\right) \times.., \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}\right),  \\ \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \Psi \rangle~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \Psi \rangle~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \Psi \rangle~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array}\right) \end{array}\right)\right)\right) = \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)
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
14ExprTuple18, 19
15ExprTuple20, 21
16ExprTuple22, 23
17ExprRangelambda_map: 24
start_index: 83
end_index: 74
18ExprRangelambda_map: 25
start_index: 83
end_index: 87
19ExprRangelambda_map: 26
start_index: 83
end_index: 84
20ExprRangelambda_map: 27
start_index: 83
end_index: 87
21ExprRangelambda_map: 28
start_index: 83
end_index: 84
22ExprRangelambda_map: 29
start_index: 83
end_index: 87
23ExprRangelambda_map: 30
start_index: 83
end_index: 84
24Lambdaparameter: 72
body: 31
25Lambdaparameter: 72
body: 32
26Lambdaparameter: 72
body: 33
27Lambdaparameter: 72
body: 34
28Lambdaparameter: 72
body: 35
29Lambdaparameter: 72
body: 36
30Lambdaparameter: 72
body: 38
31Operationoperator: 45
operands: 39
32Operationoperator: 45
operands: 40
33Operationoperator: 45
operands: 41
34Operationoperator: 45
operands: 42
35Operationoperator: 61
operands: 43
36Operationoperator: 45
operands: 44
37ExprTuple72
38Operationoperator: 45
operands: 46
39NamedExprselement: 47
targets: 48
40NamedExprselement: 49
targets: 54
41NamedExprselement: 50
targets: 56
42NamedExprselement: 51
targets: 54
43NamedExprsoperation: 52
44NamedExprselement: 53
targets: 54
45Literal
46NamedExprselement: 55
targets: 56
47Operationoperator: 60
operands: 57
48Operationoperator: 67
operands: 58
49Operationoperator: 60
operands: 59
50Operationoperator: 60
operands: 66
51Operationoperator: 61
operands: 62
52Literal
53Operationoperator: 65
operands: 63
54Operationoperator: 67
operands: 64
55Operationoperator: 65
operands: 66
56Operationoperator: 67
operands: 68
57NamedExprsstate: 69
part: 72
58ExprTuple83, 74
59NamedExprsstate: 81
part: 72
60Literal
61Literal
62NamedExprsoperation: 70
part: 72
63NamedExprsstate: 71
part: 72
64ExprTuple83, 87
65Literal
66NamedExprsstate: 82
part: 72
67Literal
68ExprTuple73, 74
69Operationoperator: 75
operands: 76
70Operationoperator: 77
operand: 87
71Literal
72Variable
73Operationoperator: 79
operands: 78
74Operationoperator: 79
operands: 80
75Literal
76ExprTuple81, 82
77Literal
78ExprTuple87, 83
79Literal
80ExprTuple87, 84
81Operationoperator: 85
operand: 87
82Literal
83Literal
84Literal
85Literal
86ExprTuple87
87Literal