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, U, m
from proveit.linear_algebra import Unitary
from proveit.logic import And, Equals, InSet
from proveit.numbers import Exp, one, two
from proveit.physics.quantum import m_ket_domain, var_ket_psi
from proveit.physics.quantum.circuits import unitary_gate_op
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Lambda([U, var_ket_psi], Conditional(Equals(Prob(unitary_gate_op), one), And(InSet(U, Unitary(Exp(two, m))), InSet(var_ket_psi, m_ket_domain))))
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(U, \lvert \psi \rangle\right) \mapsto \left\{\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi \rangle} & \gate{U} & \qout{U \thinspace \lvert \psi \rangle}
} \end{array}\right) = 1 \textrm{ if } U \in \textrm{U}\left(2^{m}\right) ,  \lvert \psi \rangle \in \mathbb{C}^{2^{m}}\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 64
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operands: 5
3Operationoperator: 6
operands: 7
4Literal
5ExprTuple8, 61
6Literal
7ExprTuple9, 10
8Operationoperator: 11
operand: 16
9Operationoperator: 14
operands: 13
10Operationoperator: 14
operands: 15
11Literal
12ExprTuple16
13ExprTuple65, 17
14Literal
15ExprTuple66, 18
16Operationoperator: 19
operands: 20
17Operationoperator: 21
operand: 29
18Operationoperator: 23
operands: 24
19Literal
20ExprTuple25, 26, 27
21Literal
22ExprTuple29
23Literal
24ExprTuple28, 29
25ExprTuple30
26ExprTuple31
27ExprTuple32
28Literal
29Operationoperator: 33
operands: 34
30ExprRangelambda_map: 35
start_index: 61
end_index: 62
31ExprRangelambda_map: 36
start_index: 61
end_index: 62
32ExprRangelambda_map: 37
start_index: 61
end_index: 62
33Literal
34ExprTuple38, 62
35Lambdaparameter: 60
body: 39
36Lambdaparameter: 60
body: 40
37Lambdaparameter: 60
body: 42
38Literal
39Operationoperator: 45
operands: 43
40Operationoperator: 45
operands: 44
41ExprTuple60
42Operationoperator: 45
operands: 46
43NamedExprselement: 47
targets: 50
44NamedExprselement: 48
targets: 50
45Literal
46NamedExprselement: 49
targets: 50
47Operationoperator: 51
operands: 52
48Operationoperator: 53
operands: 54
49Operationoperator: 55
operands: 56
50Operationoperator: 57
operands: 58
51Literal
52NamedExprsstate: 66
part: 60
53Literal
54NamedExprsoperation: 65
part: 60
55Literal
56NamedExprsstate: 59
part: 60
57Literal
58ExprTuple61, 62
59Operationoperator: 63
operands: 64
60Variable
61Literal
62Variable
63Literal
64ExprTuple65, 66
65Variable
66Variable