Skip to content
Snippets Groups Projects
Commit 73e18588 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

False progress

parent 93f0ed37
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ object SortedTree { ...@@ -23,7 +23,7 @@ object SortedTree {
}) ensuring(res => res >= 0) }) ensuring(res => res >= 0)
def content(t: Tree): Set[Int] = t match { def content(t: Tree): Set[Int] = t match {
case Leaf() => Set() case Leaf() => Set.empty[Int]
case Node(v, l, r) => Set(v) ++ content(l) ++ content(r) case Node(v, l, r) => Set(v) ++ content(l) ++ content(r)
} }
...@@ -113,7 +113,7 @@ object SortedTree { ...@@ -113,7 +113,7 @@ object SortedTree {
allGreaterThan(r, min) && allGreaterThan(r, min) &&
v > min v > min
case Leaf() => true case Leaf() => true
}) ensuring (!_ || !(content(t) contains min)) }) ensuring (res => !res || !(content(t) contains min))
@induct @induct
def ltLemma(t : Tree, v1 : Int, v2 : Int) : Boolean = { def ltLemma(t : Tree, v1 : Int, v2 : Int) : Boolean = {
...@@ -139,6 +139,55 @@ object SortedTree { ...@@ -139,6 +139,55 @@ object SortedTree {
} }
}).holds }).holds
@induct
def sortedLemma2(t: Tree) = ({
require(isSorted(t))
t match {
case Node(v, l, r) =>
!(content(l) contains v) &&
!(content(r) contains v)
case Leaf() => true
}
}).holds
def sortedLemma3(v: Int, l: Tree, r: Tree) = {
require(isSorted(Node(v, l, r)))
!((content(l) ++ content(r)) contains v)
} holds
// Proving is apparently difficult. Who knew.
@induct
def allLessThanAllOf(t: Tree, top: Int, of: Tree): Boolean = {
require(isSorted(Node(top, t, of)))
t match {
case Node(v, l, r) =>
top > v &&
allLessThanAllOf(l, v, of) &&
allLessThanAllOf(r, v, of) &&
allGreaterThan(of, v)
case Leaf() =>
true
}
} ensuring {res => !res || (allLessThan(t, top) && allGreaterThan(of, top))}
// Ne marche pas encore vraiment... c'est difficile ce truc :(
// PS
def separation(v : Int, l : Tree, r : Tree) : Boolean = {
require(isSorted(Node(v, l, r)))
(l match {
case Leaf() => true
case Node(vl, ll, rl) => separation(vl, ll, rl)
}) && (r match {
case Leaf() => true
case Node(vr, lr, rr) => separation(vr, lr, rr)
})
} ensuring(res => !res || (content(l) ** content(r)) == Set.empty[Int])
// //
// OPERATIONS: // OPERATIONS:
// //
...@@ -205,16 +254,16 @@ object SortedTree { ...@@ -205,16 +254,16 @@ object SortedTree {
} }
})} ensuring(_ == (content(t) contains searchV)) })} ensuring(_ == (content(t) contains searchV))
def contains3(t: Tree, searchV: Int): Boolean = { def containsInvalid(t: Tree, searchV: Int): Boolean = {
require(isSorted(t)) require(isSorted(t))
(t match { (t match {
case Leaf() => false case Leaf() => false
case Node(v, l, r) => case Node(v, l, r) =>
if (searchV > v) { if (searchV > v) {
contains3(r, searchV) containsInvalid(r, searchV)
} else if (searchV < v) { } else if (searchV < v) {
contains3(l, searchV) containsInvalid(l, searchV)
} else { } else {
true true
} }
...@@ -227,10 +276,8 @@ object SortedTree { ...@@ -227,10 +276,8 @@ object SortedTree {
case Leaf() => false case Leaf() => false
case Node(v, l, r) => case Node(v, l, r) =>
if (searchV > v) { if (searchV > v) {
contains4(l, searchV) &&
contains4(r, searchV) contains4(r, searchV)
} else if (searchV < v) { } else if (searchV < v) {
contains4(r, searchV) &&
contains4(l, searchV) contains4(l, searchV)
} else { } else {
true true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment