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, n
from proveit.core_expr_types import Len, x_1_to_n
from proveit.logic import Card, Distinct, Equals, Exists, Forall
from proveit.numbers import NaturalPos, greater_eq
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x_1_to_n]
expr = Forall(instance_param_or_params = [n], instance_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)), domain = 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())
\forall_{n \in \mathbb{N}^+}~\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]\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: 7
operand: 2
1ExprTuple2
2Lambdaparameter: 46
body: 4
3ExprTuple46
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 38
operands: 9
7Literal
8ExprTuple10
9ExprTuple46, 11
10Lambdaparameters: 12
body: 13
11Literal
12ExprTuple42, 37
13Conditionalvalue: 14
condition: 15
14Operationoperator: 16
operand: 20
15Operationoperator: 18
operands: 19
16Literal
17ExprTuple20
18Literal
19ExprTuple37, 21
20Lambdaparameters: 41
body: 22
21Operationoperator: 23
operand: 42
22Conditionalvalue: 25
condition: 26
23Literal
24ExprTuple42
25Operationoperator: 27
operands: 41
26Operationoperator: 28
operands: 29
27Literal
28Literal
29ExprTuple30, 31
30ExprRangelambda_map: 32
start_index: 45
end_index: 46
31Operationoperator: 33
operands: 34
32Lambdaparameter: 50
body: 35
33Literal
34ExprTuple36, 37
35Operationoperator: 38
operands: 39
36Operationoperator: 40
operands: 41
37Variable
38Literal
39ExprTuple47, 42
40Literal
41ExprTuple43
42Variable
43ExprRangelambda_map: 44
start_index: 45
end_index: 46
44Lambdaparameter: 50
body: 47
45Literal
46Variable
47IndexedVarvariable: 48
index: 50
48Variable
49ExprTuple50
50Variable