logo

Expression of type Forall

from the theory of proveit.linear_algebra.addition

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