logo
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 ExprTuple, Function, Lambda, P, n
from proveit.core_expr_types import P__x_1_to_n, P__x_1_to_np1, x_1_to_n, x_1_to_np1
from proveit.logic import And, Forall, Implies
from proveit.numbers import Natural
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [n]
sub_expr2 = Forall(instance_param_or_params = [x_1_to_n], instance_expr = P__x_1_to_n)
expr = ExprTuple(Lambda(P, Implies(And(Function(P, []), Forall(instance_param_or_params = sub_expr1, instance_expr = Implies(sub_expr2, Forall(instance_param_or_params = [x_1_to_np1], instance_expr = P__x_1_to_np1)).with_wrapping_at(2), domain = Natural)), Forall(instance_param_or_params = sub_expr1, instance_expr = sub_expr2, domain = Natural)).with_wrapping_at(1)))
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(P \mapsto \left(\begin{array}{c} \begin{array}{l} \left(P\left(\right) \land \left[\forall_{n \in \mathbb{N}}~\left(\begin{array}{c} \begin{array}{l} \left[\forall_{x_{1}, x_{2}, \ldots, x_{n}}~P\left(x_{1}, x_{2}, \ldots, x_{n}\right)\right] \Rightarrow  \\ \left[\forall_{x_{1}, x_{2}, \ldots, x_{n + 1}}~P\left(x_{1}, x_{2}, \ldots, x_{n + 1}\right)\right] \end{array} \end{array}\right)\right]\right) \\  \Rightarrow \left[\forall_{n \in \mathbb{N}}~\left[\forall_{x_{1}, x_{2}, \ldots, x_{n}}~P\left(x_{1}, x_{2}, \ldots, x_{n}\right)\right]\right] \end{array} \end{array}\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
1Lambdaparameter: 36
body: 3
2ExprTuple36
3Operationoperator: 21
operands: 4
4ExprTuple5, 6
5Operationoperator: 7
operands: 8
6Operationoperator: 29
operand: 12
7Literal
8ExprTuple10, 11
9ExprTuple12
10Operationoperator: 36
operands: 13
11Operationoperator: 29
operand: 16
12Lambdaparameter: 47
body: 15
13ExprTuple
14ExprTuple16
15Conditionalvalue: 25
condition: 20
16Lambdaparameter: 47
body: 18
17ExprTuple47
18Conditionalvalue: 19
condition: 20
19Operationoperator: 21
operands: 22
20Operationoperator: 23
operands: 24
21Literal
22ExprTuple25, 26
23Literal
24ExprTuple47, 27
25Operationoperator: 29
operand: 31
26Operationoperator: 29
operand: 32
27Literal
28ExprTuple31
29Literal
30ExprTuple32
31Lambdaparameters: 35
body: 33
32Lambdaparameters: 37
body: 34
33Operationoperator: 36
operands: 35
34Operationoperator: 36
operands: 37
35ExprTuple38
36Variable
37ExprTuple39
38ExprRangelambda_map: 40
start_index: 48
end_index: 47
39ExprRangelambda_map: 40
start_index: 48
end_index: 41
40Lambdaparameter: 49
body: 42
41Operationoperator: 43
operands: 44
42IndexedVarvariable: 45
index: 49
43Literal
44ExprTuple47, 48
45Variable
46ExprTuple49
47Variable
48Literal
49Variable