logo

Expression of type Forall

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 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, Forall, Functions
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 = Forall(instance_param_or_params = [f], instance_expr = 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)), domain = 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())
\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)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 35
body: 5
4ExprTuple35
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 33
operands: 10
8Literal
9ExprTuple11, 12
10ExprTuple35, 13
11Operationoperator: 35
operand: 18
12Operationoperator: 21
operand: 19
13Operationoperator: 16
operands: 17
14ExprTuple18
15ExprTuple19
16Literal
17ExprTuple20, 20
18Operationoperator: 21
operand: 24
19Lambdaparameter: 55
body: 23
20Literal
21Literal
22ExprTuple24
23Conditionalvalue: 25
condition: 29
24Lambdaparameter: 55
body: 26
25Operationoperator: 31
operands: 27
26Conditionalvalue: 28
condition: 29
27ExprTuple30, 37
28Operationoperator: 31
operands: 32
29Operationoperator: 33
operands: 34
30Operationoperator: 35
operand: 39
31Literal
32ExprTuple39, 37
33Literal
34ExprTuple55, 38
35Variable
36ExprTuple39
37Operationoperator: 40
operands: 41
38Operationoperator: 42
operands: 43
39IndexedVarvariable: 44
index: 55
40Literal
41ExprTuple45, 46
42Literal
43ExprTuple47, 48
44Variable
45Operationoperator: 49
operand: 52
46Operationoperator: 50
operand: 52
47Literal
48Variable
49Literal
50Literal
51ExprTuple52
52IndexedVarvariable: 53
index: 55
53Variable
54ExprTuple55
55Variable