Commit 0fcba367 authored by Joachim Bard's avatar Joachim Bard

sort preconds before checking

parent 565e31c3
...@@ -4,8 +4,7 @@ From Flover ...@@ -4,8 +4,7 @@ From Flover
Environments TypeValidator FPRangeValidator ExpressionAbbrevs ResultChecker Environments TypeValidator FPRangeValidator ExpressionAbbrevs ResultChecker
IntervalArithQ. IntervalArithQ.
Require Import List. Require Import List FunInd Sorting.Permutation Sorting.Mergesort Orders.
Require Import FunInd.
Fixpoint resultLeq e (A1 A2: analysisResult) := Fixpoint resultLeq e (A1 A2: analysisResult) :=
match e with match e with
...@@ -341,11 +340,39 @@ Proof. ...@@ -341,11 +340,39 @@ Proof.
eapply IHP; eauto. eapply IHP; eauto.
Qed. Qed.
Module PrecondOrder <: TotalLeBool.
Definition t := list (expr Q * intv).
Fixpoint leb (P1 P2: list (expr Q * intv)) :=
match P1, P2 with
| nil, _ => true
| _, nil => false
| (_, iv1) :: P1, (_, iv2) :: P2 =>
match (fst iv1) ?= (fst iv2) with
| Lt => true
| Eq => leb P1 P2
| Gt => false
end
end.
Theorem leb_total P1 P2 : leb P1 P2 = true \/ leb P2 P1 = true.
Proof.
induction P1 in P2 |- *; destruct P2 as [|[e2 iv2] P2]; auto.
destruct a as [e1 iv1]; cbn.
rewrite <- (Qcompare_antisym (fst iv1)).
destruct (fst iv1 ?= fst iv2); cbn; auto.
Qed.
End PrecondOrder.
Module Import PrecondSort := Sort PrecondOrder.
Definition checkPreconds (subdivs: list precond) (P: precond) := Definition checkPreconds (subdivs: list precond) (P: precond) :=
let Piv := FloverMap.elements (fst P) in let Piv := FloverMap.elements (fst P) in
let Ps := map (fun P => FloverMap.elements (fst P)) subdivs in let Ps := map (fun P => FloverMap.elements (fst P)) subdivs in
let S_qs := map snd subdivs in let S_qs := map snd subdivs in
covers Piv Ps && forallb (fun q => SMTLogic_eqb q (snd P)) S_qs. covers Piv (sort Ps) && forallb (fun q => SMTLogic_eqb q (snd P)) S_qs.
Lemma checkPreconds_sound (subdivs: list precond) E P : Lemma checkPreconds_sound (subdivs: list precond) E P :
checkPreconds subdivs P = true -> checkPreconds subdivs P = true ->
...@@ -356,6 +383,8 @@ Proof. ...@@ -356,6 +383,8 @@ Proof.
apply andb_true_iff in H as [cov Hqs]. apply andb_true_iff in H as [cov Hqs].
eapply covers_sound in cov; eauto. eapply covers_sound in cov; eauto.
destruct cov as [Pl1 [Hin H]]. destruct cov as [Pl1 [Hin H]].
eapply Permutation_in in Hin.
2: eapply Permutation_sym, Permuted_sort.
apply in_map_iff in Hin as [P1 [Heq1 Hin]]. apply in_map_iff in Hin as [P1 [Heq1 Hin]].
exists P1. split; auto. exists P1. split; auto.
rewrite <- Heq1 in H. rewrite <- Heq1 in H.
...@@ -376,10 +405,10 @@ Proof. ...@@ -376,10 +405,10 @@ Proof.
erewrite SMTLogic_eqb_varsLogic; eauto. erewrite SMTLogic_eqb_varsLogic; eauto.
apply NatSetProps.union_equal_1. apply NatSetProps.union_equal_1.
eapply covers_preVars; eauto. eapply covers_preVars; eauto.
eapply Permutation_in; eauto using Permuted_sort.
apply in_map_iff; eauto. apply in_map_iff; eauto.
Qed. Qed.
(* TODO: merge hd and tl again *)
(** Interval subdivisions checking function **) (** Interval subdivisions checking function **)
Definition SubdivsChecker (e: expr Q) (absenv: analysisResult) Definition SubdivsChecker (e: expr Q) (absenv: analysisResult)
(P: precond) subdivs (defVars: FloverMap.t mType) Gamma := (P: precond) subdivs (defVars: FloverMap.t mType) Gamma :=
...@@ -443,4 +472,4 @@ Proof. ...@@ -443,4 +472,4 @@ Proof.
intros vF0 m Heval. intros vF0 m Heval.
specialize (err_bounded vF0 m Heval). specialize (err_bounded vF0 m Heval).
lra. lra.
Qed. Qed.
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment