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, 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], 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), 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 \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]\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: 26
operand: 2
1ExprTuple2
2Lambdaparameter: 54
body: 4
3ExprTuple54
4Conditionalvalue: 5
condition: 6
5Operationoperator: 26
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple54, 11
10Lambdaparameter: 57
body: 13
11Operationoperator: 14
operand: 30
12ExprTuple57
13Conditionalvalue: 16
condition: 17
14Literal
15ExprTuple30
16Operationoperator: 26
operand: 20
17Operationoperator: 50
operands: 19
18ExprTuple20
19ExprTuple57, 21
20Lambdaparameter: 60
body: 23
21Literal
22ExprTuple60
23Conditionalvalue: 24
condition: 25
24Operationoperator: 26
operand: 29
25Operationoperator: 50
operands: 28
26Literal
27ExprTuple29
28ExprTuple60, 30
29Lambdaparameters: 48
body: 31
30Variable
31Conditionalvalue: 32
condition: 33
32Operationoperator: 34
operands: 35
33Operationoperator: 36
operands: 37
34Literal
35ExprTuple38, 39
36Literal
37ExprTuple40
38Operationoperator: 58
operands: 41
39Operationoperator: 47
operands: 42
40ExprRangelambda_map: 43
start_index: 56
end_index: 57
41ExprTuple60, 44
42ExprTuple45
43Lambdaparameter: 64
body: 46
44Operationoperator: 47
operands: 48
45ExprRangelambda_map: 49
start_index: 56
end_index: 57
46Operationoperator: 50
operands: 51
47Literal
48ExprTuple52
49Lambdaparameter: 64
body: 53
50Literal
51ExprTuple61, 54
52ExprRangelambda_map: 55
start_index: 56
end_index: 57
53Operationoperator: 58
operands: 59
54Variable
55Lambdaparameter: 64
body: 61
56Literal
57Variable
58Literal
59ExprTuple60, 61
60Variable
61IndexedVarvariable: 62
index: 64
62Variable
63ExprTuple64
64Variable