Last active
August 29, 2015 13:59
-
-
Save edwinb/10580905 to your computer and use it in GitHub Desktop.
Less than
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- We could define the relation like this: | |
| data LessThan : Nat -> Nat -> Type where | |
| LT_Z : LessThan Z (S m) | |
| LT_S : LessThan n m -> LessThan (S n) (S m) | |
| -- Then calculate a proof, if one exists: | |
| isLessThan : (m : Nat) -> (n : Nat) -> Maybe (LessThan m n) | |
| isLessThan Z Z = Nothing | |
| isLessThan Z (S k) = Just LT_Z | |
| isLessThan (S k) Z = Nothing | |
| isLessThan (S k) (S j) = case isLessThan k j of | |
| Nothing => Nothing | |
| Just p => Just (LT_S p) | |
| -- Some examples: | |
| {- | |
| *lt> isLessThan 3 5 | |
| Just (LT_S (LT_S (LT_S LT_Z))) : Maybe (LessThan 3 5) | |
| *lt> isLessThan 3 2 | |
| Nothing : Maybe (LessThan 3 2) | |
| -} | |
| {- P.S. A shorter way of writing the last case of isLessThan uses ! notation: | |
| isLessThan (S k) (S j) = Just (LT_S !(isLessThan k j)) | |
| -} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment