list.Sorted generalized for elements of any type

parent e2fb1f1f
......@@ -164,4 +164,5 @@ why3.conf
/modules/string/
/modules/stack/
/modules/queue/
/modules/pqueue/
......@@ -5,7 +5,7 @@ module M
use import int.Int
use import list.Length
use import list.Sorted
use import list.SortedInt
use import list.Permut
let rec insert x l variant { length l } =
......
......@@ -5,7 +5,7 @@ module M
use import int.Int
use import list.Length
use import list.Sorted
use import list.SortedInt
use import list.Append
use import list.Permut
......
......@@ -4,7 +4,7 @@ module FindInSortedList
use import int.Int
use import list.Mem
use import list.Sorted
use import list.SortedInt
lemma Sorted_not_mem:
forall x y : int, l : list int.
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE why3session SYSTEM "why3session.dtd">
<why3session name="programs/sorted_list/why3session.xml">
<prover id="alt-ergo" name="Alt-Ergo" version="0.93"/>
<prover id="coq" name="Coq" version="8.2pl1"/>
<prover id="cvc3" name="CVC3" version="2.2"/>
<prover id="gappa" name="Gappa" version="0.13.0"/>
<prover id="simplify" name="Simplify" version="1.5.4"/>
<prover id="z3" name="Z3" version="2.19"/>
<file name="../sorted_list.mlw" verified="true" expanded="true">
<theory name="WP FindInSortedList" verified="true" expanded="true">
<goal name="Sorted_not_mem" sum="065ba337071029143930bed502bf4f54" proved="true" expanded="true" shape="amemV0aConsV1V2NIasortedaConsV1V2Iainfix <V0V1F">
<proof prover="alt-ergo" timelimit="20" edited="" obsolete="false">
<result status="valid" time="0.02"/>
<why3session
name="examples/programs/sorted_list/why3session.xml">
<prover
id="alt-ergo"
name="Alt-Ergo"
version="0.93"/>
<prover
id="coq"
name="Coq"
version="8.3pl2"/>
<prover
id="cvc3"
name="CVC3"
version="2.2"/>
<prover
id="simplify"
name="Simplify"
version="1.5.4"/>
<prover
id="yices"
name="Yices"
version="1.0.27"/>
<prover
id="z3"
name="Z3"
version="2.19"/>
<file
name="../sorted_list.mlw"
verified="true"
expanded="true">
<theory
name="WP FindInSortedList"
verified="true"
expanded="true">
<goal
name="Sorted_not_mem"
sum="0e5b025f01157d802e4968ce08ccd4c4"
proved="true"
expanded="true"
shape="amemV0aConsV1V2NIasortedaConsV1V2Iainfix <V0V1F">
<proof
prover="alt-ergo"
timelimit="20"
edited=""
obsolete="false">
<result status="valid" time="0.01"/>
</proof>
</goal>
<goal name="WP_parameter find" expl="parameter find" sum="3088f11d3e64fa3492117d9f16ba16b0" proved="true" expanded="true" shape="CV1aNilamemV0V1qfaConsVVamemV0V1qainfix =V4aTrueAainfix >V0V2Oainfix =V0V2IamemV0V3qainfix =V4aTrueFAasortedV3IasortedV1FF">
<proof prover="alt-ergo" timelimit="20" edited="" obsolete="false">
<goal
name="WP_parameter find"
expl="parameter find"
sum="d06791b94cf6be238e76a7a9c8c63a80"
proved="true"
expanded="true"
shape="CV1aNilamemV0V1qfaConsVVamemV0V1qainfix =V4aTrueAainfix >V0V2Oainfix =V0V2IamemV0V3qainfix =V4aTrueFAasortedV3IasortedV1FF">
<proof
prover="alt-ergo"
timelimit="20"
edited=""
obsolete="false">
<result status="valid" time="0.03"/>
</proof>
</goal>
......
......@@ -25,7 +25,7 @@ module Queue
| Cons x t -> result = x /\ q.elts = t end }
| Empty -> { q.elts = old q.elts = Nil }
val top:
val peek:
q: t 'a ->
{}
'a
......@@ -35,7 +35,7 @@ module Queue
val clear: q: t 'a -> {} unit writes q {q.elts = Nil }
val copy: q: t 'a -> {} t 'a { result = q }
val copy: q: t 'a -> {} t 'a reads q { result = q }
val is_empty:
q: t 'a -> {} bool reads q { result=True <-> q.elts = Nil }
......@@ -61,9 +61,9 @@ module Test
let test1 () =
let s = Queue.create () in
Queue.push 1 s;
let x = Queue.top s in assert { x = 1 };
let x = Queue.peek s in assert { x = 1 };
Queue.push 2 s;
let x = Queue.top s in assert { x = 1 };
let x = Queue.peek s in assert { x = 1 };
()
end
......
......@@ -132,22 +132,31 @@ end
theory Sorted
use export List
use import int.Int
inductive sorted (l: list int) =
type t
predicate le t t
inductive sorted (l: list t) =
| Sorted_Nil:
sorted Nil
| Sorted_One:
forall x: int. sorted (Cons x Nil)
forall x: t. sorted (Cons x Nil)
| Sorted_Two:
forall x y: int, l: list int.
x <= y -> sorted (Cons y l) -> sorted (Cons x (Cons y l))
forall x y: t, l: list t.
le x y -> sorted (Cons y l) -> sorted (Cons x (Cons y l))
use import Mem
lemma Sorted_mem:
forall x: int, l: list int.
(forall y: int. mem y l -> x <= y) /\ sorted l <-> sorted (Cons x l)
lemma sorted_mem:
forall x: t, l: list t.
(forall y: t. mem y l -> le x y) /\ sorted l <-> sorted (Cons x l)
end
theory SortedInt
use import int.Int
clone export Sorted with type t = int, predicate le = (<=)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment