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 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(n, Conditional(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), InSet(n, 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())
n \mapsto \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] \textrm{ if } n \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: 44
body: 2
1ExprTuple44
2Conditionalvalue: 3
condition: 4
3Operationoperator: 12
operand: 7
4Operationoperator: 27
operands: 6
5ExprTuple7
6ExprTuple44, 8
7Lambdaparameters: 38
body: 9
8Literal
9Conditionalvalue: 10
condition: 11
10Operationoperator: 12
operand: 16
11Operationoperator: 14
operands: 15
12Literal
13ExprTuple16
14Literal
15ExprTuple17
16Lambdaparameter: 48
body: 19
17ExprRangelambda_map: 20
start_index: 43
end_index: 44
18ExprTuple48
19Conditionalvalue: 21
condition: 22
20Lambdaparameter: 51
body: 23
21Operationoperator: 24
operands: 25
22Operationoperator: 27
operands: 26
23Operationoperator: 27
operands: 28
24Literal
25ExprTuple29, 30
26ExprTuple48, 31
27Literal
28ExprTuple47, 32
29Operationoperator: 45
operands: 33
30Operationoperator: 37
operands: 34
31Variable
32Variable
33ExprTuple35, 48
34ExprTuple36
35Operationoperator: 37
operands: 38
36ExprRangelambda_map: 39
start_index: 43
end_index: 44
37Literal
38ExprTuple40
39Lambdaparameter: 51
body: 41
40ExprRangelambda_map: 42
start_index: 43
end_index: 44
41Operationoperator: 45
operands: 46
42Lambdaparameter: 51
body: 47
43Literal
44Variable
45Literal
46ExprTuple47, 48
47IndexedVarvariable: 49
index: 51
48Variable
49Variable
50ExprTuple51
51Variable