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, n, x
from proveit.core_expr_types import x_1_to_n
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 = [n], instance_expr = Forall(instance_param_or_params = [a], instance_expr = Forall(instance_param_or_params = [x_1_to_n], instance_expr = Equals(ScalarMult(a, VecAdd(x_1_to_n)), VecAdd(ExprRange(sub_expr1, ScalarMult(a, IndexedVar(x, sub_expr1)), one, n))).with_wrapping_at(2), domain = V), domain = K), 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_{n \in \mathbb{N}}~\left[\forall_{a \in K}~\left[\forall_{x_{1}, x_{2}, \ldots, x_{n} \in V}~\left(\begin{array}{c} \begin{array}{l} \left(a \cdot \left(x_{1} +  x_{2} +  \ldots +  x_{n}\right)\right) =  \\ \left(\left(a \cdot x_{1}\right) +  \left(a \cdot x_{2}\right) +  \ldots +  \left(a \cdot x_{n}\right)\right) \end{array} \end{array}\right)\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: 31
body: 1
1Operationoperator: 27
operand: 3
2ExprTuple3
3Lambdaparameter: 55
body: 5
4ExprTuple55
5Conditionalvalue: 6
condition: 7
6Operationoperator: 27
operand: 11
7Operationoperator: 9
operands: 10
8ExprTuple11
9Literal
10ExprTuple55, 12
11Lambdaparameter: 58
body: 14
12Operationoperator: 15
operand: 31
13ExprTuple58
14Conditionalvalue: 17
condition: 18
15Literal
16ExprTuple31
17Operationoperator: 27
operand: 21
18Operationoperator: 51
operands: 20
19ExprTuple21
20ExprTuple58, 22
21Lambdaparameter: 61
body: 24
22Literal
23ExprTuple61
24Conditionalvalue: 25
condition: 26
25Operationoperator: 27
operand: 30
26Operationoperator: 51
operands: 29
27Literal
28ExprTuple30
29ExprTuple61, 31
30Lambdaparameters: 49
body: 32
31Variable
32Conditionalvalue: 33
condition: 34
33Operationoperator: 35
operands: 36
34Operationoperator: 37
operands: 38
35Literal
36ExprTuple39, 40
37Literal
38ExprTuple41
39Operationoperator: 59
operands: 42
40Operationoperator: 48
operands: 43
41ExprRangelambda_map: 44
start_index: 57
end_index: 58
42ExprTuple61, 45
43ExprTuple46
44Lambdaparameter: 65
body: 47
45Operationoperator: 48
operands: 49
46ExprRangelambda_map: 50
start_index: 57
end_index: 58
47Operationoperator: 51
operands: 52
48Literal
49ExprTuple53
50Lambdaparameter: 65
body: 54
51Literal
52ExprTuple62, 55
53ExprRangelambda_map: 56
start_index: 57
end_index: 58
54Operationoperator: 59
operands: 60
55Variable
56Lambdaparameter: 65
body: 62
57Literal
58Variable
59Literal
60ExprTuple61, 62
61Variable
62IndexedVarvariable: 63
index: 65
63Variable
64ExprTuple65
65Variable