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, 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 = 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\{\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()
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
operand: 6
2Operationoperator: 19
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8, 9
6Lambdaparameters: 10
body: 11
7Operationoperator: 50
operands: 12
8Operationoperator: 50
operands: 13
9Operationoperator: 50
operands: 14
10ExprTuple37, 57, 43, 38
11Conditionalvalue: 15
condition: 16
12ExprTuple45, 17
13ExprTuple62, 17
14ExprTuple47, 17
15Operationoperator: 35
operands: 18
16Operationoperator: 19
operands: 20
17Literal
18ExprTuple21, 22
19Literal
20ExprTuple23, 24, 25, 26, 27
21Operationoperator: 29
operands: 28
22Operationoperator: 29
operands: 30
23ExprRangelambda_map: 31
start_index: 61
end_index: 45
24ExprRangelambda_map: 32
start_index: 61
end_index: 62
25Operationoperator: 50
operands: 33
26ExprRangelambda_map: 34
start_index: 61
end_index: 47
27Operationoperator: 35
operands: 36
28ExprTuple37, 42, 38
29Literal
30ExprTuple37, 43, 38
31Lambdaparameter: 66
body: 39
32Lambdaparameter: 66
body: 40
33ExprTuple43, 56
34Lambdaparameter: 66
body: 41
35Literal
36ExprTuple42, 43
37ExprRangelambda_map: 44
start_index: 61
end_index: 45
38ExprRangelambda_map: 46
start_index: 61
end_index: 47
39Operationoperator: 50
operands: 48
40Operationoperator: 50
operands: 49
41Operationoperator: 50
operands: 51
42Operationoperator: 52
operands: 53
43Variable
44Lambdaparameter: 66
body: 54
45Variable
46Lambdaparameter: 66
body: 55
47Variable
48ExprTuple54, 56
49ExprTuple63, 56
50Literal
51ExprTuple55, 56
52Literal
53ExprTuple57
54IndexedVarvariable: 58
index: 66
55IndexedVarvariable: 59
index: 66
56Literal
57ExprRangelambda_map: 60
start_index: 61
end_index: 62
58Variable
59Variable
60Lambdaparameter: 66
body: 63
61Literal
62Variable
63IndexedVarvariable: 64
index: 66
64Variable
65ExprTuple66
66Variable