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 ScalarMult, Unitary
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Exp, Mult, NaturalPos, 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(m, Conditional(Forall(instance_param_or_params = [U], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = 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))), domain = m_ket_domain, condition = normalized_var_ket_u), domain = Unitary(Exp(two, m))), InSet(m, NaturalPos)))
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())
m \mapsto \left\{\forall_{U \in \textrm{U}\left(2^{m}\right)}~\left[\forall_{\lvert u \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert u \rangle\right \| = 1}~\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)\right]\right] \textrm{ if } m \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 126
body: 2
1ExprTuple126
2Conditionalvalue: 3
condition: 4
3Operationoperator: 22
operand: 7
4Operationoperator: 31
operands: 6
5ExprTuple7
6ExprTuple126, 8
7Lambdaparameter: 109
body: 10
8Literal
9ExprTuple109
10Conditionalvalue: 11
condition: 12
11Operationoperator: 22
operand: 15
12Operationoperator: 31
operands: 14
13ExprTuple15
14ExprTuple109, 16
15Lambdaparameter: 113
body: 17
16Operationoperator: 18
operand: 49
17Conditionalvalue: 20
condition: 21
18Literal
19ExprTuple49
20Operationoperator: 22
operand: 26
21Operationoperator: 24
operands: 25
22Literal
23ExprTuple26
24Literal
25ExprTuple27, 28
26Lambdaparameter: 141
body: 30
27Operationoperator: 31
operands: 32
28Operationoperator: 39
operands: 33
29ExprTuple141
30Conditionalvalue: 34
condition: 35
31Literal
32ExprTuple113, 36
33ExprTuple37, 135
34Operationoperator: 39
operands: 38
35Operationoperator: 39
operands: 40
36Operationoperator: 41
operands: 42
37Operationoperator: 43
operand: 113
38ExprTuple45, 135
39Literal
40ExprTuple46, 47
41Literal
42ExprTuple48, 49
43Literal
44ExprTuple113
45Operationoperator: 50
operand: 56
46Operationoperator: 52
operands: 53
47Operationoperator: 118
operands: 54
48Literal
49Operationoperator: 129
operands: 55
50Literal
51ExprTuple56
52Literal
53ExprTuple109, 113
54ExprTuple124, 113
55ExprTuple138, 126
56Operationoperator: 57
operands: 58
57Literal
58ExprTuple59, 60, 61
59ExprTuple62, 63
60ExprTuple64, 65
61ExprTuple66, 67
62Operationoperator: 99
operands: 68
63ExprRangelambda_map: 69
start_index: 135
end_index: 74
64Operationoperator: 90
operands: 70
65ExprRangelambda_map: 71
start_index: 135
end_index: 74
66Operationoperator: 105
operands: 72
67ExprRangelambda_map: 73
start_index: 135
end_index: 74
68NamedExprsstate: 75
69Lambdaparameter: 114
body: 76
70NamedExprselement: 77
targets: 78
71Lambdaparameter: 114
body: 79
72NamedExprsstate: 80
73Lambdaparameter: 114
body: 82
74Operationoperator: 120
operands: 83
75Operationoperator: 131
operand: 92
76Operationoperator: 90
operands: 85
77Literal
78Operationoperator: 86
operand: 138
79Operationoperator: 90
operands: 88
80Operationoperator: 118
operands: 89
81ExprTuple114
82Operationoperator: 90
operands: 91
83ExprTuple126, 135
84ExprTuple92
85NamedExprselement: 93
targets: 98
86Literal
87ExprTuple138
88NamedExprselement: 94
targets: 98
89ExprTuple95, 96
90Literal
91NamedExprselement: 97
targets: 98
92Literal
93Operationoperator: 99
operands: 106
94Operationoperator: 100
operands: 101
95Operationoperator: 127
operands: 102
96Operationoperator: 103
operands: 104
97Operationoperator: 105
operands: 106
98Operationoperator: 107
operands: 108
99Literal
100Literal
101NamedExprsoperation: 109
part: 114
102ExprTuple135, 110
103Literal
104ExprTuple111, 112
105Literal
106NamedExprsstate: 113
part: 114
107Literal
108ExprTuple138, 115
109Variable
110Operationoperator: 129
operands: 116
111Operationoperator: 131
operand: 123
112Operationoperator: 118
operands: 119
113Variable
114Variable
115Operationoperator: 120
operands: 121
116ExprTuple138, 122
117ExprTuple123
118Literal
119ExprTuple124, 125
120Literal
121ExprTuple126, 138
122Operationoperator: 127
operands: 128
123Literal
124Operationoperator: 129
operands: 130
125Operationoperator: 131
operand: 135
126Variable
127Literal
128ExprTuple135, 138
129Literal
130ExprTuple133, 134
131Literal
132ExprTuple135
133Literal
134Operationoperator: 136
operands: 137
135Literal
136Literal
137ExprTuple138, 139, 140, 141
138Literal
139Literal
140Literal
141Variable