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, InSet
from proveit.numbers import Add, DecimalSequence, Digits, Less, nine, one, zero
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 = ExprRange(sub_expr1, sub_expr2, one, m)
expr = Lambda([sub_expr3, b], Conditional(Equals(Add(DecimalSequence(sub_expr3, b, ExprRange(sub_expr1, nine, one, k)), one), DecimalSequence(sub_expr3, Add(b, one), ExprRange(sub_expr1, zero, one, k))), And(ExprRange(sub_expr1, InSet(sub_expr2, Digits), one, m), InSet(b, Digits), Less(b, nine))))
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\right) \mapsto \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) \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) ,  b \in \mathbb{N}^{\leq 9} ,  b < 9\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
1ExprTuple31, 33
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10
7Literal
8ExprTuple11, 12, 13
9Operationoperator: 26
operands: 14
10Operationoperator: 24
operands: 15
11ExprRangelambda_map: 16
start_index: 39
end_index: 37
12Operationoperator: 29
operands: 17
13Operationoperator: 18
operands: 19
14ExprTuple20, 39
15ExprTuple31, 21, 22
16Lambdaparameter: 45
body: 23
17ExprTuple33, 35
18Literal
19ExprTuple33, 42
20Operationoperator: 24
operands: 25
21Operationoperator: 26
operands: 27
22ExprRangelambda_map: 28
start_index: 39
end_index: 40
23Operationoperator: 29
operands: 30
24Literal
25ExprTuple31, 33, 32
26Literal
27ExprTuple33, 39
28Lambdaparameter: 45
body: 34
29Literal
30ExprTuple41, 35
31ExprRangelambda_map: 36
start_index: 39
end_index: 37
32ExprRangelambda_map: 38
start_index: 39
end_index: 40
33Variable
34Literal
35Literal
36Lambdaparameter: 45
body: 41
37Variable
38Lambdaparameter: 45
body: 42
39Literal
40Variable
41IndexedVarvariable: 43
index: 45
42Literal
43Variable
44ExprTuple45
45Variable