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, i, k
from proveit.core_expr_types import a_1_to_i
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 = [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]), InSet(i, 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_{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) \textrm{ if } i \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: 3
operand: 6
2Operationoperator: 31
operands: 5
3Literal
4ExprTuple6
5ExprTuple40, 7
6Lambdaparameters: 8
body: 9
7Literal
8ExprTuple41, 34
9Conditionalvalue: 10
condition: 11
10Operationoperator: 12
operands: 13
11Operationoperator: 14
operands: 15
12Literal
13ExprTuple16, 17
14Literal
15ExprTuple18, 19
16Operationoperator: 29
operands: 20
17Operationoperator: 36
operands: 21
18Operationoperator: 31
operands: 22
19ExprRangelambda_map: 23
start_index: 39
end_index: 40
20ExprTuple24
21ExprTuple41, 25
22ExprTuple41, 26
23Lambdaparameter: 45
body: 27
24ExprRangelambda_map: 28
start_index: 39
end_index: 40
25Operationoperator: 29
operands: 30
26Variable
27Operationoperator: 31
operands: 32
28Lambdaparameter: 45
body: 33
29Literal
30ExprTuple34
31Literal
32ExprTuple42, 35
33Operationoperator: 36
operands: 37
34ExprRangelambda_map: 38
start_index: 39
end_index: 40
35Variable
36Literal
37ExprTuple41, 42
38Lambdaparameter: 45
body: 42
39Literal
40Variable
41Variable
42IndexedVarvariable: 43
index: 45
43Variable
44ExprTuple45
45Variable