logo

Expression of type Lambda

from the theory of proveit.logic.sets.cardinality

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, N, S, n
from proveit.core_expr_types import Len, x_1_to_n
from proveit.logic import Card, Distinct, Equals, Exists, Forall, InSet
from proveit.numbers import NaturalPos, greater_eq
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x_1_to_n]
expr = Lambda(n, Conditional(Forall(instance_param_or_params = [S, N], instance_expr = Exists(instance_param_or_params = sub_expr1, instance_expr = Distinct(x_1_to_n), domain = S, condition = Equals(Len(operands = sub_expr1), N)), condition = greater_eq(Card(S), N)), 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\{\forall_{S, N~|~|S| \geq N}~\left[\exists_{x_{1}, x_{2}, \ldots, x_{n} \in S~|~|\left(x_{1}, x_{2}, \ldots, x_{n}\right)| = N}~\textrm{distinct}\left(x_{1}, x_{2}, \ldots, x_{n}\right)\right] \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: 44
body: 2
1ExprTuple44
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 36
operands: 7
5Literal
6ExprTuple8
7ExprTuple44, 9
8Lambdaparameters: 10
body: 11
9Literal
10ExprTuple40, 35
11Conditionalvalue: 12
condition: 13
12Operationoperator: 14
operand: 18
13Operationoperator: 16
operands: 17
14Literal
15ExprTuple18
16Literal
17ExprTuple35, 19
18Lambdaparameters: 39
body: 20
19Operationoperator: 21
operand: 40
20Conditionalvalue: 23
condition: 24
21Literal
22ExprTuple40
23Operationoperator: 25
operands: 39
24Operationoperator: 26
operands: 27
25Literal
26Literal
27ExprTuple28, 29
28ExprRangelambda_map: 30
start_index: 43
end_index: 44
29Operationoperator: 31
operands: 32
30Lambdaparameter: 48
body: 33
31Literal
32ExprTuple34, 35
33Operationoperator: 36
operands: 37
34Operationoperator: 38
operands: 39
35Variable
36Literal
37ExprTuple45, 40
38Literal
39ExprTuple41
40Variable
41ExprRangelambda_map: 42
start_index: 43
end_index: 44
42Lambdaparameter: 48
body: 45
43Literal
44Variable
45IndexedVarvariable: 46
index: 48
46Variable
47ExprTuple48
48Variable