logo

Expression of type Conditional

from the theory of proveit.numbers.division

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, Variable, n, x, y
from proveit.core_expr_types import x_1_to_n
from proveit.logic import And, Equals, InSet, NotEquals
from proveit.numbers import Add, Complex, frac, one, zero
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(x, sub_expr1)
expr = Conditional(Equals(frac(Add(x_1_to_n), y), Add(ExprRange(sub_expr1, frac(sub_expr2, y), one, n))), And(ExprRange(sub_expr1, InSet(sub_expr2, Complex), one, n), InSet(y, Complex), NotEquals(y, zero)))
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\{\frac{x_{1} +  x_{2} +  \ldots +  x_{n}}{y} = \left(\frac{x_{1}}{y} +  \frac{x_{2}}{y} +  \ldots +  \frac{x_{n}}{y}\right) \textrm{ if } \left(x_{1} \in \mathbb{C}\right) ,  \left(x_{2} \in \mathbb{C}\right) ,  \ldots ,  \left(x_{n} \in \mathbb{C}\right) ,  y \in \mathbb{C} ,  y \neq 0\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
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8
5Literal
6ExprTuple9, 10, 11
7Operationoperator: 33
operands: 12
8Operationoperator: 22
operands: 13
9ExprRangelambda_map: 14
start_index: 31
end_index: 32
10Operationoperator: 25
operands: 15
11Operationoperator: 16
operands: 17
12ExprTuple18, 36
13ExprTuple19
14Lambdaparameter: 39
body: 20
15ExprTuple36, 29
16Literal
17ExprTuple36, 21
18Operationoperator: 22
operands: 23
19ExprRangelambda_map: 24
start_index: 31
end_index: 32
20Operationoperator: 25
operands: 26
21Literal
22Literal
23ExprTuple27
24Lambdaparameter: 39
body: 28
25Literal
26ExprTuple35, 29
27ExprRangelambda_map: 30
start_index: 31
end_index: 32
28Operationoperator: 33
operands: 34
29Literal
30Lambdaparameter: 39
body: 35
31Literal
32Variable
33Literal
34ExprTuple35, 36
35IndexedVarvariable: 37
index: 39
36Variable
37Variable
38ExprTuple39
39Variable