def forallBoolEvalFalseDerivation(PofTrueVal, PofFalseVal): # hypothesis = [P(TRUE) = PofTrueVal] and [P(FALSE) in PofFalseVal] hypothesis = And(Equals(PofTrue, PofTrueVal), Equals(PofFalse, PofFalseVal)) # P(TRUE) in BOOLEANS assuming hypothesis hypothesis.deriveLeft().inBoolViaBooleanEquality().proven({hypothesis}) # P(FALSE) in BOOLEANS assuming hypothesis hypothesis.deriveRight().inBoolViaBooleanEquality().proven({hypothesis}) # forall_{A in BOOLEANS} P(A) in BOOLEANS assuming hypothesis Forall(A, inBool(PofA), domain=BOOLEANS).concludeAsFolded().proven({hypothesis}) if PofTrueVal == FALSE: # Not(P(TRUE)) assuming hypothesis hypothesis.deriveLeft().deriveViaBooleanEquality().proven({hypothesis}) example = TRUE # TRUE in BOOLEANS trueInBool elif PofFalseVal == FALSE: # Not(P(FALSE)) assuming hypothesis hypothesis.deriveRight().deriveViaBooleanEquality().proven( {hypothesis}) example = FALSE # FALSE in BOOLEANS falseInBool # [forall_{A in BOOLEANS} P(A)] = FALSE assuming hypothesis conclusion = Exists(A, Not(PofA), domain=BOOLEANS).concludeViaExample( example).deriveNegatedForall().equateNegatedToFalse().proven( {hypothesis}) # forall_{P} [(P(TRUE) = FALSE) and (P(FALSE) in BOOLEANS)] => {[forall_{A in BOOLEANS} P(A)] = FALSE} return Implies(hypothesis, conclusion).generalize(P)
def _defineTheorems(): # Forall_{A**, B**} ([A**] in X*) and ([B**] in X*) => [A**, B**] in X** _firstAxiom = combining_in_kleene = Forall([multi_a, X], Implies( In(List(multi_a), KleeneRepetition(X)), In(List(multi_a, X), KleeneRepetition(X)))) return None
def _defineAxioms(): # Forall_X [()] in X** _firstAxiom =\ nullsetInKleene = Forall(X, In(List(), KleeneRepetition(X))) # Forall_{A**, X} [A**] in X* => [A**, X] in X* concatenationInKleene = Forall([multiA, X], Implies( In(List(multiA), KleeneRepetition(X)), In(List(multiA, X), KleeneRepetition(X)))) return _firstAxiom, locals()
from proveit.basiclogic.booleans.axioms import exists_def from proveit.basiclogic import Exists, Forall, Not, NotEquals, Implies, In, TRUE, derive_stmt_eq_true from proveit.common import P, S, X, x_etc, Px_etc, etc_Qx_etc, Qetc in_domain = In(x_etc, S) # ..x.. in S # exists_not = [exists_{..x.. in S | ..Q(..x..)..} Not(P(..x..))] exists_not = Exists(x_etc, Not(Px_etc), S, etc_Qx_etc) # [Not(forall_{..x.. in S | ..Q(..x..)..} Not(P(..x..)) != TRUE] assuming exists_not exists_def.instantiate({ Px_etc: Not(Px_etc) }).derive_right_via_equality().proven({exists_not}) # forall_{..x.. in S | ..Q(..x..)..} P(..x..) forall_px = Forall(x_etc, Px_etc, S, etc_Qx_etc) # forall_{..x.. in S | ..Q(..x..)..} Not(P(..x..)) != TRUE forall_not_px_not_true = Forall(x_etc, NotEquals(Not(Px_etc), TRUE), S, etc_Qx_etc) # forall_px in BOOLEANS, forall_not_px_not_true in BOOLEANS for expr in (forall_px, forall_not_px_not_true): expr.deduce_in_bool().proven() # Not(TRUE) != TRUE NotEquals(Not(TRUE), TRUE).prove_by_eval() # forall_not_px_not_true assuming forall_px, ..Q(..x..).., In(..x.., S) derive_stmt_eq_true(forall_px.instantiate()).lhs_statement_substitution( NotEquals(Not(X), TRUE), X).derive_conclusion().generalize( x_etc, domain=S, conditions=etc_Qx_etc).proven({forall_px, in_domain}) # Not(forall_not_px_not_true) => Not(forall_px) Implies(forall_px, forall_not_px_not_true).transpose().proven() # forall_{P, ..Q.., S} [exists_{..x.. in S | ..Q(..x..)..} Not(P(..x..))] # => [Not(forall_{..x.. in S | ..Q(..x..)..} P(..x..)] Implies(exists_not, Not(forall_px)).generalize((P, Qetc, S)).qed(__file__)
from proveit.basiclogic.booleans.axioms import implicit_not_f, implicit_not_t from proveit.basiclogic import Implies, Not, derive_stmt_eq_true from proveit.common import A # hypothesis: Not(Not(A)) hypothesis = Not(Not(A)) # [Not(Not(A)) = TRUE] assuming hypothesis derive_stmt_eq_true(hypothesis).proven({hypothesis}) # [Not(A) = FALSE] assuming hypothesis implicit_not_f.instantiate( {A: Not(A)}).derive_conclusion().proven({hypothesis}) # A assuming hypothesis implicit_not_t.instantiate().derive_conclusion( ).derive_via_boolean_equality().proven({hypothesis}) # forall_{A} Not(Not(A)) => A Implies(Not(Not(A)), A).generalize(A).qed(__file__)
from proveit.basiclogic import Forall, Implies from proveit.common import P, S, x_etc, y_etc, Qetc, Retc, Pxy_etc, etc_Qx_etc, etc_Ry_etc # forall_{..x.., ..y.. in S | ..Q(..x..).., ..R(..y..)..} P(..x.., ..y..) hypothesis = Forall((x_etc, y_etc), Pxy_etc, S, (etc_Qx_etc, etc_Ry_etc)) # forall_{..x.. in S | ..Q(..x..)..} forall_{..y.. in S | ..R(..y..)..} # P(..x.., ..y..) conclusion = hypothesis.instantiate().generalize( y_etc, S, etc_Ry_etc).generalize(x_etc, S, etc_Qx_etc).proven({hypothesis}) # forall_{P, ..Q.., ..R.., S} [forall_{..x.., ..y.. in S | ..Q(..x..).., # ..R(..y..)..} P(..x.., ..y..) => forall_{..x.. in S | ..Q(..x..)..} # forall_{..y.. in S | ..R(..y..)..} P(..x.., ..y..)] Implies(hypothesis, conclusion).generalize((P, Qetc, Retc, S)).qed(__file__)
from proveit.basiclogic import Implies, Not, FALSE, inBool from proveit.common import A, B # hypothesis = [Not(B) => Not(A)] hypothesis = Implies(Not(B), Not(A)) # A=FALSE assuming Not(B)=>Not(A) and Not(B) AeqF = Not(A).equateNegatedToFalse().proven({hypothesis, Not(B)}) # FALSE assuming Not(B)=>Not(A), Not(B), and A AeqF.deriveRightViaEquivalence().proven({hypothesis, Not(B), A}) # B assuming inBool(B), (Not(B)=>Not(A)), A Implies(Not(B), FALSE).deriveViaContradiction().proven({inBool(B), hypothesis, A}) # [Not(B) => Not(A)] => [A => B] by nested hypothetical reasoning assuming inBool(B) transpositionExpr = Implies(hypothesis, Implies(A, B)).proven({inBool(B)}) # forall_{A, B | inBool(B)} [A => B] => [Not(B) => Not(A)] transpositionExpr.generalize((A, B), conditions=inBool(B)).qed(__file__)
from proveit.basiclogic.booleans.axioms import true_axiom from proveit.basiclogic import Implies from proveit.common import A Implies(A, true_axiom).generalize(A).qed(__file__)
from proveit.basiclogic.booleans.theorems import double_negate_conclusion from proveit.basiclogic import Implies, Not, BOOLEANS, in_bool from proveit.common import A, B # [B => Not(Not(A))] => [Not(A)=>Not(B)] assuming in_bool(A), in_bool(B) to_conclusion = Implies(B, Not(Not(A))).transposition() # [B => A] => [B => Not(Not(A))] assuming in_bool(A) from_hyp = double_negate_conclusion.instantiate({ A: B, B: A }).proven({in_bool(A)}) # [B => A] => [Not(A)=>Not(B)] assuming in_bool(A), in_bool(B) transposition_expr = from_hyp.apply_syllogism(to_conclusion).proven( {in_bool(A), in_bool(B)}) # forall_{A, B in BOOLEANS} [B=>A] => [Not(A) => Not(B)] transposition_expr.generalize((A, B), domain=BOOLEANS).qed(__file__)
from proveit.basiclogic.booleans.theorems import true_not_false from proveit.basiclogic import FALSE, Implies, derive_stmt_eq_true, NotEquals from proveit.common import A, X # A=TRUE assuming A AeqT = derive_stmt_eq_true(A) # TRUE != FALSE true_not_false # (A != FALSE) assuming A Anot_f = AeqT.sub_left_side_into(NotEquals(X, FALSE), X).proven({A}) # forall_{A} A => (A != FALSE) Implies(A, Anot_f).generalize(A).qed(__file__)
from proveit.basiclogic import Implies, Equals, TRUE from proveit.common import A hypothesis = Equals(TRUE, A) Implies(hypothesis, hypothesis.deriveReversed().deriveViaBooleanEquality()).generalize( A).qed(__file__)
from proveit.basiclogic import BOOLEANS, Forall, Iff, Implies, Equals from proveit.common import A, B # Note that prove_by_eval doesn't work for bundled Forall yet, # but later we'll be able to do this kind of thing in one step. # forall_{A in BOOLEANS, B in BOOLEANS} (A <=> B) => (A = B) nested_version = Forall(A, Forall(B, Implies(Iff(A, B), Equals(A, B)), domain=BOOLEANS), domain=BOOLEANS).prove_by_eval() # forall_{A in BOOLEANS, B in BOOLEANS} (A <=> B) => (A = B) nested_version.instantiate().instantiate().generalize( (A, B), domain=BOOLEANS).qed(__file__)
from proveit.basiclogic import Implies, Equals, FALSE from proveit.common import A # FeqA := (F=A) FeqA = Equals(FALSE, A) # Not(A) assuming FeqA not_a = FeqA.derive_reversed().derive_via_boolean_equality().proven({FeqA}) Implies(FeqA, not_a).generalize(A).qed(__file__)
from proveit.basiclogic.boolean.axioms import notT from proveit.basiclogic.boolean.theorems import notFromEqFalse from proveit.basiclogic import Implies, Not, deriveStmtEqTrue from proveit.common import A, X # A=TRUE assuming A AeqT = deriveStmtEqTrue(A) # [Not(A)=FALSE] assuming A=TRUE AeqT.substitution(Not(A)).applyTransitivity(notT).proven({AeqT}) # [Not(A)=FALSE] => Not(Not(A)) notFromEqFalse.specialize({A: Not(A)}).proven() # forall_{A} A => Not(Not(A)) Implies(A, Not(Not(A))).generalize(A).qed(__file__)
from proveit.basiclogic import Implies, Not from proveit.common import A # Not(Not(A)) assuming A notNotA = Not(Not(A)).concludeViaDoubleNegation() Implies(A, notNotA.equateNegatedToFalse().deriveReversed()).generalize(A).qed( __file__)
from proveit.basiclogic import Implies, Not, FALSE from proveit.common import A # FALSE assuming Not(A) and A Not(A).equateNegatedToFalse().deriveRightViaEquivalence().proven({Not(A), A}) Implies(Not(A), Implies(A, FALSE)).generalize(A).qed(__file__)
from proveit.statement import Theorems from proveit.expression import Lambda, Operation from proveit.basiclogic import Forall, Equals, Implies, In from .mappingOps import Domain from proveit.common import f, g, x, y, Q, fx, fy, gx, gy, Qx, Qy from proveit.basiclogic.common import fx_eq_gx mappingTheorems = Theorems(__package__, locals()) lambdaDomainEquality = Forall((f, g, Q), Equals(Domain(Lambda(x, fx, Qx)), Domain(Lambda(x, gx, Qx)))) # forall_{f, g, Q} {forall_{x | Q(x)} [f(x) = g(x)]} => {[(y | Q(y)) -> f(y)] = [(y | Q(y)) -> g(y)] mapSubstitution = Forall((f, g, Q), Implies(Forall(x, fx_eq_gx, Qx), Equals(Lambda(y, fy, Qy), Lambda(y, gy, Qy)))) # forall_{f, g} {forall_{x} [f(x) = g(x)]} => {[y -> f(y)] = [y -> g(y)] mapOverAllSubstitution = Forall((f, g), Implies(Forall(x, fx_eq_gx), Equals(Lambda(y, fy), Lambda(y, gy)))) mappingTheorems.finish(locals())
from proveit.basiclogic import Implies, Iff from proveit.common import A, B hypothesis = Iff(A, B) # hypothesis = (A <=> B) # A => B given hypothesis hypothesis.derive_right_implication().proven({hypothesis}) # B => A given hypothesis hypothesis.derive_left_implication().proven({hypothesis}) # forall_{A, B} (A <=> B) => (B <=> A) Implies( hypothesis, Iff( B, A).conclude_via_composition()).generalize( (A, B)).qed(__file__)
from proveit.basiclogic import Forall, Equals, In, TRUE, Iff, Implies, And from mappingOps import Domain, CoDomain from proveit.common import f, g, x, y, Q, fx, fy, gx, Qx, Qy fxMap = Lambda(x, fx) # x -> f(x) fxGivenQxMap = Lambda(x, fx, Qx) # x -> f(x) | Q(x) gxGivenQxMap = Lambda(x, gx, Qx) # x -> g(x) | Q(x) fDomain_eq_gDomain = Equals(Domain(f), Domain(g)) # Domain(f) = Domain(g) fx_eq_gx = Equals(fx, gx) # f(x) = g(x) x_in_fDomain = In(x, Domain(f)) # x in Domain(f) f_eq_g = Equals(f, g) # f = g mappingAxioms = Axioms(__package__, locals()) mapApplication = Forall((f, Q), Forall(y, Equals(Operation(fxGivenQxMap, y), fy), Qy)) # forall_{f} [x -> f(x)] = [x -> f(x) | TRUE] lambdaOverAllDef = Forall(f, Equals(Lambda(x, fx), Lambda(x, fx, TRUE))) # forall_{f, Q} forall_{y} y in Domain(x -> f(x) | Q(x)) <=> Q(y) lambdaDomainDef = Forall((f, Q), Forall(y, Iff(In(y, Domain(fxGivenQxMap)), Qy))) # forall_{f, g} [Domain(f) = Domain(g) and forall_{x in Domain(f)} f(x) = g(x)] => (f = g)} mapIsAsMapDoes = Forall( (f, g), Implies(And(fDomain_eq_gDomain, Forall(x, fx_eq_gx, x_in_fDomain)), f_eq_g)) mappingAxioms.finish(locals())
from proveit.basiclogic.boolean.axioms import orFF from proveit.basiclogic.boolean.theorems import notFalse from proveit.basiclogic import Implies, Not, Or, FALSE from proveit.common import A, B, X # Not(A or B) = Not(F or B) assuming Not(A) notAorB_eq_notForB = Not(A).equateNegatedToFalse().substitution( Not(Or(X, B)), X).proven({Not(A)}) # Not(A or B) = Not(F or F) assuming Not(A), Not(B) notAorB_eq_notForF = notAorB_eq_notForB.applyTransitivity( Not(B).equateNegatedToFalse().substitution(Not(Or(FALSE, X)), X)).proven({Not(A), Not(B)}) # Not(A or B) = Not(F) assuming Not(A), Not(B) notAorB_eq_notF = notAorB_eq_notForF.applyTransitivity( orFF.substitution(Not(X), X)).proven({Not(A), Not(B)}) # Not(FALSE) notFalse # Not(A or B) assuming Not(A), Not(B) notAorB = notAorB_eq_notF.deriveLeftViaEquivalence().proven({Not(A), Not(B)}) # forall_{A, B} Not(A) => [Not(B) => Not(A or B)] Implies(Not(A), Implies(Not(B), notAorB)).generalize((A, B)).qed(__file__)
from proveit.basiclogic import Implies, Equals from proveit.common import a, c, f, x, fx, fa # hypothesis = (x=a) hypothesis = Equals(x, a) # [f(x) = f(a)] assuming x=a fx_eq_fa = hypothesis.substitution(fx, x).proven({hypothesis}) # [f(a)=c] => [f(x)=c] assuming x=a conclusion = fx_eq_fa.transitivity_impl(Equals(fa, c)).proven({hypothesis}) # forall_{f, x, a, c} (x=a) => {[f(a)=c] => [f(x)=c]} Implies(hypothesis, conclusion).generalize((f, x, a, c)).qed(__file__)
from proveit.basiclogic.boolean.axioms import boolsDef from proveit.basiclogic.set.axioms import singletonDef from proveit.basiclogic import Implies, In, inBool, Singleton, Union, Equals, TRUE, FALSE, Or from proveit.common import x, y, A, X # hypothesis = (A=TRUE or A=FALSE) hypothesis = Or(Equals(A, TRUE), Equals(A, FALSE)) # (A=TRUE) or (A in {FALSE}) assuming hypothesis singletonDef.specialize({ x: A, y: FALSE }).subLeftSideInto(Or(Equals(A, TRUE), X), X).proven({hypothesis}) # (A in {TRUE}) or (A in {FALSE}) assuming hypothesis singletonDef.specialize({ x: A, y: TRUE }).subLeftSideInto(Or(X, In(A, Singleton(FALSE))), X).proven({hypothesis}) # [A in ({TRUE} union {FALSE})] assuming hypothesis In(A, Union(Singleton(TRUE), Singleton(FALSE))).concludeAsFolded() # (A in BOOLEANS) assuming hypothesis boolsDef.subLeftSideInto(In(A, X), X).proven({hypothesis}) # forall_{A} (A=TRUE or A=FALSE) => inBool(A) Implies(hypothesis, inBool(A)).generalize(A).qed(__file__)
from proveit.basiclogic import Implies, Not, FALSE, in_bool from proveit.common import A, B # hypothesis = [Not(B) => Not(A)] hypothesis = Implies(Not(B), Not(A)) # A=FALSE assuming Not(B)=>Not(A) and Not(B) AeqF = Not(A).equate_negated_to_false().proven({hypothesis, Not(B)}) # FALSE assuming Not(B)=>Not(A), Not(B), and A AeqF.derive_right_via_equality().proven({hypothesis, Not(B), A}) # B assuming in_bool(B), (Not(B)=>Not(A)), A Implies(Not(B), FALSE).derive_via_contradiction().proven({in_bool(B), hypothesis, A}) # [Not(B) => Not(A)] => [A => B] by nested hypothetical reasoning assuming in_bool(B) transposition_expr = Implies(hypothesis, Implies(A, B)).proven({in_bool(B)}) # forall_{A, B | in_bool(B)} [A => B] => [Not(B) => Not(A)] transposition_expr.generalize((A, B), conditions=in_bool(B)).qed(__file__)
from proveit.basiclogic.boolean.theorems import foldForallOverBool from proveit.basiclogic import Implies, deriveStmtEqTrue from proveit.common import P # P(TRUE) and P(FALSE) => forall_{A in BOOLEANS} P(A) folding = foldForallOverBool.specialize() # forall_{P} [P(TRUE) and P(FALSE)] => {[forall_{A in BOOLEANS} P(A)] = TRUE} Implies(folding.hypothesis, deriveStmtEqTrue( folding.deriveConclusion())).generalize(P).qed(__file__)
from proveit.basiclogic import Implies, Equals, derive_stmt_eq_true from proveit.common import x, y, P, Px, Py # hypothesis = (x=y) hypothesis = Equals(x, y) # P(x) = P(y) assuming (x=y) Px_eq_Py = hypothesis.substitution(Px, x).proven({hypothesis}) # P(x) assuming (x=y), P(y) derive_stmt_eq_true(Py).apply_transitivity( Px_eq_Py).derive_via_boolean_equality().proven({hypothesis, Py}) # forall_{P, x, y} {(x = y) => [P(x) => P(y)]}, by (nested) hypothetical # reasoning Implies(Equals(x, y), Implies(Py, Px)).generalize((P, x, y)).qed(__file__)
from proveit.basiclogic import Implies, BOOLEANS, FALSE, in_bool, compose, NotEquals from proveit.common import A # Anot_f = (A != FALSE) Anot_f = NotEquals(A, FALSE) # not_aeq_f = Not(A = FALSE) not_aeq_f = Anot_f.unfold() # (A=TRUE or A=FALSE) assuming in_bool(A) AeqT_or_AeqF = in_bool(A).unfold() AeqT = AeqT_or_AeqF.operands[0] # Not(A=FALSE) and (A=TRUE or A=FALSE) assuming each compose(not_aeq_f, AeqT_or_AeqF).proven({Anot_f, AeqT_or_AeqF}) # in_bool(A=TRUE) AeqT.deduce_in_bool() # A assuming in_bool(A), Not(A=FALSE) AeqT_or_AeqF.derive_left_if_not_right().derive_via_boolean_equality().proven( {in_bool(A), Anot_f}) # forall_{A in BOOLEANS} Not(A=FALSE) => A Implies(Anot_f, A).generalize(A, domain=BOOLEANS).qed(__file__)
from proveit.basiclogic import FALSE, Equals, Implies from proveit.common import A # FALSE = A FeqA = Equals(FALSE, A) # FALSE assumen FALSE=A and A FeqA.derive_reversed().derive_contradiction().proven({FeqA, A}) # forall_{A} (FALSE=A) => [A => FALSE] Implies(FeqA, Implies(A, FALSE)).generalize([A]).qed(__file__)
from proveit.basiclogic.boolean.axioms import existsDef from proveit.basiclogic import Forall, NotEquals, Implies, TRUE, FALSE, deriveStmtEqTrue, In from proveit.common import X, P, S, xEtc, yEtc, PxEtc, PyEtc, Qetc, etc_QxEtc, etc_QyEtc inDomain = In(xEtc, S) # ..x.. in S # neverPy = [forall_{..y.. in S | ..Q(..y..)..} (P(..y..) != TRUE)] neverPy = Forall(yEtc, NotEquals(PyEtc, TRUE), S, etc_QyEtc) # (P(..x..) != TRUE) assuming ..Q(..x..).., neverPy neverPy.specialize({yEtc: xEtc}).proven({etc_QxEtc, neverPy, inDomain}) # (TRUE != TRUE) assuming ..Q(..x..).., P(..x..), neverPy trueNotEqTrue = deriveStmtEqTrue(PxEtc).subRightSideInto( NotEquals(X, TRUE), X).proven({etc_QxEtc, PxEtc, neverPy, inDomain}) # FALSE assuming ..Q(..x..).., P(..x..), neverPy trueNotEqTrue.evaluation().deriveContradiction().deriveConclusion().proven( {etc_QxEtc, PxEtc, neverPy, inDomain}) # [forall_{..y.. in S | ..Q(..y..)..} (P(..y..) != TRUE)] in BOOLEANS neverPy.deduceInBool().proven() # Not(forall_{..y.. in S | ..Q(..y..)..} (P(..y..) != TRUE) assuming ..Q(..x..).., P(..x..) Implies(neverPy, FALSE).deriveViaContradiction().proven({etc_QxEtc, PxEtc, inDomain}) # exists_{..y.. in S | ..Q(..y..)..} P(..y..) assuming Q(..x..), P(..x..) existence = existsDef.specialize({ xEtc: yEtc }).deriveLeftViaEquivalence().proven({etc_QxEtc, PxEtc, inDomain}) # forall_{P, ..Q.., S} forall_{..x.. in S | ..Q(..x..)..} [P(..x..) => exists_{..y.. in S | ..Q(..y..)..} P(..y..)] Implies(PxEtc, existence).generalize(xEtc, S, etc_QxEtc).generalize( (P, Qetc, S)).qed(__file__)
from proveit.basiclogic.booleans.theorems import true_is_bool from proveit.basiclogic import TRUE, in_bool, Implies, Equals from proveit.common import A, X # hypothesis = (A=TRUE) hypothesis = Equals(A, TRUE) # in_bool(TRUE) true_is_bool.proven() # in_bool(A) assuming hypothesis conclusion = hypothesis.sub_left_side_into(in_bool(X), X).proven({hypothesis}) # forall_{A} A=TRUE => in_bool(A) Implies(hypothesis, conclusion).generalize(A).qed(__file__)
from proveit.basiclogic import Implies, Iff from proveit.common import A, B Implies( Iff(A, B), Iff(A, B).definition().deriveRightViaEquivalence().deriveRight()).generalize( (A, B)).qed(__file__)