logo

Expression of type Conditional

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 Conditional, 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, InClass
from proveit.numbers import Natural, one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = Conditional(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), InClass(V, 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())
\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] \textrm{ if } V \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\right)\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 21
operand: 6
2Operationoperator: 4
operands: 5
3ExprTuple6
4Literal
5ExprTuple40, 7
6Lambdaparameter: 53
body: 9
7Operationoperator: 10
operand: 41
8ExprTuple53
9Conditionalvalue: 12
condition: 13
10Literal
11ExprTuple41
12Operationoperator: 21
operand: 16
13Operationoperator: 36
operands: 15
14ExprTuple16
15ExprTuple53, 17
16Lambdaparameters: 47
body: 18
17Literal
18Conditionalvalue: 19
condition: 20
19Operationoperator: 21
operand: 25
20Operationoperator: 23
operands: 24
21Literal
22ExprTuple25
23Literal
24ExprTuple26
25Lambdaparameter: 57
body: 28
26ExprRangelambda_map: 29
start_index: 52
end_index: 53
27ExprTuple57
28Conditionalvalue: 30
condition: 31
29Lambdaparameter: 60
body: 32
30Operationoperator: 33
operands: 34
31Operationoperator: 36
operands: 35
32Operationoperator: 36
operands: 37
33Literal
34ExprTuple38, 39
35ExprTuple57, 40
36Literal
37ExprTuple56, 41
38Operationoperator: 54
operands: 42
39Operationoperator: 46
operands: 43
40Variable
41Variable
42ExprTuple44, 57
43ExprTuple45
44Operationoperator: 46
operands: 47
45ExprRangelambda_map: 48
start_index: 52
end_index: 53
46Literal
47ExprTuple49
48Lambdaparameter: 60
body: 50
49ExprRangelambda_map: 51
start_index: 52
end_index: 53
50Operationoperator: 54
operands: 55
51Lambdaparameter: 60
body: 56
52Literal
53Variable
54Literal
55ExprTuple56, 57
56IndexedVarvariable: 58
index: 60
57Variable
58Variable
59ExprTuple60
60Variable