import proveit
# Prepare this notebook for defining the theorems of a theory:
%theorems_notebook # Keep this at the top following 'import proveit'.
from proveit import Lambda, ExprRange, IndexedVar
from proveit import i, j, k, l, m, n, A, B, C, D, E, P, Pk
from proveit.logic import (Or, TRUE, FALSE, Forall, Exists, Implies, Not, in_bool,
And, Boolean, Equals, Set)
from proveit.core_expr_types import A_1_to_l, A_1_to_m, B_1_to_m, C_1_to_m, C_1_to_n, D_1_to_n
from proveit.numbers import Natural, NaturalPos, Add, Exp, one, LessEq, Integer, Interval
%begin theorems
true_or_true = Or(TRUE, TRUE)
true_or_false = Or(TRUE, FALSE)
false_or_true = Or(FALSE, TRUE)
false_or_false_negated = Not(Or(FALSE, FALSE))
or_if_both = Forall((A, B), Or(A, B), conditions=[A, B])
or_if_only_left = Forall((A, B), Or(A, B), conditions=[A, Not(B)])
or_if_only_right = Forall((A, B), Or(A, B), conditions=[Not(A), B])
neither_intro = Forall((A, B), Not(Or(A, B)), conditions=[Not(A), Not(B)])
binary_or_contradiction = Forall((A, B), FALSE, conditions=(Or(A, B), Not(A), Not(B)))
left_if_not_right = Forall((A, B), A, domain=Boolean, conditions=(Or(A, B), Not(B)))
right_if_not_left = Forall((A, B), B, domain=Boolean, conditions=(Or(A, B), Not(A)))
This singular constructive dilemma lemma will require a single provable $C$ be designated as a Boolean. The main (non-lemma) version will drop this constraint. This will all culminate to the constructive dilemma, below, that can prove some $C \lor D$ given $A \lor B$, $A \Rightarrow C$ and $B \Rightarrow D$.
singular_constructive_dilemma_lemma = Forall((A, B, C), C, conditions=[Or(A, B), Implies(A, C), Implies(B, C)],
domain=Boolean)
singular_constructive_dilemma = Forall((A, B), Forall(C, C, conditions=[Implies(A, C), Implies(B, C)]),
domain=Boolean, conditions=[Or(A, B)])
singular_constructive_multi_dilemma = \
Forall(m,
Forall(A_1_to_m,
Forall(C, C,
conditions=[ExprRange(i, Implies(IndexedVar(A,i),
C),
one, m)]),
domain=Boolean,
conditions=[Or(A_1_to_m)]),
domain = Natural)
or_if_left = Forall((A, B), Or(A, B), domain=Boolean, conditions=[A])
or_if_right = Forall((A, B), Or(A, B), domain=Boolean, conditions=[B])
constructive_dilemma = Forall((A, B, C, D), Or(C, D), domain=Boolean,
conditions=[Or(A, B), Implies(A, C), Implies(B, D)])
constructive_multi_dilemma = \
Forall(m,
Forall((A_1_to_m, B_1_to_m),
Or(B_1_to_m),
domain=Boolean,
conditions=[Or(A_1_to_m),
ExprRange(i,Implies(IndexedVar(A,i),
IndexedVar(B,i)),
one, m)]),
domain = Natural)
destructive_dilemma = Forall((A, B, C, D), Or(Not(A), Not(B)), domain=Boolean,
conditions=[Or(Not(C), Not(D)), Implies(A, C), Implies(B, D)])
destructive_multi_dilemma = \
Forall(m,
Forall((A_1_to_m, B_1_to_m),
Or(ExprRange(i, Not(IndexedVar(B,i)), one, m)),
domain=Boolean,
conditions=[Or(ExprRange(i, Not(IndexedVar(A,i)),
one, m)),
ExprRange(i,Implies(IndexedVar(A, i),
IndexedVar(B, i)),
one,m)]),
domain=Natural)
not_left_if_neither = Forall((A, B), Not(A), conditions=(Not(Or(A, B))))
not_right_if_neither = Forall((A, B), Not(B), conditions=(Not(Or(A, B))))
empty_disjunction_eval = Equals(Or(), FALSE)
unary_or_lemma = Forall(A, (Equals(Or(A), Or(FALSE, A))), domain = Boolean)
unary_or_reduction = Forall(A, Equals(Or(A), A), domain = Boolean)
each_is_bool = \
Forall((m, n),
Forall((A_1_to_m, B, C_1_to_n),
in_bool(B),
conditions=in_bool(Or(A_1_to_m, B, C_1_to_n))),
domain=Natural)
or_if_any = Forall((m, n),
Forall((A_1_to_m, B, C_1_to_n),
Or(A_1_to_m, B, C_1_to_n),
domain=Boolean,
conditions=[B]),
domain=Natural)
not_or_if_not_any = \
Forall(m, Forall(A_1_to_m, Not(Or(A_1_to_m)),
conditions=[ExprRange(i, Not(IndexedVar(A, i)),
one, m)]),
domain=Natural)
# As long as there is at least one operand then "if all then any."
any_if_all = \
Forall(m, Forall(A_1_to_m, Or(A_1_to_m),
conditions=[A_1_to_m]),
domain=NaturalPos)
or_contradiction = \
Forall(m, Forall(A_1_to_m, FALSE,
conditions=(Or(A_1_to_m),
ExprRange(i, Not(IndexedVar(A, i)),
one, m))),
domain=Natural)
true_eval = Forall((m, n),
Forall((A_1_to_m, C_1_to_n),
Equals(Or(A_1_to_m, TRUE, C_1_to_n), TRUE),
domain=Boolean),
domain=Natural)
false_eval = Forall(m, Forall(A_1_to_m,
Equals(Or(A_1_to_m), FALSE),
domain=Set(FALSE)),
domain=Natural)
binary_closure = Forall((A, B), in_bool(Or(A, B)), domain=Boolean)
closure = Forall(m, Forall(A_1_to_m,
in_bool(Or(A_1_to_m)),
domain=Boolean),
domain=NaturalPos)
demorgans_law_and_to_or_bin_explicit = \
Forall((A,B), Or(A,B),
conditions=[Not(And(Not(A), Not(B)))],
domain=Boolean)
demorgans_law_and_to_or_bin = Forall((A,B), Or(A,B),
conditions=[Not(And(Not(A), Not(B)))])
demorgans_law_and_to_or = \
Forall(m, Forall(A_1_to_m, Or(A_1_to_m),
condition=Not(And(ExprRange(i, Not(IndexedVar(A,i)), one, m)))),
domain=Natural)
commutation = Forall((A, B), Equals(Or(A, B), Or(B, A)),
domain=Boolean)
leftward_commutation = \
Forall((l, m, n),
Forall((A_1_to_l,B_1_to_m,C,D_1_to_n),
Equals(Or(A_1_to_l, B_1_to_m, C, D_1_to_n),
Or(A_1_to_l, C, B_1_to_m, D_1_to_n)) \
.with_wrapping_at(2),
domain=Boolean),
domain=Natural)
rightward_commutation = \
Forall((l, m, n),
Forall((A_1_to_l,B,C_1_to_m,D_1_to_n),
Equals(Or(A_1_to_l, B, C_1_to_m, D_1_to_n),
Or(A_1_to_l, C_1_to_m, B, D_1_to_n)) \
.with_wrapping_at(2),
domain=Boolean),
domain = Natural)
commute = Forall((A, B), Or(B, A), conditions=[Or(A, B)])
rightward_commute = \
Forall((l, m, n),
Forall((A_1_to_l,B,C_1_to_m,D_1_to_n),
Or(A_1_to_l, C_1_to_m, B, D_1_to_n),
conditions=[Or(A_1_to_l, B, C_1_to_m, D_1_to_n)]),
domain=Natural)
leftward_commute = \
Forall((l, m, n),
Forall((A_1_to_l,B_1_to_m,C,D_1_to_n),
Or(A_1_to_l, C, B_1_to_m,D_1_to_n),
conditions=[Or(A_1_to_l, B_1_to_m, C, D_1_to_n)]),
domain=Natural)
association = \
Forall((l,m,n),
Forall((A_1_to_l,B_1_to_m,C_1_to_n),
Equals(Or(A_1_to_l, B_1_to_m, C_1_to_n),
Or(A_1_to_l, Or(B_1_to_m), C_1_to_n)) \
.with_wrapping_at(2),
domain=Boolean),
domain=Natural)
disassociation = \
Forall((l,m,n),
Forall((A_1_to_l,B_1_to_m,C_1_to_n),
Equals(Or(A_1_to_l, Or(B_1_to_m), C_1_to_n),
Or(A_1_to_l, B_1_to_m, C_1_to_n)) \
.with_wrapping_at(2),
domain=Boolean),
domain=Natural)
associate = \
Forall((l,m,n),
Forall((A_1_to_l,B_1_to_m,C_1_to_n),
Or(A_1_to_l, Or(B_1_to_m), C_1_to_n),
conditions=[Or(A_1_to_l, B_1_to_m, C_1_to_n)]),
domain=Natural)
disassociate = \
Forall((l,m,n),
Forall((A_1_to_l,B_1_to_m,C_1_to_n),
Or(A_1_to_l, B_1_to_m, C_1_to_n),
conditions=[Or(A_1_to_l, Or(B_1_to_m), C_1_to_n)]),
domain=Natural)
disjunction_eq_quantification = Forall(
(i, j), Forall(P, Equals(Or(ExprRange(k, Pk, i, j)),
Exists(k, Pk, domain=Interval(i,j))),
conditions=[LessEq(i, Add(j, one))]),
domain=Integer)
disjunction_from_quantification = Forall(
(i, j), Forall(P, Implies(Exists(k, Pk, domain=Interval(i,j)),
Or(ExprRange(k, Pk, i, j))),
conditions=[LessEq(i, Add(j, one))]),
domain=Integer)
quantification_from_disjunction = Forall(
(i, j), Forall(P, Implies(Or(ExprRange(k, Pk, i, j)),
Exists(k, Pk, domain=Interval(i,j)))),
domain=Integer)
%end theorems