Skip to content
Snippets Groups Projects
Commit bee510e9 authored by Régis Blanc's avatar Régis Blanc
Browse files

add euclidian division testcase for verification. Prove validity

parent ea45d885
No related branches found
No related tags found
No related merge requests found
...@@ -70,4 +70,15 @@ object Arithmetic { ...@@ -70,4 +70,15 @@ object Arithmetic {
r r
} ensuring(_ >= n) } ensuring(_ >= n)
def divide(x: Int, y: Int): (Int, Int) = {
require(x >= 0 && y > 0)
var r = x
var q = 0
(while(r >= y) {
r = r - y
q = q + 1
}) invariant(x == y*q + r && r >= 0)
(q, r)
} ensuring(res => x == y*res._1 + res._2 && res._2 >= 0 && res._2 < y)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment