logo

Expression of type Lambda

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, 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 = 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(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..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 30
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 8
3Operationoperator: 6
operands: 7
4Literal
5ExprTuple8
6Literal
7ExprTuple9
8Lambdaparameter: 40
body: 11
9ExprRangelambda_map: 12
start_index: 35
end_index: 36
10ExprTuple40
11Conditionalvalue: 13
condition: 14
12Lambdaparameter: 43
body: 15
13Operationoperator: 16
operands: 17
14Operationoperator: 19
operands: 18
15Operationoperator: 19
operands: 20
16Literal
17ExprTuple21, 22
18ExprTuple40, 23
19Literal
20ExprTuple39, 24
21Operationoperator: 37
operands: 25
22Operationoperator: 29
operands: 26
23Variable
24Variable
25ExprTuple27, 40
26ExprTuple28
27Operationoperator: 29
operands: 30
28ExprRangelambda_map: 31
start_index: 35
end_index: 36
29Literal
30ExprTuple32
31Lambdaparameter: 43
body: 33
32ExprRangelambda_map: 34
start_index: 35
end_index: 36
33Operationoperator: 37
operands: 38
34Lambdaparameter: 43
body: 39
35Literal
36Variable
37Literal
38ExprTuple39, 40
39IndexedVarvariable: 41
index: 43
40Variable
41Variable
42ExprTuple43
43Variable