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, 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 = 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\{\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()
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: 20
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8, 9, 10, 11, 12
6Operationoperator: 14
operands: 13
7Operationoperator: 14
operands: 15
8ExprRangelambda_map: 16
start_index: 46
end_index: 30
9ExprRangelambda_map: 17
start_index: 46
end_index: 47
10Operationoperator: 35
operands: 18
11ExprRangelambda_map: 19
start_index: 46
end_index: 32
12Operationoperator: 20
operands: 21
13ExprTuple22, 27, 23
14Literal
15ExprTuple22, 28, 23
16Lambdaparameter: 51
body: 24
17Lambdaparameter: 51
body: 25
18ExprTuple28, 41
19Lambdaparameter: 51
body: 26
20Literal
21ExprTuple27, 28
22ExprRangelambda_map: 29
start_index: 46
end_index: 30
23ExprRangelambda_map: 31
start_index: 46
end_index: 32
24Operationoperator: 35
operands: 33
25Operationoperator: 35
operands: 34
26Operationoperator: 35
operands: 36
27Operationoperator: 37
operands: 38
28Variable
29Lambdaparameter: 51
body: 39
30Variable
31Lambdaparameter: 51
body: 40
32Variable
33ExprTuple39, 41
34ExprTuple48, 41
35Literal
36ExprTuple40, 41
37Literal
38ExprTuple42
39IndexedVarvariable: 43
index: 51
40IndexedVarvariable: 44
index: 51
41Literal
42ExprRangelambda_map: 45
start_index: 46
end_index: 47
43Variable
44Variable
45Lambdaparameter: 51
body: 48
46Literal
47Variable
48IndexedVarvariable: 49
index: 51
49Variable
50ExprTuple51
51Variable