Skip to content
Snippets Groups Projects
Commit be71561e authored by Samuel Gruetter's avatar Samuel Gruetter
Browse files

fix int2Nat function (was non-terminating for negative arguments)

parent 18d98289
Branches
Tags
No related merge requests found
...@@ -18,7 +18,10 @@ object Nat { ...@@ -18,7 +18,10 @@ object Nat {
case Succ(n1) => 1 + nat2Int(n1) case Succ(n1) => 1 + nat2Int(n1)
} }
def int2Nat(n: Int): Nat = if (n == 0) Zero() else Succ(int2Nat(n-1)) def int2Nat(n: Int): Nat = {
require(n >= 0)
if (n == 0) Zero() else Succ(int2Nat(n-1))
}
def sum_lemma(): Boolean = { def sum_lemma(): Boolean = {
3 == nat2Int(plus(int2Nat(1), int2Nat(2))) 3 == nat2Int(plus(int2Nat(1), int2Nat(2)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment