logo

Expression of type NamedExprs

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 IndexedVar, NamedExprs, Variable
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Exp, Mult, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import ket0, ket1, varphi
In [2]:
# build up the expression from sub-expressions
expr = NamedExprs(("state", ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, IndexedVar(varphi, Variable("_a", latex_format = r"{_{-}a}")))), ket1)))))
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}{l}
{\rm state}: \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{{_{-}a}}} \cdot \lvert 1 \rangle\right)\right)\right)\\
\end{array} \right\}

In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0NamedExprsstate: 1
1Operationoperator: 13
operands: 2
2ExprTuple3, 4
3Operationoperator: 19
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple27, 8
6Literal
7ExprTuple9, 10
8Operationoperator: 21
operands: 11
9Operationoperator: 23
operand: 16
10Operationoperator: 13
operands: 14
11ExprTuple30, 15
12ExprTuple16
13Literal
14ExprTuple17, 18
15Operationoperator: 19
operands: 20
16Literal
17Operationoperator: 21
operands: 22
18Operationoperator: 23
operand: 27
19Literal
20ExprTuple27, 30
21Literal
22ExprTuple25, 26
23Literal
24ExprTuple27
25Literal
26Operationoperator: 28
operands: 29
27Literal
28Literal
29ExprTuple30, 31, 32, 33
30Literal
31Literal
32Literal
33IndexedVarvariable: 34
index: 36
34Variable
35ExprTuple36
36Variable