|
| 1 | +/- |
| 2 | +Copyright (c) 2026 Yury Kudryashov. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Yury Kudryashov, Gemini CLI |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.Topology.Defs.Induced |
| 9 | + |
| 10 | +/-! |
| 11 | +# Basic lemmas and instances about the `WithTopology` type synonym |
| 12 | +
|
| 13 | +`WithTopology X t` is a copy of `X` equipped with the topology `t`. |
| 14 | +This is useful for providing multiple topologies on the same type |
| 15 | +without causing instance conflicts. |
| 16 | +
|
| 17 | +In this file we setup basic API about this type |
| 18 | +and transfer instances (basic, order) from `X` to `WithTopology X t`. |
| 19 | +
|
| 20 | +## Implementation notes |
| 21 | +
|
| 22 | +The pattern here is the same one as is used by `Lex` for order structures |
| 23 | +and `WithLp` for metric structures. |
| 24 | +-/ |
| 25 | + |
| 26 | +public section |
| 27 | + |
| 28 | +variable {X : Type*} (t : TopologicalSpace X) |
| 29 | + |
| 30 | +namespace WithTopology |
| 31 | + |
| 32 | +lemma ofTopology_toTopology (x : X) : ofTopology (toTopology t x) = x := rfl |
| 33 | + |
| 34 | +@[simp] |
| 35 | +lemma toTopology_ofTopology (x : WithTopology X t) : |
| 36 | + toTopology t (ofTopology x) = x := rfl |
| 37 | + |
| 38 | +lemma ofTopology_surjective : Function.Surjective (ofTopology (t := t)) := |
| 39 | + Function.RightInverse.surjective <| ofTopology_toTopology _ |
| 40 | + |
| 41 | +lemma toTopology_surjective : Function.Surjective (toTopology t) := |
| 42 | + Function.RightInverse.surjective <| toTopology_ofTopology _ |
| 43 | + |
| 44 | +lemma ofTopology_injective : Function.Injective (ofTopology (t := t)) := |
| 45 | + Function.LeftInverse.injective <| toTopology_ofTopology _ |
| 46 | + |
| 47 | +lemma toTopology_injective : Function.Injective (toTopology t) := |
| 48 | + Function.LeftInverse.injective <| ofTopology_toTopology _ |
| 49 | + |
| 50 | +lemma ofTopology_bijective : Function.Bijective (ofTopology (t := t)) := |
| 51 | + ⟨ofTopology_injective t, ofTopology_surjective t⟩ |
| 52 | + |
| 53 | +lemma toTopology_bijective : Function.Bijective (toTopology t) := |
| 54 | + ⟨toTopology_injective t, toTopology_surjective t⟩ |
| 55 | + |
| 56 | +/-- Injectivity lemma for the constructor `toTopology t`. |
| 57 | +
|
| 58 | +It is not marked as `@[simp]`, because its autogenerated version |
| 59 | +is already in the default `simp` set. -/ |
| 60 | +lemma toTopology_inj {x y : X} : toTopology t x = toTopology t y ↔ x = y := |
| 61 | + (toTopology_injective t).eq_iff |
| 62 | + |
| 63 | +@[simp] lemma ofTopology_inj {x y : WithTopology X t} : ofTopology x = ofTopology y ↔ x = y := |
| 64 | + (ofTopology_injective t).eq_iff |
| 65 | + |
| 66 | +/-! ### Set-theoretic lemmas -/ |
| 67 | + |
| 68 | +open Set |
| 69 | + |
| 70 | +lemma image_ofTopology (s : Set (WithTopology X t)) : ofTopology '' s = toTopology t ⁻¹' s := |
| 71 | + WithTopology.equiv X t |>.symm.image_symm_eq_preimage _ |
| 72 | + |
| 73 | +lemma preimage_toTopology (s : Set (WithTopology X t)) : toTopology t ⁻¹' s = ofTopology '' s := |
| 74 | + (image_ofTopology t s).symm |
| 75 | + |
| 76 | +lemma image_toTopology (s : Set X) : toTopology t '' s = ofTopology ⁻¹' s := |
| 77 | + WithTopology.equiv X t |>.symm.image_eq_preimage_symm _ |
| 78 | + |
| 79 | +lemma preimage_ofTopology (s : Set X) : ofTopology ⁻¹' s = toTopology t '' s := |
| 80 | + (image_toTopology t s).symm |
| 81 | + |
| 82 | +/-! |
| 83 | +### Instance transfers |
| 84 | +
|
| 85 | +In this section we transfer some instances from `X` to `WithTopology X t`. |
| 86 | +-/ |
| 87 | + |
| 88 | +instance [Nonempty X] : Nonempty (WithTopology X t) := |
| 89 | + (WithTopology.equiv X t).nonempty |
| 90 | + |
| 91 | +instance [Inhabited X] : Inhabited (WithTopology X t) := |
| 92 | + ⟨toTopology t default⟩ |
| 93 | + |
| 94 | +instance [Subsingleton X] : Subsingleton (WithTopology X t) := |
| 95 | + (WithTopology.equiv X t).subsingleton |
| 96 | + |
| 97 | +instance [Unique X] : Unique (WithTopology X t) := .mk' _ |
| 98 | + |
| 99 | +instance [Finite X] : Finite (WithTopology X t) := .of_equiv _ (WithTopology.equiv X t).symm |
| 100 | + |
| 101 | +instance [Infinite X] : Infinite (WithTopology X t) := .of_injective _ <| toTopology_injective _ |
| 102 | + |
| 103 | +instance [Fintype X] : Fintype (WithTopology X t) := |
| 104 | + .ofBijective (.toTopology t) (toTopology_bijective t) |
| 105 | + |
| 106 | +deriving instance DecidableEq for WithTopology |
| 107 | + |
| 108 | +instance [LE X] : LE (WithTopology X t) where |
| 109 | + le x y := ofTopology x ≤ ofTopology y |
| 110 | + |
| 111 | +instance [LT X] : LT (WithTopology X t) where |
| 112 | + lt x y := ofTopology x < ofTopology y |
| 113 | + |
| 114 | +-- TODO: `inferInstance` works here, but it shouldn't |
| 115 | +instance [LE X] [DecidableLE X] : DecidableLE (WithTopology X t) := fun x y ↦ |
| 116 | + inferInstanceAs (Decidable (x.ofTopology ≤ y.ofTopology)) |
| 117 | + |
| 118 | +-- TODO: `inferInstance` works here, but it shouldn't |
| 119 | +instance [LT X] [DecidableLT X] : DecidableLT (WithTopology X t) := fun x y ↦ |
| 120 | + inferInstanceAs (Decidable (x.ofTopology < y.ofTopology)) |
| 121 | + |
| 122 | +instance [Preorder X] : Preorder (WithTopology X t) := |
| 123 | + .lift ofTopology |
| 124 | + |
| 125 | +instance [PartialOrder X] : PartialOrder (WithTopology X t) := |
| 126 | + ofTopology_injective t |>.partialOrder _ .rfl .rfl |
| 127 | + |
| 128 | +@[to_dual] |
| 129 | +instance [Max X] : Max (WithTopology X t) where |
| 130 | + max x y := toTopology t (max x.ofTopology y.ofTopology) |
| 131 | + |
| 132 | +@[to_dual] |
| 133 | +instance [SemilatticeSup X] : SemilatticeSup (WithTopology X t) := |
| 134 | + ofTopology_injective t |>.semilatticeSup _ .rfl .rfl fun _ _ ↦ rfl |
| 135 | + |
| 136 | +instance [Lattice X] : Lattice (WithTopology X t) where |
| 137 | + |
| 138 | +instance [DistribLattice X] : DistribLattice (WithTopology X t) where |
| 139 | + le_sup_inf _ _ _ := le_sup_inf (α := X) |
| 140 | + |
| 141 | +instance [Ord X] : Ord (WithTopology X t) where |
| 142 | + compare x y := compare x.ofTopology y.ofTopology |
| 143 | + |
| 144 | +instance [LinearOrder X] : LinearOrder (WithTopology X t) := |
| 145 | + ofTopology_injective t |>.linearOrder _ .rfl .rfl (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) |
| 146 | + |
| 147 | +end WithTopology |
0 commit comments