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 And, Equals, Forall, InSet
from proveit.numbers import one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(a, sub_expr1)
expr = Conditional(Forall(instance_param_or_params = [v], instance_expr = Equals(ScalarMult(VecAdd(a_1_to_n), v), VecAdd(ExprRange(sub_expr1, ScalarMult(sub_expr2, v), one, n))).with_wrapping_at(2), domain = V), And(ExprRange(sub_expr1, InSet(sub_expr2, K), one, n)))
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_{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) \textrm{ if } \left(a_{1} \in K\right) \land  \left(a_{2} \in K\right) \land  \ldots \land  \left(a_{n} \in 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: 3
operand: 7
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7
5Literal
6ExprTuple8
7Lambdaparameter: 39
body: 10
8ExprRangelambda_map: 11
start_index: 34
end_index: 35
9ExprTuple39
10Conditionalvalue: 12
condition: 13
11Lambdaparameter: 42
body: 14
12Operationoperator: 15
operands: 16
13Operationoperator: 18
operands: 17
14Operationoperator: 18
operands: 19
15Literal
16ExprTuple20, 21
17ExprTuple39, 22
18Literal
19ExprTuple38, 23
20Operationoperator: 36
operands: 24
21Operationoperator: 28
operands: 25
22Variable
23Variable
24ExprTuple26, 39
25ExprTuple27
26Operationoperator: 28
operands: 29
27ExprRangelambda_map: 30
start_index: 34
end_index: 35
28Literal
29ExprTuple31
30Lambdaparameter: 42
body: 32
31ExprRangelambda_map: 33
start_index: 34
end_index: 35
32Operationoperator: 36
operands: 37
33Lambdaparameter: 42
body: 38
34Literal
35Variable
36Literal
37ExprTuple38, 39
38IndexedVarvariable: 40
index: 42
39Variable
40Variable
41ExprTuple42
42Variable