logo

Expression of type Lambda

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, Lambda, 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 = Lambda([x_1_to_n, y], 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(x_{1}, x_{2}, \ldots, x_{n}, y\right) \mapsto \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()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple29, 38
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10
7Literal
8ExprTuple11, 12, 13
9Operationoperator: 35
operands: 14
10Operationoperator: 24
operands: 15
11ExprRangelambda_map: 16
start_index: 33
end_index: 34
12Operationoperator: 27
operands: 17
13Operationoperator: 18
operands: 19
14ExprTuple20, 38
15ExprTuple21
16Lambdaparameter: 41
body: 22
17ExprTuple38, 31
18Literal
19ExprTuple38, 23
20Operationoperator: 24
operands: 25
21ExprRangelambda_map: 26
start_index: 33
end_index: 34
22Operationoperator: 27
operands: 28
23Literal
24Literal
25ExprTuple29
26Lambdaparameter: 41
body: 30
27Literal
28ExprTuple37, 31
29ExprRangelambda_map: 32
start_index: 33
end_index: 34
30Operationoperator: 35
operands: 36
31Literal
32Lambdaparameter: 41
body: 37
33Literal
34Variable
35Literal
36ExprTuple37, 38
37IndexedVarvariable: 39
index: 41
38Variable
39Variable
40ExprTuple41
41Variable