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
from proveit.linear_algebra import ScalarMult
from proveit.logic import Equals
from proveit.numbers import Exp, Mult, e, i, one, pi, two
from proveit.physics.quantum import Qmult, var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Lambda(varphi, Conditional(Equals(Prob(phase_kickback_circuit), one), Equals(Qmult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, varphi)), var_ket_u))))
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())
\varphi \mapsto \left\{\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U} & \qout{\lvert u \rangle}
} \end{array}\right) = 1 \textrm{ if } \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 101
body: 2
1ExprTuple101
2Conditionalvalue: 3
condition: 4
3Operationoperator: 6
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple8, 95
6Literal
7ExprTuple9, 10
8Operationoperator: 11
operand: 16
9Operationoperator: 13
operands: 14
10Operationoperator: 78
operands: 15
11Literal
12ExprTuple16
13Literal
14ExprTuple69, 73
15ExprTuple84, 73
16Operationoperator: 17
operands: 18
17Literal
18ExprTuple19, 20, 21
19ExprTuple22, 23
20ExprTuple24, 25
21ExprTuple26, 27
22Operationoperator: 59
operands: 28
23ExprRangelambda_map: 29
start_index: 95
end_index: 34
24Operationoperator: 50
operands: 30
25ExprRangelambda_map: 31
start_index: 95
end_index: 34
26Operationoperator: 65
operands: 32
27ExprRangelambda_map: 33
start_index: 95
end_index: 34
28NamedExprsstate: 35
29Lambdaparameter: 74
body: 36
30NamedExprselement: 37
targets: 38
31Lambdaparameter: 74
body: 39
32NamedExprsstate: 40
33Lambdaparameter: 74
body: 42
34Operationoperator: 80
operands: 43
35Operationoperator: 91
operand: 52
36Operationoperator: 50
operands: 45
37Literal
38Operationoperator: 46
operand: 98
39Operationoperator: 50
operands: 48
40Operationoperator: 78
operands: 49
41ExprTuple74
42Operationoperator: 50
operands: 51
43ExprTuple86, 95
44ExprTuple52
45NamedExprselement: 53
targets: 58
46Literal
47ExprTuple98
48NamedExprselement: 54
targets: 58
49ExprTuple55, 56
50Literal
51NamedExprselement: 57
targets: 58
52Literal
53Operationoperator: 59
operands: 66
54Operationoperator: 60
operands: 61
55Operationoperator: 87
operands: 62
56Operationoperator: 63
operands: 64
57Operationoperator: 65
operands: 66
58Operationoperator: 67
operands: 68
59Literal
60Literal
61NamedExprsoperation: 69
part: 74
62ExprTuple95, 70
63Literal
64ExprTuple71, 72
65Literal
66NamedExprsstate: 73
part: 74
67Literal
68ExprTuple98, 75
69Variable
70Operationoperator: 89
operands: 76
71Operationoperator: 91
operand: 83
72Operationoperator: 78
operands: 79
73Variable
74Variable
75Operationoperator: 80
operands: 81
76ExprTuple98, 82
77ExprTuple83
78Literal
79ExprTuple84, 85
80Literal
81ExprTuple86, 98
82Operationoperator: 87
operands: 88
83Literal
84Operationoperator: 89
operands: 90
85Operationoperator: 91
operand: 95
86Variable
87Literal
88ExprTuple95, 98
89Literal
90ExprTuple93, 94
91Literal
92ExprTuple95
93Literal
94Operationoperator: 96
operands: 97
95Literal
96Literal
97ExprTuple98, 99, 100, 101
98Literal
99Literal
100Literal
101Variable