Commit 13c720af by Jean-Christophe Filliâtre

### library list.Elements changed + new example: coincidence_count_list

parent 4e666906
 (** Coincidence count Exercise proposed by Rustan Leino at Dagstuhl seminar 16131, March 2016 You are given two sequences of integers, sorted in increasing order and without duplicate elements, and you count the number of elements that appear in both sequences (in linear time and constant space). See also coincidence_count for a version using arrays. Authors: Jean-Christophe Filliâtre (CNRS) *) module CoincidenceCount use import list.List use import set.Fset use import list.Elements use list.Mem as L use import list.Length use import int.Int clone export list.Sorted with type t = int, predicate le = (<), goal Transitive.Trans let rec coincidence_count (a b: list int) : set int requires { sorted a } requires { sorted b } ensures { result == inter (elements a) (elements b) } variant { length a + length b } = match a, b with | Cons ha ta, Cons hb tb -> if ha = hb then add ha (coincidence_count ta tb) else if ha < hb then coincidence_count ta b else coincidence_count a tb | _ -> empty end end