gt22

Untitled

Oct 27th, 2024 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. \import Data.List
  2. \import Paths
  3. \import Paths.Meta
  4.  
  5. \data Tree : \Set
  6. | leaf (n : Nat)
  7. | node (t : List Tree) \with { leaf n :: nil => leaf (suc n) }
  8.  
  9. \func tsuc (a : Tree) => node (a :: nil)
  10.  
  11. \func add (a b : Tree): Tree \elim b
  12. | leaf 0 => a
  13. | leaf (suc n) => tsuc (add a (leaf n))
  14. | node nil => node nil
  15. | node (n :: nil) => tsuc (add a n)
  16. | node (n :: n' :: ns) => node (add_list a (n :: n' :: ns))
  17. \where {
  18. \func add_list (a : Tree) (b : List Tree) : List Tree \elim b
  19. | nil => nil
  20. | b :: bs => add a b :: add_list a bs
  21. }
  22.  
  23. \func add-assoc {a b c : Tree} : add a (add b c) = add (add a b) c \elim c
  24. | leaf 0 => idp
  25. | leaf (suc n) => pmap tsuc add-assoc
  26. | node nil => idp
  27. | node (n :: nil) => pmap tsuc add-assoc
  28. | node (n :: n' :: ns) => rewrite (add-assoc, add-assoc, add_list-assoc) idp
  29. \where {
  30. \func add_list-assoc {a b : Tree} {cs : List Tree}
  31. : add.add_list a (add.add_list b cs) = add.add_list (add a b) cs \elim cs
  32. | nil => idp
  33. | c :: cs => pmap2 (::) add-assoc add_list-assoc
  34. }
Advertisement
Add Comment
Please, Sign In to add comment