logo

Expression of type Forall

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 N, S
from proveit.core_expr_types import Len, x_1_to_n
from proveit.logic import Card, Distinct, Equals, Exists, Forall
from proveit.numbers import greater_eq
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x_1_to_n]
expr = 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))
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())
\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]
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameters: 4
body: 5
4ExprTuple34, 29
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operand: 12
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12
10Literal
11ExprTuple29, 13
12Lambdaparameters: 33
body: 14
13Operationoperator: 15
operand: 34
14Conditionalvalue: 17
condition: 18
15Literal
16ExprTuple34
17Operationoperator: 19
operands: 33
18Operationoperator: 20
operands: 21
19Literal
20Literal
21ExprTuple22, 23
22ExprRangelambda_map: 24
start_index: 37
end_index: 38
23Operationoperator: 25
operands: 26
24Lambdaparameter: 42
body: 27
25Literal
26ExprTuple28, 29
27Operationoperator: 30
operands: 31
28Operationoperator: 32
operands: 33
29Variable
30Literal
31ExprTuple39, 34
32Literal
33ExprTuple35
34Variable
35ExprRangelambda_map: 36
start_index: 37
end_index: 38
36Lambdaparameter: 42
body: 39
37Literal
38Variable
39IndexedVarvariable: 40
index: 42
40Variable
41ExprTuple42
42Variable