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, i, k
from proveit.core_expr_types import a_1_to_i
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 = Lambda(i, Conditional(Forall(instance_param_or_params = [k, a_1_to_i], instance_expr = Equals(VecAdd(ExprRange(sub_expr1, ScalarMult(k, IndexedVar(a, sub_expr1)), one, i)), ScalarMult(k, VecAdd(a_1_to_i))).with_wrapping_at(2), domains = [K, V]), InSet(i, 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())
i \mapsto \left\{\forall_{k \in K,\left(a_{1} \in V\right), \left(a_{2} \in V\right), \ldots, \left(a_{i} \in V\right)}~\left(\begin{array}{c} \begin{array}{l} \left(\left(k \cdot a_{1}\right) +  \left(k \cdot a_{2}\right) +  \ldots +  \left(k \cdot a_{i}\right)\right) =  \\ \left(k \cdot \left(a_{1} +  a_{2} +  \ldots +  a_{i}\right)\right) \end{array} \end{array}\right) \textrm{ if } i \in \mathbb{N}\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 42
body: 2
1ExprTuple42
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 33
operands: 7
5Literal
6ExprTuple8
7ExprTuple42, 9
8Lambdaparameters: 10
body: 11
9Literal
10ExprTuple43, 36
11Conditionalvalue: 12
condition: 13
12Operationoperator: 14
operands: 15
13Operationoperator: 16
operands: 17
14Literal
15ExprTuple18, 19
16Literal
17ExprTuple20, 21
18Operationoperator: 31
operands: 22
19Operationoperator: 38
operands: 23
20Operationoperator: 33
operands: 24
21ExprRangelambda_map: 25
start_index: 41
end_index: 42
22ExprTuple26
23ExprTuple43, 27
24ExprTuple43, 28
25Lambdaparameter: 47
body: 29
26ExprRangelambda_map: 30
start_index: 41
end_index: 42
27Operationoperator: 31
operands: 32
28Variable
29Operationoperator: 33
operands: 34
30Lambdaparameter: 47
body: 35
31Literal
32ExprTuple36
33Literal
34ExprTuple44, 37
35Operationoperator: 38
operands: 39
36ExprRangelambda_map: 40
start_index: 41
end_index: 42
37Variable
38Literal
39ExprTuple43, 44
40Lambdaparameter: 47
body: 44
41Literal
42Variable
43Variable
44IndexedVarvariable: 45
index: 47
45Variable
46ExprTuple47
47Variable