[sledge] Use integer or float constants as needed in Exp normalization

Summary:
Some constants are used during Exp normalization, to encode
subtraction using addition, units of addition and multiplication,
etc. Previously these were unconditionally integers, but need to be
floats for float arithmetic.

Reviewed By: mbouaziz

Differential Revision: D15098815

fbshipit-source-id: 13d1be142
master
Josh Berdine 6 years ago committed by Facebook Github Bot
parent 26a3058659
commit d2a97a6174

@ -655,6 +655,15 @@ let null = integer Z.zero Typ.ptr
let bool b = integer (Z.of_bool b) Typ.bool let bool b = integer (Z.of_bool b) Typ.bool
let float data = Float {data} |> check invariant let float data = Float {data} |> check invariant
let zero (typ : Typ.t) =
match typ with Float _ -> float "0" | _ -> integer Z.zero typ
let one (typ : Typ.t) =
match typ with Float _ -> float "1" | _ -> integer Z.one typ
let minus_one (typ : Typ.t) =
match typ with Float _ -> float "-1" | _ -> integer Z.minus_one typ
let simp_convert signed (dst : Typ.t) src arg = let simp_convert signed (dst : Typ.t) src arg =
match (dst, arg) with match (dst, arg) with
| _ when Typ.equal dst src -> arg | _ when Typ.equal dst src -> arg
@ -720,7 +729,7 @@ let sum_mul_const const sum =
let rec sum_to_exp typ sum = let rec sum_to_exp typ sum =
match Qset.length sum with match Qset.length sum with
| 0 -> integer Z.zero typ | 0 -> zero typ
| 1 -> ( | 1 -> (
match Qset.min_elt sum with match Qset.min_elt sum with
| Some (Integer _, q) -> rational q typ | Some (Integer _, q) -> rational q typ
@ -817,7 +826,7 @@ let rec simp_add_ typ es poly =
in in
Qset.fold ~f es ~init:poly Qset.fold ~f es ~init:poly
let simp_add typ es = simp_add_ typ es (integer Z.zero typ) let simp_add typ es = simp_add_ typ es (zero typ)
let simp_add2 typ e f = simp_add_ typ (Sum.singleton e) f let simp_add2 typ e f = simp_add_ typ (Sum.singleton e) f
(* Products of indeterminants represented by multisets. A product ∏ᵢ xᵢ^nᵢ (* Products of indeterminants represented by multisets. A product ∏ᵢ xᵢ^nᵢ
@ -876,12 +885,12 @@ let simp_mul typ es =
if Q.equal Q.zero pwr then exp if Q.equal Q.zero pwr then exp
else mul_pwr bas Q.(pwr - one) (simp_mul2 typ bas exp) else mul_pwr bas Q.(pwr - one) (simp_mul2 typ bas exp)
in in
let one = integer Z.one typ in let one = one typ in
Qset.fold es ~init:one ~f:(fun bas pwr exp -> Qset.fold es ~init:one ~f:(fun bas pwr exp ->
if Q.sign pwr >= 0 then mul_pwr bas pwr exp if Q.sign pwr >= 0 then mul_pwr bas pwr exp
else simp_div exp (mul_pwr bas (Q.neg pwr) one) ) else simp_div exp (mul_pwr bas (Q.neg pwr) one) )
let simp_negate typ x = simp_mul2 typ (integer Z.minus_one typ) x let simp_negate typ x = simp_mul2 typ (minus_one typ) x
let simp_sub typ x y = let simp_sub typ x y =
match (x, y) with match (x, y) with
@ -1345,7 +1354,7 @@ let solve e f =
let d = rational (Q.neg q) typ in let d = rational (Q.neg q) typ in
let r = div n d in let r = div n d in
Some (Map.add_exn s ~key:c ~data:r) Some (Map.add_exn s ~key:c ~data:r)
| e_f -> solve_uninterp e_f (integer Z.zero typ) ) | e_f -> solve_uninterp e_f (zero typ) )
| Concat {args= ms}, Concat {args= ns} -> ( | Concat {args= ms}, Concat {args= ns} -> (
match (concat_size ms, concat_size ns) with match (concat_size ms, concat_size ns) with
| Some p, Some q -> solve_uninterp e f >>= solve_ p q | Some p, Some q -> solve_uninterp e f >>= solve_ p q

Loading…
Cancel
Save