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