29.04.2014 Views

Presburger Arithmetic and Its Use in Verification

Presburger Arithmetic and Its Use in Verification

Presburger Arithmetic and Its Use in Verification

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

APPENDIX B. SOURCE CODE OF EXPERIMENTS<br />

B.6 OmegaTest.fs<br />

module OmegaTest<br />

open Microsoft.FSharp.Collections<br />

open Utilities<br />

open Term<br />

// Input: a list of conjunctions <strong>and</strong> a list of disjunction pairs.<br />

// Output: do cartesian products on the <strong>in</strong>put.<br />

let cartesian (cons, diss) =<br />

let rec cartesianUtil = function<br />

|[]−> [cons]<br />

| L::Ls −> cartesianUtil Ls |> List.collect (fun C −> L |> List.map (fun x<br />

−> x::C))<br />

cartesianUtil diss<br />

exception OmegaTestFail<br />

type CoeffTerm = struct<br />

val coeff: <strong>in</strong>t<br />

val term: Term<br />

new (c, t) ={coeff = c; term = t}<br />

end<br />

// Product all pairs of opposite literals<br />

let merge(outs, lowers: CoeffTerm list, uppers: CoeffTerm list) =<br />

let <strong>in</strong>s =[for l <strong>in</strong> lowers do<br />

for u <strong>in</strong> uppers do<br />

if l.coeff =1||u.coeff =1then<br />

yield ((l.coeff ∗∗ u.term ++ u.coeff ∗∗ l.term) −− One)<br />

else raise OmegaTestFail]<br />

<strong>in</strong>s@outs<br />

let project(x, fs) =<br />

let outs = List.filter (fun t −> f<strong>in</strong>dCoeff(t, x) =0)fs<br />

let lowers =[<br />

for t <strong>in</strong> fs do<br />

let c = f<strong>in</strong>dCoeff(t, x)<br />

if c >0then yield CoeffTerm(c, t)<br />

]<br />

let uppers =[<br />

for t <strong>in</strong> fs do<br />

let c = f<strong>in</strong>dCoeff(t, x)<br />

if c

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!