logo

Expression of type QcircuitEquiv

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.linear_algebra import ScalarMult, TensorProd, VecAdd
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _ket_u, _phase, _psi_t_ket, _s
from proveit.physics.quantum.circuits import 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 = Add(Neg(t), one)
sub_expr5 = TensorProd(_psi_t_ket, _ket_u)
sub_expr6 = Interval(one, sub_expr3)
expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))), sub_expr4, zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(sub_expr2, sub_expr3)), one, _s).with_wrapping_at(2,6)])), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr5, part = Add(sub_expr1, t)), targets = sub_expr6), sub_expr4, zero), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr5, part = sub_expr1), targets = sub_expr6), sub_expr2, sub_expr3).with_wrapping_at(2,6)])))
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())
\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 1} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
& \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 2} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
& \qout{\vdots} \\
& \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{0} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
& \qout{\lvert u \rangle}
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multiqout{1}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \qout{\vdots} \qwx[1] \\
& \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~0 + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} \qwx[1] \\
& \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}}
} \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
8ExprTuple10, 11
9ExprTuple12, 13
10ExprRangelambda_map: 14
start_index: 17
end_index: 72
11ExprRangelambda_map: 15
start_index: 83
end_index: 64
12ExprRangelambda_map: 16
start_index: 17
end_index: 72
13ExprRangelambda_map: 18
start_index: 46
end_index: 49
14Lambdaparameter: 96
body: 19
15Lambdaparameter: 96
body: 20
16Lambdaparameter: 96
body: 21
17Operationoperator: 57
operands: 22
18Lambdaparameter: 96
body: 23
19Operationoperator: 40
operands: 24
20Operationoperator: 28
operands: 25
21Operationoperator: 28
operands: 26
22ExprTuple27, 83
23Operationoperator: 28
operands: 29
24NamedExprsstate: 30
25NamedExprselement: 31
targets: 32
26NamedExprselement: 33
targets: 35
27Operationoperator: 94
operand: 75
28Literal
29NamedExprselement: 34
targets: 35
30Operationoperator: 67
operands: 36
31Operationoperator: 40
operands: 37
32Operationoperator: 42
operands: 38
33Operationoperator: 40
operands: 39
34Operationoperator: 40
operands: 41
35Operationoperator: 42
operands: 43
36ExprTuple44, 45
37NamedExprsstate: 63
part: 96
38ExprTuple46, 49
39NamedExprsstate: 48
part: 47
40Literal
41NamedExprsstate: 48
part: 96
42Literal
43ExprTuple83, 49
44Operationoperator: 76
operands: 50
45Operationoperator: 51
operands: 52
46Operationoperator: 57
operands: 53
47Operationoperator: 57
operands: 54
48Operationoperator: 55
operands: 56
49Operationoperator: 57
operands: 58
50ExprTuple83, 59
51Literal
52ExprTuple60, 61
53ExprTuple75, 83
54ExprTuple96, 75
55Literal
56ExprTuple62, 63
57Literal
58ExprTuple75, 64
59Operationoperator: 90
operands: 65
60Operationoperator: 79
operand: 72
61Operationoperator: 67
operands: 68
62Operationoperator: 69
operand: 75
63Literal
64Literal
65ExprTuple92, 71
66ExprTuple72
67Literal
68ExprTuple73, 74
69Literal
70ExprTuple75
71Operationoperator: 76
operands: 77
72Literal
73Operationoperator: 90
operands: 78
74Operationoperator: 79
operand: 83
75Variable
76Literal
77ExprTuple83, 92
78ExprTuple81, 82
79Literal
80ExprTuple83
81Literal
82Operationoperator: 84
operands: 85
83Literal
84Literal
85ExprTuple92, 86, 87, 88, 89
86Literal
87Literal
88Operationoperator: 90
operands: 91
89Literal
90Literal
91ExprTuple92, 93
92Literal
93Operationoperator: 94
operand: 96
94Literal
95ExprTuple96
96Variable