logo

Expression of type Conditional

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, Conditional, ExprRange, IndexedVar, Variable, 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, InSet
from proveit.numbers import Complex, Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = [i]
sub_expr3 = Interval(one, n)
sub_expr4 = Qmult(Ket(v_i), Bra(v_i))
expr = Conditional(And(Equals(A, VecSum(index_or_indices = sub_expr2, summand = ScalarMult(a_i, sub_expr4), domain = sub_expr3)), Equals(B, VecSum(index_or_indices = sub_expr2, summand = ScalarMult(b_i, sub_expr4), domain = sub_expr3))).with_wrapping_at(2), And(ExprRange(sub_expr1, InSet(IndexedVar(a, sub_expr1), Complex), one, n), ExprRange(sub_expr1, InSet(IndexedVar(b, sub_expr1), Complex), one, n)))
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} \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} \textrm{ if } \left(a_{1} \in \mathbb{C}\right) ,  \left(a_{2} \in \mathbb{C}\right) ,  \ldots ,  \left(a_{n} \in \mathbb{C}\right), \left(b_{1} \in \mathbb{C}\right) ,  \left(b_{2} \in \mathbb{C}\right) ,  \ldots ,  \left(b_{n} \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: 4
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8, 9
6Operationoperator: 11
operands: 10
7Operationoperator: 11
operands: 12
8ExprRangelambda_map: 13
start_index: 55
end_index: 56
9ExprRangelambda_map: 14
start_index: 55
end_index: 56
10ExprTuple15, 16
11Literal
12ExprTuple17, 18
13Lambdaparameter: 37
body: 19
14Lambdaparameter: 37
body: 20
15Variable
16Operationoperator: 22
operand: 26
17Variable
18Operationoperator: 22
operand: 27
19Operationoperator: 41
operands: 24
20Operationoperator: 41
operands: 25
21ExprTuple26
22Literal
23ExprTuple27
24ExprTuple28, 30
25ExprTuple29, 30
26Lambdaparameter: 63
body: 31
27Lambdaparameter: 63
body: 32
28IndexedVarvariable: 47
index: 37
29IndexedVarvariable: 48
index: 37
30Literal
31Conditionalvalue: 34
condition: 36
32Conditionalvalue: 35
condition: 36
33ExprTuple37
34Operationoperator: 39
operands: 38
35Operationoperator: 39
operands: 40
36Operationoperator: 41
operands: 42
37Variable
38ExprTuple43, 45
39Literal
40ExprTuple44, 45
41Literal
42ExprTuple63, 46
43IndexedVarvariable: 47
index: 63
44IndexedVarvariable: 48
index: 63
45Operationoperator: 49
operands: 50
46Operationoperator: 51
operands: 52
47Variable
48Variable
49Literal
50ExprTuple53, 54
51Literal
52ExprTuple55, 56
53Operationoperator: 57
operand: 60
54Operationoperator: 58
operand: 60
55Literal
56Variable
57Literal
58Literal
59ExprTuple60
60IndexedVarvariable: 61
index: 63
61Variable
62ExprTuple63
63Variable