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)
from proveit.basiclogic import Forall, Or, Equals, TRUE, FALSE, BOOLEANS, inBool from proveit.common import A, B # [(A or B) = TRUE] or [(A or B) = FALSE] assuming A, B in BOOLEANS Forall( (A, B), Or(Equals(Or(A, B), TRUE), Equals(Or(A, B), FALSE)), domain=BOOLEANS).proveByEval().specialize().proven({inBool(A), inBool(B)}) # forall_{A in BOOLEANS} (A or B) in BOOLEANS inBool(Or(A, B)).concludeAsFolded().generalize((A, B), 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.expression import Operation, Lambda from proveit.statement import Axioms 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))
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.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 Equals, FALSE Equals(FALSE, FALSE).conclude_via_reflexivity().qed(__file__)
from proveit.basiclogic.equality.axioms import not_equals_def from proveit.basiclogic import Not, Equals, in_bool from proveit.common import x, y, X # Not(x = y) in BOOLEANS Not(Equals(x, y)).deduce_in_bool().proven() # forall_{x, y} (x != y) in BOOLEANS not_equals_def.instantiate().sub_left_side_into(in_bool(X), X).generalize( (x, y)).qed(__file__)
from proveit.basiclogic import Equals, TRUE Equals(TRUE, TRUE).conclude_via_reflexivity().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, TRUE from proveit.common import A hypothesis = Equals(TRUE, A) Implies(hypothesis, hypothesis.deriveReversed().deriveViaBooleanEquality()).generalize( A).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 import Forall, Iff, Equals, TRUE, derive_stmt_eq_true from proveit.common import P, S, x_etc, Px_etc, Qetc, etc_Qx_etc # forall_px = [forall_{..x.. in S | ..Q(..x..)..} P(..x..)] forall_px = Forall(x_etc, Px_etc, S, etc_Qx_etc) # forall_px_eq_t = [forall_{..x.. in S | ..Q(..x..)..} {P(..x..)=TRUE}] forall_px_eq_t = Forall(x_etc, Equals(Px_etc, TRUE), S, etc_Qx_etc) # forall_px_eq_t assuming forall_px derive_stmt_eq_true(forall_px.instantiate()).generalize( x_etc, S, etc_Qx_etc).proven({forall_px}) # forall_px assuming forall_px_eq_t forall_px_eq_t.instantiate().derive_via_boolean_equality().generalize( x_etc, S, etc_Qx_etc).proven({forall_px_eq_t}) # [forall_{..x.. in S | ..Q(..x..)..} P(..x..)] <=> [forall_{..x.. in S | ..Q(..x..)..} {P(..x..)=TRUE}] iff_foralls = Iff(forall_px, forall_px_eq_t).conclude_via_composition().proven() # forall_px in BOOLEANS, forall_px_eq_t in BOOLEANS for expr in (forall_px, forall_px_eq_t): expr.deduce_in_bool() # forall_{P, ..Q.., S} [forall_{..x.. in S | ..Q(..x..)..} P(..x..)] = # [forall_{..x.. in S | ..Q(..x..)..} {P(..x..)=TRUE}] iff_foralls.derive_equality().generalize((P, Qetc, S)).qed(__file__)
from proveit.basiclogic.booleans.axioms import exists_def from proveit.basiclogic import Equals, Or from proveit.common import P, S, X, Qetc # exists_{..x.. in S | ..Q(..x..)..} P(..x..) = not(forall_{..x.. | # ..Q(..x..)..} P(..x..) != TRUE) exists_def_spec = exists_def.instantiate().proven() # [not(forall_{..x.. in S | ..Q(..x..)..} P(..x..) != TRUE) = TRUE] or [not(forall_{..x.. in S| ..Q(..x..)..} P(..x..) != TRUE) = FALSE] rhs_true, rhs_false = exists_def_spec.rhs.deduce_in_bool().unfold().proven( ).operands # exists_{..x.. in S | ..Q(..x..)..} P(..x..) in BOOLEANS assuming # [not(forall_{..x.. in S | ..Q(..x..)..} P(..x..) != TRUE) = TRUE] exists_in_bool_spec = rhs_true.sub_right_side_into( Equals(exists_def_spec.lhs, X), X).in_bool_via_boolean_equality().proven({rhs_true}) # exists_{..x.. | ..Q(..x..)..} P(..x..) in BOOLEANS assuming # [not(forall_{..x.. in S | ..Q..(..x..)} P(..x..) != TRUE) = FALSE] rhs_false.sub_right_side_into(Equals(exists_def_spec.lhs, X), X).in_bool_via_boolean_equality().proven( {rhs_false}) # deduce rhs_true, rhs_fals, exists_in_bool_spec all in BOOLEANS for expr in (rhs_true, rhs_false, exists_in_bool_spec): expr.deduce_in_bool() # forall_{P, ..Q.., S} exists_{..x.. | ..Q(..x..)..} P(..x..) in BOOLEANS Or(rhs_true, rhs_false).derive_common_conclusion(exists_in_bool_spec).generalize( (P, Qetc, S)).qed(__file__)
from proveit.basiclogic import Forall, And, Or, Equals, TRUE, FALSE, BOOLEANS, inBool from proveit.common import A, B # [(A and B) = TRUE] or [(A and B) = FALSE] assuming A, B in BOOLEANS Forall( (A, B), Or(Equals(And(A, B), TRUE), Equals(And(A, B), FALSE)), domain=BOOLEANS).proveByEval().specialize().proven({inBool(A), inBool(B)}) # forall_{A, B in BOOLEANS} (A and B) in BOOLEANS inBool(And(A, B)).concludeAsFolded().generalize((A, B), domain=BOOLEANS).qed(__file__)
from proveit.basiclogic.boolean.theorems import trueInBool from proveit.basiclogic import TRUE, inBool, Implies, Equals from proveit.common import A, X # hypothesis = (TRUE=A) hypothesis = Equals(TRUE, A) # inBool(TRUE) trueInBool.proven() # inBool(A) assuming hypothesis conclusion = hypothesis.subRightSideInto(inBool(X), X).proven({hypothesis}) # forall_{A} (TRUE=A) => inBool(A) Implies(hypothesis, conclusion).generalize(A).qed(__file__)
from proveit.basiclogic.boolean.theorems import trueInBool from proveit.basiclogic import TRUE, inBool, Implies, Equals from proveit.common import A, X # hypothesis = (A=TRUE) hypothesis = Equals(A, TRUE) # inBool(TRUE) trueInBool.proven() # inBool(A) assuming hypothesis conclusion = hypothesis.subLeftSideInto(inBool(X), X).proven({hypothesis}) # forall_{A} A=TRUE => inBool(A) Implies(hypothesis, conclusion).generalize(A).qed(__file__)
from proveit.basiclogic import Forall, Or, Not, Equals, TRUE, FALSE, BOOLEANS, inBool from proveit.common import A # Not(A) = TRUE or Not(A) = FALSE assuming A in BOOLEANS Forall(A, Or(Equals(Not(A), TRUE), Equals(Not(A), FALSE)), domain=BOOLEANS).proveByEval().specialize().proven({inBool(A)}) # forall_{A in BOOLEANS} Not(A) in BOOLEANS inBool(Not(A)).concludeAsFolded().generalize(A, domain=BOOLEANS).qed(__file__)
from proveit.basiclogic import FALSE, Equals, Implies from proveit.common import A # A = FALSE AeqF = Equals(A, FALSE) # FALSE assuming A=FALSE and A AeqF.deriveRightViaEquivalence().proven({AeqF, A}) # forall_{A} (A=FALSE) => [A => FALSE] Implies(AeqF, Implies(A, FALSE)).generalize([A]).qed(__file__)
from proveit.basiclogic.booleans.axioms import implicit_not_f from proveit.basiclogic import Not, Implies, Equals, FALSE, derive_stmt_eq_true from proveit.common import A # [Not(A) = TRUE] => [A = FALSE] implicit_not_f.instantiate().proven() # [Not(A) = TRUE] assuming Not(A) derive_stmt_eq_true(Not(A)).proven({Not(A)}) # forall_{A} Not(A) => [A=FALSE] Implies(Not(A), Equals(A, FALSE)).generalize(A).qed(__file__)
from proveit.basiclogic import Implies, Not, Equals, NotEquals from proveit.basiclogic.equality.axioms import equalsSymmetry from proveit.common import x, y # hypothesis = (x != y) hypothesis = NotEquals(x, y) # inBool(x=y) Equals(x, y).deduceInBool() # inBool(y=x) Equals(y, x).deduceInBool() # Not(x=y) => Not(y=x) equalsSymmetry.specialize({x: y, y: x}).transpose().proven() # Not(x=y) assuming (x != y) NotEquals(x, y).unfold({hypothesis}) # (y != x) assuming Not(x = y) y_neq_x = Not(Equals(y, x)).deriveNotEquals({Not(Equals(y, x))}) # forall_{x, y} (x != y) => (y != x) y_neq_x.asImplication({hypothesis}).generalize((x, y)).qed(__file__)
from proveit.basiclogic import Implies, Not, Equals, NotEquals from proveit.basiclogic.equality.axioms import equals_symmetry from proveit.common import x, y # hypothesis = (x != y) hypothesis = NotEquals(x, y) # in_bool(x=y) Equals(x, y).deduce_in_bool() # in_bool(y=x) Equals(y, x).deduce_in_bool() # Not(x=y) => Not(y=x) equals_symmetry.instantiate({x: y, y: x}).transpose().proven() # Not(x=y) assuming (x != y) NotEquals(x, y).unfold({hypothesis}) # (y != x) assuming Not(x = y) y_neq_x = Not(Equals(y, x)).derive_not_equals({Not(Equals(y, x))}) # forall_{x, y} (x != y) => (y != x) y_neq_x.as_implication({hypothesis}).generalize((x, y)).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.boolean.axioms import orFT, falseNotTrue from proveit.basiclogic.boolean.theorems import falseEqFalse from proveit.basiclogic import FALSE, inBool, Or, Equals, deriveStmtEqTrue from proveit.common import X # [FALSE or TRUE] orFT.deriveViaBooleanEquality().proven() # [FALSE or FALSE=FALSE] via [FALSE or TRUE] and FALSE=FALSE deriveStmtEqTrue(falseEqFalse).subLeftSideInto(Or(FALSE, X), X).proven() # [FALSE=TRUE or FALSE=FALSE] via [FALSE or FALSE=FALSE] and Not(FALSE=TRUE) falseNotTrue.unfold().equateNegatedToFalse().subLeftSideInto( Or(X, Equals(FALSE, FALSE)), X).proven() # inBool(FALSE) via [FALSE=TRUE or FALSE=FALSE] inBool(FALSE).concludeAsFolded().qed(__file__)
from proveit.basiclogic import Implies, And, Equals from proveit.common import a, b, f, x, y, fxy, fab # hypothesis = (x=a and y=b) hypothesis = And(Equals(x, a), Equals(y, b)) # f(x, y) = f(a, y) assuming hypothesis fxy_eq_fay = hypothesis.deriveLeft().substitution(fxy, x).proven({hypothesis}) # f(a, y) = f(a, b) assuming hypothesis fay_eq_fab = hypothesis.deriveRight().substitution(fab, b).proven({hypothesis}) # f(x, y) = f(a, b) assuming hypothesis conclusion = fxy_eq_fay.applyTransitivity(fay_eq_fab).proven({hypothesis}) # forall_{f, x, y, a, b} (x=a and y=b) => [f(x, y) = f(a, b)] Implies(hypothesis, conclusion).generalize((f, x, y, a, b)).qed(__file__)
from proveit.basiclogic.booleans.theorems import false_is_bool from proveit.basiclogic import FALSE, in_bool, Implies, Equals from proveit.common import A, X # hypothesis = (FALSE=A) hypothesis = Equals(FALSE, A) # in_bool(FALSE) false_is_bool.proven() # in_bool(A) assuming hypothesis conclusion = hypothesis.sub_right_side_into(in_bool(X), X).proven({hypothesis}) # forall_{A} (FALSE=A) => in_bool(A) Implies(hypothesis, conclusion).generalize(A).qed(__file__)
from proveit.basiclogic.equality.theorems import binary_substitution from proveit.basiclogic import Implies, And, Equals from proveit.common import a, b, c, f, x, y, fab # hypothesis = (x=a and y=b) hypothesis = And(Equals(x, a), Equals(y, b)) # [f(x, y) = f(a, b)] assuming hypothesis fxy_eq_fab = binary_substitution.instantiate().derive_conclusion().proven( {hypothesis}) # [f(a, b)=c] => [f(x, y)=c] assuming hypothesis conclusion = fxy_eq_fab.transitivity_impl(Equals(fab, c)).proven({hypothesis}) # forall_{f, x, y, a, b, c} [x=a and y=b] => {[f(a, b)=c] => [f(x, y)=c]} Implies(hypothesis, conclusion).generalize((f, x, y, a, b, c)).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 Forall, Iff, Equals, TRUE, deriveStmtEqTrue from proveit.common import P, S, xEtc, PxEtc, Qetc, etc_QxEtc # forallPx = [forall_{..x.. in S | ..Q(..x..)..} P(..x..)] forallPx = Forall(xEtc, PxEtc, S, etc_QxEtc) # forallPxEqT = [forall_{..x.. in S | ..Q(..x..)..} {P(..x..)=TRUE}] forallPxEqT = Forall(xEtc, Equals(PxEtc, TRUE), S, etc_QxEtc) # forallPxEqT assuming forallPx deriveStmtEqTrue(forallPx.specialize()).generalize(xEtc, S, etc_QxEtc).proven({forallPx}) # forallPx assuming forallPxEqT forallPxEqT.specialize().deriveViaBooleanEquality().generalize(xEtc, S, etc_QxEtc).proven({forallPxEqT}) # [forall_{..x.. in S | ..Q(..x..)..} P(..x..)] <=> [forall_{..x.. in S | ..Q(..x..)..} {P(..x..)=TRUE}] iffForalls = Iff(forallPx, forallPxEqT).concludeViaComposition().proven() # forallPx in BOOLEANS, forallPxEqT in BOOLEANS for expr in (forallPx, forallPxEqT): expr.deduceInBool() # forall_{P, ..Q.., S} [forall_{..x.. in S | ..Q(..x..)..} P(..x..)] = [forall_{..x.. in S | ..Q(..x..)..} {P(..x..)=TRUE}] iffForalls.deriveEquality().generalize((P, Qetc, S)).qed(__file__)