logo

Expression of type Implies

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 Implies
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE, _Psi_circuit, _Psi_ket, _U, _ket_u, _s, _t
from proveit.physics.quantum.circuits import Gate, Input, MultiQubitElem, Output, Qcircuit, QcircuitEquiv
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 = Interval(one, sub_expr3)
sub_expr6 = MultiQubitElem(element = Output(state = TensorProd(_Psi_ket, _ket_u), part = sub_expr1), targets = sub_expr5)
sub_expr7 = MultiQubitElem(element = Gate(operation = QPE(_U, _t), part = sub_expr1), targets = sub_expr5)
sub_expr8 = [ExprRange(sub_expr1, sub_expr6, one, _t).with_wrapping_at(2,6), ExprRange(sub_expr1, sub_expr6, sub_expr2, sub_expr3).with_wrapping_at(2,6)]
expr = Implies(QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_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)])), Qcircuit(vert_expr_array = VertExprArray(sub_expr8))), QcircuitEquiv(_Psi_circuit, 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_expr7, one, _t), ExprRange(sub_expr1, sub_expr7, sub_expr2, sub_expr3)], sub_expr8))).with_wrapping_at(1)).with_wrapping_at(2)
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())
\begin{array}{c} \begin{array}{l} \left(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qout{\lvert \Psi \rangle} \\
& \qout{\lvert u \rangle}
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multiqout{1}{\lvert \Psi \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\lvert \Psi \rangle {\otimes} \lvert u \rangle}
} \end{array}\right)\right) \Rightarrow  \\ \left(\begin{array}{c} \begin{array}{l} \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \multiqout{3}{\lvert \Psi \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \ghostqout{\lvert \Psi \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \ghostqout{\lvert \Psi \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \ghostqout{\lvert \Psi \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \qout{\lvert u \rangle}
} \end{array}\right) \\  \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \multiqout{4}{\lvert \Psi \rangle {\otimes} \lvert u \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \ghostqout{\lvert \Psi \rangle {\otimes} \lvert u \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \ghostqout{\lvert \Psi \rangle {\otimes} \lvert u \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \ghostqout{\lvert \Psi \rangle {\otimes} \lvert u \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \ghostqout{\lvert \Psi \rangle {\otimes} \lvert u \rangle}
} \end{array}\right) \end{array} \end{array}\right) \end{array} \end{array}
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.()(2)('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
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple8, 9
6Literal
7ExprTuple10, 11
8Operationoperator: 15
operand: 17
9Operationoperator: 15
operand: 20
10Operationoperator: 15
operands: 14
11Operationoperator: 15
operands: 16
12ExprTuple17
13ExprTuple20
14ExprTuple18, 19, 17
15Literal
16ExprTuple18, 19, 20
17ExprTuple21, 22
18ExprTuple23, 24
19ExprTuple25, 26
20ExprTuple27, 28
21ExprRangelambda_map: 29
start_index: 84
end_index: 88
22ExprRangelambda_map: 30
start_index: 84
end_index: 89
23ExprRangelambda_map: 31
start_index: 84
end_index: 88
24ExprRangelambda_map: 32
start_index: 84
end_index: 89
25ExprRangelambda_map: 33
start_index: 84
end_index: 88
26ExprRangelambda_map: 33
start_index: 72
end_index: 76
27ExprRangelambda_map: 34
start_index: 84
end_index: 88
28ExprRangelambda_map: 34
start_index: 72
end_index: 76
29Lambdaparameter: 75
body: 35
30Lambdaparameter: 75
body: 36
31Lambdaparameter: 75
body: 37
32Lambdaparameter: 75
body: 38
33Lambdaparameter: 75
body: 39
34Lambdaparameter: 75
body: 41
35Operationoperator: 47
operands: 42
36Operationoperator: 47
operands: 43
37Operationoperator: 62
operands: 44
38Operationoperator: 47
operands: 45
39Operationoperator: 47
operands: 46
40ExprTuple75
41Operationoperator: 47
operands: 48
42NamedExprselement: 49
targets: 50
43NamedExprselement: 51
targets: 54
44NamedExprsstate: 52
45NamedExprselement: 53
targets: 54
46NamedExprselement: 55
targets: 57
47Literal
48NamedExprselement: 56
targets: 57
49Operationoperator: 67
operands: 58
50Operationoperator: 69
operands: 59
51Operationoperator: 67
operands: 63
52Operationoperator: 60
operand: 71
53Operationoperator: 62
operands: 63
54Operationoperator: 69
operands: 64
55Operationoperator: 65
operands: 66
56Operationoperator: 67
operands: 68
57Operationoperator: 69
operands: 70
58NamedExprsstate: 86
part: 75
59ExprTuple84, 88
60Literal
61ExprTuple71
62Literal
63NamedExprsstate: 87
part: 75
64ExprTuple72, 76
65Literal
66NamedExprsoperation: 73
part: 75
67Literal
68NamedExprsstate: 74
part: 75
69Literal
70ExprTuple84, 76
71Literal
72Operationoperator: 82
operands: 77
73Operationoperator: 78
operands: 79
74Operationoperator: 80
operands: 81
75Variable
76Operationoperator: 82
operands: 83
77ExprTuple88, 84
78Literal
79ExprTuple85, 88
80Literal
81ExprTuple86, 87
82Literal
83ExprTuple88, 89
84Literal
85Literal
86Literal
87Literal
88Literal
89Literal