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, c, d, k, m, n
from proveit.core_expr_types import b_1_to_n
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import Add, DecimalSequence, Digits, Natural, one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = ExprRange(sub_expr1, IndexedVar(a, sub_expr1), one, m)
sub_expr3 = ExprRange(sub_expr1, IndexedVar(d, sub_expr1), one, k)
sub_expr4 = Add(b_1_to_n)
expr = Lambda([m, n, k], Conditional(Forall(instance_param_or_params = [sub_expr2, b_1_to_n, c, sub_expr3], instance_expr = Equals(DecimalSequence(sub_expr2, sub_expr4, sub_expr3), DecimalSequence(sub_expr2, c, sub_expr3)), domain = Digits, condition = Equals(sub_expr4, c)), And(InSet(m, Natural), InSet(n, Natural), InSet(k, 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(m, n, k\right) \mapsto \left\{\forall_{a_{1}, a_{2}, \ldots, a_{m}, b_{1}, b_{2}, \ldots, b_{n}, c, d_{1}, d_{2}, \ldots, d_{k} \in \mathbb{N}^{\leq 9}~|~\left(b_{1} +  b_{2} +  \ldots +  b_{n}\right) = c}~\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})\right) \textrm{ if } m \in \mathbb{N} ,  n \in \mathbb{N} ,  k \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
1ExprTuple47, 64, 49
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 21
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10, 11
8Lambdaparameters: 12
body: 13
9Operationoperator: 52
operands: 14
10Operationoperator: 52
operands: 15
11Operationoperator: 52
operands: 16
12ExprTuple39, 59, 45, 40
13Conditionalvalue: 17
condition: 18
14ExprTuple47, 19
15ExprTuple64, 19
16ExprTuple49, 19
17Operationoperator: 37
operands: 20
18Operationoperator: 21
operands: 22
19Literal
20ExprTuple23, 24
21Literal
22ExprTuple25, 26, 27, 28, 29
23Operationoperator: 31
operands: 30
24Operationoperator: 31
operands: 32
25ExprRangelambda_map: 33
start_index: 63
end_index: 47
26ExprRangelambda_map: 34
start_index: 63
end_index: 64
27Operationoperator: 52
operands: 35
28ExprRangelambda_map: 36
start_index: 63
end_index: 49
29Operationoperator: 37
operands: 38
30ExprTuple39, 44, 40
31Literal
32ExprTuple39, 45, 40
33Lambdaparameter: 68
body: 41
34Lambdaparameter: 68
body: 42
35ExprTuple45, 58
36Lambdaparameter: 68
body: 43
37Literal
38ExprTuple44, 45
39ExprRangelambda_map: 46
start_index: 63
end_index: 47
40ExprRangelambda_map: 48
start_index: 63
end_index: 49
41Operationoperator: 52
operands: 50
42Operationoperator: 52
operands: 51
43Operationoperator: 52
operands: 53
44Operationoperator: 54
operands: 55
45Variable
46Lambdaparameter: 68
body: 56
47Variable
48Lambdaparameter: 68
body: 57
49Variable
50ExprTuple56, 58
51ExprTuple65, 58
52Literal
53ExprTuple57, 58
54Literal
55ExprTuple59
56IndexedVarvariable: 60
index: 68
57IndexedVarvariable: 61
index: 68
58Literal
59ExprRangelambda_map: 62
start_index: 63
end_index: 64
60Variable
61Variable
62Lambdaparameter: 68
body: 65
63Literal
64Variable
65IndexedVarvariable: 66
index: 68
66Variable
67ExprTuple68
68Variable