logo

Expression of type Lambda

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, Lambda, 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
from proveit.physics.quantum.circuits import Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = Lambda(sub_expr1, Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, IndexedVar(varphi, sub_expr1))), 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())
{_{-}a} \mapsto \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_{{_{-}a}}} \cdot \lvert 1 \rangle\right)\right)} 
} \end{array}
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 39
body: 1
1Operationoperator: 2
operands: 3
2Literal
3NamedExprsstate: 4
4Operationoperator: 16
operands: 5
5ExprTuple6, 7
6Operationoperator: 22
operands: 8
7Operationoperator: 9
operands: 10
8ExprTuple30, 11
9Literal
10ExprTuple12, 13
11Operationoperator: 24
operands: 14
12Operationoperator: 26
operand: 19
13Operationoperator: 16
operands: 17
14ExprTuple33, 18
15ExprTuple19
16Literal
17ExprTuple20, 21
18Operationoperator: 22
operands: 23
19Literal
20Operationoperator: 24
operands: 25
21Operationoperator: 26
operand: 30
22Literal
23ExprTuple30, 33
24Literal
25ExprTuple28, 29
26Literal
27ExprTuple30
28Literal
29Operationoperator: 31
operands: 32
30Literal
31Literal
32ExprTuple33, 34, 35, 36
33Literal
34Literal
35Literal
36IndexedVarvariable: 37
index: 39
37Variable
38ExprTuple39
39Variable