Guest User

Untitled

a guest
Jan 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. open import Agda.Builtin.Nat renaming (Nat to ℕ) hiding (_-_)
  2. open import Agda.Builtin.List
  3. open import Agda.Builtin.Equality
  4.  
  5. data ⊥ : Set where
  6.  
  7. infix 3 ¬_
  8. ¬_ : (A : Set) → Set
  9. ¬ A = A → ⊥
  10.  
  11. ⊥-elim : {A : Set} → ⊥ → A
  12. ⊥-elim ()
  13.  
  14. data Dec (A : Set) : Set where
  15. yes : A → Dec A
  16. no : ¬ A → Dec A
  17.  
  18. natEq : (n m : ℕ) → Dec (n ≡ m)
  19. natEq zero zero = yes refl
  20. natEq zero (suc m) = no (λ ())
  21. natEq (suc n) zero = no (λ ())
  22. natEq (suc n) (suc m) with natEq n m
  23. ... | yes refl = yes refl
  24. ... | no neq = no φ
  25. where φ : _
  26. φ refl = neq refl
  27.  
  28. infixl 3 _-_
  29. _-_ : List ℕ → ℕ → List ℕ
  30. [] - x = []
  31. x ∷ xs - y with natEq x y
  32. .y ∷ xs - y | yes refl = xs - y
  33. x ∷ xs - y | no _ = x ∷ (xs - y)
  34.  
  35.  
  36. data Foo : List ℕ → Set where
  37. create : Foo (0 ∷ [])
  38. delete : {xs : List ℕ} → (y : ℕ) → Foo xs → Foo (xs - y)
  39.  
  40. foo[] : Foo []
  41. foo[] = delete zero create
  42.  
  43. data Bar : List ℕ → Set where
  44. create : (x : ℕ) → Bar (x ∷ [])
  45. delete : {xs : List ℕ} → (y : ℕ) → Bar xs → Bar (xs - y)
  46.  
  47. bar[] : Bar []
  48. bar[] = delete zero (create zero)
  49.  
  50. data Baz : ℕ → List ℕ → Set where
  51. create : (x : ℕ) → Baz x (x ∷ [])
  52. delete : {x : ℕ} {xs : List ℕ} → (y : ℕ) → Baz x xs → Baz x (xs - y)
  53.  
  54. baz[] : (x : ℕ) → Baz x []
  55. baz[] x = lemma x (x ∷ [] - x) [] (delete x (create x)) (inv x)
  56. where
  57. inv : (x : ℕ) → (x ∷ [] - x) ≡ []
  58. inv x with natEq x x
  59. inv x | yes refl = refl
  60. inv x | no x₁ = ⊥-elim (x₁ refl)
  61. lemma : ∀ x xs ys → Baz x xs → xs ≡ ys → Baz x ys
  62. lemma x₁ xs .xs x₂ refl = x₂
Add Comment
Please, Sign In to add comment