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, Bijections, 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
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Set(zero, one)
expr = Lambda(var_ket_psi, Conditional(InSet(Lambda(b, qubit_meas), Bijections(sub_expr1, SetOfAll(instance_param_or_params = [b], instance_element = qubit_meas, domain = sub_expr1))).with_wrapping_at(2), 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\{\begin{array}{c} \begin{array}{l} \left[b \mapsto \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \meter & \qout{\lvert b \rangle}
} \end{array}\right)\right] \in  \\ \left[\left\{0, 1\right\} \xrightarrow[\text{onto}]{\text{1-to-1}} \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\}}\right] \end{array} \end{array} \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: 52
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 33
operands: 4
3Operationoperator: 5
operands: 6
4ExprTuple7, 8
5Literal
6ExprTuple9, 10
7Lambdaparameter: 57
body: 29
8Operationoperator: 11
operands: 12
9Operationoperator: 33
operands: 13
10Operationoperator: 14
operands: 15
11Literal
12ExprTuple38, 16
13ExprTuple52, 17
14Literal
15ExprTuple18, 51
16Operationoperator: 19
operand: 25
17Operationoperator: 21
operands: 22
18Operationoperator: 23
operand: 52
19Literal
20ExprTuple25
21Literal
22ExprTuple26, 27
23Literal
24ExprTuple52
25Lambdaparameter: 57
body: 28
26Literal
27Literal
28Conditionalvalue: 29
condition: 30
29Operationoperator: 31
operands: 32
30Operationoperator: 33
operands: 34
31Literal
32ExprTuple35, 36, 37
33Literal
34ExprTuple57, 38
35ExprTuple39
36ExprTuple40
37ExprTuple41
38Operationoperator: 42
operands: 43
39Operationoperator: 44
operands: 45
40Operationoperator: 46
operands: 47
41Operationoperator: 48
operands: 49
42Literal
43ExprTuple50, 51
44Literal
45NamedExprsstate: 52
46Literal
47NamedExprsbasis: 53
48Literal
49NamedExprsstate: 54
50Literal
51Literal
52Variable
53Literal
54Operationoperator: 55
operand: 57
55Literal
56ExprTuple57
57Variable