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, v
from proveit.core_expr_types import a_1_to_n
from proveit.linear_algebra import ScalarMult, VecAdd, VecSpaces
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 = [V], instance_expr = Forall(instance_param_or_params = [n], instance_expr = Forall(instance_param_or_params = [a_1_to_n], instance_expr = Forall(instance_param_or_params = [v], instance_expr = Equals(ScalarMult(VecAdd(a_1_to_n), v), VecAdd(ExprRange(sub_expr1, ScalarMult(IndexedVar(a, sub_expr1), v), one, n))).with_wrapping_at(2), domain = V), domain = K), domain = Natural), domain = VecSpaces(K))
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 \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\right)}~\left[\forall_{n \in \mathbb{N}}~\left[\forall_{a_{1}, a_{2}, \ldots, a_{n} \in K}~\left[\forall_{v \in V}~\left(\begin{array}{c} \begin{array}{l} \left(\left(a_{1} +  a_{2} +  \ldots +  a_{n}\right) \cdot v\right) =  \\ \left(\left(a_{1} \cdot v\right) +  \left(a_{2} \cdot v\right) +  \ldots +  \left(a_{n} \cdot v\right)\right) \end{array} \end{array}\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: 25
operand: 2
1ExprTuple2
2Lambdaparameter: 44
body: 4
3ExprTuple44
4Conditionalvalue: 5
condition: 6
5Operationoperator: 25
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple44, 11
10Lambdaparameter: 57
body: 13
11Operationoperator: 14
operand: 45
12ExprTuple57
13Conditionalvalue: 16
condition: 17
14Literal
15ExprTuple45
16Operationoperator: 25
operand: 20
17Operationoperator: 40
operands: 19
18ExprTuple20
19ExprTuple57, 21
20Lambdaparameters: 51
body: 22
21Literal
22Conditionalvalue: 23
condition: 24
23Operationoperator: 25
operand: 29
24Operationoperator: 27
operands: 28
25Literal
26ExprTuple29
27Literal
28ExprTuple30
29Lambdaparameter: 61
body: 32
30ExprRangelambda_map: 33
start_index: 56
end_index: 57
31ExprTuple61
32Conditionalvalue: 34
condition: 35
33Lambdaparameter: 64
body: 36
34Operationoperator: 37
operands: 38
35Operationoperator: 40
operands: 39
36Operationoperator: 40
operands: 41
37Literal
38ExprTuple42, 43
39ExprTuple61, 44
40Literal
41ExprTuple60, 45
42Operationoperator: 58
operands: 46
43Operationoperator: 50
operands: 47
44Variable
45Variable
46ExprTuple48, 61
47ExprTuple49
48Operationoperator: 50
operands: 51
49ExprRangelambda_map: 52
start_index: 56
end_index: 57
50Literal
51ExprTuple53
52Lambdaparameter: 64
body: 54
53ExprRangelambda_map: 55
start_index: 56
end_index: 57
54Operationoperator: 58
operands: 59
55Lambdaparameter: 64
body: 60
56Literal
57Variable
58Literal
59ExprTuple60, 61
60IndexedVarvariable: 62
index: 64
61Variable
62Variable
63ExprTuple64
64Variable