logo

Expression of type ExprTuple

from the theory of proveit.physics.quantum.circuits

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, ExprTuple, Variable, m
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Interval, Mult, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import ket0, ket1, var_ket_u, varphi
from proveit.physics.quantum.circuits import MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = ExprTuple(Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, varphi)), ket1)))), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = Interval(two, Add(m, two))), one, Add(m, one)))
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 \varphi} \cdot \lvert 1 \rangle\right)\right)} 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~m + 1~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} 
} \end{array}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Operationoperator: 20
operands: 3
2ExprRangelambda_map: 4
start_index: 49
end_index: 5
3NamedExprsstate: 6
4Lambdaparameter: 28
body: 8
5Operationoperator: 34
operands: 9
6Operationoperator: 32
operands: 10
7ExprTuple28
8Operationoperator: 11
operands: 12
9ExprTuple40, 49
10ExprTuple13, 14
11Literal
12NamedExprselement: 15
targets: 16
13Operationoperator: 41
operands: 17
14Operationoperator: 18
operands: 19
15Operationoperator: 20
operands: 21
16Operationoperator: 22
operands: 23
17ExprTuple49, 24
18Literal
19ExprTuple25, 26
20Literal
21NamedExprsstate: 27
part: 28
22Literal
23ExprTuple52, 29
24Operationoperator: 43
operands: 30
25Operationoperator: 45
operand: 37
26Operationoperator: 32
operands: 33
27Variable
28Variable
29Operationoperator: 34
operands: 35
30ExprTuple52, 36
31ExprTuple37
32Literal
33ExprTuple38, 39
34Literal
35ExprTuple40, 52
36Operationoperator: 41
operands: 42
37Literal
38Operationoperator: 43
operands: 44
39Operationoperator: 45
operand: 49
40Variable
41Literal
42ExprTuple49, 52
43Literal
44ExprTuple47, 48
45Literal
46ExprTuple49
47Literal
48Operationoperator: 50
operands: 51
49Literal
50Literal
51ExprTuple52, 53, 54, 55
52Literal
53Literal
54Literal
55Variable