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, i, k
from proveit.core_expr_types import a_1_to_i
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 = [i], instance_expr = Forall(instance_param_or_params = [k, a_1_to_i], instance_expr = Equals(VecAdd(ExprRange(sub_expr1, ScalarMult(k, IndexedVar(a, sub_expr1)), one, i)), ScalarMult(k, VecAdd(a_1_to_i))).with_wrapping_at(2), domains = [K, V]), 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_{i \in \mathbb{N}}~\left[\forall_{k \in K,\left(a_{1} \in V\right), \left(a_{2} \in V\right), \ldots, \left(a_{i} \in V\right)}~\left(\begin{array}{c} \begin{array}{l} \left(\left(k \cdot a_{1}\right) +  \left(k \cdot a_{2}\right) +  \ldots +  \left(k \cdot a_{i}\right)\right) =  \\ \left(k \cdot \left(a_{1} +  a_{2} +  \ldots +  a_{i}\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: 18
operand: 2
1ExprTuple2
2Lambdaparameter: 50
body: 4
3ExprTuple50
4Conditionalvalue: 5
condition: 6
5Operationoperator: 18
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple50, 11
10Lambdaparameter: 55
body: 13
11Operationoperator: 14
operand: 41
12ExprTuple55
13Conditionalvalue: 16
condition: 17
14Literal
15ExprTuple41
16Operationoperator: 18
operand: 21
17Operationoperator: 46
operands: 20
18Literal
19ExprTuple21
20ExprTuple55, 22
21Lambdaparameters: 23
body: 24
22Literal
23ExprTuple56, 49
24Conditionalvalue: 25
condition: 26
25Operationoperator: 27
operands: 28
26Operationoperator: 29
operands: 30
27Literal
28ExprTuple31, 32
29Literal
30ExprTuple33, 34
31Operationoperator: 44
operands: 35
32Operationoperator: 51
operands: 36
33Operationoperator: 46
operands: 37
34ExprRangelambda_map: 38
start_index: 54
end_index: 55
35ExprTuple39
36ExprTuple56, 40
37ExprTuple56, 41
38Lambdaparameter: 60
body: 42
39ExprRangelambda_map: 43
start_index: 54
end_index: 55
40Operationoperator: 44
operands: 45
41Variable
42Operationoperator: 46
operands: 47
43Lambdaparameter: 60
body: 48
44Literal
45ExprTuple49
46Literal
47ExprTuple57, 50
48Operationoperator: 51
operands: 52
49ExprRangelambda_map: 53
start_index: 54
end_index: 55
50Variable
51Literal
52ExprTuple56, 57
53Lambdaparameter: 60
body: 57
54Literal
55Variable
56Variable
57IndexedVarvariable: 58
index: 60
58Variable
59ExprTuple60
60Variable