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

Maybe need some sort of induction to prove map acc.?

parent b1181499
No related branches found
No related tags found
No related merge requests found
...@@ -4,20 +4,24 @@ object Abs { ...@@ -4,20 +4,24 @@ object Abs {
def abs(tab: Map[Int, Int], size: Int, j: Int): Map[Int, Int] = ({ def abs(tab: Map[Int, Int], size: Int, j: Int): Map[Int, Int] = ({
require(j >= 0 && j < size && size > 0) require(j >= 0 && j < size)
var k = 0 var k = 0
var tabres = Map.empty[Int, Int] var tabres = Map.empty[Int, Int]
(while(k < size) { (while(k < size) {
if(tab.isDefinedAt(k)) { if(tab(k) < 0)
if(tab(k) < 0) tabres = tabres.updated(k, -tab(k))
tabres = tabres.updated(k, -tab(k)) else
else tabres = tabres.updated(k, tab(k))
tabres = tabres.updated(k, tab(k))
} else
tabres = tabres.updated(k, 0)
k = k + 1 k = k + 1
}) invariant(k >= 0 && (if(j < k) tabres(j) >= 0 else true)) }) invariant(k >= 0 && k <= size && (if(j < k) tabres(j) >= 0 else true))
tabres tabres
}) ensuring(res => res(j) >= 0) }) ensuring(res => res(j) >= 0)
def isArray(a: Map[Int, Int], size: Int): Boolean = {
def rec(i: Int): Boolean = if(i >= size) true else {
if(a.isDefinedAt(i)) rec(i+1) else false
}
size > 0 && rec(0)
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment