@@ -5,6 +5,10 @@
5||| other metric of size.
5||| other metric of size.
6module Prelude.WellFounded
6module Prelude.WellFounded
10+import Prelude.Uninhabited
8%default total
12%default total
9%access public export
13%access public export
@@ -81,3 +85,21 @@ wfInd : WellFounded rel => {P : a -> Type} ->
81 (x : a) -> P x
85 (x : a) -> P x
82wfInd {rel} step x = accInd step x (wellFounded {rel} x)
86wfInd {rel} step x = accInd step x (wellFounded {rel} x)
88+-- Some basic useful relations
90+||| LT is a well-founded relation on numbers
91+ltAccessible : (m : Nat) -> LT n m -> Accessible LT n
92+ltAccessible Z x = absurd x
93+ltAccessible (S k) (LTESucc x)
94+ = Access (\val, p => ltAccessible k (lteTransitive p x))
96+-- First list is smaller than the second
97+smaller : List a -> List a -> Type
98+smaller xs ys = LT (length xs) (length ys)
100+||| `smaller` is a well-founded relation on lists
101+smallerAcc : (ys : List a) -> smaller xs ys -> Accessible smaller xs
102+smallerAcc [] x = absurd x
103+smallerAcc (y :: ys) (LTESucc x)
104+ = Access (\val, p => smallerAcc ys (lteTransitive p x))