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, i, j, n
from proveit.core_expr_types import Len, f_1_to_n, i_to_j_len
from proveit.core_expr_types.tuples import f_i_to_j__1_to_n
from proveit.logic import Equals, InSet
from proveit.numbers import Mult, Natural
In [2]:
# build up the expression from sub-expressions
expr = Lambda([f_1_to_n, i, j], Conditional(Equals(Len(operands = [f_i_to_j__1_to_n]), Mult(n, i_to_j_len)).with_wrapping_at(1), InSet(i_to_j_len, 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())
\left(f_{1}, f_{2}, \ldots, f_{n}, i, j\right) \mapsto \left\{\begin{array}{c} \begin{array}{l} |\left(f_{1}\left(i\right), f_{1}\left(i + 1\right), \ldots, f_{1}\left(j\right), f_{2}\left(i\right), f_{2}\left(i + 1\right), \ldots, f_{2}\left(j\right), \ldots\ldots, f_{n}\left(i\right), f_{n}\left(i + 1\right), \ldots, f_{n}\left(j\right)\right)| \\  = \left(n \cdot \left(j - i + 1\right)\right) \end{array} \end{array} \textrm{ if } \left(j - i + 1\right) \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
0Lambdaparameters: 1
body: 2
1ExprTuple3, 33, 29
2Conditionalvalue: 4
condition: 5
3ExprRangelambda_map: 6
start_index: 27
end_index: 22
4Operationoperator: 7
operands: 8
5Operationoperator: 9
operands: 10
6Lambdaparameter: 38
body: 11
7Literal
8ExprTuple12, 13
9Literal
10ExprTuple20, 14
11IndexedVarvariable: 36
index: 38
12Operationoperator: 15
operands: 16
13Operationoperator: 17
operands: 18
14Literal
15Literal
16ExprTuple19
17Literal
18ExprTuple22, 20
19ExprRangelambda_map: 21
start_index: 27
end_index: 22
20Operationoperator: 23
operands: 24
21Lambdaparameter: 39
body: 25
22Variable
23Literal
24ExprTuple29, 26, 27
25ExprRangelambda_map: 28
start_index: 33
end_index: 29
26Operationoperator: 30
operand: 33
27Literal
28Lambdaparameter: 38
body: 32
29Variable
30Literal
31ExprTuple33
32Operationoperator: 34
operand: 38
33Variable
34IndexedVarvariable: 36
index: 39
35ExprTuple38
36Variable
37ExprTuple39
38Variable
39Variable