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_1_to_n, 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 = [a_1_to_n], instance_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)), domain = 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_{a_{1}, a_{2}, \ldots, a_{n} \in \mathbb{C}}~\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)\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: 9
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple5
4Conditionalvalue: 6
condition: 7
5ExprRangelambda_map: 8
start_index: 64
end_index: 65
6Operationoperator: 9
operand: 13
7Operationoperator: 11
operands: 12
8Lambdaparameter: 37
body: 28
9Literal
10ExprTuple13
11Literal
12ExprTuple14
13Lambdaparameter: 52
body: 16
14ExprRangelambda_map: 17
start_index: 64
end_index: 65
15ExprTuple52
16Conditionalvalue: 18
condition: 19
17Lambdaparameter: 37
body: 20
18Operationoperator: 21
operands: 22
19Operationoperator: 50
operands: 23
20Operationoperator: 50
operands: 24
21Literal
22ExprTuple25, 26
23ExprTuple52, 27
24ExprTuple28, 36
25Operationoperator: 52
operand: 34
26Operationoperator: 38
operand: 35
27Operationoperator: 31
operands: 32
28IndexedVarvariable: 61
index: 37
29ExprTuple34
30ExprTuple35
31Literal
32ExprTuple36, 36
33ExprTuple37
34Operationoperator: 38
operand: 41
35Lambdaparameter: 72
body: 40
36Literal
37Variable
38Literal
39ExprTuple41
40Conditionalvalue: 42
condition: 46
41Lambdaparameter: 72
body: 43
42Operationoperator: 48
operands: 44
43Conditionalvalue: 45
condition: 46
44ExprTuple47, 54
45Operationoperator: 48
operands: 49
46Operationoperator: 50
operands: 51
47Operationoperator: 52
operand: 56
48Literal
49ExprTuple56, 54
50Literal
51ExprTuple72, 55
52Variable
53ExprTuple56
54Operationoperator: 57
operands: 58
55Operationoperator: 59
operands: 60
56IndexedVarvariable: 61
index: 72
57Literal
58ExprTuple62, 63
59Literal
60ExprTuple64, 65
61Variable
62Operationoperator: 66
operand: 69
63Operationoperator: 67
operand: 69
64Literal
65Variable
66Literal
67Literal
68ExprTuple69
69IndexedVarvariable: 70
index: 72
70Variable
71ExprTuple72
72Variable