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 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, QcircuitEquiv
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Interval(one, _t)
sub_expr3 = Add(_t, one)
sub_expr4 = Add(_t, _s)
sub_expr5 = Interval(sub_expr3, sub_expr4)
sub_expr6 = MultiQubitElem(element = Input(state = TensorProd(_psi__t_ket, _ket_u), part = sub_expr1), targets = Interval(one, sub_expr4))
sub_expr7 = [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_expr5), one, _s)]
sub_expr8 = [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)]
sub_expr9 = [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_expr5), one, _s)]
sub_expr10 = [ExprRange(sub_expr1, sub_expr6, one, _t).with_wrapping_at(2,6), ExprRange(sub_expr1, sub_expr6, sub_expr3, sub_expr4).with_wrapping_at(2,6)]
expr = Implies(QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray(sub_expr7)), Qcircuit(vert_expr_array = VertExprArray(sub_expr10))), QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray(sub_expr7, sub_expr8, sub_expr9)), Qcircuit(vert_expr_array = VertExprArray(sub_expr10, sub_expr8, sub_expr9))).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{
\qin{\lvert \psi_{t} \rangle} & { /^{t} } \qw \\
\qin{\lvert u \rangle} & { /^{s} } \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{1}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} & { /^{t} } \qw \\
\ghostqin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} & { /^{s} } \qw
} \end{array}\right)\right) \Rightarrow  \\ \left(\begin{array}{c} \begin{array}{l} \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) \\  \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{1}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} & \gate{{\mathrm {FT}}^{\dag}_{t}} & \qout{\lvert \Psi \rangle} \\
\ghostqin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} & { /^{s} } \qw & \qout{\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: 18
10Operationoperator: 15
operands: 14
11Operationoperator: 15
operands: 16
12ExprTuple17
13ExprTuple18
14ExprTuple17, 19, 20
15Literal
16ExprTuple18, 19, 20
17ExprTuple21, 22
18ExprTuple23, 24
19ExprTuple25, 26
20ExprTuple27, 28
21ExprRangelambda_map: 29
start_index: 88
end_index: 92
22ExprRangelambda_map: 30
start_index: 88
end_index: 89
23ExprRangelambda_map: 31
start_index: 88
end_index: 92
24ExprRangelambda_map: 31
start_index: 78
end_index: 79
25ExprRangelambda_map: 32
start_index: 88
end_index: 92
26ExprRangelambda_map: 33
start_index: 88
end_index: 89
27ExprRangelambda_map: 34
start_index: 88
end_index: 92
28ExprRangelambda_map: 35
start_index: 88
end_index: 89
29Lambdaparameter: 77
body: 36
30Lambdaparameter: 77
body: 37
31Lambdaparameter: 77
body: 38
32Lambdaparameter: 77
body: 39
33Lambdaparameter: 77
body: 40
34Lambdaparameter: 77
body: 41
35Lambdaparameter: 77
body: 43
36Operationoperator: 50
operands: 44
37Operationoperator: 50
operands: 45
38Operationoperator: 50
operands: 46
39Operationoperator: 50
operands: 47
40Operationoperator: 66
operands: 48
41Operationoperator: 50
operands: 49
42ExprTuple77
43Operationoperator: 50
operands: 51
44NamedExprselement: 52
targets: 59
45NamedExprselement: 53
targets: 61
46NamedExprselement: 54
targets: 55
47NamedExprselement: 56
targets: 59
48NamedExprsoperation: 57
49NamedExprselement: 58
targets: 59
50Literal
51NamedExprselement: 60
targets: 61
52Operationoperator: 63
operands: 62
53Operationoperator: 63
operands: 71
54Operationoperator: 63
operands: 64
55Operationoperator: 72
operands: 65
56Operationoperator: 66
operands: 67
57Literal
58Operationoperator: 70
operands: 68
59Operationoperator: 72
operands: 69
60Operationoperator: 70
operands: 71
61Operationoperator: 72
operands: 73
62NamedExprsstate: 86
part: 77
63Literal
64NamedExprsstate: 74
part: 77
65ExprTuple88, 79
66Literal
67NamedExprsoperation: 75
part: 77
68NamedExprsstate: 76
part: 77
69ExprTuple88, 92
70Literal
71NamedExprsstate: 87
part: 77
72Literal
73ExprTuple78, 79
74Operationoperator: 80
operands: 81
75Operationoperator: 82
operand: 92
76Literal
77Variable
78Operationoperator: 84
operands: 83
79Operationoperator: 84
operands: 85
80Literal
81ExprTuple86, 87
82Literal
83ExprTuple92, 88
84Literal
85ExprTuple92, 89
86Operationoperator: 90
operand: 92
87Literal
88Literal
89Literal
90Literal
91ExprTuple92
92Literal