logo

Expression of type Forall

from the theory of proveit.linear_algebra.scalar_multiplication

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 ExprRange, IndexedVar, K, V, Variable, a, n, x
from proveit.core_expr_types import x_1_to_n
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.logic import Equals, Forall
from proveit.numbers import Natural, one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = Forall(instance_param_or_params = [n], instance_expr = Forall(instance_param_or_params = [a], instance_expr = Forall(instance_param_or_params = [x_1_to_n], instance_expr = Equals(ScalarMult(a, VecAdd(x_1_to_n)), VecAdd(ExprRange(sub_expr1, ScalarMult(a, IndexedVar(x, sub_expr1)), one, n))).with_wrapping_at(2), domain = V), domain = K), domain = 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())
\forall_{n \in \mathbb{N}}~\left[\forall_{a \in K}~\left[\forall_{x_{1}, x_{2}, \ldots, x_{n} \in V}~\left(\begin{array}{c} \begin{array}{l} \left(a \cdot \left(x_{1} +  x_{2} +  \ldots +  x_{n}\right)\right) =  \\ \left(\left(a \cdot x_{1}\right) +  \left(a \cdot x_{2}\right) +  \ldots +  \left(a \cdot x_{n}\right)\right) \end{array} \end{array}\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: 15
operand: 2
1ExprTuple2
2Lambdaparameter: 46
body: 4
3ExprTuple46
4Conditionalvalue: 5
condition: 6
5Operationoperator: 15
operand: 9
6Operationoperator: 39
operands: 8
7ExprTuple9
8ExprTuple46, 10
9Lambdaparameter: 49
body: 12
10Literal
11ExprTuple49
12Conditionalvalue: 13
condition: 14
13Operationoperator: 15
operand: 18
14Operationoperator: 39
operands: 17
15Literal
16ExprTuple18
17ExprTuple49, 19
18Lambdaparameters: 37
body: 20
19Variable
20Conditionalvalue: 21
condition: 22
21Operationoperator: 23
operands: 24
22Operationoperator: 25
operands: 26
23Literal
24ExprTuple27, 28
25Literal
26ExprTuple29
27Operationoperator: 47
operands: 30
28Operationoperator: 36
operands: 31
29ExprRangelambda_map: 32
start_index: 45
end_index: 46
30ExprTuple49, 33
31ExprTuple34
32Lambdaparameter: 53
body: 35
33Operationoperator: 36
operands: 37
34ExprRangelambda_map: 38
start_index: 45
end_index: 46
35Operationoperator: 39
operands: 40
36Literal
37ExprTuple41
38Lambdaparameter: 53
body: 42
39Literal
40ExprTuple50, 43
41ExprRangelambda_map: 44
start_index: 45
end_index: 46
42Operationoperator: 47
operands: 48
43Variable
44Lambdaparameter: 53
body: 50
45Literal
46Variable
47Literal
48ExprTuple49, 50
49Variable
50IndexedVarvariable: 51
index: 53
51Variable
52ExprTuple53
53Variable