logo

Expression of type Lambda

from the theory of proveit.numbers.numerals.decimals

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, Lambda, Variable, a, b, c, d, k, m, n
from proveit.core_expr_types import b_1_to_n
from proveit.logic import And, Equals, InSet
from proveit.numbers import Add, DecimalSequence, Digits, one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(a, sub_expr1)
sub_expr3 = IndexedVar(d, sub_expr1)
sub_expr4 = ExprRange(sub_expr1, sub_expr2, one, m)
sub_expr5 = ExprRange(sub_expr1, sub_expr3, one, k)
sub_expr6 = Add(b_1_to_n)
expr = Lambda([sub_expr4, b_1_to_n, c, sub_expr5], Conditional(Equals(DecimalSequence(sub_expr4, sub_expr6, sub_expr5), DecimalSequence(sub_expr4, c, sub_expr5)), And(ExprRange(sub_expr1, InSet(sub_expr2, Digits), one, m), ExprRange(sub_expr1, InSet(IndexedVar(b, sub_expr1), Digits), one, n), InSet(c, Digits), ExprRange(sub_expr1, InSet(sub_expr3, Digits), one, k), Equals(sub_expr6, c))))
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(a_{1}, a_{2}, \ldots, a_{m}, b_{1}, b_{2}, \ldots, b_{n}, c, d_{1}, d_{2}, \ldots, d_{k}\right) \mapsto \left\{\texttt{\#}(a_{1}, a_{2}, \ldots, a_{m} ~ \left(b_{1} +  b_{2} +  \ldots +  b_{n}\right) ~ d_{1}, d_{2}, \ldots, d_{k}) = \texttt{\#}(a_{1}, a_{2}, \ldots, a_{m} ~ c ~ d_{1}, d_{2}, \ldots, d_{k}) \textrm{ if } \left(a_{1} \in \mathbb{N}^{\leq 9}\right) ,  \left(a_{2} \in \mathbb{N}^{\leq 9}\right) ,  \ldots ,  \left(a_{m} \in \mathbb{N}^{\leq 9}\right), \left(b_{1} \in \mathbb{N}^{\leq 9}\right) ,  \left(b_{2} \in \mathbb{N}^{\leq 9}\right) ,  \ldots ,  \left(b_{n} \in \mathbb{N}^{\leq 9}\right) ,  c \in \mathbb{N}^{\leq 9}, \left(d_{1} \in \mathbb{N}^{\leq 9}\right) ,  \left(d_{2} \in \mathbb{N}^{\leq 9}\right) ,  \ldots ,  \left(d_{k} \in \mathbb{N}^{\leq 9}\right) ,  \left(b_{1} +  b_{2} +  \ldots +  b_{n}\right) = c\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
1ExprTuple24, 44, 30, 25
2Conditionalvalue: 3
condition: 4
3Operationoperator: 22
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple8, 9
6Literal
7ExprTuple10, 11, 12, 13, 14
8Operationoperator: 16
operands: 15
9Operationoperator: 16
operands: 17
10ExprRangelambda_map: 18
start_index: 48
end_index: 32
11ExprRangelambda_map: 19
start_index: 48
end_index: 49
12Operationoperator: 37
operands: 20
13ExprRangelambda_map: 21
start_index: 48
end_index: 34
14Operationoperator: 22
operands: 23
15ExprTuple24, 29, 25
16Literal
17ExprTuple24, 30, 25
18Lambdaparameter: 53
body: 26
19Lambdaparameter: 53
body: 27
20ExprTuple30, 43
21Lambdaparameter: 53
body: 28
22Literal
23ExprTuple29, 30
24ExprRangelambda_map: 31
start_index: 48
end_index: 32
25ExprRangelambda_map: 33
start_index: 48
end_index: 34
26Operationoperator: 37
operands: 35
27Operationoperator: 37
operands: 36
28Operationoperator: 37
operands: 38
29Operationoperator: 39
operands: 40
30Variable
31Lambdaparameter: 53
body: 41
32Variable
33Lambdaparameter: 53
body: 42
34Variable
35ExprTuple41, 43
36ExprTuple50, 43
37Literal
38ExprTuple42, 43
39Literal
40ExprTuple44
41IndexedVarvariable: 45
index: 53
42IndexedVarvariable: 46
index: 53
43Literal
44ExprRangelambda_map: 47
start_index: 48
end_index: 49
45Variable
46Variable
47Lambdaparameter: 53
body: 50
48Literal
49Variable
50IndexedVarvariable: 51
index: 53
51Variable
52ExprTuple53
53Variable