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, VecSpaces
from proveit.logic import Equals, Forall, InClass
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(V, Conditional(Forall(instance_param_or_params = [n], instance_expr = 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), domain = Natural), InClass(V, VecSpaces(K))))
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())
V \mapsto \left\{\forall_{n \in \mathbb{N}}~\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]\right] \textrm{ if } V \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(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
0Lambdaparameter: 42
body: 2
1ExprTuple42
2Conditionalvalue: 3
condition: 4
3Operationoperator: 23
operand: 8
4Operationoperator: 6
operands: 7
5ExprTuple8
6Literal
7ExprTuple42, 9
8Lambdaparameter: 55
body: 11
9Operationoperator: 12
operand: 43
10ExprTuple55
11Conditionalvalue: 14
condition: 15
12Literal
13ExprTuple43
14Operationoperator: 23
operand: 18
15Operationoperator: 38
operands: 17
16ExprTuple18
17ExprTuple55, 19
18Lambdaparameters: 49
body: 20
19Literal
20Conditionalvalue: 21
condition: 22
21Operationoperator: 23
operand: 27
22Operationoperator: 25
operands: 26
23Literal
24ExprTuple27
25Literal
26ExprTuple28
27Lambdaparameter: 59
body: 30
28ExprRangelambda_map: 31
start_index: 54
end_index: 55
29ExprTuple59
30Conditionalvalue: 32
condition: 33
31Lambdaparameter: 62
body: 34
32Operationoperator: 35
operands: 36
33Operationoperator: 38
operands: 37
34Operationoperator: 38
operands: 39
35Literal
36ExprTuple40, 41
37ExprTuple59, 42
38Literal
39ExprTuple58, 43
40Operationoperator: 56
operands: 44
41Operationoperator: 48
operands: 45
42Variable
43Variable
44ExprTuple46, 59
45ExprTuple47
46Operationoperator: 48
operands: 49
47ExprRangelambda_map: 50
start_index: 54
end_index: 55
48Literal
49ExprTuple51
50Lambdaparameter: 62
body: 52
51ExprRangelambda_map: 53
start_index: 54
end_index: 55
52Operationoperator: 56
operands: 57
53Lambdaparameter: 62
body: 58
54Literal
55Variable
56Literal
57ExprTuple58, 59
58IndexedVarvariable: 60
index: 62
59Variable
60Variable
61ExprTuple62
62Variable