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, n
from proveit.logic import InSet
from proveit.physics.quantum import m_bit_interval
from proveit.physics.quantum.circuits import register_meas
In [2]:
# build up the expression from sub-expressions
expr = Lambda(n, Conditional(register_meas, InSet(n, m_bit_interval)))
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())
n \mapsto \left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{3}{\lvert \psi \rangle} & \meter & \multiqout{3}{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \meter & \ghostqout{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \measure{\begin{array}{c}:\\ \left(m - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \meter & \ghostqout{\lvert n \rangle_{m}}
} \end{array} \textrm{ if } n \in \{0~\ldotp \ldotp~2^{m} - 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: 56
body: 2
1ExprTuple56
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10, 11
7Literal
8ExprTuple56, 12
9ExprTuple13
10ExprTuple14
11ExprTuple15
12Operationoperator: 47
operands: 16
13ExprRangelambda_map: 17
start_index: 53
end_index: 57
14ExprRangelambda_map: 18
start_index: 53
end_index: 57
15ExprRangelambda_map: 19
start_index: 53
end_index: 57
16ExprTuple20, 21
17Lambdaparameter: 52
body: 22
18Lambdaparameter: 52
body: 23
19Lambdaparameter: 52
body: 25
20Literal
21Operationoperator: 26
operands: 27
22Operationoperator: 31
operands: 28
23Operationoperator: 29
operands: 30
24ExprTuple52
25Operationoperator: 31
operands: 32
26Literal
27ExprTuple33, 34
28NamedExprselement: 35
targets: 38
29Literal
30NamedExprsbasis: 36
31Literal
32NamedExprselement: 37
targets: 38
33Operationoperator: 39
operands: 40
34Operationoperator: 41
operand: 53
35Operationoperator: 43
operands: 44
36Literal
37Operationoperator: 45
operands: 46
38Operationoperator: 47
operands: 48
39Literal
40ExprTuple49, 57
41Literal
42ExprTuple53
43Literal
44NamedExprsstate: 50
part: 52
45Literal
46NamedExprsstate: 51
part: 52
47Literal
48ExprTuple53, 57
49Literal
50Variable
51Operationoperator: 54
operands: 55
52Variable
53Literal
54Literal
55ExprTuple56, 57
56Variable
57Variable