antoinemine / apron

Apron Numerical Abstract Domain Library
Other
114 stars 33 forks source link

Is there a way to have precise assignments on PPL Grid? #73

Open rmonat opened 1 year ago

rmonat commented 1 year ago

I'd like the assignment m = n % 12 to be handled precisely by assign_texpr in the PPL Grid domain. It currently does not work precisely, while a similar code meeting constraints work when we use the EQMOD operator. I was wondering if you had any hint as to why this is imprecise, or how to fix it?

open Apron

let man = Ppl.manager_alloc_grid () 
let env = Environment.make [|Var.of_string "n"; Var.of_string "m"|] [||]
let top = Abstract1.top man env
let t3 = Texpr1.binop Mod (Texpr1.var env (Var.of_string "n")) (Texpr1.cst env (Coeff.s_of_int 12)) Int Rnd  (* n % 12 *)
let a3 = Abstract1.assign_texpr_array man top [|(Var.of_string "m")|] [|t3|] None  (* m := n % 12 *)
let () = Format.printf "@.test3: " 
let () = Tcons1.array_print Format.std_formatter (Abstract1.to_tcons_array man a3)
let () = Format.printf "@."
antoinemine commented 1 year ago

The problem is that, currently, due to the modulo operator, the expression is considered as non-linear and goes through the same generic linearisation process that outputs an affine expression, without modulo.

Possible fixes are: