Skip to content

Instantly share code, notes, and snippets.

@MarcelineVQ
Created December 11, 2019 18:30
Show Gist options
  • Select an option

  • Save MarcelineVQ/cb3b3728bfc47d934ab26421b0ca85a7 to your computer and use it in GitHub Desktop.

Select an option

Save MarcelineVQ/cb3b3728bfc47d934ab26421b0ca85a7 to your computer and use it in GitHub Desktop.
module plfa.part1.Relations where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Properties using (+-comm)
infix 4 _≤_
data _≤_ : ℕ → ℕ → Set where
z≤n : ∀ {n : ℕ} → zero ≤ n
s≤s : ∀ {m n : ℕ} → m ≤ n → suc m ≤ suc n
≤-refl : ∀ {n : ℕ} → n ≤ n
≤-refl {zero} = z≤n
≤-refl {suc n} = s≤s ≤-refl
≤-trans : ∀ {m n p : ℕ} → m ≤ n → n ≤ p → m ≤ p
≤-trans z≤n _ = z≤n
≤-trans (s≤s m) (s≤s n) = s≤s (≤-trans m n)
≤-antisym : ∀ {m n : ℕ} → m ≤ n → n ≤ m → m ≡ n
≤-antisym z≤n z≤n = refl
≤-antisym (s≤s m) (s≤s n) = cong suc (≤-antisym m n)
data Total (m n : ℕ) : Set where
forward : m ≤ n → Total m n
flipped : n ≤ m → Total m n
≤-total : ∀ (m n : ℕ) → Total m n
≤-total zero n = forward z≤n
≤-total (suc m) zero = flipped z≤n
≤-total (suc m) (suc n) with ≤-total m n
... | forward m≤n = forward (s≤s {! !})
... | flipped n≤m = flipped (s≤s n≤m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment