Skip to content

Commit

Permalink
Not simplifying substrations of the form (0 - x)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven de Oliveira committed May 24, 2019
1 parent 0a83f5b commit 934bedf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
48 changes: 31 additions & 17 deletions sources/lib/frontend/simple_reasoner_expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ sig
(** Represents no explanation. *)
val empty : t

(** Tests if the explanation is empty *)
val is_empty : t -> bool

(** Merges two explanations. *)
val union : t -> t -> t
end
Expand Down Expand Up @@ -292,10 +295,10 @@ struct
(* Wrapper for op. Checks that it has been called.
If it has never been called, then there have been no
simplification. *)
let op_has_been_called = ref false in
let op_has_been_called = ref 0 in
let op v1 v2 =
op_has_been_called := true ;
debug "Calling operator.@.";
op_has_been_called := !op_has_been_called + 1 ;
debug "Calling operator@.";
op v1 v2
in

Expand All @@ -314,19 +317,19 @@ struct
(None, Expl.empty, [])
e_list
in
if not (!op_has_been_called)
then
begin
debug "Operator has not been called.@.";
identity e_list
end
else
match vals with
None -> identity e_list
| Some v ->
let cst_expr = value_to_expr ty v in
debug "Result of simplifyable operations : %a@." E.pretty cst_expr;
{v = List.rev exprs @ [value_to_expr ty v]; diff = true; expl}
if !op_has_been_called = 0
then
begin
debug "Operator has not been called.@.";
identity e_list
end
else
match vals with
None -> identity e_list
| Some v ->
let cst_expr = value_to_expr ty v in
debug "Result of simplifyable operations : %a@." E.pretty cst_expr;
{v = List.rev exprs @ [value_to_expr ty v]; diff = true; expl}

let oper (op : value -> value -> bool) (l : expr list) : bool * bool * expl =
(* all_true is a boolean stating that every call of 'op' returned 'true'.
Expand Down Expand Up @@ -435,7 +438,18 @@ struct
(expr list, expl) simp * bool =
match op with
| Symbols.Plus -> arith ty (++) elist, false
| Symbols.Minus -> arith ty (--) elist, false
| Symbols.Minus -> (
match elist with
hd :: _ :: [] -> (
(* in the case 0 - sthg, we don't want to do anything. *)
match E.get_comp hd with
| Int s
| Real s when Q.equal (Q.of_string (Hstring.view s)) Q.zero ->
identity elist, false
| _ -> arith ty ( -- ) elist, false
)
| _ -> arith ty ( -- ) elist, false
)
| Symbols.Mult -> arith ty ( ** ) elist, false
| Symbols.Tite -> (
match elist with
Expand Down
7 changes: 7 additions & 0 deletions sources/lib/frontend/simple_reasoner_expr.mli
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ end
module type Expl =
sig
type t

(** Represents no explanation. *)
val empty : t

(** Tests if the explanation is empty *)
val is_empty : t -> bool

(** Merges two explanations. *)
val union : t -> t -> t
end

Expand Down
1 change: 1 addition & 0 deletions sources/lib/structures/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,7 @@ module SimpExprDummy =
(struct
type t = unit
let empty = ()
let is_empty _ = true
let union _ _ = ()
end)
(struct
Expand Down

0 comments on commit 934bedf

Please sign in to comment.