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, 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], 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), 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 \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]\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: 22
operand: 6
2Operationoperator: 4
operands: 5
3ExprTuple6
4Literal
5ExprTuple50, 7
6Lambdaparameter: 53
body: 9
7Operationoperator: 10
operand: 26
8ExprTuple53
9Conditionalvalue: 12
condition: 13
10Literal
11ExprTuple26
12Operationoperator: 22
operand: 16
13Operationoperator: 46
operands: 15
14ExprTuple16
15ExprTuple53, 17
16Lambdaparameter: 56
body: 19
17Literal
18ExprTuple56
19Conditionalvalue: 20
condition: 21
20Operationoperator: 22
operand: 25
21Operationoperator: 46
operands: 24
22Literal
23ExprTuple25
24ExprTuple56, 26
25Lambdaparameters: 44
body: 27
26Variable
27Conditionalvalue: 28
condition: 29
28Operationoperator: 30
operands: 31
29Operationoperator: 32
operands: 33
30Literal
31ExprTuple34, 35
32Literal
33ExprTuple36
34Operationoperator: 54
operands: 37
35Operationoperator: 43
operands: 38
36ExprRangelambda_map: 39
start_index: 52
end_index: 53
37ExprTuple56, 40
38ExprTuple41
39Lambdaparameter: 60
body: 42
40Operationoperator: 43
operands: 44
41ExprRangelambda_map: 45
start_index: 52
end_index: 53
42Operationoperator: 46
operands: 47
43Literal
44ExprTuple48
45Lambdaparameter: 60
body: 49
46Literal
47ExprTuple57, 50
48ExprRangelambda_map: 51
start_index: 52
end_index: 53
49Operationoperator: 54
operands: 55
50Variable
51Lambdaparameter: 60
body: 57
52Literal
53Variable
54Literal
55ExprTuple56, 57
56Variable
57IndexedVarvariable: 58
index: 60
58Variable
59ExprTuple60
60Variable