logo

Expression of type And

from the theory of proveit.physics.quantum.algebra

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 A, B, i, n
from proveit.core_expr_types import a_i, b_i, v_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import And, Equals
from proveit.numbers import Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [i]
sub_expr2 = Interval(one, n)
sub_expr3 = Qmult(Ket(v_i), Bra(v_i))
expr = And(Equals(A, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(a_i, sub_expr3), domain = sub_expr2)), Equals(B, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(b_i, sub_expr3), domain = 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} \left(A = \left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right) \land  \\ \left(B = \left(\sum_{i=1}^{n} \left(b_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right) \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',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 6
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple8, 9
6Literal
7ExprTuple10, 11
8Variable
9Operationoperator: 13
operand: 15
10Variable
11Operationoperator: 13
operand: 16
12ExprTuple15
13Literal
14ExprTuple16
15Lambdaparameter: 47
body: 17
16Lambdaparameter: 47
body: 18
17Conditionalvalue: 19
condition: 21
18Conditionalvalue: 20
condition: 21
19Operationoperator: 23
operands: 22
20Operationoperator: 23
operands: 24
21Operationoperator: 25
operands: 26
22ExprTuple27, 29
23Literal
24ExprTuple28, 29
25Literal
26ExprTuple47, 30
27IndexedVarvariable: 31
index: 47
28IndexedVarvariable: 32
index: 47
29Operationoperator: 33
operands: 34
30Operationoperator: 35
operands: 36
31Variable
32Variable
33Literal
34ExprTuple37, 38
35Literal
36ExprTuple39, 40
37Operationoperator: 41
operand: 44
38Operationoperator: 42
operand: 44
39Literal
40Variable
41Literal
42Literal
43ExprTuple44
44IndexedVarvariable: 45
index: 47
45Variable
46ExprTuple47
47Variable