-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added transitivity axiom, added tests
- Loading branch information
1 parent
9d07532
commit 0dccfad
Showing
7 changed files
with
257 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
|
||
domain Val {} | ||
|
||
adt List[V] { | ||
Nil() | ||
Cons(value: V, tail: List[V]) | ||
} | ||
|
||
function len(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
l.isNil ? 0 : 1 + len(l.tail) | ||
} | ||
|
||
function len2(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
l.isNil ? 0 : (l.tail.isNil ? 1 : 2 + len2(l.tail.tail)) | ||
} | ||
|
||
function lenBad(l: List[Val], v: Val): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
lenBad(Cons(v, Nil()), v) | ||
} | ||
|
||
function lenBad2(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
1 + lenBad2(l) | ||
} | ||
|
||
//////////////////////// | ||
|
||
adt IntList { | ||
INil() | ||
ICons(ivalue: Int, itail: IntList) | ||
} | ||
|
||
function ilen(l: IntList): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
l.isINil ? 0 : 1 + ilen(l.itail) | ||
} | ||
|
||
function ilen2(l: IntList): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
l.isINil ? 0 : (l.itail.isINil ? 1 : 2 + ilen2(l.itail.itail)) | ||
} | ||
|
||
function ilenBad(l: IntList, v: Int): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
ilenBad(ICons(v, INil()), v) | ||
} | ||
|
||
//////////////////////// | ||
|
||
// non-recursive data type with two type variables | ||
adt Pair[T, V] { | ||
pair(fst: T, snd: V) | ||
} | ||
|
||
function stupidFunc(p: Pair[Int, Val]): Val | ||
decreases p | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
stupidFunc(p) | ||
} | ||
|
||
// two type variables | ||
adt DList[V, T] { | ||
DNil() | ||
DCons(dvalue1: V, dvalue2: T, dtail: DList[V, T]) | ||
} | ||
|
||
function dlen(l: DList[Int, Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
l.isDNil ? 0 : 1 + dlen(l.dtail) | ||
} | ||
|
||
function dlenBad(l: DList[Int, Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
l.isDNil ? 0 : 1 + dlenBad(l) | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
|
||
// Part of termination_1.vpr, but with the WellFoundedness domain already there. | ||
import <decreases/declaration.vpr> | ||
|
||
|
||
domain Val {} | ||
|
||
adt List[V] { | ||
Nil() | ||
Cons(value: V, tail: List[V]) | ||
} | ||
|
||
function len(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
l.isNil ? 0 : 1 + len(l.tail) | ||
} | ||
|
||
function len2(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
l.isNil ? 0 : (l.tail.isNil ? 1 : 2 + len2(l.tail.tail)) | ||
} | ||
|
||
function lenBad(l: List[Val], v: Val): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
lenBad(Cons(v, Nil()), v) | ||
} | ||
|
||
function lenBad2(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
1 + lenBad2(l) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
|
||
// Part of termination_1.vpr, but with the WellFoundedness domain already there and a custom domain for | ||
// the list well founded order. | ||
import <decreases/declaration.vpr> | ||
|
||
domain ListWellFoundedOrder[W] { | ||
// Domain already being present will prevent auto-generation of axioms. | ||
// Thus, we should not be able to prove termination based on List measures here. | ||
} | ||
|
||
domain Val {} | ||
|
||
adt List[V] { | ||
Nil() | ||
Cons(value: V, tail: List[V]) | ||
} | ||
|
||
function len(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
l.isNil ? 0 : 1 + len(l.tail) | ||
} | ||
|
||
function len2(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
l.isNil ? 0 : (l.tail.isNil ? 1 : 2 + len2(l.tail.tail)) | ||
} | ||
|
||
function lenBad(l: List[Val], v: Val): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
lenBad(Cons(v, Nil()), v) | ||
} | ||
|
||
function lenBad2(l: List[Val]): Int | ||
ensures result >= 0 | ||
decreases l | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
1 + lenBad2(l) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
domain $domain$to_int { | ||
|
||
function to_int(to_int1: Perm): Int interpretation "to_int" | ||
} | ||
|
||
function round(x: Perm): Perm | ||
decreases | ||
ensures x == 3/1 ==> result == 3/2 | ||
//:: ExpectedOutput(postcondition.violated:assertion.false) | ||
ensures result == to_int(x) / 1 | ||
{ | ||
to_int(x + (1/2)) / 1 | ||
to_int(x) / 2 | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/resources/termination/functions/basic/preventAutoImport.vpr
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
import <decreases/declaration.vpr> | ||
|
||
domain IntWellFoundedOrder{ | ||
// Domain already being present will prevent auto-import of the default domain. | ||
// Thus, we have no defined order for type Int and proofs should fail. | ||
} | ||
|
||
//Example decreasing Int | ||
function fact(x:Int): Int | ||
decreases x | ||
requires x>=0 | ||
{ | ||
//:: ExpectedOutput(termination.failed:tuple.false) | ||
x==0 ? 1 : x*fact(x-1) | ||
} |