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
from proveit.logic import Equals, Forall, InSet
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 = [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), InSet(n, 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())
\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] \textrm{ if } n \in \mathbb{N}\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: 10
operand: 5
2Operationoperator: 25
operands: 4
3ExprTuple5
4ExprTuple42, 6
5Lambdaparameters: 36
body: 7
6Literal
7Conditionalvalue: 8
condition: 9
8Operationoperator: 10
operand: 14
9Operationoperator: 12
operands: 13
10Literal
11ExprTuple14
12Literal
13ExprTuple15
14Lambdaparameter: 46
body: 17
15ExprRangelambda_map: 18
start_index: 41
end_index: 42
16ExprTuple46
17Conditionalvalue: 19
condition: 20
18Lambdaparameter: 49
body: 21
19Operationoperator: 22
operands: 23
20Operationoperator: 25
operands: 24
21Operationoperator: 25
operands: 26
22Literal
23ExprTuple27, 28
24ExprTuple46, 29
25Literal
26ExprTuple45, 30
27Operationoperator: 43
operands: 31
28Operationoperator: 35
operands: 32
29Variable
30Variable
31ExprTuple33, 46
32ExprTuple34
33Operationoperator: 35
operands: 36
34ExprRangelambda_map: 37
start_index: 41
end_index: 42
35Literal
36ExprTuple38
37Lambdaparameter: 49
body: 39
38ExprRangelambda_map: 40
start_index: 41
end_index: 42
39Operationoperator: 43
operands: 44
40Lambdaparameter: 49
body: 45
41Literal
42Variable
43Literal
44ExprTuple45, 46
45IndexedVarvariable: 47
index: 49
46Variable
47Variable
48ExprTuple49
49Variable