-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Real numbers, based on Cauchy sequences #2487
base: master
Are you sure you want to change the base?
Changes from 16 commits
a8b4452
e4a67d6
bfaa7cc
36f222b
80bed0f
968d44c
27ba9ad
a469d48
a3d9d70
371fd51
eccf291
9d25f90
7103493
8dcdc37
98c4499
0f86c1c
8f965da
5b6b5d0
571b4bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -49,6 +49,7 @@ open import Data.Sum.Base as Sum using (inj₁; inj₂; [_,_]′; _⊎_) | |||||||||
import Data.Sign.Base as Sign | ||||||||||
open import Function.Base using (_∘_; _∘′_; _∘₂_; _$_; flip) | ||||||||||
open import Function.Definitions using (Injective) | ||||||||||
open import Function.Metric.Rational as Metric hiding (Symmetric) | ||||||||||
open import Level using (0ℓ) | ||||||||||
open import Relation.Binary | ||||||||||
open import Relation.Binary.Morphism.Structures | ||||||||||
|
@@ -1340,6 +1341,34 @@ module _ where | |||||||||
*-cancelˡ-≤-neg : ∀ r .{{_ : Negative r}} → r * p ≤ r * q → p ≥ q | ||||||||||
*-cancelˡ-≤-neg {p} {q} r rewrite *-comm r p | *-comm r q = *-cancelʳ-≤-neg r | ||||||||||
|
||||||||||
nonNeg*nonNeg⇒nonNeg : ∀ p .{{_ : NonNegative p}} q .{{_ : NonNegative q}} → NonNegative (p * q) | ||||||||||
nonNeg*nonNeg⇒nonNeg p q = nonNegative $ begin | ||||||||||
0ℚ ≡⟨ *-zeroʳ p ⟨ | ||||||||||
p * 0ℚ ≤⟨ *-monoˡ-≤-nonNeg p (nonNegative⁻¹ q) ⟩ | ||||||||||
p * q ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
nonNeg*nonPos⇒nonPos : ∀ p .{{_ : NonNegative p}} q .{{_ : NonPositive q}} → NonPositive (p * q) | ||||||||||
nonNeg*nonPos⇒nonPos p q = nonPositive $ begin | ||||||||||
p * q ≤⟨ *-monoˡ-≤-nonNeg p (nonPositive⁻¹ q) ⟩ | ||||||||||
p * 0ℚ ≡⟨ *-zeroʳ p ⟩ | ||||||||||
0ℚ ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
nonPos*nonNeg⇒nonPos : ∀ p .{{_ : NonPositive p}} q .{{_ : NonNegative q}} → NonPositive (p * q) | ||||||||||
nonPos*nonNeg⇒nonPos p q = nonPositive $ begin | ||||||||||
p * q ≤⟨ *-monoˡ-≤-nonPos p (nonNegative⁻¹ q) ⟩ | ||||||||||
p * 0ℚ ≡⟨ *-zeroʳ p ⟩ | ||||||||||
0ℚ ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
nonPos*nonPos⇒nonNeg : ∀ p .{{_ : NonPositive p}} q .{{_ : NonPositive q}} → NonNegative (p * q) | ||||||||||
nonPos*nonPos⇒nonNeg p q = nonNegative $ begin | ||||||||||
0ℚ ≡⟨ *-zeroʳ p ⟨ | ||||||||||
p * 0ℚ ≤⟨ *-monoˡ-≤-nonPos p (nonPositive⁻¹ q) ⟩ | ||||||||||
p * q ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
------------------------------------------------------------------------ | ||||||||||
-- Properties of _*_ and _<_ | ||||||||||
|
||||||||||
|
@@ -1387,6 +1416,34 @@ module _ where | |||||||||
*-cancelʳ-<-nonPos : ∀ r .{{_ : NonPositive r}} → p * r < q * r → p > q | ||||||||||
*-cancelʳ-<-nonPos {p} {q} r rewrite *-comm p r | *-comm q r = *-cancelˡ-<-nonPos r | ||||||||||
|
||||||||||
pos*pos⇒pos : ∀ p .{{_ : Positive p}} q .{{_ : Positive q}} → Positive (p * q) | ||||||||||
pos*pos⇒pos p q = positive $ begin-strict | ||||||||||
0ℚ ≡⟨ *-zeroʳ p ⟨ | ||||||||||
p * 0ℚ <⟨ *-monoʳ-<-pos p (positive⁻¹ q) ⟩ | ||||||||||
p * q ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
pos*neg⇒neg : ∀ p .{{_ : Positive p}} q .{{_ : Negative q}} → Negative (p * q) | ||||||||||
pos*neg⇒neg p q = negative $ begin-strict | ||||||||||
p * q <⟨ *-monoʳ-<-pos p (negative⁻¹ q) ⟩ | ||||||||||
p * 0ℚ ≡⟨ *-zeroʳ p ⟩ | ||||||||||
0ℚ ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
neg*pos⇒neg : ∀ p .{{_ : Negative p}} q .{{_ : Positive q}} → Negative (p * q) | ||||||||||
neg*pos⇒neg p q = negative $ begin-strict | ||||||||||
p * q <⟨ *-monoʳ-<-neg p (positive⁻¹ q) ⟩ | ||||||||||
p * 0ℚ ≡⟨ *-zeroʳ p ⟩ | ||||||||||
0ℚ ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
neg*neg⇒pos : ∀ p .{{_ : Negative p}} q .{{_ : Negative q}} → Positive (p * q) | ||||||||||
neg*neg⇒pos p q = positive $ begin-strict | ||||||||||
0ℚ ≡⟨ *-zeroʳ p ⟨ | ||||||||||
p * 0ℚ <⟨ *-monoʳ-<-neg p (negative⁻¹ q) ⟩ | ||||||||||
p * q ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
------------------------------------------------------------------------ | ||||||||||
-- Properties of _⊓_ | ||||||||||
------------------------------------------------------------------------ | ||||||||||
|
@@ -1719,6 +1776,89 @@ toℚᵘ-homo-∣-∣ (mkℚ -[1+ _ ] _ _) = *≡* refl | |||||||||
∣∣p∣∣≡∣p∣ : ∀ p → ∣ ∣ p ∣ ∣ ≡ ∣ p ∣ | ||||||||||
∣∣p∣∣≡∣p∣ p = 0≤p⇒∣p∣≡p (0≤∣p∣ p) | ||||||||||
|
||||||||||
------------------------------------------------------------------------ | ||||||||||
-- Metric space | ||||||||||
------------------------------------------------------------------------ | ||||||||||
|
||||||||||
private | ||||||||||
d : ℚ → ℚ → ℚ | ||||||||||
d p q = ∣ p - q ∣ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really very frustrating. Anyone have any nice ideas how we can make this a function in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea on how to name this properly in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my global comment: we should have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: notation. UPDATED since I learnt how to write the symbols ;-)
Suggested change
which reuses the 'long minus' |
||||||||||
|
||||||||||
d-cong : Congruent _≡_ d | ||||||||||
d-cong = cong₂ _ | ||||||||||
|
||||||||||
d-nonNegative : ∀ {p q} → 0ℚ ≤ d p q | ||||||||||
d-nonNegative {p} {q} = nonNegative⁻¹ _ {{∣-∣-nonNeg (p - q)}} | ||||||||||
|
||||||||||
d-definite : Definite _≡_ d | ||||||||||
d-definite {p} refl = cong ∣_∣ (+-inverseʳ p) | ||||||||||
|
||||||||||
d-indiscernable : Indiscernable _≡_ d | ||||||||||
d-indiscernable {p} {q} ∣p-q∣≡0 = begin | ||||||||||
p ≡⟨ +-identityʳ p ⟨ | ||||||||||
p - 0ℚ ≡⟨ cong (_-_ p) (∣p∣≡0⇒p≡0 (p - q) ∣p-q∣≡0) ⟨ | ||||||||||
p - (p - q) ≡⟨ cong (_+_ p) (neg-distrib-+ p (- q)) ⟩ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It actually requires commutativity! (this is hidden in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following proof looks commutativity-free to me?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The step There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh whoops. Yes, you don't get distributivity for free. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See |
||||||||||
p + (- p - - q) ≡⟨ +-assoc p (- p) (- - q) ⟨ | ||||||||||
(p - p) - - q ≡⟨ cong₂ _+_ (+-inverseʳ p) (⁻¹-involutive q) ⟩ | ||||||||||
0ℚ + q ≡⟨ +-identityˡ q ⟩ | ||||||||||
q ∎ | ||||||||||
where | ||||||||||
open ≡-Reasoning | ||||||||||
open GroupProperties +-0-group | ||||||||||
|
||||||||||
d-sym : Metric.Symmetric d | ||||||||||
d-sym p q = begin | ||||||||||
∣ p - q ∣ ≡˘⟨ ∣-p∣≡∣p∣ (p - q) ⟩ | ||||||||||
∣ - (p - q) ∣ ≡⟨ cong ∣_∣ (⁻¹-anti-homo-// p q) ⟩ | ||||||||||
∣ q - p ∣ ∎ | ||||||||||
where | ||||||||||
open ≡-Reasoning | ||||||||||
open GroupProperties +-0-group | ||||||||||
|
||||||||||
d-triangle : TriangleInequality d | ||||||||||
d-triangle p q r = begin | ||||||||||
∣ p - r ∣ ≡⟨ cong (λ # → ∣ # - r ∣) (+-identityʳ p) ⟨ | ||||||||||
∣ p + 0ℚ - r ∣ ≡⟨ cong (λ # → ∣ p + # - r ∣) (+-inverseˡ q) ⟨ | ||||||||||
∣ p + (- q + q) - r ∣ ≡⟨ cong (λ # → ∣ # - r ∣) (+-assoc p (- q) q) ⟨ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this 'middle4' for semigroup? (i.e. all these |
||||||||||
∣ ((p - q) + q) - r ∣ ≡⟨ cong ∣_∣ (+-assoc (p - q) q (- r)) ⟩ | ||||||||||
∣ (p - q) + (q - r) ∣ ≤⟨ ∣p+q∣≤∣p∣+∣q∣ (p - q) (q - r) ⟩ | ||||||||||
∣ p - q ∣ + ∣ q - r ∣ ∎ | ||||||||||
where open ≤-Reasoning | ||||||||||
|
||||||||||
d-isProtoMetric : IsProtoMetric _≡_ d | ||||||||||
d-isProtoMetric = record | ||||||||||
{ isPartialOrder = ≤-isPartialOrder | ||||||||||
; ≈-isEquivalence = isEquivalence | ||||||||||
; cong = cong₂ _ | ||||||||||
; nonNegative = λ {p q} → d-nonNegative {p} {q} | ||||||||||
} | ||||||||||
|
||||||||||
d-isPreMetric : IsPreMetric _≡_ d | ||||||||||
d-isPreMetric = record | ||||||||||
{ isProtoMetric = d-isProtoMetric | ||||||||||
; ≈⇒0 = d-definite | ||||||||||
} | ||||||||||
|
||||||||||
d-isQuasiSemiMetric : IsQuasiSemiMetric _≡_ d | ||||||||||
d-isQuasiSemiMetric = record | ||||||||||
{ isPreMetric = d-isPreMetric | ||||||||||
; 0⇒≈ = d-indiscernable | ||||||||||
} | ||||||||||
|
||||||||||
d-isSemiMetric : IsSemiMetric _≡_ d | ||||||||||
d-isSemiMetric = record | ||||||||||
{ isQuasiSemiMetric = d-isQuasiSemiMetric | ||||||||||
; sym = d-sym | ||||||||||
} | ||||||||||
|
||||||||||
d-isMetric : IsMetric _≡_ d | ||||||||||
d-isMetric = record | ||||||||||
{ isSemiMetric = d-isSemiMetric | ||||||||||
; triangle = d-triangle | ||||||||||
} | ||||||||||
|
||||||||||
d-metric : Metric _ _ | ||||||||||
d-metric = record { isMetric = d-isMetric } | ||||||||||
|
||||||||||
------------------------------------------------------------------------ | ||||||||||
-- DEPRECATED NAMES | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here (and for all the newly added bits):
assoc assoc₁
is super ugly. One of the two should be renamed.