{-# OPTIONS --safe --cubical-compatible --guardedness --exact-split --double-check #-}
module Real.Interval.Apartness where
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]′)
open import Relation.Nullary using (¬_)
open import Relation.Binary.Structures using (IsApartnessRelation)
open import Real.Interval using (RealI)
open import Real.Interval.Equiv using (_≈ℝ_; ≈ℝ-sym)
open import Real.Interval.Order using (_<ℝ_; <-irrefl; <-cotrans)
open import Real.Interval.OrderLaws using (≈-<-resp)
infix 4 _#ℝ_
_#ℝ_ : RealI → RealI → Set
x #ℝ y = (x <ℝ y) ⊎ (y <ℝ x)
#ℝ-sym : ∀ {x y} → x #ℝ y → y #ℝ x
#ℝ-sym (inj₁ x<y) = inj₂ x<y
#ℝ-sym (inj₂ y<x) = inj₁ y<x
#ℝ-cotrans : ∀ {x y} → x #ℝ y → (z : RealI) → (x #ℝ z) ⊎ (z #ℝ y)
#ℝ-cotrans {x} {y} (inj₁ x<y) z =
[ (λ x<z → inj₁ (inj₁ x<z)) , (λ z<y → inj₂ (inj₁ z<y)) ]′
(<-cotrans {x} {z} {y} x<y)
#ℝ-cotrans {x} {y} (inj₂ y<x) z =
[ (λ y<z → inj₂ (inj₂ y<z)) , (λ z<x → inj₁ (inj₂ z<x)) ]′
(<-cotrans {y} {z} {x} y<x)
#ℝ-irrefl : ∀ {x y} → x ≈ℝ y → ¬ (x #ℝ y)
#ℝ-irrefl {x} {y} x≈y (inj₁ x<y) = <-irrefl y (≈-<-resp x≈y x<y)
#ℝ-irrefl {x} {y} x≈y (inj₂ y<x) = <-irrefl x (≈-<-resp (≈ℝ-sym x≈y) y<x)
#ℝ-isApartnessRelation : IsApartnessRelation _≈ℝ_ _#ℝ_
#ℝ-isApartnessRelation = record
{ irrefl = λ {x} {y} x≈y x#y → #ℝ-irrefl {x} {y} x≈y x#y
; sym = λ {x} {y} → #ℝ-sym {x} {y}
; cotrans = #ℝ-cotrans
}
#ℝ⇒≉ : ∀ {x y} → x #ℝ y → ¬ (x ≈ℝ y)
#ℝ⇒≉ {x} {y} x#y x≈y = #ℝ-irrefl {x} {y} x≈y x#y