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 And, Equals, Forall, InSet
from proveit.numbers import Exp, Mult, e, i, one, pi, two
from proveit.physics.quantum import Qmult, m_ket_domain, normalized_var_ket_u, 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(var_ket_u, Conditional(Forall(instance_param_or_params = [varphi], instance_expr = Equals(Prob(phase_kickback_circuit), one), condition = Equals(Qmult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, varphi)), var_ket_u))), And(InSet(var_ket_u, m_ket_domain), normalized_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())
\lvert u \rangle \mapsto \left\{\forall_{\varphi~|~\left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\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\right) \textrm{ if } \lvert u \rangle \in \mathbb{C}^{2^{m}} ,  \left \|\lvert u \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: 95
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 8
3Operationoperator: 6
operands: 7
4Literal
5ExprTuple8
6Literal
7ExprTuple9, 10
8Lambdaparameter: 123
body: 12
9Operationoperator: 13
operands: 14
10Operationoperator: 21
operands: 15
11ExprTuple123
12Conditionalvalue: 16
condition: 17
13Literal
14ExprTuple95, 18
15ExprTuple19, 117
16Operationoperator: 21
operands: 20
17Operationoperator: 21
operands: 22
18Operationoperator: 23
operands: 24
19Operationoperator: 25
operand: 95
20ExprTuple27, 117
21Literal
22ExprTuple28, 29
23Literal
24ExprTuple30, 31
25Literal
26ExprTuple95
27Operationoperator: 32
operand: 38
28Operationoperator: 34
operands: 35
29Operationoperator: 100
operands: 36
30Literal
31Operationoperator: 111
operands: 37
32Literal
33ExprTuple38
34Literal
35ExprTuple91, 95
36ExprTuple106, 95
37ExprTuple120, 108
38Operationoperator: 39
operands: 40
39Literal
40ExprTuple41, 42, 43
41ExprTuple44, 45
42ExprTuple46, 47
43ExprTuple48, 49
44Operationoperator: 81
operands: 50
45ExprRangelambda_map: 51
start_index: 117
end_index: 56
46Operationoperator: 72
operands: 52
47ExprRangelambda_map: 53
start_index: 117
end_index: 56
48Operationoperator: 87
operands: 54
49ExprRangelambda_map: 55
start_index: 117
end_index: 56
50NamedExprsstate: 57
51Lambdaparameter: 96
body: 58
52NamedExprselement: 59
targets: 60
53Lambdaparameter: 96
body: 61
54NamedExprsstate: 62
55Lambdaparameter: 96
body: 64
56Operationoperator: 102
operands: 65
57Operationoperator: 113
operand: 74
58Operationoperator: 72
operands: 67
59Literal
60Operationoperator: 68
operand: 120
61Operationoperator: 72
operands: 70
62Operationoperator: 100
operands: 71
63ExprTuple96
64Operationoperator: 72
operands: 73
65ExprTuple108, 117
66ExprTuple74
67NamedExprselement: 75
targets: 80
68Literal
69ExprTuple120
70NamedExprselement: 76
targets: 80
71ExprTuple77, 78
72Literal
73NamedExprselement: 79
targets: 80
74Literal
75Operationoperator: 81
operands: 88
76Operationoperator: 82
operands: 83
77Operationoperator: 109
operands: 84
78Operationoperator: 85
operands: 86
79Operationoperator: 87
operands: 88
80Operationoperator: 89
operands: 90
81Literal
82Literal
83NamedExprsoperation: 91
part: 96
84ExprTuple117, 92
85Literal
86ExprTuple93, 94
87Literal
88NamedExprsstate: 95
part: 96
89Literal
90ExprTuple120, 97
91Variable
92Operationoperator: 111
operands: 98
93Operationoperator: 113
operand: 105
94Operationoperator: 100
operands: 101
95Variable
96Variable
97Operationoperator: 102
operands: 103
98ExprTuple120, 104
99ExprTuple105
100Literal
101ExprTuple106, 107
102Literal
103ExprTuple108, 120
104Operationoperator: 109
operands: 110
105Literal
106Operationoperator: 111
operands: 112
107Operationoperator: 113
operand: 117
108Variable
109Literal
110ExprTuple117, 120
111Literal
112ExprTuple115, 116
113Literal
114ExprTuple117
115Literal
116Operationoperator: 118
operands: 119
117Literal
118Literal
119ExprTuple120, 121, 122, 123
120Literal
121Literal
122Literal
123Variable