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 Lambda, f, i, j, x
from proveit.core_expr_types import Len, f_i_to_j
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Add, Natural, Neg, two
In [2]:
# build up the expression from sub-expressions
expr = Lambda([f, x], Forall(instance_param_or_params = [i, j], instance_expr = Equals(Len(operands = [f_i_to_j, x]), Add(j, Neg(i), two)), condition = InSet(Len(operands = [f_i_to_j]), 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, x\right) \mapsto \left[\forall_{i, j~|~|\left(f\left(i\right), f\left(i + 1\right), \ldots, f\left(j\right)\right)| \in \mathbb{N}}~\left(|\left(f\left(i\right), f\left(i + 1\right), \ldots, f\left(j\right), x\right)| = \left(j - i + 2\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
0Lambdaparameters: 1
body: 2
1ExprTuple33, 23
2Operationoperator: 3
operand: 5
3Literal
4ExprTuple5
5Lambdaparameters: 6
body: 7
6ExprTuple31, 30
7Conditionalvalue: 8
condition: 9
8Operationoperator: 10
operands: 11
9Operationoperator: 12
operands: 13
10Literal
11ExprTuple14, 15
12Literal
13ExprTuple16, 17
14Operationoperator: 21
operands: 18
15Operationoperator: 19
operands: 20
16Operationoperator: 21
operands: 22
17Literal
18ExprTuple26, 23
19Literal
20ExprTuple30, 24, 25
21Literal
22ExprTuple26
23Variable
24Operationoperator: 27
operand: 31
25Literal
26ExprRangelambda_map: 29
start_index: 31
end_index: 30
27Literal
28ExprTuple31
29Lambdaparameter: 35
body: 32
30Variable
31Variable
32Operationoperator: 33
operand: 35
33Variable
34ExprTuple35
35Variable