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 a, b, c, fx, x
from proveit.logic import Equals, Forall
from proveit.numbers import Add, Integer, Interval, Less, LessEq, Sum, one, subtract
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
expr = Forall(instance_param_or_params = [a, b, c], instance_expr = Equals(Sum(index_or_indices = sub_expr1, summand = fx, domain = Interval(a, c)), Add(Sum(index_or_indices = sub_expr1, summand = fx, domain = Interval(a, subtract(b, one))), Sum(index_or_indices = sub_expr1, summand = fx, domain = Interval(b, c)))), domain = Integer, conditions = [Less(a, b), LessEq(b, 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())
\forall_{a, b, c \in \mathbb{Z}~|~a < b, b \leq c}~\left(\left(\sum_{x = a}^{c} f\left(x\right)\right) = \left(\left(\sum_{x = a}^{b - 1} f\left(x\right)\right) + \left(\sum_{x = b}^{c} f\left(x\right)\right)\right)\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
3Lambdaparameters: 4
body: 5
4ExprTuple57, 62, 59
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13
10Literal
11ExprTuple14, 15, 16, 17, 18
12Operationoperator: 33
operand: 27
13Operationoperator: 60
operands: 20
14Operationoperator: 49
operands: 21
15Operationoperator: 49
operands: 22
16Operationoperator: 49
operands: 23
17Operationoperator: 24
operands: 25
18Operationoperator: 26
operands: 56
19ExprTuple27
20ExprTuple28, 29
21ExprTuple57, 30
22ExprTuple62, 30
23ExprTuple59, 30
24Literal
25ExprTuple57, 62
26Literal
27Lambdaparameter: 52
body: 31
28Operationoperator: 33
operand: 36
29Operationoperator: 33
operand: 37
30Literal
31Conditionalvalue: 43
condition: 35
32ExprTuple36
33Literal
34ExprTuple37
35Operationoperator: 49
operands: 38
36Lambdaparameter: 52
body: 39
37Lambdaparameter: 52
body: 40
38ExprTuple52, 41
39Conditionalvalue: 43
condition: 42
40Conditionalvalue: 43
condition: 44
41Operationoperator: 55
operands: 45
42Operationoperator: 49
operands: 46
43Operationoperator: 47
operand: 52
44Operationoperator: 49
operands: 50
45ExprTuple57, 59
46ExprTuple52, 51
47Variable
48ExprTuple52
49Literal
50ExprTuple52, 53
51Operationoperator: 55
operands: 54
52Variable
53Operationoperator: 55
operands: 56
54ExprTuple57, 58
55Literal
56ExprTuple62, 59
57Variable
58Operationoperator: 60
operands: 61
59Variable
60Literal
61ExprTuple62, 63
62Variable
63Operationoperator: 64
operand: 66
64Literal
65ExprTuple66
66Literal