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, ExprRange, Function, IndexedVar, Variable, a, f, i, n
from proveit.core_expr_types import a_i, v_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import And, Equals, Forall, 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 = 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(Forall(instance_param_or_params = [f], instance_expr = Equals(Function(f, [VecSum(index_or_indices = sub_expr2, summand = ScalarMult(a_i, sub_expr4), domain = sub_expr3)]), VecSum(index_or_indices = sub_expr2, summand = ScalarMult(Function(f, [a_i]), sub_expr4), domain = sub_expr3)), domain = Functions(Complex, Complex)), And(ExprRange(sub_expr1, InSet(IndexedVar(a, 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\{\forall_{f \in \left[\mathbb{C} \rightarrow \mathbb{C}\right]}~\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)\right) \textrm{ if } \left(a_{1} \in \mathbb{C}\right) \land  \left(a_{2} \in \mathbb{C}\right) \land  \ldots \land  \left(a_{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: 3
operand: 7
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7
5Literal
6ExprTuple8
7Lambdaparameter: 46
body: 10
8ExprRangelambda_map: 11
start_index: 58
end_index: 59
9ExprTuple46
10Conditionalvalue: 12
condition: 13
11Lambdaparameter: 31
body: 14
12Operationoperator: 15
operands: 16
13Operationoperator: 44
operands: 17
14Operationoperator: 44
operands: 18
15Literal
16ExprTuple19, 20
17ExprTuple46, 21
18ExprTuple22, 30
19Operationoperator: 46
operand: 28
20Operationoperator: 32
operand: 29
21Operationoperator: 25
operands: 26
22IndexedVarvariable: 55
index: 31
23ExprTuple28
24ExprTuple29
25Literal
26ExprTuple30, 30
27ExprTuple31
28Operationoperator: 32
operand: 35
29Lambdaparameter: 66
body: 34
30Literal
31Variable
32Literal
33ExprTuple35
34Conditionalvalue: 36
condition: 40
35Lambdaparameter: 66
body: 37
36Operationoperator: 42
operands: 38
37Conditionalvalue: 39
condition: 40
38ExprTuple41, 48
39Operationoperator: 42
operands: 43
40Operationoperator: 44
operands: 45
41Operationoperator: 46
operand: 50
42Literal
43ExprTuple50, 48
44Literal
45ExprTuple66, 49
46Variable
47ExprTuple50
48Operationoperator: 51
operands: 52
49Operationoperator: 53
operands: 54
50IndexedVarvariable: 55
index: 66
51Literal
52ExprTuple56, 57
53Literal
54ExprTuple58, 59
55Variable
56Operationoperator: 60
operand: 63
57Operationoperator: 61
operand: 63
58Literal
59Variable
60Literal
61Literal
62ExprTuple63
63IndexedVarvariable: 64
index: 66
64Variable
65ExprTuple66
66Variable