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.

B.5.<br />

COOPER.FS (EXCERPT)<br />

let rec genTermFormula (x, leftProjection, aLits, bLits, lcm, form) =<br />

let newX = if lcm =1then One else var x<br />

if leftProjection then<br />

bLits |> List.map (fun (c, b) −> match substituteFormula (c, x, b ++ newX)<br />

form with<br />

| And fs −> if c =1then And fs else And ((<br />

D(c, b ++ newX))::fs)<br />

| f −> if c =1then f else And [f; D(c, b<br />

++ newX)]<br />

)<br />

else<br />

aLits |> List.map (fun (c, a) −> match substituteFormula (c, x, a −− newX)<br />

form with<br />

| And fs −> if c =1then And fs else And ((<br />

D(c, a −− newX))::fs)<br />

| f −> if c =1then f else And [f; D(c, a<br />

−− newX)]<br />

)<br />

let elimVariable x formula =<br />

// Choice of left projection or right projection depends on the number of literals.<br />

let divCoeffs, aLits, bLits = retrieveInfo (x, formula)<br />

let leftProjection = aLits.Length >= bLits.Length<br />

//let _ = if leftProjection then bLits.Length |>pr<strong>in</strong>tfn"Leftprojection:%i"elseaLits<br />

.Length |> pr<strong>in</strong>tfn "Right projection:%i"<br />

let lcm = divCoeffs |> lcms<br />

match formula with<br />

| SOr(f’, vr) −> match genInfFormula (x, leftProjection, lcm) f’,<br />

genTermFormula (x, leftProjection, aLits, bLits, lcm, f’) with<br />

| TT, _ −> TT<br />

| FF, []−> FF<br />

| FF, fs−> if lcm =1then (fs |> Or, vr) |>SOr else (fs |> Or,<br />

(x, lcm)::vr) |>SOr<br />

| f, []−> if lcm =1then (f, vr) |>SOr else (f, (x, lcm)::vr) |><br />

SOr<br />

| f, fs −> if lcm =1then (f::fs |> Or, vr) |>SOr else (f::fs<br />

|> Or, (x, lcm)::vr) |>SOr<br />

| _ −> match genInfFormula (x, leftProjection, lcm) formula, genTermFormula (<br />

x, leftProjection, aLits, bLits, lcm, formula) with<br />

| TT, _ −> TT<br />

| FF, []−> FF<br />

| FF, fs−> if lcm =1then fs |> Or else (fs |> Or, [(x, lcm)])<br />

|> SOr<br />

| f, []−> if lcm =1then f else (f, [(x, lcm)]) |> SOr<br />

| f, fs −> if lcm =1then f::fs |> Or else (f::fs |> Or, [(x, lcm<br />

)]) |> SOr<br />

81

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

Saved successfully!

Ooh no, something went wrong!