logo

Expression of type Lambda

from the theory of proveit.numbers.summation

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, Lambda, k, n
from proveit.logic import Equals, InSet
from proveit.numbers import Add, Interval, Mult, NaturalPos, Sum, frac, one, two
In [2]:
# build up the expression from sub-expressions
expr = Lambda(n, Conditional(Equals(Sum(index_or_indices = [k], summand = k, domain = Interval(one, n)), frac(Mult(n, Add(n, one)), two)), InSet(n, NaturalPos)))
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())
n \mapsto \left\{\left(\sum_{k = 1}^{n} k\right) = \frac{n \cdot \left(n + 1\right)}{2} \textrm{ if } n \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 33
body: 2
1ExprTuple33
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 24
operands: 7
5Literal
6ExprTuple8, 9
7ExprTuple33, 10
8Operationoperator: 11
operand: 15
9Operationoperator: 13
operands: 14
10Literal
11Literal
12ExprTuple15
13Literal
14ExprTuple16, 17
15Lambdaparameter: 28
body: 19
16Operationoperator: 20
operands: 21
17Literal
18ExprTuple28
19Conditionalvalue: 28
condition: 22
20Literal
21ExprTuple33, 23
22Operationoperator: 24
operands: 25
23Operationoperator: 26
operands: 27
24Literal
25ExprTuple28, 29
26Literal
27ExprTuple33, 32
28Variable
29Operationoperator: 30
operands: 31
30Literal
31ExprTuple32, 33
32Literal
33Variable