-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.agda
62 lines (49 loc) · 1.82 KB
/
Utils.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Utils where
open import Data.Product
open import Data.Nat
open import Data.Empty
open import Data.Sum
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
_-_ : ℕ → ℕ → ℕ
m - zero = m
m - suc n = pred (m - n)
≤cases : ∀{n m} → n ≤ m → n ≡ m ⊎ n < m
≤cases {m = zero} z≤n = inj₁ refl
≤cases {m = suc m} z≤n = inj₂ (s≤s z≤n)
≤cases (s≤s p) with ≤cases p
≤cases (s≤s p) | inj₁ x = inj₁ (cong suc x)
≤cases (s≤s p) | inj₂ y = inj₂ (s≤s y)
qwerty : ∀ m n → ¬ m ≤ n → m > n
qwerty zero zero p = ⊥-elim (p z≤n)
qwerty zero (suc n) p = ⊥-elim (p z≤n)
qwerty (suc m) zero p = s≤s z≤n
qwerty (suc m) (suc n) p = s≤s (qwerty m n (λ z → p (s≤s z)))
same≤ : ∀{x y} → (p q : x ≤ y) → p ≡ q
same≤ z≤n z≤n = refl
same≤ (s≤s p) (s≤s q) = cong s≤s (same≤ p q)
plus-succ : ∀ x y → x + suc y ≡ suc (x + y)
plus-succ zero y = refl
plus-succ (suc x) y = cong suc (plus-succ x y)
plus-0 : ∀ x → x + 0 ≡ x
plus-0 zero = refl
plus-0 (suc x) = cong suc (plus-0 x)
plus-comm : ∀ x y → x + y ≡ y + x
plus-comm zero y = sym (plus-0 y)
plus-comm (suc x) zero = cong suc (plus-comm x zero)
plus-comm (suc x) (suc y) =
trans (cong suc (plus-succ x y)) (cong suc (plus-comm (suc x) y))
≤refl : ∀ x → x ≤ x
≤refl zero = z≤n
≤refl (suc x) = s≤s (≤refl x)
≤succ : ∀ {x y} → x ≤ y → x ≤ suc y
≤succ z≤n = z≤n
≤succ (s≤s p) = s≤s (≤succ p)
>succ : ∀ {n m} → n > m → suc n > m
>succ (s≤s p) = s≤s (≤succ p)
≤trans : ∀{p q r} → p ≤ q → q ≤ r → p ≤ r
≤trans z≤n z≤n = z≤n
≤trans z≤n (s≤s q) = z≤n
≤trans (s≤s p) (s≤s q) = s≤s (≤trans p q)
absurd-suc : ∀{n} → suc n ≤ n → ⊥
absurd-suc (s≤s p) = absurd-suc p