logo

Expression of type Lambda

from the theory of proveit.physics.quantum.QPE

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, Lambda, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import And, Equals, InSet
from proveit.numbers import Add, Exp, Interval, Mult, Real, e, i, one, pi, subtract, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, one)
sub_expr3 = Add(t, s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = Mult(two_pow_t, phase)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Lambda(phase, Conditional(Equals(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)], [ExprRange(sub_expr1, sub_expr6, one, t), ExprRange(sub_expr1, sub_expr6, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(sub_expr5, t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)]))), one), And(InSet(phase, Real), InSet(sub_expr5, Interval(zero, subtract(two_pow_t, one))), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), 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} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = 1 \textrm{ if } \varphi \in \mathbb{R} ,  \left(2^{t} \cdot \varphi\right) \in \{0~\ldotp \ldotp~2^{t} - 1\} ,  \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: 123
body: 2
1ExprTuple123
2Conditionalvalue: 3
condition: 4
3Operationoperator: 17
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple8, 118
6Literal
7ExprTuple9, 10, 11
8Operationoperator: 12
operand: 19
9Operationoperator: 15
operands: 14
10Operationoperator: 15
operands: 16
11Operationoperator: 17
operands: 18
12Literal
13ExprTuple19
14ExprTuple123, 20
15Literal
16ExprTuple117, 21
17Literal
18ExprTuple22, 23
19Operationoperator: 24
operands: 25
20Literal
21Operationoperator: 100
operands: 26
22Operationoperator: 27
operands: 28
23Operationoperator: 29
operands: 30
24Literal
25ExprTuple31, 32, 33, 34
26ExprTuple35, 36
27Literal
28ExprTuple116, 105
29Literal
30ExprTuple37, 105
31ExprTuple38, 39
32ExprTuple40, 41
33ExprTuple42, 43
34ExprTuple44, 45
35Literal
36Operationoperator: 114
operands: 46
37Operationoperator: 124
operands: 47
38ExprRangelambda_map: 48
start_index: 118
end_index: 127
39ExprRangelambda_map: 49
start_index: 118
end_index: 119
40ExprRangelambda_map: 50
start_index: 118
end_index: 127
41ExprRangelambda_map: 50
start_index: 107
end_index: 108
42ExprRangelambda_map: 51
start_index: 118
end_index: 127
43ExprRangelambda_map: 52
start_index: 118
end_index: 119
44ExprRangelambda_map: 53
start_index: 118
end_index: 127
45ExprRangelambda_map: 54
start_index: 118
end_index: 119
46ExprTuple122, 55
47ExprTuple56, 57
48Lambdaparameter: 106
body: 58
49Lambdaparameter: 106
body: 59
50Lambdaparameter: 106
body: 60
51Lambdaparameter: 106
body: 61
52Lambdaparameter: 106
body: 62
53Lambdaparameter: 106
body: 63
54Lambdaparameter: 106
body: 65
55Operationoperator: 66
operand: 118
56Literal
57Operationoperator: 120
operands: 68
58Operationoperator: 92
operands: 69
59Operationoperator: 76
operands: 70
60Operationoperator: 76
operands: 71
61Operationoperator: 72
operands: 73
62Operationoperator: 93
operands: 74
63Operationoperator: 76
operands: 75
64ExprTuple106
65Operationoperator: 76
operands: 77
66Literal
67ExprTuple118
68ExprTuple126, 78, 79, 123
69NamedExprsstate: 80
70NamedExprselement: 81
targets: 89
71NamedExprselement: 82
targets: 83
72Literal
73NamedExprsbasis: 84
74NamedExprsoperation: 85
75NamedExprselement: 86
targets: 87
76Literal
77NamedExprselement: 88
targets: 89
78Literal
79Literal
80Operationoperator: 90
operand: 102
81Operationoperator: 92
operands: 99
82Operationoperator: 93
operands: 94
83Operationoperator: 100
operands: 95
84Literal
85Literal
86Operationoperator: 98
operands: 96
87Operationoperator: 100
operands: 97
88Operationoperator: 98
operands: 99
89Operationoperator: 100
operands: 101
90Literal
91ExprTuple102
92Literal
93Literal
94NamedExprsoperation: 103
part: 106
95ExprTuple118, 108
96NamedExprsstate: 104
part: 106
97ExprTuple118, 127
98Literal
99NamedExprsstate: 105
part: 106
100Literal
101ExprTuple107, 108
102Literal
103Operationoperator: 109
operands: 110
104Operationoperator: 111
operands: 112
105Variable
106Variable
107Operationoperator: 114
operands: 113
108Operationoperator: 114
operands: 115
109Literal
110ExprTuple116, 127
111Literal
112ExprTuple117, 127
113ExprTuple127, 118
114Literal
115ExprTuple127, 119
116Variable
117Operationoperator: 120
operands: 121
118Literal
119Variable
120Literal
121ExprTuple122, 123
122Operationoperator: 124
operands: 125
123Variable
124Literal
125ExprTuple126, 127
126Literal
127Variable