1-- The transfinite iteration of the derived set: stages indexed by the2-- ordinals, intersecting at limits, with the three recursion laws, the3-- membership form at limits, and the stages closed and decreasing4-- Part of Cumulus, the Grace17 mathematics library.5-- Copyright (c) 2026 Grant Passmore.6-- Released under the Apache License 2.0. See LICENSE in the repository root.7-- Authors: Grant Passmore89module Grace.Cumulus.Topology.CantorBendixson.Iterate10import Derived1112-- The stages of a set A: the set itself, then the derived set of the13-- previous stage, and at a limit the intersection of the earlier stages.14noncomputabletransfinitedef derived (X T A : Set, α : Ordinal) : Set15|0=> A16| succ β => derivedSet(X, T, derived(X, T, A, β))17| limit λ => ⋂(Relation.range(history))1819theorem derived.zero (X T A : Set)20shows derived(X, T, A, 0) = A21proof22simp [derived, nat.zero]2324theorem derived.next (X T A : Set, α : Ordinal)25shows derived(X, T, A, next(α)) = derivedSet(X, T, derived(X, T, A, α))26proof27simp [derived.equation.successor]2829theorem derived.limit (X T A λ : Set)30requires limit : Limit(λ)31shows derived(X, T, A, λ) = ⋂(Relation.range(derived.history(X, T, A, λ)))32proof33simp [derived.equation.limit]3435theorem derived.history_membership (p X T A λ : Set)36shows p ∈ derived.history(X, T, A, λ) ↔37∃ β ∈ λ, p = (β ↦ derived(X, T, A, β))38proof39simp [derived.history.membership]4041theorem derived.history_range (y X T A λ : Set)42shows y ∈ Relation.range(derived.history(X, T, A, λ)) ↔43∃ β ∈ λ, y = derived(X, T, A, β)44proof45constructor46 . intro hy47obtain⟨β, hPair⟩:= range.membership_iff.forward with hy48have member : (β, y) ∈ derived.history(X, T, A, λ) := hPair49obtain⟨γ, hγ, shape⟩:= derived.history_membership.forward with50 member51have coordinates := orderedPair.injective with shape52witness γ53constructor54 . exact hγ55 . exact coordinates.right56 . intro h57obtain⟨β, hβ, shape⟩:= h58have member : (β ↦ derived(X, T, A, β)) ∈ derived.history(X, T, A, λ)59exact derived.history_membership.backward with⟨β, hβ, rfl⟩60rw shape61exact range.contains with member6263theorem derived.stage_in_range (X T A β λ : Set)64requires hβ : β ∈ λ65shows derived(X, T, A, β) ∈ Relation.range(derived.history(X, T, A, λ))66proof67exact derived.history_range.backward with⟨β, hβ, rfl⟩6869-- At a limit, a point lies in the stage exactly when it lies in every70-- earlier stage.71theorem derived.limit_membership (X T A x λ : Set)72requires limit : Limit(λ)73shows x ∈ derived(X, T, A, λ) ↔∀ β ∈ λ, x ∈ derived(X, T, A, β)74proof75have equation := derived.limit at X, T, A, λ with limit76rw equation77constructor78 . intros hx β hβ79have parts := familyIntersection.membership.forward with hx80have stage := derived.stage_in_range at X, T, A with hβ81exact parts.right with derived(X, T, A, β), stage82 . intro below83obtain⟨ordinal, nonzero, successors⟩:= limit84obtain⟨β, hβ⟩:= Nonempty.of_ne_empty with nonzero85have stage := derived.stage_in_range at X, T, A with hβ86have inhabited : Nonempty(Relation.range(derived.history(X, T, A, λ)))87exact⟨derived(X, T, A, β), stage⟩88apply familyIntersection.membership_of_nonempty.backward with inhabited89intros S hS90obtain⟨γ, hγ, shape⟩:= derived.history_range.forward with hS91rw shape92exact below with γ, hγ9394-- Every stage of a closed set is closed: the derived set of a closed set95-- is closed, and so is an intersection of closed sets. The induction runs96-- over the ordinals up to a bound, ordered by membership.97theorem derived.closed_below (X T A β : Set)98requires topology : IsTopology(X, T)99requires closed : IsClosed(X, T, A)100requires hBeta : β ∈Ordinal101shows∀ α ∈ next(β), IsClosed(X, T, derived(X, T, A, α))102proof103have hNext :=Ordinal.next with hBeta104have transitive :=Ordinal.transitive with hNext105induction α over next(β) orderedby membershipOn(next(β)) certifiedby membershipOn.wellFounded at next(β)106intros current hCurrentIn ih107have hCurrent :=Ordinal.member with hNext, hCurrentIn108havesplit:=Ordinal.cases with hCurrent109casessplitwith zero | rest110 . rw [zero, ← nat.zero, derived.zero]111exact closed112 . cases rest with successor | limit113 . obtain⟨γ, hγ, equal⟩:= successor114have hGamma :=Ordinal.member with hCurrent, hγ115have hGammaIn := transitive with current, hCurrentIn, γ, hγ116have rule := membershipOn.relates with hGammaIn, hCurrentIn117have predecessor : γ ∈ next(β) ∧118 relates(membershipOn(next(β)), γ, current)119exact⟨hGammaIn, (rule.backward with hγ)⟩120have closedGamma := ih with γ, predecessor121rw [← equal, derived.next]122exact derivedSet.closed with topology, closedGamma123 . have equation := derived.limit at X, T, A, current with limit124rw equation125obtain⟨ordinal, nonzero, successors⟩:= limit126obtain⟨γ, hγ⟩:= Nonempty.of_ne_empty with nonzero127have stage := derived.stage_in_range at X, T, A with hγ128have inhabited : Nonempty(Relation.range(derived.history(X, T, A, current)))129exact⟨derived(X, T, A, γ), stage⟩130apply IsClosed.family_intersection with topology, inhabited131intros S hS132obtain⟨ε, hε, shape⟩:= derived.history_range.forward with hS133rw shape134have hEpsilonIn := transitive with current, hCurrentIn, ε, hε135have rule := membershipOn.relates with hEpsilonIn, hCurrentIn136have predecessor : ε ∈ next(β) ∧137 relates(membershipOn(next(β)), ε, current)138exact⟨hEpsilonIn, (rule.backward with hε)⟩139exact ih with ε, predecessor140141theorem derived.closed (X T A α : Set)142requires topology : IsTopology(X, T)143requires closed : IsClosed(X, T, A)144requires hAlpha : α ∈Ordinal145shows IsClosed(X, T, derived(X, T, A, α))146proof147have below := derived.closed_below at X, T, A, α with148 topology, closed, hAlpha149exact below with α, (next.contains at α)150151theorem derived.subset_whole (X T A α : Set)152requires topology : IsTopology(X, T)153requires closed : IsClosed(X, T, A)154requires hAlpha : α ∈Ordinal155shows derived(X, T, A, α) ⊆ X156proof157have closedStage := derived.closed with topology, closed, hAlpha158exact closedStage.left159160-- The stages decrease along the ordinals: a successor stage is the161-- derived set of a closed stage, which lies inside it, and a limit stage162-- is the intersection of the earlier ones.163theorem derived.decreasing_below (X T A δ : Set)164requires topology : IsTopology(X, T)165requires closed : IsClosed(X, T, A)166requires hDelta : δ ∈Ordinal167shows∀ β ∈ next(δ), ∀ α, α ∈Ordinal→ α ∈ next(β) →168 (derived(X, T, A, β) ⊆ derived(X, T, A, α))169proof170have hNext :=Ordinal.next with hDelta171have transitive :=Ordinal.transitive with hNext172induction β over next(δ) orderedby membershipOn(next(δ)) certifiedby membershipOn.wellFounded at next(δ)173intros current hCurrentIn ih α hAlpha hBound174have hCurrent :=Ordinal.member with hNext, hCurrentIn175have bound := next.membership.forward with hBound176cases bound with earlier | equal177 . havesplit:=Ordinal.cases with hCurrent178casessplitwith zero | rest179 . exfalso180rw zero at earlier181exactset.empty with earlier182 . cases rest with successor | limit183 . obtain⟨γ, hγ, equal⟩:= successor184have hGamma :=Ordinal.member with hCurrent, hγ185have hGammaIn := transitive with current, hCurrentIn, γ, hγ186have rule := membershipOn.relates with hGammaIn, hCurrentIn187have predecessor : γ ∈ next(δ) ∧188 relates(membershipOn(next(δ)), γ, current)189exact⟨hGammaIn, (rule.backward with hγ)⟩190have closedGamma := derived.closed with topology, closed, hGamma191rw← equal at earlier192have toAlpha := ih with γ, predecessor, α, hAlpha, earlier193have drop := derivedSet.subset with topology, closedGamma194rw [← equal, derived.next]195exact Subset.transitive with drop, toAlpha196 . have equation := derived.limit at X, T, A, current with limit197rw equation198have stage := derived.stage_in_range at X, T, A with earlier199exact familyIntersection.subset_of_member with stage200 . rw equal201exact Subset.reflexive202203theorem derived.decreasing (X T A α β : Set)204requires topology : IsTopology(X, T)205requires closed : IsClosed(X, T, A)206requires hAlpha : α ∈Ordinal207requires hBeta : β ∈Ordinal208requires hBound : α ∈ next(β)209shows derived(X, T, A, β) ⊆ derived(X, T, A, α)210proof211have below := derived.decreasing_below at X, T, A, β with212 topology, closed, hBeta213exact below with β, (next.contains at β), α, hAlpha, hBound214215theorem derived.antitone (X T A α β : Set)216requires topology : IsTopology(X, T)217requires closed : IsClosed(X, T, A)218requires hAlpha : α ∈Ordinal219requires hBeta : β ∈Ordinal220requires hLess : α ∈ β221shows derived(X, T, A, β) ⊆ derived(X, T, A, α)222proof223have bound : α ∈ next(β)224apply next.membership.backward225left226exact hLess227exact derived.decreasing with topology, closed, hAlpha, hBeta, bound228229theorem derived.next_subset (X T A α : Set)230requires topology : IsTopology(X, T)231requires closed : IsClosed(X, T, A)232requires hAlpha : α ∈Ordinal233shows derived(X, T, A, next(α)) ⊆ derived(X, T, A, α)234proof235have closedStage := derived.closed with topology, closed, hAlpha236rw derived.next237exact derivedSet.subset with topology, closedStage238239theorem derived.subset (X T A α : Set)240requires topology : IsTopology(X, T)241requires closed : IsClosed(X, T, A)242requires hAlpha : α ∈Ordinal243shows derived(X, T, A, α) ⊆ A244proof245have bound :=Ordinal.subset_bound at∅, α with246Ordinal.empty, hAlpha, (empty.subset at α)247have below := derived.decreasing at X, T, A, ∅, α with248 topology, closed, Ordinal.empty, hAlpha, bound249rw [← nat.zero, derived.zero] at below250exact below251