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, ExprRange, IndexedVar, Lambda, U, Variable, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import And, Equals
from proveit.numbers import Exp, Mult, e, i, one, pi, two
from proveit.physics.quantum import var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_on_register_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(varphi, sub_expr1)
expr = Lambda([ExprRange(sub_expr1, sub_expr2, one, t)], Conditional(Equals(Prob(phase_kickback_on_register_circuit), one), And(ExprRange(sub_expr1, Equals(MatrixMult(IndexedVar(U, sub_expr1), var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, sub_expr2)), var_ket_u)), one, t))))
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(\varphi_{1}, \varphi_{2}, \ldots, \varphi_{t}\right) \mapsto \left\{\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \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_{t}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U_{1}} & \gate{U_{2}} & \gate{\cdots} & \gate{U_{t}} & \qout{\lvert u \rangle}
} \end{array}\right) = 1 \textrm{ if } \left(\left(U_{1} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert u \rangle\right)\right) \land  \left(\left(U_{2} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert u \rangle\right)\right) \land  \ldots \land  \left(\left(U_{t} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert u \rangle\right)\right)\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple3
2Conditionalvalue: 4
condition: 5
3ExprRangelambda_map: 6
start_index: 125
end_index: 124
4Operationoperator: 85
operands: 7
5Operationoperator: 8
operands: 9
6Lambdaparameter: 134
body: 131
7ExprTuple10, 125
8Literal
9ExprTuple11
10Operationoperator: 12
operand: 15
11ExprRangelambda_map: 14
start_index: 125
end_index: 124
12Literal
13ExprTuple15
14Lambdaparameter: 134
body: 16
15Operationoperator: 17
operands: 18
16Operationoperator: 85
operands: 19
17Literal
18ExprTuple20, 21, 22
19ExprTuple23, 24
20ExprTuple25, 26
21ExprRangelambda_map: 27
start_index: 125
end_index: 124
22ExprTuple28, 29
23Operationoperator: 30
operands: 31
24Operationoperator: 103
operands: 32
25ExprRangelambda_map: 33
start_index: 125
end_index: 124
26ExprRangelambda_map: 34
start_index: 125
end_index: 108
27Lambdaparameter: 107
body: 35
28ExprRangelambda_map: 36
start_index: 125
end_index: 124
29ExprRangelambda_map: 37
start_index: 125
end_index: 108
30Literal
31ExprTuple38, 72
32ExprTuple111, 72
33Lambdaparameter: 134
body: 39
34Lambdaparameter: 134
body: 40
35ExprTuple41, 42
36Lambdaparameter: 134
body: 43
37Lambdaparameter: 134
body: 44
38IndexedVarvariable: 98
index: 134
39Operationoperator: 58
operands: 45
40Operationoperator: 83
operands: 46
41ExprRangelambda_map: 47
start_index: 125
end_index: 124
42ExprRangelambda_map: 48
start_index: 125
end_index: 108
43Operationoperator: 63
operands: 49
44Operationoperator: 83
operands: 50
45NamedExprsstate: 51
46NamedExprselement: 52
targets: 69
47Lambdaparameter: 134
body: 53
48Lambdaparameter: 134
body: 54
49NamedExprsstate: 55
50NamedExprselement: 56
targets: 69
51Operationoperator: 118
operand: 65
52Operationoperator: 58
operands: 64
53Operationoperator: 59
operands: 60
54Operationoperator: 83
operands: 61
55Operationoperator: 103
operands: 62
56Operationoperator: 63
operands: 64
57ExprTuple65
58Literal
59Literal
60ExprTuple66, 67
61NamedExprselement: 68
targets: 69
62ExprTuple70, 71
63Literal
64NamedExprsstate: 72
part: 134
65Literal
66Conditionalvalue: 73
condition: 74
67Conditionalvalue: 75
condition: 76
68Operationoperator: 86
operands: 77
69Operationoperator: 78
operands: 79
70Operationoperator: 114
operands: 80
71Operationoperator: 81
operands: 82
72Variable
73Operationoperator: 83
operands: 84
74Operationoperator: 85
operands: 89
75Operationoperator: 86
operands: 87
76Operationoperator: 88
operands: 89
77NamedExprsoperation: 90
part: 134
78Literal
79ExprTuple113, 91
80ExprTuple125, 92
81Literal
82ExprTuple93, 94
83Literal
84NamedExprselement: 95
targets: 96
85Literal
86Literal
87NamedExprsoperation: 97
88Literal
89ExprTuple107, 134
90IndexedVarvariable: 98
index: 107
91Operationoperator: 120
operands: 100
92Operationoperator: 116
operands: 101
93Operationoperator: 118
operand: 110
94Operationoperator: 103
operands: 104
95Literal
96Operationoperator: 105
operand: 113
97Literal
98Variable
99ExprTuple107
100ExprTuple124, 108
101ExprTuple128, 109
102ExprTuple110
103Literal
104ExprTuple111, 112
105Literal
106ExprTuple113
107Variable
108Variable
109Operationoperator: 114
operands: 115
110Literal
111Operationoperator: 116
operands: 117
112Operationoperator: 118
operand: 125
113Operationoperator: 120
operands: 121
114Literal
115ExprTuple125, 128
116Literal
117ExprTuple122, 123
118Literal
119ExprTuple125
120Literal
121ExprTuple124, 125
122Literal
123Operationoperator: 126
operands: 127
124Variable
125Literal
126Literal
127ExprTuple128, 129, 130, 131
128Literal
129Literal
130Literal
131IndexedVarvariable: 132
index: 134
132Variable
133ExprTuple134
134Variable