[pulse] substitute entire linear expressions

Summary:
This allows further normalisation now that terms contain linear
expressions in normal form.

Reviewed By: skcho

Differential Revision: D23241499

fbshipit-source-id: f8e4e759c
master
Jules Villard 4 years ago committed by Facebook GitHub Bot
parent 36af901d79
commit eb37d2ced5

@ -1069,11 +1069,11 @@ end = struct
let normalize_term phi t = let normalize_term phi t =
Term.map_variables t ~f:(fun v -> Term.map_variables t ~f:(fun v ->
let v_canon = (VarUF.find phi.var_eqs v :> Var.t) in let v_canon = (VarUF.find phi.var_eqs v :> Var.t) in
let q_opt = match Var.Map.find_opt v_canon phi.linear_eqs with
let open Option.Monad_infix in | None ->
Var.Map.find_opt v_canon phi.linear_eqs >>= LinArith.get_as_const VarSubst v_canon
in | Some l -> (
match q_opt with None -> VarSubst v_canon | Some q -> QSubst q ) match LinArith.get_as_const l with None -> LinSubst l | Some q -> QSubst q ) )
in in
let atom' = Atom.map_terms atom ~f:(fun t -> normalize_term phi t) in let atom' = Atom.map_terms atom ~f:(fun t -> normalize_term phi t) in
Atom.eval atom' |> sat_of_eval_result Atom.eval atom' |> sat_of_eval_result

@ -168,7 +168,7 @@ let%test_module "normalization" =
let%expect_test _ = let%expect_test _ =
normalize (x + y < x + y) ; normalize (x + y < x + y) ;
[%expect {|true (no var=var) && v6 = x + y v7 = x + y && {[v6 + -v7] < 0}|}] [%expect {|unsat|}]
let%expect_test "nonlinear arithmetic" = let%expect_test "nonlinear arithmetic" =
normalize (z * (x + (v * y) + i 1) / w = i 0) ; normalize (z * (x + (v * y) + i 1) / w = i 0) ;
@ -178,7 +178,7 @@ let%test_module "normalization" =
&& &&
v7 = x + v6 v8 = x + v6 +1 v10 = 0 v7 = x + v6 v8 = x + v6 +1 v10 = 0
&& &&
{0 = [v9]÷[w]}{[v6] = [v]×[y]}{[v9] = [z]×[v8]} |}] {0 = [v9]÷[w]}{[v6] = [v]×[y]}{[v9] = [z]×[x + v6 +1]} |}]
(* check that this becomes all linear equalities *) (* check that this becomes all linear equalities *)
let%expect_test _ = let%expect_test _ =

Loading…
Cancel
Save