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 Unitary
from proveit.logic import And, Forall, InSet
from proveit.numbers import Add, Exp, Interval, NaturalPos, one, two
from proveit.physics.quantum import I
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import QPE, QPE1
from proveit.physics.quantum.circuits import Gate, MultiQubitElem, Qcircuit, QcircuitEquiv
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, s)
sub_expr3 = Add(t, one)
sub_expr4 = Interval(one, sub_expr2)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = sub_expr4)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE1(U, t), part = sub_expr1), targets = sub_expr4)
expr = Lambda([s, t], Conditional(Forall(instance_param_or_params = [U], instance_expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr3, sub_expr2)])), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr6, one, t), ExprRange(sub_expr1, sub_expr6, sub_expr3, sub_expr2)], [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)]))), domain = Unitary(Exp(two, s))), And(InSet(s, NaturalPos), InSet(t, 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())
\left(s, t\right) \mapsto \left\{\forall_{U \in \textrm{U}\left(2^{s}\right)}~\left(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multigate{1}{\textrm{QPE}\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multigate{1}{\textrm{QPE}_1\left(U, t\right)} & \gate{{\mathrm {FT}}^{\dag}_{t}} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw & { /^{s} } \qw
} \end{array}\right)\right) \textrm{ if } s \in \mathbb{N}^+ ,  t \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
0Lambdaparameters: 1
body: 2
1ExprTuple87, 88
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 9
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9
7Literal
8ExprTuple10, 11
9Lambdaparameter: 86
body: 13
10Operationoperator: 21
operands: 14
11Operationoperator: 21
operands: 15
12ExprTuple86
13Conditionalvalue: 16
condition: 17
14ExprTuple87, 18
15ExprTuple88, 18
16Operationoperator: 19
operands: 20
17Operationoperator: 21
operands: 22
18Literal
19Literal
20ExprTuple23, 24
21Literal
22ExprTuple86, 25
23Operationoperator: 27
operand: 31
24Operationoperator: 27
operands: 28
25Operationoperator: 29
operand: 34
26ExprTuple31
27Literal
28ExprTuple32, 33
29Literal
30ExprTuple34
31ExprTuple35, 36
32ExprTuple37, 38
33ExprTuple39, 40
34Operationoperator: 41
operands: 42
35ExprRangelambda_map: 43
start_index: 78
end_index: 88
36ExprRangelambda_map: 43
start_index: 45
end_index: 75
37ExprRangelambda_map: 44
start_index: 78
end_index: 88
38ExprRangelambda_map: 44
start_index: 45
end_index: 75
39ExprRangelambda_map: 46
start_index: 78
end_index: 88
40ExprRangelambda_map: 47
start_index: 78
end_index: 87
41Literal
42ExprTuple48, 87
43Lambdaparameter: 77
body: 49
44Lambdaparameter: 77
body: 50
45Operationoperator: 82
operands: 51
46Lambdaparameter: 77
body: 52
47Lambdaparameter: 77
body: 54
48Literal
49Operationoperator: 57
operands: 55
50Operationoperator: 57
operands: 56
51ExprTuple88, 78
52Operationoperator: 57
operands: 58
53ExprTuple77
54Operationoperator: 69
operands: 59
55NamedExprselement: 60
targets: 62
56NamedExprselement: 61
targets: 62
57Literal
58NamedExprselement: 63
targets: 64
59NamedExprsoperation: 65
60Operationoperator: 69
operands: 66
61Operationoperator: 69
operands: 67
62Operationoperator: 71
operands: 68
63Operationoperator: 69
operands: 70
64Operationoperator: 71
operands: 72
65Literal
66NamedExprsoperation: 73
part: 77
67NamedExprsoperation: 74
part: 77
68ExprTuple78, 75
69Literal
70NamedExprsoperation: 76
part: 77
71Literal
72ExprTuple78, 88
73Operationoperator: 79
operands: 81
74Operationoperator: 80
operands: 81
75Operationoperator: 82
operands: 83
76Operationoperator: 84
operand: 88
77Variable
78Literal
79Literal
80Literal
81ExprTuple86, 88
82Literal
83ExprTuple88, 87
84Literal
85ExprTuple88
86Variable
87Variable
88Variable