logo

Expression of type Lambda

from the theory of proveit.core_expr_types.tuples

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, Lambda
from proveit.core_expr_types import Len, f_1_to_n, i_1_to_n, j_1_to_n
from proveit.core_expr_types.tuples import f_ik_to_jk__1_to_n, range_len_conditions, range_len_sum
from proveit.logic import And, Equals
In [2]:
# build up the expression from sub-expressions
expr = Lambda([f_1_to_n, i_1_to_n, j_1_to_n], Conditional(Equals(Len(operands = [f_ik_to_jk__1_to_n]), range_len_sum).with_wrapping_at(1), And(range_len_conditions)))
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())
\left(f_{1}, f_{2}, \ldots, f_{n}, i_{1}, i_{2}, \ldots, i_{n}, j_{1}, j_{2}, \ldots, j_{n}\right) \mapsto \left\{\begin{array}{c} \begin{array}{l} |\left(f_{1}\left(i_{1}\right), f_{1}\left(i_{1} + 1\right), \ldots, f_{1}\left(j_{1}\right), f_{2}\left(i_{2}\right), f_{2}\left(i_{2} + 1\right), \ldots, f_{2}\left(j_{2}\right), \ldots\ldots, f_{n}\left(i_{n}\right), f_{n}\left(i_{n} + 1\right), \ldots, f_{n}\left(j_{n}\right)\right)| \\  = \left(\left(j_{1} - i_{1} + 1\right) +  \left(j_{2} - i_{2} + 1\right) +  \ldots +  \left(j_{n} - i_{n} + 1\right)\right) \end{array} \end{array} \textrm{ if } \left(\left(j_{1} - i_{1} + 1\right) \in \mathbb{N}\right) \land  \left(\left(j_{2} - i_{2} + 1\right) \in \mathbb{N}\right) \land  \ldots \land  \left(\left(j_{n} - i_{n} + 1\right) \in \mathbb{N}\right)\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple3, 4, 5
2Conditionalvalue: 6
condition: 7
3ExprRangelambda_map: 8
start_index: 42
end_index: 28
4ExprRangelambda_map: 9
start_index: 42
end_index: 28
5ExprRangelambda_map: 10
start_index: 42
end_index: 28
6Operationoperator: 11
operands: 12
7Operationoperator: 13
operands: 14
8Lambdaparameter: 53
body: 15
9Lambdaparameter: 53
body: 49
10Lambdaparameter: 53
body: 40
11Literal
12ExprTuple16, 17
13Literal
14ExprTuple18
15IndexedVarvariable: 47
index: 53
16Operationoperator: 19
operands: 20
17Operationoperator: 37
operands: 21
18ExprRangelambda_map: 22
start_index: 42
end_index: 28
19Literal
20ExprTuple23
21ExprTuple24
22Lambdaparameter: 53
body: 25
23ExprRangelambda_map: 26
start_index: 42
end_index: 28
24ExprRangelambda_map: 27
start_index: 42
end_index: 28
25Operationoperator: 29
operands: 30
26Lambdaparameter: 50
body: 31
27Lambdaparameter: 53
body: 32
28Variable
29Literal
30ExprTuple32, 33
31ExprRangelambda_map: 34
start_index: 35
end_index: 36
32Operationoperator: 37
operands: 38
33Literal
34Lambdaparameter: 53
body: 39
35IndexedVarvariable: 51
index: 50
36IndexedVarvariable: 44
index: 50
37Literal
38ExprTuple40, 41, 42
39Operationoperator: 43
operand: 53
40IndexedVarvariable: 44
index: 53
41Operationoperator: 45
operand: 49
42Literal
43IndexedVarvariable: 47
index: 50
44Variable
45Literal
46ExprTuple49
47Variable
48ExprTuple50
49IndexedVarvariable: 51
index: 53
50Variable
51Variable
52ExprTuple53
53Variable