logo

Expression of type Forall

from the theory of proveit.numbers.summation

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 k, m
from proveit.logic import Equals, Forall
from proveit.numbers import Add, Interval, Mult, NaturalPos, Sum, frac, one, two
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [k]
sub_expr2 = Add(m, one)
expr = Forall(instance_param_or_params = [m], instance_expr = Equals(Sum(index_or_indices = sub_expr1, summand = k, domain = Interval(one, sub_expr2)), frac(Mult(sub_expr2, Add(m, two)), two)), domain = NaturalPos, condition = Equals(Sum(index_or_indices = sub_expr1, summand = k, domain = Interval(one, m)), frac(Mult(m, sub_expr2), two)))
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())
\forall_{m \in \mathbb{N}^+~|~\left(\sum_{k = 1}^{m} k\right) = \frac{m \cdot \left(m + 1\right)}{2}}~\left(\left(\sum_{k = 1}^{m + 1} k\right) = \frac{\left(m + 1\right) \cdot \left(m + 2\right)}{2}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 55
body: 5
4ExprTuple55
5Conditionalvalue: 6
condition: 7
6Operationoperator: 18
operands: 8
7Operationoperator: 9
operands: 10
8ExprTuple11, 12
9Literal
10ExprTuple13, 14
11Operationoperator: 27
operand: 20
12Operationoperator: 29
operands: 16
13Operationoperator: 45
operands: 17
14Operationoperator: 18
operands: 19
15ExprTuple20
16ExprTuple21, 42
17ExprTuple55, 22
18Literal
19ExprTuple23, 24
20Lambdaparameter: 48
body: 25
21Operationoperator: 39
operands: 26
22Literal
23Operationoperator: 27
operand: 33
24Operationoperator: 29
operands: 30
25Conditionalvalue: 48
condition: 31
26ExprTuple47, 32
27Literal
28ExprTuple33
29Literal
30ExprTuple34, 42
31Operationoperator: 45
operands: 35
32Operationoperator: 50
operands: 36
33Lambdaparameter: 48
body: 38
34Operationoperator: 39
operands: 40
35ExprTuple48, 41
36ExprTuple55, 42
37ExprTuple48
38Conditionalvalue: 48
condition: 43
39Literal
40ExprTuple55, 47
41Operationoperator: 52
operands: 44
42Literal
43Operationoperator: 45
operands: 46
44ExprTuple54, 47
45Literal
46ExprTuple48, 49
47Operationoperator: 50
operands: 51
48Variable
49Operationoperator: 52
operands: 53
50Literal
51ExprTuple55, 54
52Literal
53ExprTuple54, 55
54Literal
55Variable