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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

B.2.<br />

TERM.FS<br />

Term(t.constant, t.vars, Array.map2(fun vc−> if v=x then 0 else c) t.vars t.<br />

coeffs) // Not remov<strong>in</strong>g for better performance.<br />

// Substitute variable c∗x <strong>in</strong> term t by a new term tx<br />

let substitute (c, x, tx, t): Term =<br />

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

if c0 =0then t<br />

else<br />

let lcm = lcm(abs(c0), abs(c))<br />

let d = lcm/abs(c0)<br />

let t’ =filterOut (d∗∗t, x)<br />

t’ ++(d∗c0/abs(c)) ∗∗ tx<br />

let rec subst (t: Term, xts) =<br />

match xts with<br />

|[]−> t<br />

|(x, tx)::xts’ −> subst (substitute (1, x, constTerm tx, t), xts’)<br />

let getCoeffsWithoutConst (t: Term) =<br />

List.ofArray t.coeffs<br />

let getCoeffs (t: Term) =<br />

t.constant::getCoeffsWithoutConst(t)<br />

// Note: may change for optimization<br />

let redCoeffs (t: Term) =<br />

let vars =[|for i=0 to t.vars.Length−1 do<br />

if t.coeffs.[i] 0then yield t.vars.[i]<br />

|]<br />

let coeffs = Array.filter(fun c −> c 0) t.coeffs<br />

let t’ =Term(t.constant, vars, coeffs)<br />

let g = getCoeffs t’ |>gcds<br />

if g =0||g =1then t’ else t’ ∗/∗g<br />

let isConstTerm (t: Term) =<br />

Array.isEmpty t.vars || Array.forall (fun c −> c =0)t.coeffs<br />

let getConst (t: Term) =t.constant<br />

75

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

Saved successfully!

Ooh no, something went wrong!