logo

Expression of type ExprTuple

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, ExprRange, ExprTuple, IndexedVar, Lambda, N, S, Variable, n, x
from proveit.core_expr_types import Len, x_1_to_n
from proveit.logic import And, Distinct, Equals, InSet
from proveit.numbers import one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = [x_1_to_n]
expr = ExprTuple(Lambda(sub_expr2, Conditional(Distinct(x_1_to_n), And(ExprRange(sub_expr1, InSet(IndexedVar(x, sub_expr1), S), one, n), Equals(Len(operands = sub_expr2), 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(\left(x_{1}, x_{2}, \ldots, x_{n}\right) \mapsto \left\{\textrm{distinct}\left(x_{1}, x_{2}, \ldots, x_{n}\right) \textrm{ if } \left(x_{1} \in S\right) ,  \left(x_{2} \in S\right) ,  \ldots ,  \left(x_{n} \in S\right) ,  |\left(x_{1}, x_{2}, \ldots, x_{n}\right)| = N\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameters: 19
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 19
4Operationoperator: 6
operands: 7
5Literal
6Literal
7ExprTuple8, 9
8ExprRangelambda_map: 10
start_index: 23
end_index: 24
9Operationoperator: 11
operands: 12
10Lambdaparameter: 28
body: 13
11Literal
12ExprTuple14, 15
13Operationoperator: 16
operands: 17
14Operationoperator: 18
operands: 19
15Variable
16Literal
17ExprTuple25, 20
18Literal
19ExprTuple21
20Variable
21ExprRangelambda_map: 22
start_index: 23
end_index: 24
22Lambdaparameter: 28
body: 25
23Literal
24Variable
25IndexedVarvariable: 26
index: 28
26Variable
27ExprTuple28
28Variable