logo

Expression of type ExprTuple

from the theory of proveit.linear_algebra.scalar_multiplication

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, ExprTuple, IndexedVar, K, Lambda, V, Variable, a, n, v
from proveit.core_expr_types import a_1_to_n
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(a, sub_expr1)
expr = ExprTuple(Lambda([a_1_to_n], Conditional(Forall(instance_param_or_params = [v], instance_expr = Equals(ScalarMult(VecAdd(a_1_to_n), v), VecAdd(ExprRange(sub_expr1, ScalarMult(sub_expr2, v), one, n))).with_wrapping_at(2), domain = V), And(ExprRange(sub_expr1, InSet(sub_expr2, K), 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(\left(a_{1}, a_{2}, \ldots, a_{n}\right) \mapsto \left\{\forall_{v \in V}~\left(\begin{array}{c} \begin{array}{l} \left(\left(a_{1} +  a_{2} +  \ldots +  a_{n}\right) \cdot v\right) =  \\ \left(\left(a_{1} \cdot v\right) +  \left(a_{2} \cdot v\right) +  \ldots +  \left(a_{n} \cdot v\right)\right) \end{array} \end{array}\right) \textrm{ if } \left(a_{1} \in K\right) \land  \left(a_{2} \in K\right) \land  \ldots \land  \left(a_{n} \in K\right)\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameters: 31
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 9
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9
7Literal
8ExprTuple10
9Lambdaparameter: 41
body: 12
10ExprRangelambda_map: 13
start_index: 36
end_index: 37
11ExprTuple41
12Conditionalvalue: 14
condition: 15
13Lambdaparameter: 44
body: 16
14Operationoperator: 17
operands: 18
15Operationoperator: 20
operands: 19
16Operationoperator: 20
operands: 21
17Literal
18ExprTuple22, 23
19ExprTuple41, 24
20Literal
21ExprTuple40, 25
22Operationoperator: 38
operands: 26
23Operationoperator: 30
operands: 27
24Variable
25Variable
26ExprTuple28, 41
27ExprTuple29
28Operationoperator: 30
operands: 31
29ExprRangelambda_map: 32
start_index: 36
end_index: 37
30Literal
31ExprTuple33
32Lambdaparameter: 44
body: 34
33ExprRangelambda_map: 35
start_index: 36
end_index: 37
34Operationoperator: 38
operands: 39
35Lambdaparameter: 44
body: 40
36Literal
37Variable
38Literal
39ExprTuple40, 41
40IndexedVarvariable: 42
index: 44
41Variable
42Variable
43ExprTuple44
44Variable