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, x
from proveit.core_expr_types import x_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], 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), 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 \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] \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: 11
operand: 5
2Operationoperator: 35
operands: 4
3ExprTuple5
4ExprTuple42, 6
5Lambdaparameter: 45
body: 8
6Literal
7ExprTuple45
8Conditionalvalue: 9
condition: 10
9Operationoperator: 11
operand: 14
10Operationoperator: 35
operands: 13
11Literal
12ExprTuple14
13ExprTuple45, 15
14Lambdaparameters: 33
body: 16
15Variable
16Conditionalvalue: 17
condition: 18
17Operationoperator: 19
operands: 20
18Operationoperator: 21
operands: 22
19Literal
20ExprTuple23, 24
21Literal
22ExprTuple25
23Operationoperator: 43
operands: 26
24Operationoperator: 32
operands: 27
25ExprRangelambda_map: 28
start_index: 41
end_index: 42
26ExprTuple45, 29
27ExprTuple30
28Lambdaparameter: 49
body: 31
29Operationoperator: 32
operands: 33
30ExprRangelambda_map: 34
start_index: 41
end_index: 42
31Operationoperator: 35
operands: 36
32Literal
33ExprTuple37
34Lambdaparameter: 49
body: 38
35Literal
36ExprTuple46, 39
37ExprRangelambda_map: 40
start_index: 41
end_index: 42
38Operationoperator: 43
operands: 44
39Variable
40Lambdaparameter: 49
body: 46
41Literal
42Variable
43Literal
44ExprTuple45, 46
45Variable
46IndexedVarvariable: 47
index: 49
47Variable
48ExprTuple49
49Variable