logo

Expression of type Equals

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 e, l
from proveit.logic import Equals
from proveit.numbers import Add, Exp, Interval, Mult, Sum, four, frac, one, subtract, two
from proveit.physics.quantum.QPE import _two_pow__t_minus_one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = frac(one, four)
sub_expr2 = frac(one, Exp(e, two))
sub_expr3 = Sum(index_or_indices = [l], summand = frac(one, Exp(l, two)), domain = Interval(Add(e, one), subtract(_two_pow__t_minus_one, one)))
expr = Equals(Mult(sub_expr1, Add(Mult(two, sub_expr3), sub_expr2)), Add(Mult(frac(one, two), sub_expr3), Mult(sub_expr1, sub_expr2))).with_wrapping_at(2)
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())
\begin{array}{c} \begin{array}{l} \left(\frac{1}{4} \cdot \left(\left(2 \cdot \left(\sum_{l = e + 1}^{2^{t - 1} - 1} \frac{1}{l^{2}}\right)\right) + \frac{1}{e^{2}}\right)\right) =  \\ \left(\left(\frac{1}{2} \cdot \left(\sum_{l = e + 1}^{2^{t - 1} - 1} \frac{1}{l^{2}}\right)\right) + \left(\frac{1}{4} \cdot \frac{1}{e^{2}}\right)\right) \end{array} \end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()(2)('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 17
operands: 5
4Operationoperator: 53
operands: 6
5ExprTuple15, 7
6ExprTuple8, 9
7Operationoperator: 53
operands: 10
8Operationoperator: 17
operands: 11
9Operationoperator: 17
operands: 12
10ExprTuple13, 16
11ExprTuple14, 22
12ExprTuple15, 16
13Operationoperator: 17
operands: 18
14Operationoperator: 33
operands: 19
15Operationoperator: 33
operands: 20
16Operationoperator: 33
operands: 21
17Literal
18ExprTuple51, 22
19ExprTuple59, 51
20ExprTuple59, 23
21ExprTuple59, 24
22Operationoperator: 25
operand: 28
23Literal
24Operationoperator: 49
operands: 27
25Literal
26ExprTuple28
27ExprTuple47, 51
28Lambdaparameter: 42
body: 30
29ExprTuple42
30Conditionalvalue: 31
condition: 32
31Operationoperator: 33
operands: 34
32Operationoperator: 35
operands: 36
33Literal
34ExprTuple59, 37
35Literal
36ExprTuple42, 38
37Operationoperator: 49
operands: 39
38Operationoperator: 40
operands: 41
39ExprTuple42, 51
40Literal
41ExprTuple43, 44
42Variable
43Operationoperator: 53
operands: 45
44Operationoperator: 53
operands: 46
45ExprTuple47, 59
46ExprTuple48, 56
47Variable
48Operationoperator: 49
operands: 50
49Literal
50ExprTuple51, 52
51Literal
52Operationoperator: 53
operands: 54
53Literal
54ExprTuple55, 56
55Literal
56Operationoperator: 57
operand: 59
57Literal
58ExprTuple59
59Literal