|
| 1 | +-- Metric spaces definitions and results. |
| 2 | +-- Work on this file was discontinued when I realized I would need square roots to define the |
| 3 | +-- Cauchy-Schwarz inequality, which would, in turn, require calculus to define. |
| 4 | + |
| 5 | +{-# OPTIONS --without-K --safe #-} |
| 6 | + |
| 7 | +module MetricBase where |
| 8 | + |
| 9 | +open import Algebra |
| 10 | +open import Data.Bool.Base using (Bool; if_then_else_) |
| 11 | +open import Function.Base using (_∘_) |
| 12 | +open import Data.Integer.Base as ℤ |
| 13 | + using (ℤ; +_; +0; +[1+_]; -[1+_]) |
| 14 | +import Data.Integer.Properties as ℤP |
| 15 | +open import Data.Integer.DivMod as ℤD |
| 16 | +open import Data.Nat as ℕ using (ℕ; zero; suc) |
| 17 | +open import Data.Nat.Properties as ℕP using (≤-step) |
| 18 | +import Data.Nat.DivMod as ℕD |
| 19 | +open import Level using (0ℓ) |
| 20 | +open import Data.Product |
| 21 | +open import Relation.Nullary |
| 22 | +open import Relation.Nullary.Negation using (contraposition) |
| 23 | +open import Relation.Nullary.Decidable |
| 24 | +open import Relation.Unary using (Pred) |
| 25 | +open import Relation.Binary.PropositionalEquality.Core using (_≡_; _≢_; refl; cong; sym; subst; trans; ≢-sym) |
| 26 | +open import Relation.Binary |
| 27 | +open import Data.Rational.Unnormalised as ℚ using (ℚᵘ; mkℚᵘ; _≢0; _/_; 0ℚᵘ; 1ℚᵘ; ↥_; ↧_; ↧ₙ_) |
| 28 | +import Data.Rational.Unnormalised.Properties as ℚP |
| 29 | +open import Algebra.Bundles |
| 30 | +open import Algebra.Structures |
| 31 | +open import Data.Empty |
| 32 | +open import Data.Sum |
| 33 | +open import Data.Maybe.Base |
| 34 | +open import Data.List |
| 35 | +open import Function.Structures {_} {_} {_} {_} {ℕ} _≡_ {ℕ} _≡_ |
| 36 | + |
| 37 | +{- |
| 38 | +The solvers are used and renamed often enough to warrant them being opened up here |
| 39 | +for the sake of consistency and cleanliness. |
| 40 | +-} |
| 41 | +open import NonReflectiveZ as ℤ-Solver using () |
| 42 | + renaming |
| 43 | + ( solve to ℤsolve |
| 44 | + ; _⊕_ to _:+_ |
| 45 | + ; _⊗_ to _:*_ |
| 46 | + ; _⊖_ to _:-_ |
| 47 | + ; ⊝_ to :-_ |
| 48 | + ; _⊜_ to _:=_ |
| 49 | + ; Κ to ℤΚ |
| 50 | + ) |
| 51 | +open import NonReflectiveQ as ℚ-Solver using () |
| 52 | + renaming |
| 53 | + ( solve to ℚsolve |
| 54 | + ; _⊕_ to _+:_ |
| 55 | + ; _⊗_ to _*:_ |
| 56 | + ; _⊖_ to _-:_ |
| 57 | + ; ⊝_ to -:_ |
| 58 | + ; _⊜_ to _=:_ |
| 59 | + ; Κ to ℚΚ |
| 60 | + ) |
| 61 | + |
| 62 | +open import ExtraProperties |
| 63 | +open import Real |
| 64 | +open import RealProperties |
| 65 | +open import Inverse |
| 66 | +open ℝ-Solver |
| 67 | + |
| 68 | +{- |
| 69 | +(M,ρ) is a metric space if: |
| 70 | +(i) x = y ⇒ ρ x y = 0 |
| 71 | +(ii) ρ x y ≤ ρ x z + ρ z y |
| 72 | +(iii) ρ x y = ρ y x |
| 73 | +(iv) ρ x y ≥ 0 |
| 74 | +
|
| 75 | +-} |
| 76 | +record PseudoMetricSpace (M : Set) (ρ : M → M → ℝ) (_≈_ : Rel M 0ℓ) : Set where |
| 77 | + constructor mkPseudo |
| 78 | + field |
| 79 | + ≈-isEquivalence : IsEquivalence _≈_ |
| 80 | + positivity : {x y : M} → ρ x y ≥ 0ℝ |
| 81 | + nondegen-if : {x y : M} → x ≈ y → ρ x y ≃ 0ℝ |
| 82 | + symmetry : {x y : M} → ρ x y ≃ ρ y x |
| 83 | + triangle-inequality : {x y z : M} → ρ x y ≤ ρ x z + ρ z y |
| 84 | + |
| 85 | +open PseudoMetricSpace public |
| 86 | + |
| 87 | +record MetricSpace (M : Set) (ρ : M → M → ℝ) (_≈_ : Rel M 0ℓ) : Set where |
| 88 | + constructor mkMetric |
| 89 | + field |
| 90 | + pseudo : PseudoMetricSpace M ρ _≈_ |
| 91 | + nondegen-onlyif : {x y : M} → ρ x y ≃ 0ℝ → x ≈ y |
| 92 | + |
| 93 | +open MetricSpace public |
| 94 | + |
| 95 | +productFunction : {M₁ M₂ : Set} (ρ₁ : M₁ → M₁ → ℝ) (ρ₂ : M₂ → M₂ → ℝ) → |
| 96 | + M₁ × M₂ → M₁ × M₂ → ℝ |
| 97 | +productFunction ρ₁ ρ₂ x y = ρ₁ (proj₁ x) (proj₁ y) + ρ₂ (proj₂ x) (proj₂ y) |
| 98 | + |
| 99 | +productEquality : {M₁ M₂ : Set} (_≈₁_ : Rel M₁ 0ℓ) (_≈₂ : Rel M₂ 0ℓ) → |
| 100 | + Rel (M₁ × M₂) 0ℓ |
| 101 | +productEquality _≈₁_ _≈₂_ x y = (proj₁ x ≈₁ proj₁ y) × (proj₂ x ≈₂ proj₂ y) |
| 102 | + |
| 103 | +productPseudoMetric : {M₁ M₂ : Set} {ρ₁ : M₁ → M₁ → ℝ} {ρ₂ : M₂ → M₂ → ℝ} |
| 104 | + {_≈₁_ : Rel M₁ 0ℓ} {_≈₂_ : Rel M₂ 0ℓ} → |
| 105 | + PseudoMetricSpace M₁ ρ₁ _≈₁_ → |
| 106 | + PseudoMetricSpace M₂ ρ₂ _≈₂_ → |
| 107 | + PseudoMetricSpace (M₁ × M₂) (productFunction ρ₁ ρ₂) (productEquality _≈₁_ _≈₂_) |
| 108 | +productPseudoMetric {M₁} {M₂} {ρ₁} {ρ₂} {_≈₁_} {_≈₂_} spaceM₁ spaceM₂ = mkPseudo {!!} {!!} {!!} {!!} {!!} |
| 109 | + where |
| 110 | + ρ : (x y : M₁ × M₂) → ℝ |
| 111 | + ρ = productFunction ρ₁ ρ₂ |
| 112 | + |
| 113 | + _≈_ : Rel (M₁ × M₂) 0ℓ |
| 114 | + _≈_ = productEquality _≈₁_ _≈₂_ |
| 115 | + |
| 116 | + ≈-isEq : IsEquivalence _≈_ |
| 117 | + ≈-isEq = {!!} |
0 commit comments