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, t
from proveit.logic import Equals
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE1, _U, _ket_u, _psi_t_ket, _s
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(sub_expr2, sub_expr3)
sub_expr5 = 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_expr4), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _psi_t_ket, 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)]))), 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)} & \multiqout{3}{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \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, 70
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: 70
end_index: 71
13ExprRangelambda_map: 19
start_index: 70
end_index: 72
14ExprRangelambda_map: 20
start_index: 70
end_index: 71
15ExprRangelambda_map: 20
start_index: 60
end_index: 61
16ExprRangelambda_map: 21
start_index: 70
end_index: 71
17ExprRangelambda_map: 22
start_index: 70
end_index: 72
18Lambdaparameter: 59
body: 23
19Lambdaparameter: 59
body: 24
20Lambdaparameter: 59
body: 25
21Lambdaparameter: 59
body: 26
22Lambdaparameter: 59
body: 28
23Operationoperator: 45
operands: 29
24Operationoperator: 33
operands: 30
25Operationoperator: 33
operands: 31
26Operationoperator: 33
operands: 32
27ExprTuple59
28Operationoperator: 33
operands: 34
29NamedExprsstate: 35
30NamedExprselement: 36
targets: 42
31NamedExprselement: 37
targets: 38
32NamedExprselement: 39
targets: 40
33Literal
34NamedExprselement: 41
targets: 42
35Operationoperator: 43
operand: 55
36Operationoperator: 45
operands: 52
37Operationoperator: 46
operands: 47
38Operationoperator: 53
operands: 48
39Operationoperator: 51
operands: 49
40Operationoperator: 53
operands: 50
41Operationoperator: 51
operands: 52
42Operationoperator: 53
operands: 54
43Literal
44ExprTuple55
45Literal
46Literal
47NamedExprsoperation: 56
part: 59
48ExprTuple70, 61
49NamedExprsstate: 57
part: 59
50ExprTuple70, 71
51Literal
52NamedExprsstate: 58
part: 59
53Literal
54ExprTuple60, 61
55Literal
56Operationoperator: 62
operands: 63
57Operationoperator: 64
operand: 71
58Literal
59Variable
60Operationoperator: 67
operands: 66
61Operationoperator: 67
operands: 68
62Literal
63ExprTuple69, 71
64Literal
65ExprTuple71
66ExprTuple71, 70
67Literal
68ExprTuple71, 72
69Literal
70Literal
71Variable
72Literal