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, 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, _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}")
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(Add(t, one), Add(t, _s))), one, _s).with_wrapping_at(2,6)])), Qcircuit(vert_expr_array = VertExprArray(Variable("_b", latex_format = r"{_{-}b}"))))
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{
& \gate{\begin{array}{c} \uparrow \\{_{-}b} \\ \downarrow\end{array}} & \qw
} \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
9Variable
10ExprRangelambda_map: 12
start_index: 13
end_index: 52
11ExprRangelambda_map: 14
start_index: 62
end_index: 46
12Lambdaparameter: 75
body: 15
13Operationoperator: 40
operands: 16
14Lambdaparameter: 75
body: 17
15Operationoperator: 27
operands: 18
16ExprTuple19, 62
17Operationoperator: 20
operands: 21
18NamedExprsstate: 22
19Operationoperator: 73
operand: 45
20Literal
21NamedExprselement: 24
targets: 25
22Operationoperator: 49
operands: 26
23ExprTuple45
24Operationoperator: 27
operands: 28
25Operationoperator: 29
operands: 30
26ExprTuple31, 32
27Literal
28NamedExprsstate: 33
part: 75
29Literal
30ExprTuple34, 35
31Operationoperator: 55
operands: 36
32Operationoperator: 37
operands: 38
33Literal
34Operationoperator: 40
operands: 39
35Operationoperator: 40
operands: 41
36ExprTuple62, 42
37Literal
38ExprTuple43, 44
39ExprTuple45, 62
40Literal
41ExprTuple45, 46
42Operationoperator: 69
operands: 47
43Operationoperator: 58
operand: 52
44Operationoperator: 49
operands: 50
45Variable
46Literal
47ExprTuple71, 51
48ExprTuple52
49Literal
50ExprTuple53, 54
51Operationoperator: 55
operands: 56
52Literal
53Operationoperator: 69
operands: 57
54Operationoperator: 58
operand: 62
55Literal
56ExprTuple62, 71
57ExprTuple60, 61
58Literal
59ExprTuple62
60Literal
61Operationoperator: 63
operands: 64
62Literal
63Literal
64ExprTuple71, 65, 66, 67, 68
65Literal
66Literal
67Operationoperator: 69
operands: 70
68Literal
69Literal
70ExprTuple71, 72
71Literal
72Operationoperator: 73
operand: 75
73Literal
74ExprTuple75
75Variable