1-- Continuous maps between topological spaces: preimages of open sets are2-- open. Identity and composition, the closed-set characterisation, the3-- closure inclusion, and homeomorphisms4-- 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.Continuity10import Space1112predicate ContinuousMap (f X T Y S : Set) :=13 FunctionBetween(f, X, Y) ∧ (∀ V ∈ S, functionPreimage(f, X, V) ∈ T)1415predicate IsHomeomorphism (f X T Y S : Set) :=16 BijectiveBetween(f, X, Y) ∧ ContinuousMap(f, X, T, Y, S) ∧17 ContinuousMap(converse(f, X, Y), Y, S, X, T)1819theorem ContinuousMap.function (f X T Y S : Set)20requires continuous : ContinuousMap(f, X, T, Y, S)21shows f : X → Y22proof23exact continuous.left2425theorem ContinuousMap.preimage (f X T Y S V : Set)26requires continuous : ContinuousMap(f, X, T, Y, S)27requires hV : V ∈ S28shows functionPreimage(f, X, V) ∈ T29proof30exact continuous.right with V, hV3132theorem ContinuousMap.identity (X T : Set)33requires topology : IsTopology(X, T)34shows ContinuousMap(identity(X), X, T, X, T)35proof36have function := identity.function at X37constructor38 . exact function39 . intros V hV40have inside := IsTopology.subset with topology, hV41have same : functionPreimage(identity(X), X, V) = V42ext x43constructor44 . intro hx45have parts := functionPreimage.membership.forward with hx46have fixed := identity.apply with parts.left47rw fixed at parts48exact parts.right49 . intro hx50have hxX := inside with x, hx51have fixed := identity.apply with hxX52apply functionPreimage.membership.backward53rw fixed54exact⟨hxX, hx⟩55 rwa same5657theorem ContinuousMap.compose (g f X T Y S Z R : Set)58requires first : ContinuousMap(f, X, T, Y, S)59requires second : ContinuousMap(g, Y, S, Z, R)60shows ContinuousMap(compose(g, f, X, Y, Z), X, T, Z, R)61proof62have fFunction := first.left63have gFunction := second.left64constructor65 . exact compose.function with fFunction, gFunction66 . intros W hW67have step := functionPreimage.compose at g, f, X, Y, Z, W with fFunction, gFunction68rw step69have inner := second.right with W, hW70exact first.right with functionPreimage(g, Y, W), inner7172theorem ContinuousMap.closed_preimage (f X T Y S C : Set)73requires continuous : ContinuousMap(f, X, T, Y, S)74requires closed : IsClosed(Y, S, C)75shows IsClosed(X, T, functionPreimage(f, X, C))76proof77have function := continuous.left78constructor79 . exact functionPreimage.subset at f, X, C80 . have isOpen := continuous.right with complement(Y, C), closed.right81have swap := functionPreimage.complement at f, X, Y, C with function82unfold complement at isOpen83rw swap at isOpen84unfold complement85exact isOpen8687theorem ContinuousMap.of_closed_preimages (f X T Y S : Set)88requires topologyX : IsTopology(X, T)89requires topologyY : IsTopology(Y, S)90requires function : f : X → Y91requires closed : ∀ C, IsClosed(Y, S, C) → IsClosed(X, T, functionPreimage(f, X, C))92shows ContinuousMap(f, X, T, Y, S)93proof94constructor95 . exact function96 . intros V hV97have closedV := Open.complement_closed with topologyY, hV98have closedPreimage := closed with complement(Y, V), closedV99have swap := functionPreimage.complement at f, X, Y, V with function100unfold complement at closedPreimage101rw swap at closedPreimage102have inside := functionPreimage.subset at f, X, V103have double := complement.complement with inside104have isOpen := closedPreimage.right105have fold : complement(X, functionPreimage(f, X, V)) = X ∖ functionPreimage(f, X, V)106unfold complement107rfl108 rwa [← fold, double] at isOpen109110-- A continuous map sends the closure of A into the closure of its image.111theorem ContinuousMap.image_closure (f X T Y S A : Set)112requires topologyX : IsTopology(X, T)113requires topologyY : IsTopology(Y, S)114requires continuous : ContinuousMap(f, X, T, Y, S)115requires hA : A ⊆ X116shows functionImage(f, closure(X, T, A), Y) ⊆ closure(Y, S, functionImage(f, A, Y))117proof118have function := continuous.left119have closureInside := closure.subset with topologyX, hA120have imageInside := functionImage.subset at f, A, Y121intros y hy122simp [functionImage.membership] at hy123obtain⟨hyY, x, hx, shape⟩:= hy124apply closure.membership.backward with topologyY, imageInside125refine⟨hyY, ?_⟩126intros V hV hyV127have hxX := closureInside with x, hx128have preimageOpen := continuous.right with V, hV129have hxPreimage : x ∈ functionPreimage(f, X, V)130apply functionPreimage.membership.backward131rw← shape132exact⟨hxX, hyV⟩133have touches := closure.membership.forward with topologyX, hA, hx134obtain⟨a, ha⟩:= touches.right with functionPreimage(f, X, V), preimageOpen, hxPreimage135have parts := intersection.membership.forward with ha136have preimageParts := functionPreimage.membership.forward with parts.left137witness f(a)138apply intersection.membership.backward139constructor140 . exact preimageParts.right141 . have value := FunctionBetween.apply_closed with function, preimageParts.left142simp [functionImage.membership]143constructor144 . exact value145 . witness a146constructor147 . exact parts.right148 . rfl149150theorem IsHomeomorphism.inverse (f X T Y S : Set)151requires homeomorphism : IsHomeomorphism(f, X, T, Y, S)152shows IsHomeomorphism(converse(f, X, Y), Y, S, X, T)153proof154obtain⟨bijective, forward, backward⟩:= homeomorphism155have inverse := converse.bijective with bijective156refine⟨inverse, backward, ?_⟩157have relation := FunctionBetween.relation with (Injective.function with (Bijective.injective with bijective))158have same := converse.converse with relation159 rwa same160