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 Equals, Forall, InSet
from proveit.numbers import Natural, one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = ExprTuple(Lambda(n, Conditional(Forall(instance_param_or_params = [a_1_to_n], instance_expr = Forall(instance_param_or_params = [v], instance_expr = Equals(ScalarMult(VecAdd(a_1_to_n), v), VecAdd(ExprRange(sub_expr1, ScalarMult(IndexedVar(a, sub_expr1), v), one, n))).with_wrapping_at(2), domain = V), domain = K), InSet(n, Natural))))
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(n \mapsto \left\{\forall_{a_{1}, a_{2}, \ldots, a_{n} \in K}~\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)\right] \textrm{ if } n \in \mathbb{N}\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
1Lambdaparameter: 45
body: 3
2ExprTuple45
3Conditionalvalue: 4
condition: 5
4Operationoperator: 13
operand: 8
5Operationoperator: 28
operands: 7
6ExprTuple8
7ExprTuple45, 9
8Lambdaparameters: 39
body: 10
9Literal
10Conditionalvalue: 11
condition: 12
11Operationoperator: 13
operand: 17
12Operationoperator: 15
operands: 16
13Literal
14ExprTuple17
15Literal
16ExprTuple18
17Lambdaparameter: 49
body: 20
18ExprRangelambda_map: 21
start_index: 44
end_index: 45
19ExprTuple49
20Conditionalvalue: 22
condition: 23
21Lambdaparameter: 52
body: 24
22Operationoperator: 25
operands: 26
23Operationoperator: 28
operands: 27
24Operationoperator: 28
operands: 29
25Literal
26ExprTuple30, 31
27ExprTuple49, 32
28Literal
29ExprTuple48, 33
30Operationoperator: 46
operands: 34
31Operationoperator: 38
operands: 35
32Variable
33Variable
34ExprTuple36, 49
35ExprTuple37
36Operationoperator: 38
operands: 39
37ExprRangelambda_map: 40
start_index: 44
end_index: 45
38Literal
39ExprTuple41
40Lambdaparameter: 52
body: 42
41ExprRangelambda_map: 43
start_index: 44
end_index: 45
42Operationoperator: 46
operands: 47
43Lambdaparameter: 52
body: 48
44Literal
45Variable
46Literal
47ExprTuple48, 49
48IndexedVarvariable: 50
index: 52
49Variable
50Variable
51ExprTuple52
52Variable