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 Conditional, Function, f, i, n
from proveit.core_expr_types import a_i, v_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import Equals, Functions, 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 = [i]
sub_expr2 = Interval(one, n)
sub_expr3 = Qmult(Ket(v_i), Bra(v_i))
expr = Conditional(Equals(Function(f, [VecSum(index_or_indices = sub_expr1, summand = ScalarMult(a_i, sub_expr3), domain = sub_expr2)]), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(Function(f, [a_i]), sub_expr3), domain = sub_expr2)), InSet(f, Functions(Complex, Complex)))
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\{f\left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right) = \left(\sum_{i=1}^{n} \left(f\left(a_{i}\right) \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right) \textrm{ if } f \in \left[\mathbb{C} \rightarrow \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: 28
operands: 5
3Literal
4ExprTuple6, 7
5ExprTuple30, 8
6Operationoperator: 30
operand: 13
7Operationoperator: 16
operand: 14
8Operationoperator: 11
operands: 12
9ExprTuple13
10ExprTuple14
11Literal
12ExprTuple15, 15
13Operationoperator: 16
operand: 19
14Lambdaparameter: 50
body: 18
15Literal
16Literal
17ExprTuple19
18Conditionalvalue: 20
condition: 24
19Lambdaparameter: 50
body: 21
20Operationoperator: 26
operands: 22
21Conditionalvalue: 23
condition: 24
22ExprTuple25, 32
23Operationoperator: 26
operands: 27
24Operationoperator: 28
operands: 29
25Operationoperator: 30
operand: 34
26Literal
27ExprTuple34, 32
28Literal
29ExprTuple50, 33
30Variable
31ExprTuple34
32Operationoperator: 35
operands: 36
33Operationoperator: 37
operands: 38
34IndexedVarvariable: 39
index: 50
35Literal
36ExprTuple40, 41
37Literal
38ExprTuple42, 43
39Variable
40Operationoperator: 44
operand: 47
41Operationoperator: 45
operand: 47
42Literal
43Variable
44Literal
45Literal
46ExprTuple47
47IndexedVarvariable: 48
index: 50
48Variable
49ExprTuple50
50Variable