logo

Expression of type Conditional

from the theory of proveit.core_expr_types.tuples

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, i, n
from proveit.core_expr_types import Len, f_1_to_n
from proveit.core_expr_types.tuples import f_1_to_i__1_to_n
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Mult, Natural, NaturalPos
In [2]:
# build up the expression from sub-expressions
expr = Conditional(Forall(instance_param_or_params = [f_1_to_n, i], instance_expr = Equals(Len(operands = [f_1_to_i__1_to_n]), Mult(n, i)).with_wrapping_at(1), condition = InSet(i, Natural)), InSet(n, NaturalPos))
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_{f_{1}, f_{2}, \ldots, f_{n}, i~|~i \in \mathbb{N}}~\left(\begin{array}{c} \begin{array}{l} |\left(f_{1}\left(1\right), f_{1}\left(2\right), \ldots, f_{1}\left(i\right), f_{2}\left(1\right), f_{2}\left(2\right), \ldots, f_{2}\left(i\right), \ldots\ldots, f_{n}\left(1\right), f_{n}\left(2\right), \ldots, f_{n}\left(i\right)\right)| \\  = \left(n \cdot i\right) \end{array} \end{array}\right) \textrm{ if } n \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: 16
operands: 5
3Literal
4ExprTuple6
5ExprTuple28, 7
6Lambdaparameters: 8
body: 9
7Literal
8ExprTuple10, 32
9Conditionalvalue: 11
condition: 12
10ExprRangelambda_map: 13
start_index: 31
end_index: 28
11Operationoperator: 14
operands: 15
12Operationoperator: 16
operands: 17
13Lambdaparameter: 38
body: 18
14Literal
15ExprTuple19, 20
16Literal
17ExprTuple32, 21
18IndexedVarvariable: 36
index: 38
19Operationoperator: 22
operands: 23
20Operationoperator: 24
operands: 25
21Literal
22Literal
23ExprTuple26
24Literal
25ExprTuple28, 32
26ExprRangelambda_map: 27
start_index: 31
end_index: 28
27Lambdaparameter: 39
body: 29
28Variable
29ExprRangelambda_map: 30
start_index: 31
end_index: 32
30Lambdaparameter: 38
body: 33
31Literal
32Variable
33Operationoperator: 34
operand: 38
34IndexedVarvariable: 36
index: 39
35ExprTuple38
36Variable
37ExprTuple39
38Variable
39Variable