Relations

We first import propositional logic and first-order logic.  import (CLASSICAL Interface:Classical_propositional_calculus ) import (FIRSTORDER Interface:First-order_logic_with_quantifiability (CLASSICAL) ) 

We also import Interface:Basic operations of Zermelo–Fraenkel set theory, which is the current home of some of the basic results involving singletons, unordered pairs, and the like.  import (BASIC Interface:Basic_operations_of_Zermelo–Fraenkel_set_theory (CLASSICAL FIRSTORDER) ) 

As usual, capital letters starting from  are set expressions (that is, objects or "classes") and lowercase letters starting with   are set variables.  var (object A B C D A0 A1 B0 B1 α β Z) var (variable a b x y z w a′ b′ x′ y′ z′) var (formula φ ψ antecedent) 

Ordered pair
The ordered pair  can be defined in several ways as long as the definition implies the key ordered pair theorem. The most widely adopted definition is, which is the one we use. Because the notation  is not available in JHilbert, we call it.  def ((orderedPair A B) (unorderedPair (singleton A) (unorderedPair A B))) 

Ordered pair builder
Equals can be substituted for equals in ordered pairs, that is,. This forms one direction of the ordered pair theorem (it is the less interesting of the two, as it holds for a wide variety of operations, not just ordered pairs).  thm (OrderedPairBuilder  (((A0 = A1) ∧ (B0 = B1)) → ((orderedPair A0 B0) = (orderedPair A1 B1))) ( (A0 = A1) (B0 = B1) ConjunctionRightElimination A0 A1 SingletonBuilder applySyllogism

A0 A1 B0 B1 UnorderedPairBuilder

composeConjunction

(singleton A0) (singleton A1) (unorderedPair A0 B0) (unorderedPair A1 B1) UnorderedPairBuilder applySyllogism )) 

We also provide the usual convenience builders.  thm (OrderedPairBuilderLL  ((B0 = B1) → ((orderedPair A B0) = (orderedPair A B1))) ( A EqualityReflexivity A A B0 B1 OrderedPairBuilder export applyModusPonens ))

thm (buildOrderedPairLLInConsequent  ((H (antecedent → (B0 = B1))))  (antecedent → ((orderedPair A B0) = (orderedPair A B1))) ( H       B0 B1 A OrderedPairBuilderLL applySyllogism ))

thm (OrderedPairBuilderRR  ((A0 = A1) → ((orderedPair A0 B) = (orderedPair A1 B))) ( B EqualityReflexivity A0 A1 B B OrderedPairBuilder export applyComm applyModusPonens ))

thm (buildOrderedPairRRInConsequent  ((H (antecedent → (A0 = A1))))  (antecedent → ((orderedPair A0 B) = (orderedPair A1 B))) ( H       A0 A1 B OrderedPairBuilderRR applySyllogism )) 

First half of the ordered pair theorem
In this section we prove.

Our first lemma is a simple consequence of our definition of ordered pair.  thm (OrderedPairTheoremForwardFirst-1  ((singleton A) ∈ (orderedPair A B)) ( (singleton A) (unorderedPair A B) UnorderedPairLeftMembership )) 

The next lemma,, also follows directly from our definition of ordered pair.  thm (OrderedPairTheoremForwardFirst-2  ((A ∈ (orderedPair B C)) ↔ ((A = (singleton B)) ∨ (A = (unorderedPair B C)))) ( A (singleton B) (unorderedPair B C) UnorderedPair )) 

We're ready for. We rename the variables in an effort to make the proof easier to read:  thm (OrderedPairTheoremForwardFirst  (((orderedPair A B) = (orderedPair C D)) → (A = C)) ( </jh> The first step is, from our builder for.

But  is true unconditionally, so this formula reduces to.  C D OrderedPairTheoremForwardFirst-1 (orderedPair A B) (orderedPair C D) (singleton C) MembershipBuilderLL detachImplicationBiconditionalRight </jh> We now apply our other lemma to turn  into.  (singleton C) A B OrderedPairTheoremForwardFirst-2 eliminateBiconditionalReverse applySyllogism </jh> We'll show that each half of  implies. The left half follows from  once we detach the theorem.  A SingletonMembership (singleton C) (singleton A) A MembershipBuilderLL detachImplicationBiconditionalRight </jh> The right half is similar: the builder gives us  and we can detach.  A B UnorderedPairLeftMembership (singleton C) (unorderedPair A B) A MembershipBuilderLL detachImplicationBiconditionalRight </jh> We now compose the two and combine with our earlier result to get  composeDisjunction applySyllogism </jh> Transforming  to   finishes the proof.  A C Singleton eliminateBiconditionalReverse applySyllogism )) </jh>

Second half of the ordered pair theorem
In this section we prove.

Our first lemma is.  thm (OrderedPairTheoremForwardSecond-1  (((orderedPair C D) = (orderedPair C B)) → (D = B)) ( </jh> The definition of ordered pair gives us  and two applications of   give us.  (singleton C) (unorderedPair C D) (unorderedPair C B) UnorderedPairSecondMembersEqual C D B UnorderedPairSecondMembersEqual applySyllogism )) </jh>

The next lemma is most of the work. It is.  thm (OrderedPairTheoremForwardSecond-2  (((orderedPair A B) = (orderedPair C D)) → ((A = C) → (D = B))) ( </jh> We start with.  (orderedPair A B) (orderedPair C D) (orderedPair C B) EqualityBuilderRR </jh> The ordered pair builder and a bit of rearrangment turns that into.  ((orderedPair A B) = (orderedPair C B)) ((orderedPair C D) = (orderedPair C B)) BiconditionalReverseElimination applySyllogism

A C B OrderedPairBuilderRR ((orderedPair C D) = (orderedPair C B)) addCommonConsequent applySyllogism </jh> Applying the lemma  turns this into , our desired result.  C D B OrderedPairTheoremForwardSecond-1 (A = C) addCommonAntecedent applySyllogism )) </jh>

We now combine  and   to get.  thm (OrderedPairTheoremForwardSecond  (((orderedPair A B) = (orderedPair C D)) → (B = D)) ( A B C D OrderedPairTheoremForwardFirst A B C D OrderedPairTheoremForwardSecond-2 applyModusPonensInConsequent

D B EqualitySymmetry eliminateBiconditionalReverse applySyllogism )) </jh>

Ordered pair theorem
We are now ready to combine these results to prove the ordered pair theorem. We prove the forward implication,  thm (OrderedPairTheoremForward  (((orderedPair A0 B0) = (orderedPair A1 B1)) → ((A0 = A1) ∧ (B0 = B1))) ( A0 B0 A1 B1 OrderedPairTheoremForwardFirst A0 B0 A1 B1 OrderedPairTheoremForwardSecond composeConjunction )) </jh>

and the biconditionalized theorem.  thm (OrderedPairTheorem  (((orderedPair A0 B0) = (orderedPair A1 B1)) ↔ ((A0 = A1) ∧ (B0 = B1))) ( A0 B0 A1 B1 OrderedPairTheoremForward A0 A1 B0 B1 OrderedPairBuilder introduceBiconditionalFromImplications )) </jh>

Relations
A relation is a set of ordered pairs. We typically use the letters R, S, T, and U for relations. <jh> def ((relation A) (∀ z (((value z) ∈ A) → (∃ x (∃ y ((value z) = (orderedPair (value x) (value y)))))))) var (object R S T U) </jh>

Here we prove a theorem form of the definition. The distinct variable constraints are needed for soundness (analogous to the distinct variable constraints in, for example, metamath's dfss2 ). <jh> thm (Relation ((x y z A) (x′ y′ z′ x y z A))  ((relation A) ↔ (∀ z (((value z) ∈ A) → (∃ x (∃ y ((value z) = (orderedPair (value x) (value y)))))))) ( </jh> To prove this we need to prove that the truth of the formula doesn't depend on the choice of variables for,  , and. In other words,

We'll first worry about the explicit substitutions and getting them in the right place relative to the quantifiers. We work from the outside in, so the first step is <jh> z (((value z) ∈ A) → (∃ x (∃ y ((value z) = (orderedPair (value x) (value y)))))) z′ ChangeVariableExplicitForAll </jh> We now move the substitution inside all quantifiers. <jh> (value z′) z ((value z) ∈ A) (∃ x (∃ y ((value z) = (orderedPair (value x) (value y))))) SubstImplication z′ buildForAll applyBiconditionalTransitivity

(value z′) z x (∃ y ((value z) = (orderedPair (value x) (value y)))) SubstThereExists (subst (value z′) z ((value z) ∈ A)) buildImplicationAntecedent z′ buildForAll applyBiconditionalTransitivity

(value z′) z y ((value z) = (orderedPair (value x) (value y))) SubstThereExists x buildThereExists (subst (value z′) z ((value z) ∈ A)) buildImplicationAntecedent z′ buildForAll applyBiconditionalTransitivity </jh> That gives us. The next step is to add the substitution for. <jh> x (∃ y (subst (value z′) z ((value z) = (orderedPair (value x) (value y))))) x′ ChangeVariableExplicitThereExists (subst (value z′) z ((value z) ∈ A)) buildImplicationAntecedent z′ buildForAll applyBiconditionalTransitivity

(value x′) x y (subst (value z′) z ((value z) = (orderedPair (value x) (value y)))) SubstThereExists x′ buildThereExists (subst (value z′) z ((value z) ∈ A)) buildImplicationAntecedent z′ buildForAll applyBiconditionalTransitivity </jh> That gives us. The next step is to add the substitution for. <jh> y (subst (value x′) x (subst (value z′) z ((value z) = (orderedPair (value x) (value y))))) y′ ChangeVariableExplicitThereExists x′ buildThereExists (subst (value z′) z ((value z) ∈ A)) buildImplicationAntecedent z′ buildForAll applyBiconditionalTransitivity </jh> Now we perform the substitutions. The first one is. <jh> (value z) (value z′) A MembershipBuilderRR makeSubstExplicit </jh> The next is. <jh> (value z) (value z′) (orderedPair (value x) (value y)) EqualityBuilderRR makeSubstExplicit

(value x′) x buildSubst </jh> The next is. <jh> (value x) (value x′) (value y) OrderedPairBuilderRR (value z′) buildEqualityLLInConsequent makeSubstExplicit applyBiconditionalTransitivity

(value y′) y buildSubst </jh> The next is. <jh> (value y) (value y′) (value x′) OrderedPairBuilderLL (value z′) buildEqualityLLInConsequent makeSubstExplicit applyBiconditionalTransitivity </jh> We combine with the  substitution. <jh> y′ buildThereExists x′ buildThereExists

buildImplication z′ buildForAll applyBiconditionalTransitivity </jh> We have proved. JHilbert will unify the one with the primes with, if we just put it on the left hand side. <jh> swapBiconditional )) </jh>

A relation for two objects holds if and only if the corresponding ordered pair is an element of the relation. A more conventional notation would just write this as  rather than , but JHilbert does not offer that option. <jh> def ((relates A R B) ((orderedPair A B) ∈ R)) </jh>

The domain of a relation
A relation is a set of ordered pairs, and the domain of a relation is a set consisting of all of the first elements of those ordered pairs.

Our notation is  (a slight variation of the common notation  ). To show that the domain of a relation exists, we will show that the domain is contained in. That is, we define  as  and then show that this definition works as expected, that is that. One detail: the definition, and the theorems that follow, do not insist that  is a relation. But we will refer to it as a relation simply because the definition and the theorems aren't particularly interesting if it is not. <jh> def ((domain R) (separate x (⋃ (⋃ R)) (∃ y ((orderedPair (value x) (value y)) ∈ R)))) </jh>

As usual, we may sometimes need to fold or unfold the definition while specifying the dummy variables in the definition. Unlike some such cases, we do not export this definition, but just use it in this file. That is because our definition of domain is specific to our definition of ordered pair, and isn't really needed once we prove  below. <jh> thm (Domain-def ((x R) (y R) (x y)  (x′ y′) (x y′) (x′ R) (y′ R) (x′ x) (y′ y))   ((domain R) = (separate x (⋃ (⋃ R)) (∃ y ((orderedPair (value x) (value y)) ∈ R)))) ( </jh> We start by changing  to , that is. <jh> (value x′) (value x) (value y′) OrderedPairBuilderRR R buildMembershipRRInConsequent y′ buildThereExistsInConsequent (⋃ (⋃ R)) ChangeVariableSeparation </jh> Then we show , <jh> (value y′) (value y) (value x) OrderedPairBuilderLL R buildMembershipRRInConsequent ChangeVariableThereExists </jh> and combine the two parts. <jh> x (⋃ (⋃ R)) buildSeparation applyEqualityTransitivity )) </jh>

The first lemma is. This is the part where we make use of our definition of the ordered pair. <jh> thm (Domain-1 ( (z A) (z B) (z R))  (((orderedPair A B) ∈ R) → ((unorderedPair A B) ∈ (⋃ R))) ( </jh> We will prove  by. That is, we need. We prove this by presenting such a, which is just   (matters will be clearer if we write it with the definition of ordered pair expanded:.

The first step is. <jh> ((unorderedPair (singleton A) (unorderedPair A B)) ∈ R) ImplicationReflexivity (unorderedPair A B) (singleton A) UnorderedPairRightMembership introduceLeftConjunctToConsequent </jh> Now we need to replace  with a variable. <jh> (value z)         (unorderedPair (singleton A) (unorderedPair A B)) (unorderedPair A B)         MembershipBuilderLL

(value z)         (unorderedPair (singleton A) (unorderedPair A B)) R         MembershipBuilderRR

buildConjunctionInConsequent

makeSubstExplicit eliminateBiconditionalForward applySyllogism </jh> Turning the substitution into ∃ gives us, and applying   we are done. <jh> (unorderedPair (singleton A) (unorderedPair A B)) z         (((unorderedPair A B) ∈ (value z)) ∧ ((value z) ∈ R)) ThereExistsIntroductionFromObject applySyllogism

(unorderedPair A B) R z Union eliminateBiconditionalForward applySyllogism )) </jh>

Our second lemma is, which goes most of the way towards showing that our definition of domain does what we expect it to. <jh> thm (Domain-2 ((y A) (y R))  ((∃ y ((orderedPair A (value y)) ∈ R)) → (A ∈ (⋃ (⋃ R)))) ( </jh> First we put  on the proof stack for later use. <jh> A (value y) UnorderedPairLeftMembership </jh> Leaving that aside for the moment, we start with the previous lemma, which is, and turn the consequent into. <jh> A (value y) R Domain-1

(unorderedPair A (value y)) (⋃ R) MembershipSubsetUnion applySyllogism </jh> Now we turn  into  , <jh> (unorderedPair A (value y)) (⋃ (⋃ R)) A SubsetMembership applySyllogism </jh> and then detach. That gives us  so adding   to the antecedent we are done. <jh> detachImplicationImplication y addThereExistsToAntecedent )) </jh>

We're now ready to prove the main result,. The proof follows fairly directly from the previous lemma, via  and a substitution. <jh> thm (Domain ((y B) (y R) (x y) (x B) (x R))   ((B ∈ (domain R)) ↔ (∃ y ((orderedPair B (value y)) ∈ R))) ( </jh> We expand  so that we can specify the variables involved. <jh> R x y Domain-def B buildMembershipLL </jh> We first apply  to get. <jh> y (value x) R Domain-2 B FormulaBound applyBiconditionalTransitivity </jh> The left side of that is just ; the right side is a subsitution away from being what we need. <jh> (value x) B (value y) OrderedPairBuilderRR R buildMembershipRRInConsequent y buildThereExistsInConsequent makeSubstExplicit applyBiconditionalTransitivity )) </jh>

Builder
Here we prove the domain builder from the definition. Another proof would invoke  and extensionality, although that would be more awkward as long as JHilbert's automatic expansion of definitions can lead to distinct variable problems. <jh> thm (DomainBuilder ( (y R) (y S) (y x) (x R) (x S)) ((R = S) → ((domain R) = (domain S))) ( </jh> We prove the builder based on the definition. The first step is. <jh> R S UnionBuilder (⋃ R) (⋃ S) UnionBuilder applySyllogism </jh> Next is <jh> R S (orderedPair (value x) (value y)) MembershipBuilderLL y buildThereExistsInConsequent x addForAllToConsequent </jh> Now we can apply the separation builder. <jh> composeConjunction (⋃ (⋃ R)) (⋃ (⋃ S)) x         (∃ y ((orderedPair (value x) (value y)) ∈ R)) (∃ y ((orderedPair (value x) (value y)) ∈ S)) SeparationBuilder applySyllogism )) </jh>

The domain of a singleton relation
Consider a relation which just contains a single ordered pair:. Its domain is simply.

<jh> thm (DomainSingletonRelationLemma ((y B) (y C) (y A))  ((∃ y ((orderedPair C (value y)) ∈ (singleton (orderedPair A B)))) ↔ (C = A)) ( (orderedPair C (value y)) (orderedPair A B) Singleton C (value y) A B OrderedPairTheorem applyBiconditionalTransitivity </jh> So far that gives us. Now we add  to both sides, and then move   outside the quantifier. <jh> y buildThereExists

y (C = A) ((value y) = B) ThereExistsConjunctionMovement applyBiconditionalTransitivity </jh> We have  and the   part is a theorem. <jh> y B Quantifiability (∃ y ((value y) = B)) (C = A) BiconditionalConjunct applyModusPonens swapBiconditional applyBiconditionalTransitivity ))

thm (DomainSingletonRelation ( (x A) (x B) (y x) (y A) (y B)  (x′ y′) (x′ A) (x′ B) (x′ x) (y′ A) (y′ B) (y′ x))   ((domain (singleton (orderedPair A B))) = (singleton A)) ( </jh> Because we are still in the same proof module as the definition of, we need to expand the definition manually (rather than automatically), and specify some distinct variable constraints for   and. <jh> (singleton (orderedPair A B)) x′ y′ Domain-def (value x) buildMembershipLL swapBiconditional </jh> We start with <jh> (value x) (singleton (orderedPair A B)) y Domain applyBiconditionalTransitivity </jh> The right hand side is equivalent to  by our lemma, <jh> y (value x) A B DomainSingletonRelationLemma applyBiconditionalTransitivity </jh> and to, which is all we need to apply extensionality. <jh> (value x) A Singleton swapBiconditional applyBiconditionalTransitivity

applyExtensionality )) </jh>

Range
We define range analogously to domain: the values which the second members of the ordered pairs in the relation can take on. At least for functions, range is sometimes defined to a be a set which contains the values, but here we pick the definition where it contains exactly the values and no others. <jh> def ((range R) (separate y (⋃ (⋃ R)) (∃ x ((orderedPair (value x) (value y)) ∈ R)))) </jh>

Metamath defines the range as the domain of the inverse relation. We haven't yet proved that the inverse relation exists, so at least for now we handle range much like we handled domain, rather than defining range in terms of domain.

A theorem expressing what the range is
As with domain, we provide a theorem to fold or unfold the definition while specifying the dummy variables in the definition. Also as with domain, we won't need this once we prove  below. <jh> thm (Range-def ((x R) (y R) (x y)  (x′ y′) (x′ y) (x y′) (x′ R) (y′ R) (x′ x) (y′ y))   ((range R) = (separate y (⋃ (⋃ R)) (∃ x ((orderedPair (value x) (value y)) ∈ R)))) ( </jh> We start by changing  to , that is. <jh> (value y′) (value y) (value x′) OrderedPairBuilderLL R buildMembershipRRInConsequent x′ buildThereExistsInConsequent (⋃ (⋃ R)) ChangeVariableSeparation </jh> Then we show , <jh> (value x′) (value x) (value y) OrderedPairBuilderRR R buildMembershipRRInConsequent ChangeVariableThereExists </jh> and combine the two parts. <jh> y (⋃ (⋃ R)) buildSeparation applyEqualityTransitivity )) </jh>

The next lemma is, which goes most of the way towards showing that our definition of range does what we expect it to. <jh> thm (Range-2 ((x A) (x R))  ((∃ x ((orderedPair (value x) A) ∈ R)) → (A ∈ (⋃ (⋃ R)))) ( </jh> First we put  on the proof stack for later use. <jh> A (value x) UnorderedPairRightMembership </jh> Leaving that aside for the moment, we start with, which is  , and turn the consequent into. <jh> (value x) A R Domain-1

(unorderedPair (value x) A) (⋃ R) MembershipSubsetUnion applySyllogism </jh> Now we turn  into  , <jh> (unorderedPair (value x) A) (⋃ (⋃ R)) A SubsetMembership applySyllogism </jh> and then detach. That gives us  so adding   to the antecedent we are done. <jh> detachImplicationImplication x addThereExistsToAntecedent )) </jh>

We're now ready to prove the main result,. The proof follows fairly directly from the previous lemma, via  and a substitution. <jh> thm (Range ((x B) (x R) (x y) (y B) (y R))   ((B ∈ (range R)) ↔ (∃ x ((orderedPair (value x) B) ∈ R))) ( </jh> We expand  so that we can specify the variables involved. <jh> R y x Range-def B buildMembershipLL </jh> We first apply  to get. <jh> x (value y) R Range-2 B FormulaBound applyBiconditionalTransitivity </jh> The left side of that is just ; the right side is a subsitution away from being what we need. <jh> (value y) B (value x) OrderedPairBuilderLL R buildMembershipRRInConsequent x buildThereExistsInConsequent makeSubstExplicit applyBiconditionalTransitivity )) </jh>

Builder
Here we prove the range builder, in a similar way to how we proved the domain builder. <jh> thm (RangeBuilder ( (y R) (y S) (y x) (x R) (x S)) ((R = S) → ((range R) = (range S))) ( </jh> We prove the builder based on the definition. The first step is. <jh> R S UnionBuilder (⋃ R) (⋃ S) UnionBuilder applySyllogism </jh> Next is <jh> R S (orderedPair (value x) (value y)) MembershipBuilderLL x buildThereExistsInConsequent y addForAllToConsequent </jh> Now we can apply the separation builder. <jh> composeConjunction (⋃ (⋃ R)) (⋃ (⋃ S)) y         (∃ x ((orderedPair (value x) (value y)) ∈ R)) (∃ x ((orderedPair (value x) (value y)) ∈ S)) SeparationBuilder applySyllogism )) </jh>

The range of a singleton relation
Analogously to domain, the range of  is simply.

<jh> thm (RangeSingletonRelationLemma ((x A) (x C) (x B))  ((∃ x ((orderedPair (value x) C) ∈ (singleton (orderedPair A B)))) ↔ (C = B)) ( (orderedPair (value x) C) (orderedPair A B) Singleton (value x) C A B OrderedPairTheorem applyBiconditionalTransitivity </jh> So far that gives us. Now we add  to both sides, and then move   outside the quantifier. <jh> x buildThereExists

x ((value x) = A) (C = B) ThereExistsConjunctionRightMovement applyBiconditionalTransitivity </jh> We have  and the   part is a theorem. <jh> x A Quantifiability (∃ x ((value x) = A)) (C = B) BiconditionalConjunct applyModusPonens

(C = B) (∃ x ((value x) = A)) ConjunctionCommutativity applyBiconditionalTransitivity

swapBiconditional applyBiconditionalTransitivity ))

thm (RangeSingletonRelation ( (x A) (x B) (y x) (y A) (y B)  (x′ y′) (x′ A) (x′ B) (x′ x) (x′ y) (y′ A) (y′ B) (y′ x) (y′ y))   ((range (singleton (orderedPair A B))) = (singleton B)) ( </jh> Because we are still in the same proof module as the definition of, we need to expand the definition manually (rather than automatically), and specify some distinct variable constraints for   and. <jh> (singleton (orderedPair A B)) x′ y′ Range-def (value y) buildMembershipLL swapBiconditional </jh> We start with <jh> (value y) (singleton (orderedPair A B)) x Range applyBiconditionalTransitivity </jh> The right hand side is equivalent to  by our lemma, <jh> x (value y) A B RangeSingletonRelationLemma applyBiconditionalTransitivity </jh> and to, which is all we need to apply extensionality. <jh> (value y) B Singleton swapBiconditional applyBiconditionalTransitivity

applyExtensionality )) </jh>

The first and second elements of an ordered pair
Here we attend to a notational detail: given an ordered pair, we want an expression for its first or second element. We define the first element of  as. <jh> def ((1st C) (⋃ (domain (singleton C)))) </jh>

The builder for  follows straightforwardly for the builders for the things which make up the definition. <jh> thm (FirstBuilder  ((A = B) → ((1st A) = (1st B))) ( A B SingletonBuilder

(singleton A) (singleton B) DomainBuilder applySyllogism

(domain (singleton A)) (domain (singleton B)) UnionBuilder applySyllogism )) </jh>

This theorem shows that  really does extract the first element of an ordered pair. The proof follows readily from  and our definitions, and can be summarized as. <jh> thm (First  ((1st (orderedPair A B)) = A) ( A B DomainSingletonRelation buildUnion

A UnionSingleton

applyEqualityTransitivity )) </jh>

Similarly, the second element of  is. <jh> def ((2nd C) (⋃ (range (singleton C)))) </jh>

The builder for  is proved much like the one for. <jh> thm (SecondBuilder  ((A = B) → ((2nd A) = (2nd B))) ( A B SingletonBuilder

(singleton A) (singleton B) RangeBuilder applySyllogism

(range (singleton A)) (range (singleton B)) UnionBuilder applySyllogism )) </jh>

Likewise,  really does extract the second element of an ordered pair. The proof is. <jh> thm (Second  ((2nd (orderedPair A B)) = B) ( A B RangeSingletonRelation buildUnion

B UnionSingleton

applyEqualityTransitivity )) </jh>

Cartesian product
The Cartesian product of two sets is the set of all ordered pairs consisting of one set from the first given set and one set from the second given set.

To show that it exists, we need to define it terms of a larger set which contains it. The larger set is  (this choice depends on our definition of ordered pair). Based on this concept, we define  to be. <jh> def ((× A B) (separate z (power (power (A ∪ B))) (∃ a (∃ b (((value z) = (orderedPair (value a) (value b))) ∧   (((value a) ∈ A) ∧ ((value b) ∈ B))))))) </jh>

Changing quantifiers
We first add the ability to specify the variables of quantification, as we do with most such definitions. Currently we do this for  and  ; we could also do it for   if need be. <jh> thm (CartesianProduct ((b′ z) (b′ a) (b′ b) (b′ A) (b′ B)    (b z) (b a) (b A) (b B)    (a′ z) (a′ b′) (a′ A) (a′ B)    (a z) (a A) (a B)    (a a′) (b b′) (z A) (z B) )   ((separate z (power (power (A ∪ B)))      (∃ a′ (∃ b′ (((value z) = (orderedPair (value a′) (value b′))) ∧ (((value a′) ∈ A) ∧ ((value b′) ∈ B)))))) = (separate z (power (power (A ∪ B)))     (∃ a (∃ b (((value z) = (orderedPair (value a) (value b))) ∧ (((value a) ∈ A) ∧ ((value b) ∈ B))))))) ( </jh> First we show. <jh> (value a′) (value a) (value b′) OrderedPairBuilderRR (value z) buildEqualityLLInConsequent

(value a′) (value a) A MembershipBuilderRR ((value b′) ∈ B) buildConjunctionRRInConsequent

buildConjunctionInConsequent b′ buildThereExistsInConsequent

ChangeVariableThereExists </jh> The change of the inner quantifier starts with, which then leads to  <jh> (value b′) (value b) (value a) OrderedPairBuilderLL (value z) buildEqualityLLInConsequent

(value b′) (value b) B MembershipBuilderRR ((value a) ∈ A) buildConjunctionLLInConsequent

buildConjunctionInConsequent

ChangeVariableThereExists </jh> Combining the two variable changes gives us everything except the separation, which we then add. <jh> a buildThereExists applyBiconditionalTransitivity

z (power (power (A ∪ B))) buildSeparation )) </jh>

Membership in a Cartesian product
To go from the definition to various theorems which restate what a Cartesian product is, our first lemma is. <jh> thm (MembershipCartesianProductLemma   (((α ∈ A) ∧ (β ∈ B)) → ((orderedPair α β) ∈ (power (power (A ∪ B))))) ( </jh> The ordered pair  has two elements,   and. We start with the former, and the first step is <jh> (α ∈ A) (β ∈ B) ConjunctionRightElimination

α A SingletonSubset eliminateBiconditionalReverse applySyllogism </jh> The consequent in turn implies , <jh> (singleton α) A B SubsetUnionRightIntroduction applySyllogism </jh> which then becomes. <jh> (singleton α) (A ∪ B) PowerSet eliminateBiconditionalForward applySyllogism </jh> Turning our attention to, we start with. <jh> α A B MembershipUnionRightIntroduction β B A MembershipUnionLeftIntroduction conjoin </jh> The consequent implies , <jh> α (A ∪ B) β UnorderedPairSubset eliminateBiconditionalReverse applySyllogism </jh> which in turn implies. <jh> (unorderedPair α β) (A ∪ B) PowerSet eliminateBiconditionalForward applySyllogism </jh> Combining  and   gives. <jh> composeConjunction (singleton α) (power (A ∪ B)) (unorderedPair α β) UnorderedPairSubset eliminateBiconditionalReverse applySyllogism </jh> That in turn is just, which is what we are seeking to prove. <jh> (orderedPair α β) (power (A ∪ B)) PowerSet eliminateBiconditionalForward applySyllogism )) </jh>

The next lemma combines the previous one with a substitution and adds some quantifiers: <jh> thm (MembershipCartesianProduct-2 ((a Z) (b Z) (a A) (b A) (a B) (b B))  ((∃ a (∃ b ((Z = (orderedPair (value a) (value b))) ∧ (((value a) ∈ A) ∧ ((value b) ∈ B))))) → (Z ∈ (power (power (A ∪ B))))) ( </jh> We start with  (which was the previous lemma), and then conjoin   to both antecedent and consequent. <jh> (value a) A (value b) B MembershipCartesianProductLemma (Z = (orderedPair (value a) (value b))) conjoinLL </jh> Next we take the substitution  and rearrange it into <jh> Z         (orderedPair (value a) (value b)) (power (power (A ∪ B))) MembershipBuilderRR eliminateBiconditionalForwardInConsequent import </jh> That's almost it. Combining those implications gives, and then we just add the quantifiers. <jh> applySyllogism

b addThereExistsToAntecedent a addThereExistsToAntecedent )) </jh>

It just takes some logic to turn that into, which we can take as a basic equivalence which "defines" the meaning of a Cartesian product. <jh> thm (MembershipCartesianProduct ((a b A) (a b B) (a b C)    (C z a′ b′) (a b z a′ b′) (A z a′ b′) (B z a′ b′))   ((C ∈ (A × B)) ↔ (∃ a (∃ b ((C = (orderedPair (value a) (value b)))     ∧ (((value a) ∈ A) ∧ ((value b) ∈ B)))))) ( </jh> We start by expanding the definition of. <jh> z A B a′ b′ a b CartesianProduct C buildMembershipLL </jh> We now proceed to. <jh> a b (value z) A B MembershipCartesianProduct-2 C FormulaBound applyBiconditionalTransitivity </jh> We now have. We now just perform the substitution, starting with <jh> (value z) C (orderedPair (value a) (value b)) EqualityBuilderRR (((value a) ∈ A) ∧ ((value b) ∈ B)) buildConjunctionRRInConsequent b buildThereExistsInConsequent a buildThereExistsInConsequent makeSubstExplicit

applyBiconditionalTransitivity )) </jh>

An ordered pair which is a member of a Cartesian product
Here we show that. <jh> thm (OrderedPairCartesianProduct ( (a b A) (a b B) (a b A0) (a b B0))  (((orderedPair A0 B0) ∈ (A × B)) ↔ ((A0 ∈ A) ∧ (B0 ∈ B))) ( </jh> The first step is invoking  with the ordered pair as the element. That is, <jh> (orderedPair A0 B0) A B a b MembershipCartesianProduct </jh> Applying the ordered pair theorem and rearranging the conjunctions turns this into. <jh> A0 B0 (value a) (value b) OrderedPairTheorem (((value a) ∈ A) ∧ ((value b) ∈ B)) buildConjunctionRR b buildThereExists a buildThereExists applyBiconditionalTransitivity

(A0 = (value a)) (B0 = (value b)) ((value a) ∈ A) ((value b) ∈ B) Conjunction4 b buildThereExists a buildThereExists applyBiconditionalTransitivity </jh> We now scatter the quantifiers to give. <jh> a         b          ((A0 = (value a)) ∧ ((value a) ∈ A)) ((B0 = (value b)) ∧ ((value b) ∈ B)) ThereExistsScattering applyBiconditionalTransitivity </jh> Each half of that is equivalent to a membership formula (that is,  and likewise for the other half). <jh> A0 (value a) EqualitySymmetry ((value a) ∈ A) buildConjunctionRR a buildThereExists

A0 A a MembershipThereExists swapBiconditional applyBiconditionalTransitivity

B0 (value b) EqualitySymmetry ((value b) ∈ B) buildConjunctionRR b buildThereExists

B0 B b MembershipThereExists swapBiconditional applyBiconditionalTransitivity

buildConjunction applyBiconditionalTransitivity )) </jh>

To be added
Either here or in other set theory files: induction, recursion, ordinal successors. some kinds of unions, intersection, set difference, and so on.

Export
<jh> export (RESULT Interface:Relations_1 (CLASSICAL FIRSTORDER) ) </jh>