同値関係
module equivalence-relation where open import identity-type using (_=_; refl; sym; trans; transport)
record Equiv (A : Set) : Set₁ where field _≈_ : A → A → Set refl-≈ : ∀ x → x ≈ x sym-≈ : ∀ {x y} → x ≈ y → y ≈ x trans-≈ : ∀ {x y z} → x ≈ y → y ≈ z → x ≈ z id→equiv : ∀ {x y} → x = y → x ≈ y id→equiv {x = x} p = transport (x ≈_) p (refl-≈ x)
record Setoid : Set₁ where field X : Set equiv : Equiv X
IdEquiv : ∀ {X} → Equiv X IdEquiv = record { _≈_ = _=_ ; refl-≈ = λ _ → refl ; sym-≈ = sym ; trans-≈ = trans }
module SetoidReasoning (S : Setoid) where open Equiv (Setoid.equiv S) infix 60 _∎ _∎ : ∀ x → x ≈ x x ∎ = refl-≈ x infixr 40 _≈⟨_⟩_ _≈⟨_⟩_ : ∀ x {y z} → (x ≈ y) → (y ≈ z) → x ≈ z _ ≈⟨ e1 ⟩ e2 = trans-≈ e1 e2 infixr 40 _≈˘⟨_⟩_ _≈˘⟨_⟩_ : ∀ x {y z} → (y ≈ x) → (y ≈ z) → x ≈ z _ ≈˘⟨ e1 ⟩ e2 = trans-≈ (sym-≈ e1) e2