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__)
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 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, 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, 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.theorems import double_negation, from_double_negation from proveit.basiclogic import BOOLEANS, in_bool, Not, Iff from proveit.common import A # A => Not(Not(A)) double_negation_implied = double_negation.instantiate().proven() # Not(Not(A)) => A implies_double_negation = from_double_negation.instantiate().proven() # [A => Not(Not(A))] in BOOLEANS if A in BOOLEANS double_negation_implied.deduce_in_bool().proven({in_bool(A)}) # [Not(Not(A)) => A] in BOOLEANS if A in BOOLEANS implies_double_negation.deduce_in_bool().proven({in_bool(A)}) # forall_{A} A = Not(Not(A)) Iff(A, Not(Not(A))).conclude_via_composition().derive_equality().generalize( A, domain=BOOLEANS).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__)
from proveit.basiclogic import Implies, Iff from proveit.common import A, B Implies(Iff(A, B), Iff(A, B).definition().derive_right_via_equality( ).derive_left()).generalize((A, B)).qed(__file__)
fx_map = Lambda(x, fx) # x -> f(x) fx_given_qx_map = Lambda(x, fx, Qx) # x -> f(x) | Q(x) gx_given_qx_map = Lambda(x, gx, Qx) # x -> g(x) | Q(x) f_domain_eq_gDomain = Equals(Domain(f), Domain(g)) # Domain(f) = Domain(g) fx_eq_gx = Equals(fx, gx) # f(x) = g(x) x_in_f_domain = In(x, Domain(f)) # x in Domain(f) f_eq_g = Equals(f, g) # f = g mapping_axioms = Axioms(__package__, locals()) map_application = Forall((f, Q), Forall(y, Equals(Operation(fx_given_qx_map, y), fy), Qy)) # forall_{f} [x -> f(x)] = [x -> f(x) | TRUE] lambda_over_all_def = 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) lambda_domain_def = Forall((f, Q), Forall(y, Iff(In(y, Domain(fx_given_qx_map)), Qy))) # forall_{f, g} [Domain(f) = Domain(g) and forall_{x in Domain(f)} f(x) = # g(x)] => (f = g)} map_is_as_map_does = Forall( (f, g), Implies(And(f_domain_eq_gDomain, Forall(x, fx_eq_gx, x_in_f_domain)), f_eq_g)) mapping_axioms.finish(locals())
from proveit.basiclogic import And, Implies, Iff from proveit.common import A, B, C # hypothesis = (A <=> B) and (B <=> C) hypothesis = And(Iff(A, B), Iff(B, C)) AiffB, BiffC = hypothesis.decompose() # B assuming A <=> B and A AiffB.deriveRight().proven({AiffB, A}) # A => C assuming A <=> B, B <=> C Implies(A, BiffC.deriveRight()).proven({hypothesis}) # C assuming B <=> C and C BiffC.deriveLeft().proven({BiffC, C}) # C => A assuming A <=> B, B <=> C Implies(C, AiffB.deriveLeft()).proven({hypothesis}) # A <=> C assuming hypothesis AiffC = Iff(A, C).concludeViaComposition().proven({hypothesis}) # forall_{A, B, C} (A <=> B and B <=> C) => (A <=> C) Implies(hypothesis, AiffC).generalize((A, B, C)).qed(__file__)
from proveit.basiclogic import Forall, Iff, Or, Equals, TRUE, FALSE, BOOLEANS, in_bool from proveit.common import A, B # [(A<=>B) = TRUE] or [(A<=>B) = FALSE] assuming A, B in BOOLEANS Forall((A, B), Or(Equals(Iff(A, B), TRUE), Equals(Iff(A, B), FALSE)), domain=BOOLEANS).prove_by_eval().instantiate().proven({in_bool(A), in_bool(B)}) # forall_{A in BOOLEANS} (A <=> B) in BOOLEANS in_bool(Iff(A, B)).conclude_as_folded().generalize( (A, B), domain=BOOLEANS).qed(__file__)
from proveit.basiclogic import Forall, Iff, Or, Equals, TRUE, FALSE, BOOLEANS, inBool from proveit.common import A, B # [(A<=>B) = TRUE] or [(A<=>B) = FALSE] assuming A, B in BOOLEANS Forall( (A, B), Or(Equals(Iff(A, B), TRUE), Equals(Iff(A, B), FALSE)), domain=BOOLEANS).proveByEval().specialize().proven({inBool(A), inBool(B)}) # forall_{A in BOOLEANS} (A <=> B) in BOOLEANS inBool(Iff(A, B)).concludeAsFolded().generalize((A, B), domain=BOOLEANS).qed(__file__)
from proveit.basiclogic.boolean.theorems import forallBundling, forallUnraveling from proveit.basiclogic import Iff from proveit.common import P, S, Qetc, Retc # forall_{..x.. in S | ..Q(..x..)..} forall_{..y.. in S | ..R(..y..)..} P(..x.., ..y..) => forall_{..x.., ..y.. in S | ..Q(..x..).., ..R(..y..)..} P(..x.., ..y..) forallBundlingSpec = forallBundling.specialize().proven() # 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..) forallUnraveling.specialize().proven() # lhs = forall_{..x.. in S | ..Q(..x..)..} forall_{..y.. in S | ..R(..y..)..} P(..x.., ..y..) # rhs = forall_{..x.., ..y.. in S | ..Q(..x..).., ..R(..y..)..} P(..x.., ..y..) lhs, rhs = forallBundlingSpec.conclusion, forallBundlingSpec.hypothesis # lhs in BOOLEANS, rhs in BOOLEANS for expr in (lhs, rhs): expr.deduceInBool().proven() # lhs = rhs equiv = Iff(lhs, rhs).concludeViaComposition().deriveEquality().proven() # 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..)] equiv.generalize((P, Qetc, Retc, S)).qed(__file__)
from proveit.basiclogic import Implies, Iff from proveit.common import A, B hypothesis = Iff(A, B) # hypothesis = (A <=> B) # A => B given hypothesis hypothesis.deriveRightImplication().proven({hypothesis}) # B => A given hypothesis hypothesis.deriveLeftImplication().proven({hypothesis}) # forall_{A, B} (A <=> B) => (B <=> A) Implies(hypothesis, Iff(B, A).concludeViaComposition()).generalize((A, B)).qed(__file__)
from proveit.basiclogic import BOOLEANS, Forall, Iff, Implies, Equals from proveit.common import A, B # Note that proveByEval 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) nestedVersion = Forall(A, Forall(B, Implies(Iff(A, B), Equals(A, B)), domain=BOOLEANS), domain=BOOLEANS).proveByEval() # forall_{A in BOOLEANS, B in BOOLEANS} (A <=> B) => (A = B) nestedVersion.specialize().specialize().generalize((A, B), domain=BOOLEANS).qed(__file__)