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 = MultiQubitElem(element = Output(state = TensorProd(_psi_t_ket, _ket_u), part = sub_expr1), targets = 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)))), Add(Neg(t), one), 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, sub_expr4, one, t), ExprRange(sub_expr1, sub_expr4, 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}
} \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: 15
end_index: 65
11ExprRangelambda_map: 16
start_index: 76
end_index: 57
12ExprRangelambda_map: 17
start_index: 76
end_index: 68
13ExprRangelambda_map: 17
start_index: 41
end_index: 43
14Lambdaparameter: 89
body: 18
15Operationoperator: 50
operands: 19
16Lambdaparameter: 89
body: 20
17Lambdaparameter: 89
body: 21
18Operationoperator: 35
operands: 22
19ExprTuple23, 76
20Operationoperator: 25
operands: 24
21Operationoperator: 25
operands: 26
22NamedExprsstate: 27
23Operationoperator: 87
operand: 68
24NamedExprselement: 28
targets: 29
25Literal
26NamedExprselement: 30
targets: 31
27Operationoperator: 60
operands: 32
28Operationoperator: 35
operands: 33
29Operationoperator: 37
operands: 34
30Operationoperator: 35
operands: 36
31Operationoperator: 37
operands: 38
32ExprTuple39, 40
33NamedExprsstate: 56
part: 89
34ExprTuple41, 43
35Literal
36NamedExprsstate: 42
part: 89
37Literal
38ExprTuple76, 43
39Operationoperator: 69
operands: 44
40Operationoperator: 45
operands: 46
41Operationoperator: 50
operands: 47
42Operationoperator: 48
operands: 49
43Operationoperator: 50
operands: 51
44ExprTuple76, 52
45Literal
46ExprTuple53, 54
47ExprTuple68, 76
48Literal
49ExprTuple55, 56
50Literal
51ExprTuple68, 57
52Operationoperator: 83
operands: 58
53Operationoperator: 72
operand: 65
54Operationoperator: 60
operands: 61
55Operationoperator: 62
operand: 68
56Literal
57Literal
58ExprTuple85, 64
59ExprTuple65
60Literal
61ExprTuple66, 67
62Literal
63ExprTuple68
64Operationoperator: 69
operands: 70
65Literal
66Operationoperator: 83
operands: 71
67Operationoperator: 72
operand: 76
68Variable
69Literal
70ExprTuple76, 85
71ExprTuple74, 75
72Literal
73ExprTuple76
74Literal
75Operationoperator: 77
operands: 78
76Literal
77Literal
78ExprTuple85, 79, 80, 81, 82
79Literal
80Literal
81Operationoperator: 83
operands: 84
82Literal
83Literal
84ExprTuple85, 86
85Literal
86Operationoperator: 87
operand: 89
87Literal
88ExprTuple89
89Variable