logo

Expression of type Conditional

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, 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 = 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\{\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()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8
5Literal
6ExprTuple9, 10
7Operationoperator: 65
operands: 11
8Operationoperator: 18
operand: 16
9Operationoperator: 32
operands: 13
10ExprRangelambda_map: 14
start_index: 67
end_index: 38
11ExprTuple29, 15, 31
12ExprTuple16
13ExprTuple29, 24
14Lambdaparameter: 50
body: 17
15Operationoperator: 18
operand: 22
16Lambdaparameter: 56
body: 20
17Operationoperator: 32
operands: 21
18Literal
19ExprTuple22
20Conditionalvalue: 23
condition: 28
21ExprTuple41, 24
22Lambdaparameter: 56
body: 26
23Operationoperator: 65
operands: 27
24Literal
25ExprTuple56
26Conditionalvalue: 30
condition: 28
27ExprTuple29, 30, 31
28Operationoperator: 32
operands: 33
29IndexedVarvariable: 34
index: 67
30Operationoperator: 35
operands: 36
31ExprRangelambda_map: 37
start_index: 67
end_index: 38
32Literal
33ExprTuple56, 39
34Variable
35Literal
36ExprTuple67, 40
37Lambdaparameter: 50
body: 41
38Literal
39Operationoperator: 42
operands: 43
40Operationoperator: 70
operands: 44
41IndexedVarvariable: 45
index: 50
42Literal
43ExprTuple47, 48
44ExprTuple49, 74
45Variable
46ExprTuple50
47Operationoperator: 58
operands: 51
48Operationoperator: 70
operands: 52
49Operationoperator: 58
operands: 53
50Variable
51ExprTuple54, 67
52ExprTuple74, 55
53ExprTuple56, 57
54Variable
55Operationoperator: 58
operands: 59
56Variable
57Operationoperator: 63
operand: 62
58Literal
59ExprTuple75, 61
60ExprTuple62
61Operationoperator: 63
operand: 67
62Operationoperator: 65
operands: 66
63Literal
64ExprTuple67
65Literal
66ExprTuple68, 69
67Literal
68Operationoperator: 70
operands: 71
69Operationoperator: 72
operand: 76
70Literal
71ExprTuple74, 75
72Literal
73ExprTuple76
74Literal
75Literal
76Literal