Skip to content
Snippets Groups Projects
Commit e945d78d authored by Julien Signoles's avatar Julien Signoles
Browse files

[e-acsl:interval] simplify the case of \sum

parent d6a7ebf5
No related branches found
No related tags found
No related merge requests found
...@@ -351,36 +351,41 @@ let extended_interv_of_typ ty = match interv_of_typ ty with ...@@ -351,36 +351,41 @@ let extended_interv_of_typ ty = match interv_of_typ ty with
of the lower (resp. upper) bound and [name] is the identifier of the extended of the lower (resp. upper) bound and [name] is the identifier of the extended
quantifier (\sum, \product or \numof). The returned ival is the interval of quantifier (\sum, \product or \numof). The returned ival is the interval of
the extended quantifier. *) the extended quantifier. *)
let interv_of_extended_quantifier lambda i j name = let interv_of_extended_quantifier lambda lb up name =
match lambda, i, j, name.lv_name with match lambda, lb, up, name.lv_name with
| Ival lbd_iv, Ival i_iv, Ival j_iv, "\\sum" -> | Ival lbd_iv, Ival lb_iv, Ival ub_iv, "\\sum" ->
(try (try
let min_lambda, max_lambda = Ival.min_and_max lbd_iv in let min_lambda, max_lambda = Ival.min_and_max lbd_iv in
let i_lb, i_ub = Ival.min_and_max i_iv in let min_lb, min_ub = Ival.min_and_max lb_iv in
let j_lb, j_ub = Ival.min_and_max j_iv in let max_lb, max_ub = Ival.min_and_max ub_iv in
let compute_bound bound_lambda is_lower_bound = (* the number of iterations is the distance between the upper bound and
let cond = match bound_lambda with the lower bound, or 0 if it is negative. *)
| Some lambda -> let delta a b = Z.max Z.zero (Z.sub a b) in
(is_lower_bound && Z.compare lambda Z.zero = 1) || let min_iteration_number =
(not is_lower_bound && Z.compare lambda Z.zero = -1) (* the minimum number of iterations is the distance between the
| None -> false smallest upper bound and the biggest lower bound. *)
in match min_ub, max_lb with
match bound_lambda, i_lb, i_ub, j_lb, j_ub with | Some mub, Some mlb -> delta mub mlb
| Some lambda, _, Some i_ub, Some j_lb, _ when cond-> | _, None | None, _ -> Z.zero
Some (Z.mul lambda (Z.max (Z.sub j_lb i_ub) Z.zero)) in
| _, _, _, _, _ when cond -> Some Z.zero let max_iteration_number =
| Some lambda, Some i_lb, _, _, Some j_ub -> (* the maximum number of iterations is the distance between the
Some (Z.mul lambda (Z.max (Z.sub j_ub i_lb) Z.zero)) biggest upper bound and the smallest lower bound. *)
| Some lambda, _, _ , _, _ when Z.compare lambda Z.zero = 0 -> match max_ub, min_lb with
Some Z.zero | Some mub, Some mlb -> Some (delta mub mlb)
| None, Some i_lb, _, _, Some j_ub when Z.compare j_ub i_lb = 0 -> | _, None | None, _ -> None
Some Z.zero
| _, _, _, _, _ -> None
in in
Ival (* the lower (resp. upper) bound is the min (resp. max) value of
(Ival.inject_range the lambda term times the min (resp. max) number of iterations *)
(compute_bound min_lambda true) let lower_bound = match min_lambda with
(compute_bound max_lambda false)) | None -> None
| Some z -> Some (Z.mul z min_iteration_number)
in
let upper_bound = match max_lambda, max_iteration_number with
| None, _ | _, None -> None
| Some z, Some n -> Some (Z.mul z n)
in
Ival (Ival.inject_range lower_bound upper_bound)
with Abstract_interp.Error_Bottom -> with Abstract_interp.Error_Bottom ->
bottom) bottom)
| _, _, _, "\\product" -> Error.not_yet "product" | _, _, _, "\\product" -> Error.not_yet "product"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment