logo

Expression of type Conditional

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, 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 = 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\{\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()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8
5Literal
6ExprTuple9, 10, 11
7Operationoperator: 24
operands: 12
8Operationoperator: 22
operands: 13
9ExprRangelambda_map: 14
start_index: 37
end_index: 35
10Operationoperator: 27
operands: 15
11Operationoperator: 16
operands: 17
12ExprTuple18, 37
13ExprTuple29, 19, 20
14Lambdaparameter: 43
body: 21
15ExprTuple31, 33
16Literal
17ExprTuple31, 40
18Operationoperator: 22
operands: 23
19Operationoperator: 24
operands: 25
20ExprRangelambda_map: 26
start_index: 37
end_index: 38
21Operationoperator: 27
operands: 28
22Literal
23ExprTuple29, 31, 30
24Literal
25ExprTuple31, 37
26Lambdaparameter: 43
body: 32
27Literal
28ExprTuple39, 33
29ExprRangelambda_map: 34
start_index: 37
end_index: 35
30ExprRangelambda_map: 36
start_index: 37
end_index: 38
31Variable
32Literal
33Literal
34Lambdaparameter: 43
body: 39
35Variable
36Lambdaparameter: 43
body: 40
37Literal
38Variable
39IndexedVarvariable: 41
index: 43
40Literal
41Variable
42ExprTuple43
43Variable