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
from proveit.core_expr_types import Len, x_1_to_n
from proveit.logic import Card, Distinct, Equals, Exists
from proveit.numbers import greater_eq
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x_1_to_n]
expr = Lambda([S, N], Conditional(Exists(instance_param_or_params = sub_expr1, instance_expr = Distinct(x_1_to_n), domain = S, condition = Equals(Len(operands = sub_expr1), N)), greater_eq(Card(S), N)))
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(S, N\right) \mapsto \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) \textrm{ if } |S| \geq N\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
1ExprTuple31, 26
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 9
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9
7Literal
8ExprTuple26, 10
9Lambdaparameters: 30
body: 11
10Operationoperator: 12
operand: 31
11Conditionalvalue: 14
condition: 15
12Literal
13ExprTuple31
14Operationoperator: 16
operands: 30
15Operationoperator: 17
operands: 18
16Literal
17Literal
18ExprTuple19, 20
19ExprRangelambda_map: 21
start_index: 34
end_index: 35
20Operationoperator: 22
operands: 23
21Lambdaparameter: 39
body: 24
22Literal
23ExprTuple25, 26
24Operationoperator: 27
operands: 28
25Operationoperator: 29
operands: 30
26Variable
27Literal
28ExprTuple36, 31
29Literal
30ExprTuple32
31Variable
32ExprRangelambda_map: 33
start_index: 34
end_index: 35
33Lambdaparameter: 39
body: 36
34Literal
35Variable
36IndexedVarvariable: 37
index: 39
37Variable
38ExprTuple39
39Variable