# from the theory of proveit.logic.sets.cartesian_products¶

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.
# import Expression classes needed to build the expression
from proveit import m, x
from proveit.core_expr_types import A_1_to_m, a_1_to_m
from proveit.logic import And, CartProd, Equals, Forall, InSet
from proveit.logic.sets.cartesian_products import a_in_A__1_to_m
from proveit.numbers import NaturalPos

In [2]:
# build up the expression from sub-expressions
expr = Forall(instance_param_or_params = [m], instance_expr = Forall(instance_param_or_params = [x, A_1_to_m, a_1_to_m], instance_expr = Equals(InSet(x, CartProd(A_1_to_m)), And(Equals(x, [a_1_to_m]), a_in_A__1_to_m)).with_wrapping_at(2)), domain = NaturalPos)

Out[2]:
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_{m \in \mathbb{N}^+}~\left[\forall_{x, A_{1}, A_{2}, \ldots, A_{m}, a_{1}, a_{2}, \ldots, a_{m}}~\left(\begin{array}{c} \begin{array}{l} \left(x \in \left(A_{1} \times  A_{2} \times  \ldots \times  A_{m}\right)\right) =  \\ \left(\left(x = \left(a_{1}, a_{2}, \ldots, a_{m}\right)\right)\land \left(a_{1} \in A_{1}\right) \land  \left(a_{2} \in A_{2}\right) \land  \ldots \land  \left(a_{m} \in A_{m}\right)\right) \end{array} \end{array}\right)\right]

In [5]:
stored_expr.style_options()

Out[5]:
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()

Out[6]:
core typesub-expressionsexpression
0Operationoperator: 7
operand: 2
1ExprTuple2
2Lambdaparameter: 38
body: 4
3ExprTuple38
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 34
operands: 9
7Literal
8ExprTuple10
9ExprTuple38, 11
10Lambdaparameters: 12
body: 13
11Literal
12ExprTuple29, 28, 33
13Operationoperator: 25
operands: 14
14ExprTuple15, 16
15Operationoperator: 34
operands: 17
16Operationoperator: 18
operands: 19
17ExprTuple29, 20
18Literal
19ExprTuple21, 22
20Operationoperator: 23
operands: 24
21Operationoperator: 25
operands: 26
22ExprRangelambda_map: 27
start_index: 37
end_index: 38
23Literal
24ExprTuple28
25Literal
26ExprTuple29, 30
27Lambdaparameter: 44
body: 31
28ExprRangelambda_map: 32
start_index: 37
end_index: 38
29Variable
30ExprTuple33
31Operationoperator: 34
operands: 35
32Lambdaparameter: 44
body: 39
33ExprRangelambda_map: 36
start_index: 37
end_index: 38
34Literal
35ExprTuple40, 39
36Lambdaparameter: 44
body: 40
37Literal
38Variable
39IndexedVarvariable: 41
index: 44
40IndexedVarvariable: 42
index: 44
41Variable
42Variable
43ExprTuple44
44Variable