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 = Neg(t)
sub_expr3 = Add(t, one)
sub_expr4 = Add(t, _s)
sub_expr5 = TensorProd(_psi_t_ket, _ket_u)
sub_expr6 = Interval(one, sub_expr4)
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(sub_expr2, one), zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(sub_expr3, sub_expr4)), one, _s).with_wrapping_at(2,6)])), Qcircuit(vert_expr_array = VertExprArray([MultiQubitElem(element = Output(state = sub_expr5, part = one), targets = sub_expr6), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr5, part = Add(sub_expr1, t)), targets = sub_expr6), Add(sub_expr2, two), zero), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr5, part = sub_expr1), targets = sub_expr6), sub_expr3, sub_expr4).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{2}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\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, 14
10ExprRangelambda_map: 15
start_index: 16
end_index: 78
11ExprRangelambda_map: 17
start_index: 89
end_index: 70
12Operationoperator: 34
operands: 18
13ExprRangelambda_map: 19
start_index: 20
end_index: 78
14ExprRangelambda_map: 21
start_index: 52
end_index: 55
15Lambdaparameter: 102
body: 22
16Operationoperator: 63
operands: 23
17Lambdaparameter: 102
body: 24
18NamedExprselement: 25
targets: 41
19Lambdaparameter: 102
body: 26
20Operationoperator: 63
operands: 27
21Lambdaparameter: 102
body: 28
22Operationoperator: 46
operands: 29
23ExprTuple33, 89
24Operationoperator: 34
operands: 30
25Operationoperator: 46
operands: 31
26Operationoperator: 34
operands: 32
27ExprTuple33, 98
28Operationoperator: 34
operands: 35
29NamedExprsstate: 36
30NamedExprselement: 37
targets: 38
31NamedExprsstate: 54
part: 89
32NamedExprselement: 39
targets: 41
33Operationoperator: 100
operand: 81
34Literal
35NamedExprselement: 40
targets: 41
36Operationoperator: 73
operands: 42
37Operationoperator: 46
operands: 43
38Operationoperator: 48
operands: 44
39Operationoperator: 46
operands: 45
40Operationoperator: 46
operands: 47
41Operationoperator: 48
operands: 49
42ExprTuple50, 51
43NamedExprsstate: 69
part: 102
44ExprTuple52, 55
45NamedExprsstate: 54
part: 53
46Literal
47NamedExprsstate: 54
part: 102
48Literal
49ExprTuple89, 55
50Operationoperator: 82
operands: 56
51Operationoperator: 57
operands: 58
52Operationoperator: 63
operands: 59
53Operationoperator: 63
operands: 60
54Operationoperator: 61
operands: 62
55Operationoperator: 63
operands: 64
56ExprTuple89, 65
57Literal
58ExprTuple66, 67
59ExprTuple81, 89
60ExprTuple102, 81
61Literal
62ExprTuple68, 69
63Literal
64ExprTuple81, 70
65Operationoperator: 96
operands: 71
66Operationoperator: 85
operand: 78
67Operationoperator: 73
operands: 74
68Operationoperator: 75
operand: 81
69Literal
70Literal
71ExprTuple98, 77
72ExprTuple78
73Literal
74ExprTuple79, 80
75Literal
76ExprTuple81
77Operationoperator: 82
operands: 83
78Literal
79Operationoperator: 96
operands: 84
80Operationoperator: 85
operand: 89
81Variable
82Literal
83ExprTuple89, 98
84ExprTuple87, 88
85Literal
86ExprTuple89
87Literal
88Operationoperator: 90
operands: 91
89Literal
90Literal
91ExprTuple98, 92, 93, 94, 95
92Literal
93Literal
94Operationoperator: 96
operands: 97
95Literal
96Literal
97ExprTuple98, 99
98Literal
99Operationoperator: 100
operand: 102
100Literal
101ExprTuple102
102Variable