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, k, m
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import Add, DecimalSequence, Digits, Less, Natural, nine, one, zero
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)
expr = Lambda([m, k], Conditional(Forall(instance_param_or_params = [sub_expr2, b], instance_expr = Equals(Add(DecimalSequence(sub_expr2, b, ExprRange(sub_expr1, nine, one, k)), one), DecimalSequence(sub_expr2, Add(b, one), ExprRange(sub_expr1, zero, one, k))), domain = Digits, condition = Less(b, nine)), And(InSet(m, 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, k\right) \mapsto \left\{\forall_{a_{1}, a_{2}, \ldots, a_{m}, b \in \mathbb{N}^{\leq 9}~|~b < 9}~\left(\left(\texttt{\#}(a_{1}, a_{2}, \ldots, a_{m} ~ b ~ 9, 9, ..\left(k - 3\right) \times.., 9) + 1\right) = \texttt{\#}(a_{1}, a_{2}, \ldots, a_{m} ~ \left(b + 1\right) ~ 0, 0, ..\left(k - 3\right) \times.., 0)\right) \textrm{ if } m \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
1ExprTuple50, 53
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 20
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameters: 11
body: 12
9Operationoperator: 42
operands: 13
10Operationoperator: 42
operands: 14
11ExprTuple44, 46
12Conditionalvalue: 15
condition: 16
13ExprTuple50, 17
14ExprTuple53, 17
15Operationoperator: 18
operands: 19
16Operationoperator: 20
operands: 21
17Literal
18Literal
19ExprTuple22, 23
20Literal
21ExprTuple24, 25, 26
22Operationoperator: 39
operands: 27
23Operationoperator: 37
operands: 28
24ExprRangelambda_map: 29
start_index: 52
end_index: 50
25Operationoperator: 42
operands: 30
26Operationoperator: 31
operands: 32
27ExprTuple33, 52
28ExprTuple44, 34, 35
29Lambdaparameter: 58
body: 36
30ExprTuple46, 48
31Literal
32ExprTuple46, 55
33Operationoperator: 37
operands: 38
34Operationoperator: 39
operands: 40
35ExprRangelambda_map: 41
start_index: 52
end_index: 53
36Operationoperator: 42
operands: 43
37Literal
38ExprTuple44, 46, 45
39Literal
40ExprTuple46, 52
41Lambdaparameter: 58
body: 47
42Literal
43ExprTuple54, 48
44ExprRangelambda_map: 49
start_index: 52
end_index: 50
45ExprRangelambda_map: 51
start_index: 52
end_index: 53
46Variable
47Literal
48Literal
49Lambdaparameter: 58
body: 54
50Variable
51Lambdaparameter: 58
body: 55
52Literal
53Variable
54IndexedVarvariable: 56
index: 58
55Literal
56Variable
57ExprTuple58
58Variable