Guest User

Untitled

a guest
Jan 12th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. module ListProof
  2.  
  3. import Prelude.List
  4. import Prelude.Nat
  5. import Prelude.Bool
  6.  
  7. %access public export
  8.  
  9. ifelse : (b : Bool) -> (t : a) -> (e : a) -> a
  10. ifelse False t e = e
  11. ifelse True t e = t
  12.  
  13. placeSorted : (n : Nat) -> (l : List Nat) -> List Nat
  14. placeSorted n [] = [n]
  15. placeSorted n (x :: xs) =
  16. ifelse (n <= x) (n :: x :: xs) (x :: (placeSorted n xs))
  17.  
  18. bubbleSortNat : (l : List Nat) -> List Nat
  19. bubbleSortNat [] = []
  20. bubbleSortNat (x :: xs) =
  21. let nl = bubbleSortNat xs in
  22. placeSorted x nl
  23.  
  24. testSort : bubbleSortNat [3, 2, 4, 1] = [1, 2, 3, 4]
  25. testSort = Refl
  26.  
  27. msorted : (l : List Nat) -> Bool
  28. msorted [] = True
  29. msorted (x :: []) = True
  30. msorted (x :: (y :: xs)) = ifelse (x <= y) (msorted (y :: xs)) False
  31.  
  32. testSorted : msorted [3, 2, 4, 1] = False
  33. testSorted = Refl
  34.  
  35. lemMsorted : (x : Nat) -> (xs : List Nat) -> msorted (x :: xs) = True -> msorted xs = True
  36. lemMsorted x [] prf = Refl
  37. lemMsorted x (y :: ys) prf with (x <= y) proof p
  38. lemMsorted x (y :: ys) prf | True = prf
  39. lemMsorted x (y :: ys) prf | False = absurd prf
  40.  
  41.  
  42. placeSortedProof : (x : Nat) -> (xs : List Nat) -> msorted xs = True -> msorted (placeSorted x xs) = True
  43. placeSortedProof x [] prf = Refl
  44. placeSortedProof x (y :: xs) prf with (x <= y) proof p
  45. placeSortedProof x (y :: xs) prf | True = rewrite sym p in prf
  46. placeSortedProof x (y :: xs) prf | False = ?placeSortedProof_rhs
Add Comment
Please, Sign In to add comment