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 TensorProd
from proveit.numbers import Add, Interval, Neg, one, two, zero
from proveit.physics.quantum.QPE import _ket_u, _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, _s)
sub_expr3 = TensorProd(_psi_t_ket, _ket_u)
sub_expr4 = Interval(one, sub_expr2)
expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray(Variable("_b", latex_format = r"{_{-}b}"))), Qcircuit(vert_expr_array = VertExprArray([MultiQubitElem(element = Output(state = sub_expr3, part = one), targets = sub_expr4), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr3, part = Add(sub_expr1, t)), targets = sub_expr4), Add(Neg(t), two), zero), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr3, part = sub_expr1), targets = sub_expr4), Add(t, one), sub_expr2).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{
& \gate{\begin{array}{c} \uparrow \\{_{-}b} \\ \downarrow\end{array}} & \qw
} \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
8Variable
9ExprTuple10, 11, 12
10Operationoperator: 29
operands: 13
11ExprRangelambda_map: 14
start_index: 15
end_index: 16
12ExprRangelambda_map: 17
start_index: 18
end_index: 43
13NamedExprselement: 19
targets: 34
14Lambdaparameter: 49
body: 20
15Operationoperator: 47
operands: 21
16Literal
17Lambdaparameter: 49
body: 23
18Operationoperator: 47
operands: 24
19Operationoperator: 36
operands: 25
20Operationoperator: 29
operands: 26
21ExprTuple27, 28
22ExprTuple49
23Operationoperator: 29
operands: 30
24ExprTuple55, 42
25NamedExprsstate: 41
part: 42
26NamedExprselement: 31
targets: 34
27Operationoperator: 32
operand: 55
28Literal
29Literal
30NamedExprselement: 33
targets: 34
31Operationoperator: 36
operands: 35
32Literal
33Operationoperator: 36
operands: 37
34Operationoperator: 38
operands: 39
35NamedExprsstate: 41
part: 40
36Literal
37NamedExprsstate: 41
part: 49
38Literal
39ExprTuple42, 43
40Operationoperator: 47
operands: 44
41Operationoperator: 45
operands: 46
42Literal
43Operationoperator: 47
operands: 48
44ExprTuple49, 55
45Literal
46ExprTuple50, 51
47Literal
48ExprTuple55, 52
49Variable
50Operationoperator: 53
operand: 55
51Literal
52Literal
53Literal
54ExprTuple55
55Variable