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, InClass, InSet, Set, SetOfAll
from proveit.numbers import one, zero
from proveit.physics.quantum import QubitSpace, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import qubit_meas
from proveit.statistics import SampleSpaces
In [2]:
# build up the expression from sub-expressions
expr = Lambda(var_ket_psi, Conditional(InClass(SetOfAll(instance_param_or_params = [b], instance_element = qubit_meas, domain = Set(zero, one)), SampleSpaces), And(InSet(var_ket_psi, QubitSpace), 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())
\lvert \psi \rangle \mapsto \left\{\left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \meter & \qout{\lvert b \rangle}
} \end{array}\right\}_{b \in \left\{0, 1\right\}} \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces} \textrm{ if } \lvert \psi \rangle \in \mathbb{C}^{2} ,  \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
0Lambdaparameter: 50
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operands: 5
3Operationoperator: 6
operands: 7
4Literal
5ExprTuple8, 9
6Literal
7ExprTuple10, 11
8Operationoperator: 12
operand: 17
9Literal
10Operationoperator: 31
operands: 14
11Operationoperator: 15
operands: 16
12Literal
13ExprTuple17
14ExprTuple50, 18
15Literal
16ExprTuple19, 49
17Lambdaparameter: 55
body: 20
18Operationoperator: 21
operands: 22
19Operationoperator: 23
operand: 50
20Conditionalvalue: 25
condition: 26
21Literal
22ExprTuple27, 28
23Literal
24ExprTuple50
25Operationoperator: 29
operands: 30
26Operationoperator: 31
operands: 32
27Literal
28Literal
29Literal
30ExprTuple33, 34, 35
31Literal
32ExprTuple55, 36
33ExprTuple37
34ExprTuple38
35ExprTuple39
36Operationoperator: 40
operands: 41
37Operationoperator: 42
operands: 43
38Operationoperator: 44
operands: 45
39Operationoperator: 46
operands: 47
40Literal
41ExprTuple48, 49
42Literal
43NamedExprsstate: 50
44Literal
45NamedExprsbasis: 51
46Literal
47NamedExprsstate: 52
48Literal
49Literal
50Variable
51Literal
52Operationoperator: 53
operand: 55
53Literal
54ExprTuple55
55Variable