[sledge] Simplify Term.Sum.to_term

Reviewed By: jvillard

Differential Revision: D21042514

fbshipit-source-id: 9e0365e21
master
Josh Berdine 5 years ago committed by Facebook GitHub Bot
parent 2fc8bc1f84
commit cd72d3a82e

@ -80,6 +80,13 @@ struct
let pop = M.pop
let min_elt = M.min_elt
let pop_min_elt = M.pop_min_elt
let classify s =
match pop s with
| None -> `Zero
| Some (elt, q, s') when is_empty s' -> `One (elt, q)
| _ -> `Many
let to_list m = M.to_alist m
let iter m ~f = M.iteri ~f:(fun ~key ~data -> f key data) m
let exists m ~f = M.existsi ~f:(fun ~key ~data -> f key data) m

@ -65,6 +65,9 @@ module type S = sig
val pop_min_elt : t -> (elt * Q.t * t) option
(** Find and remove minimum element. [O(log n)]. *)
val classify : t -> [`Zero | `One of elt * Q.t | `Many]
(** Classify a set as either empty, singleton, or otherwise. *)
val find_and_remove : t -> elt -> (Q.t * t) option
(** Find and remove an element. *)

@ -480,16 +480,16 @@ module Sum = struct
else Qset.map_counts ~f:(fun _ -> Q.mul const) sum
let to_term sum =
match Qset.pop sum with
| None -> zero
| Some (arg, q, sum') when Qset.is_empty sum' -> (
match Qset.classify sum with
| `Zero -> zero
| `One (arg, q) -> (
match arg with
| Integer {data} ->
assert (Z.equal Z.one data) ;
rational q
| _ when Q.equal Q.one q -> arg
| _ -> Add sum )
| _ -> Add sum
| `Many -> Add sum
end
(* Products of indeterminants represented by multisets. A product ∏ᵢ xᵢ^nᵢ

Loading…
Cancel
Save