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, IndexedVar, Lambda, Variable, a, c, l
from proveit.logic import And, Equals, InSet
from proveit.numbers import Complex, Exp, Mult, Sum, frac, one, two, zero
from proveit.physics.quantum.QPE import _diff_l_scaled_delta_floor, _pos_domain
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = [l]
sub_expr3 = IndexedVar(a, one)
sub_expr4 = IndexedVar(c, sub_expr1)
sub_expr5 = ExprRange(sub_expr1, sub_expr4, one, zero)
sub_expr6 = frac(one, Exp(_diff_l_scaled_delta_floor, two))
expr = Lambda([sub_expr3, sub_expr5], Conditional(Equals(Mult(sub_expr3, Sum(index_or_indices = sub_expr2, summand = sub_expr6, domain = _pos_domain), sub_expr5), Sum(index_or_indices = sub_expr2, summand = Mult(sub_expr3, sub_expr6, sub_expr5), domain = _pos_domain)).with_wrapping_at(2), And(InSet(sub_expr3, Complex), ExprRange(sub_expr1, InSet(sub_expr4, Complex), one, zero))))
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(a_{1}, c_{1}, c_{2}, \ldots, c_{0}\right) \mapsto \left\{\begin{array}{c} \begin{array}{l} \left(a_{1} \cdot \left(\sum_{l = e + 1}^{2^{t - 1}} \frac{1}{\left(l - \left(2^{t} \cdot \delta_{b_{\textit{f}}}\right)\right)^{2}}\right)\cdot c_{1} \cdot  c_{2} \cdot  \ldots \cdot  c_{0}\right) =  \\ \left(\sum_{l = e + 1}^{2^{t - 1}} \left(a_{1} \cdot \frac{1}{\left(l - \left(2^{t} \cdot \delta_{b_{\textit{f}}}\right)\right)^{2}}\cdot c_{1} \cdot  c_{2} \cdot  \ldots \cdot  c_{0}\right)\right) \end{array} \end{array} \textrm{ if } a_{1} \in \mathbb{C}, \left(c_{1} \in \mathbb{C}\right) ,  \left(c_{2} \in \mathbb{C}\right) ,  \ldots ,  \left(c_{0} \in \mathbb{C}\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
1ExprTuple31, 33
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10
7Literal
8ExprTuple11, 12
9Operationoperator: 67
operands: 13
10Operationoperator: 20
operand: 18
11Operationoperator: 34
operands: 15
12ExprRangelambda_map: 16
start_index: 69
end_index: 40
13ExprTuple31, 17, 33
14ExprTuple18
15ExprTuple31, 26
16Lambdaparameter: 52
body: 19
17Operationoperator: 20
operand: 24
18Lambdaparameter: 58
body: 22
19Operationoperator: 34
operands: 23
20Literal
21ExprTuple24
22Conditionalvalue: 25
condition: 30
23ExprTuple43, 26
24Lambdaparameter: 58
body: 28
25Operationoperator: 67
operands: 29
26Literal
27ExprTuple58
28Conditionalvalue: 32
condition: 30
29ExprTuple31, 32, 33
30Operationoperator: 34
operands: 35
31IndexedVarvariable: 36
index: 69
32Operationoperator: 37
operands: 38
33ExprRangelambda_map: 39
start_index: 69
end_index: 40
34Literal
35ExprTuple58, 41
36Variable
37Literal
38ExprTuple69, 42
39Lambdaparameter: 52
body: 43
40Literal
41Operationoperator: 44
operands: 45
42Operationoperator: 72
operands: 46
43IndexedVarvariable: 47
index: 52
44Literal
45ExprTuple49, 50
46ExprTuple51, 76
47Variable
48ExprTuple52
49Operationoperator: 60
operands: 53
50Operationoperator: 72
operands: 54
51Operationoperator: 60
operands: 55
52Variable
53ExprTuple56, 69
54ExprTuple76, 57
55ExprTuple58, 59
56Variable
57Operationoperator: 60
operands: 61
58Variable
59Operationoperator: 65
operand: 64
60Literal
61ExprTuple77, 63
62ExprTuple64
63Operationoperator: 65
operand: 69
64Operationoperator: 67
operands: 68
65Literal
66ExprTuple69
67Literal
68ExprTuple70, 71
69Literal
70Operationoperator: 72
operands: 73
71Operationoperator: 74
operand: 78
72Literal
73ExprTuple76, 77
74Literal
75ExprTuple78
76Literal
77Literal
78Literal