1-- Order isomorphisms: the pointwise characterisation, identity, inverse,2-- composition, restriction, images of initial segments, and the rigidity3-- of ordinals: an isomorphism between ordinals under membership is the4-- identity5-- Part of Cumulus, the Grace17 mathematics library.6-- Copyright (c) 2026 Grant Passmore.7-- Released under the Apache License 2.0. See LICENSE in the repository root.8-- Authors: Grant Passmore910module Grace.Cumulus.Set.WellOrder.Isomorphism11import WellOrder1213-- An order isomorphism, read through function application: for x and y14-- in A, x is below y exactly when f(x) is below f(y).15theorem OrderIsomorphism.apply_iff (f A r B s x y : Set)16requires iso : OrderIsomorphism(f, A, r, B, s)17requires hx : x ∈ A18requires hy : y ∈ A19shows relates(r, x, y) ↔ relates(s, f(x), f(y))20proof21have function := Bijective.injective with iso.left22have fFunction := Injective.function with function23have valueX := FunctionBetween.apply_closed with fFunction, hx24have valueY := FunctionBetween.apply_closed with fFunction, hy25have relatedX := FunctionBetween.relates_apply with fFunction, hx26have relatedY := FunctionBetween.relates_apply with fFunction, hy27exact iso.right with x, hx, y, hy, f(x), valueX, f(y), valueY, relatedX, relatedY2829theorem OrderIsomorphism.of_apply (f A r B s : Set)30requires bijective : BijectiveBetween(f, A, B)31requires preserves : ∀ x ∈ A, ∀ y ∈ A, relates(r, x, y) ↔ relates(s, f(x), f(y))32shows OrderIsomorphism(f, A, r, B, s)33proof34have fFunction := Injective.function with (Bijective.injective with bijective)35constructor36 . exact bijective37 . intros x hx y hy u hu v hv hxu hyv38have valueU := FunctionBetween.apply_value with fFunction, hx, hxu39have valueV := FunctionBetween.apply_value with fFunction, hy, hyv40rw [← valueU, ← valueV]41exact preserves with x, hx, y, hy4243theorem OrderIsomorphism.identity (A r : Set)44shows OrderIsomorphism(identity(A), A, r, A, r)45proof46apply OrderIsomorphism.of_apply with (identity.bijective at A)47intros x hx y hy48have fixedX := identity.apply with hx49have fixedY := identity.apply with hy50rw [fixedX, fixedY]51constructor52 . intro h53exact h54 . intro h55exact h5657theorem OrderIsomorphism.inverse (f A r B s : Set)58requires iso : OrderIsomorphism(f, A, r, B, s)59shows OrderIsomorphism(converse(f, A, B), B, s, A, r)60proof61have bijective := iso.left62have inverse := converse.bijective with bijective63have fFunction := Injective.function with (Bijective.injective with bijective)64have gFunction := Injective.function with (Bijective.injective with inverse)65apply OrderIsomorphism.of_apply with inverse66intros u hu v hv67have preimageU := FunctionBetween.apply_closed with gFunction, hu68have preimageV := FunctionBetween.apply_closed with gFunction, hv69have backU := Bijective.apply_inverse with bijective, hu70have backV := Bijective.apply_inverse with bijective, hv71have characterization := OrderIsomorphism.apply_iff with iso, preimageU, preimageV72rw [backU, backV] at characterization73constructor74 . intro h75exact characterization.backward with h76 . intro h77exact characterization.forward with h7879theorem OrderIsomorphism.compose (g f A r B s C t : Set)80requires first : OrderIsomorphism(f, A, r, B, s)81requires second : OrderIsomorphism(g, B, s, C, t)82shows OrderIsomorphism(compose(g, f, A, B, C), A, r, C, t)83proof84have fFunction := Injective.function with (Bijective.injective with first.left)85have gFunction := Injective.function with (Bijective.injective with second.left)86have bijective := compose.bijective with first.left, second.left87apply OrderIsomorphism.of_apply with bijective88intros x hx y hy89have valueX := FunctionBetween.apply_closed with fFunction, hx90have valueY := FunctionBetween.apply_closed with fFunction, hy91have stepX := compose.apply with fFunction, gFunction, hx92have stepY := compose.apply with fFunction, gFunction, hy93rw [stepX, stepY]94have innerCharacterization := OrderIsomorphism.apply_iff with first, hx, hy95have outerCharacterization := OrderIsomorphism.apply_iff with second, valueX, valueY96constructor97 . intro h98exact outerCharacterization.forward with (innerCharacterization.forward with h)99 . intro h100exact innerCharacterization.backward with (outerCharacterization.backward with h)101102-- Replacing the order on the domain by one that agrees on it.103theorem OrderIsomorphism.congr_left (f A r t B s : Set)104requires iso : OrderIsomorphism(f, A, r, B, s)105requires agree : ∀ x ∈ A, ∀ y ∈ A, relates(t, x, y) ↔ relates(r, x, y)106shows OrderIsomorphism(f, A, t, B, s)107proof108apply OrderIsomorphism.of_apply with iso.left109intros x hx y hy110have inner := agree with x, hx, y, hy111have characterization := OrderIsomorphism.apply_iff with iso, hx, hy112constructor113 . intro h114exact characterization.forward with (inner.forward with h)115 . intro h116exact inner.backward with (characterization.backward with h)117118-- The image of an initial segment under an isomorphism is an initial segment.119theorem OrderIsomorphism.image_initial (f A r B s I : Set)120requires iso : OrderIsomorphism(f, A, r, B, s)121requires initial : InitialSegment(A, r, I)122shows InitialSegment(B, s, functionImage(f, I, B))123proof124have hI := InitialSegment.subset with initial125have bijective := iso.left126have inverse := converse.bijective with bijective127have gFunction := Injective.function with (Bijective.injective with inverse)128constructor129 . intros y hy130simp [functionImage.membership] at hy131exact hy.left132 . intros y hy z hz hzy133simp [functionImage.membership] at hy134obtain⟨inB, x, hx, shape⟩:= hy135have hxA := hI with x, hx136have hw := FunctionBetween.apply_closed with gFunction, hz137have back := Bijective.apply_inverse with bijective, hz138rw [shape, ← back] at hzy139have characterization := OrderIsomorphism.apply_iff with iso, hw, hxA140have below := characterization.backward with hzy141have inI := initial.right with x, hx, converse(f, A, B)(z), hw, below142rw← back at hz143rw← back144simp [functionImage.membership]145constructor146 . exact hz147 . witness converse(f, A, B)(z)148constructor149 . exact inI150 . rfl151152-- The order carried to the image of an injection is the transported order153-- of Set/OrderTransport; the restriction of an isomorphism to a subset of154-- its domain is an isomorphism onto the image under the restricted orders.155theorem OrderIsomorphism.restrict (f A r B s S : Set)156requires iso : OrderIsomorphism(f, A, r, B, s)157requires hS : S ⊆ A158shows OrderIsomorphism(restrict(f, S), S, restrictOrder(r, S), functionImage(f, S, B), restrictOrder(s, functionImage(f, S, B)))159proof160have fFunction := Injective.function with (Bijective.injective with iso.left)161have closed : ∀ x ∈ S, f(x) ∈ functionImage(f, S, B)162intros x hx163have value := FunctionBetween.apply_closed with fFunction, (hS with x, hx)164simp [functionImage.membership]165have restricted := restrict.function with fFunction, hS, closed166have injective : InjectiveBetween(restrict(f, S), S, functionImage(f, S, B))167constructor168 . exact restricted169 . intros x hx y hy z hz hxz hyz170have valueX := FunctionBetween.apply_value with restricted, hx, hxz171have valueY := FunctionBetween.apply_value with restricted, hy, hyz172have stepX := restrict.apply with fFunction, hS, closed, hx173have stepY := restrict.apply with fFunction, hS, closed, hy174rw stepX at valueX175rw stepY at valueY176have agree : f(x) = f(y)177rw [valueX, valueY]178rfl179exact Injective.apply_cancel with (Bijective.injective with iso.left), (hS with x, hx), (hS with y, hy), agree180have surjective : SurjectiveBetween(restrict(f, S), S, functionImage(f, S, B))181constructor182 . exact restricted183 . intros y hy184simp [functionImage.membership] at hy185obtain⟨inB, x, hx, shape⟩:= hy186witness x187constructor188 . exact hx189 . have related := FunctionBetween.relates_apply with restricted, hx190have step := restrict.apply with fFunction, hS, closed, hx191 rwa [step, ← shape] at related192apply OrderIsomorphism.of_apply with⟨injective, surjective⟩193intros x hx y hy194have stepX := restrict.apply with fFunction, hS, closed, hx195have stepY := restrict.apply with fFunction, hS, closed, hy196rw [stepX, stepY]197have characterization := OrderIsomorphism.apply_iff with iso, (hS with x, hx), (hS with y, hy)198have imageX := closed with x, hx199have imageY := closed with y, hy200constructor201 . intro h202have inner := restrictOrder.relates.forward with h203apply restrictOrder.relates.backward204exact⟨(characterization.forward with inner.left), imageX, imageY⟩205 . intro h206have inner := restrictOrder.relates.forward with h207apply restrictOrder.relates.backward208exact⟨(characterization.backward with inner.left), hx, hy⟩209210-- Ordinals are rigid: an order isomorphism between two ordinals, each211-- under membership, fixes every point, so isomorphic ordinals are equal.212theorem OrderIsomorphism.ordinal_fixed (f α β γ : Set)213requires hAlpha : α ∈Ordinal214requires hBeta : β ∈Ordinal215requires iso : OrderIsomorphism(f, α, membershipOn(α), β, membershipOn(β))216requires hγ : γ ∈ α217shows f(γ) = γ218proof219revert hγ220induction γ using membership221intros current ih hCurrent222have bijective := iso.left223have fFunction := Injective.function with (Bijective.injective with bijective)224have inverse := converse.bijective with bijective225have gFunction := Injective.function with (Bijective.injective with inverse)226have value := FunctionBetween.apply_closed with fFunction, hCurrent227ext z228constructor229 . intro hz230have below :=Ordinal.member_subset with hBeta, value231have hzB := below with z, hz232have hw := FunctionBetween.apply_closed with gFunction, hzB233have back := Bijective.apply_inverse with bijective, hzB234have fw := FunctionBetween.apply_closed with fFunction, hw235have outerRule := membershipOn.relates with fw, value236have innerRule := membershipOn.relates with hw, hCurrent237have characterization := OrderIsomorphism.apply_iff with iso, hw, hCurrent238rw← back at hz239have outer := outerRule.backward with hz240have inner := characterization.backward with outer241have member := innerRule.forward with inner242have fixed := ih with converse(f, α, β)(z), member, hw243 rwa [← back, fixed]244 . intro hz245have below :=Ordinal.member_subset with hAlpha, hCurrent246have hzA := below with z, hz247have innerRule := membershipOn.relates with hzA, hCurrent248have inner := innerRule.backward with hz249have characterization := OrderIsomorphism.apply_iff with iso, hzA, hCurrent250have outer := characterization.forward with inner251have fz := FunctionBetween.apply_closed with fFunction, hzA252have outerRule := membershipOn.relates with fz, value253have member := outerRule.forward with outer254have fixed := ih with z, hz, hzA255 rwa fixed at member256257theorem OrderIsomorphism.ordinal_equal (f α β : Set)258requires hAlpha : α ∈Ordinal259requires hBeta : β ∈Ordinal260requires iso : OrderIsomorphism(f, α, membershipOn(α), β, membershipOn(β))261shows α = β262proof263have bijective := iso.left264have fFunction := Injective.function with (Bijective.injective with bijective)265have inverse := OrderIsomorphism.inverse with iso266have gFunction := Injective.function with (Bijective.injective with inverse.left)267apply Subset.antisymmetric268 . intros γ hγ269have fixed := OrderIsomorphism.ordinal_fixed with hAlpha, hBeta, iso, hγ270have value := FunctionBetween.apply_closed with fFunction, hγ271 rwa fixed at value272 . intros γ hγ273have fixed := OrderIsomorphism.ordinal_fixed with hBeta, hAlpha, inverse, hγ274have value := FunctionBetween.apply_closed with gFunction, hγ275 rwa fixed at value276