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.QPE import QPE1, QPE1_U_t_circuit
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 = MultiQubitElem(element = Gate(operation = QPE1(U, t), part = sub_expr1), targets = Interval(one, sub_expr2))
expr = Lambda([s, t], Conditional(Forall(instance_param_or_params = [U], instance_expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr3, one, t), ExprRange(sub_expr1, sub_expr3, Add(t, one), sub_expr2)])), QPE1_U_t_circuit), 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}_1\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qw \\
& \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qw \\
& \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & { /^{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
1ExprTuple97, 105
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 9
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9
7Literal
8ExprTuple10, 11
9Lambdaparameter: 95
body: 13
10Operationoperator: 21
operands: 14
11Operationoperator: 21
operands: 15
12ExprTuple95
13Conditionalvalue: 16
condition: 17
14ExprTuple97, 18
15ExprTuple105, 18
16Operationoperator: 19
operands: 20
17Operationoperator: 21
operands: 22
18Literal
19Literal
20ExprTuple23, 24
21Literal
22ExprTuple95, 25
23Operationoperator: 27
operand: 31
24Operationoperator: 27
operands: 28
25Operationoperator: 29
operand: 33
26ExprTuple31
27Literal
28ExprTuple32
29Literal
30ExprTuple33
31ExprTuple34, 35
32ExprRangelambda_map: 36
start_index: 37
end_index: 38
33Operationoperator: 99
operands: 39
34ExprRangelambda_map: 40
start_index: 106
end_index: 105
35ExprRangelambda_map: 40
start_index: 98
end_index: 83
36Lambdaparameter: 109
body: 41
37Operationoperator: 101
operands: 42
38Literal
39ExprTuple103, 97
40Lambdaparameter: 88
body: 43
41ExprTuple44, 45
42ExprTuple46, 106
43Operationoperator: 75
operands: 47
44ExprRangelambda_map: 48
start_index: 106
end_index: 105
45ExprRangelambda_map: 49
start_index: 106
end_index: 97
46Operationoperator: 107
operand: 105
47NamedExprselement: 51
targets: 52
48Lambdaparameter: 88
body: 53
49Lambdaparameter: 88
body: 55
50ExprTuple105
51Operationoperator: 78
operands: 56
52Operationoperator: 73
operands: 57
53Operationoperator: 58
operands: 59
54ExprTuple88
55Operationoperator: 75
operands: 60
56NamedExprsoperation: 61
part: 88
57ExprTuple106, 83
58Literal
59ExprTuple62, 63
60NamedExprselement: 64
targets: 65
61Operationoperator: 66
operands: 67
62Conditionalvalue: 68
condition: 69
63Conditionalvalue: 70
condition: 71
64Operationoperator: 78
operands: 72
65Operationoperator: 73
operands: 74
66Literal
67ExprTuple95, 105
68Operationoperator: 75
operands: 76
69Operationoperator: 77
operands: 81
70Operationoperator: 78
operands: 79
71Operationoperator: 80
operands: 81
72NamedExprsoperation: 82
part: 88
73Literal
74ExprTuple98, 83
75Literal
76NamedExprselement: 84
targets: 85
77Literal
78Literal
79NamedExprsoperation: 86
80Literal
81ExprTuple87, 88
82Operationoperator: 89
operands: 90
83Operationoperator: 101
operands: 91
84Literal
85Operationoperator: 92
operand: 98
86Literal
87Operationoperator: 101
operands: 94
88Variable
89Literal
90ExprTuple95, 96
91ExprTuple105, 97
92Literal
93ExprTuple98
94ExprTuple109, 105
95Variable
96Operationoperator: 99
operands: 100
97Variable
98Operationoperator: 101
operands: 102
99Literal
100ExprTuple103, 104
101Literal
102ExprTuple105, 106
103Literal
104Operationoperator: 107
operand: 109
105Variable
106Literal
107Literal
108ExprTuple109
109Variable