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 Conditional, Lambda, b
from proveit.logic import And, Equals, InSet, Set
from proveit.numbers import Abs, Exp, one, two, zero
from proveit.physics.quantum import Bra, Qmult, QubitSpace, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import qubit_meas
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Lambda([var_ket_psi, b], Conditional(Equals(Prob(qubit_meas), Exp(Abs(Qmult(Bra(b), var_ket_psi)), two)), And(InSet(var_ket_psi, QubitSpace), InSet(b, Set(zero, one)), normalized_var_ket_psi)))
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(\lvert \psi \rangle, b\right) \mapsto \left\{\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \meter & \qout{\lvert b \rangle}
} \end{array}\right) = \left|\langle b \rvert \thinspace \lvert \psi \rangle\right|^{2} \textrm{ if } \lvert \psi \rangle \in \mathbb{C}^{2} ,  b \in \left\{0, 1\right\} ,  \left \|\lvert \psi \rangle\right \| = 1\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple57, 63
2Conditionalvalue: 3
condition: 4
3Operationoperator: 20
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple8, 9
6Literal
7ExprTuple10, 11, 12
8Operationoperator: 13
operand: 22
9Operationoperator: 15
operands: 16
10Operationoperator: 18
operands: 17
11Operationoperator: 18
operands: 19
12Operationoperator: 20
operands: 21
13Literal
14ExprTuple22
15Literal
16ExprTuple23, 42
17ExprTuple57, 24
18Literal
19ExprTuple63, 25
20Literal
21ExprTuple26, 44
22Operationoperator: 27
operands: 28
23Operationoperator: 29
operand: 40
24Operationoperator: 31
operands: 32
25Operationoperator: 33
operands: 34
26Operationoperator: 35
operand: 57
27Literal
28ExprTuple37, 38, 39
29Literal
30ExprTuple40
31Literal
32ExprTuple41, 42
33Literal
34ExprTuple43, 44
35Literal
36ExprTuple57
37ExprTuple45
38ExprTuple46
39ExprTuple47
40Operationoperator: 48
operands: 49
41Literal
42Literal
43Literal
44Literal
45Operationoperator: 50
operands: 51
46Operationoperator: 52
operands: 53
47Operationoperator: 54
operands: 55
48Literal
49ExprTuple56, 57
50Literal
51NamedExprsstate: 57
52Literal
53NamedExprsbasis: 58
54Literal
55NamedExprsstate: 59
56Operationoperator: 60
operand: 63
57Variable
58Literal
59Operationoperator: 61
operand: 63
60Literal
61Literal
62ExprTuple63
63Variable