Theory Equality_Detection_Impl
subsection ‹Algorithm to Detect all Implicit Equalities in ‹ℚ››
text ‹Use incremental simplex algorithm to recursively detect all
implied equalities.›
theory Equality_Detection_Impl
imports
Equality_Detection_Theory
Simplex.Simplex_Incremental
Deriving.Compare_Instances
begin
lemma indexed_sat_mono: "(S,v) ⊨⇩i⇩c⇩s cs ⟹ T ⊆ S ⟹ (T,v) ⊨⇩i⇩c⇩s cs"
by auto
lemma assert_all_simplex_plain_unsat: assumes "invariant_simplex cs J s"
and "assert_all_simplex K s = Unsat I"
shows "¬ (set K ∪ J, v) ⊨⇩i⇩c⇩s set cs"
proof -
from assert_all_simplex_unsat[OF assms]
show ?thesis unfolding minimal_unsat_core_def by force
qed
lemma check_simplex_plain_unsat: assumes "invariant_simplex cs J s"
and "check_simplex s = (s',Some I)"
shows "¬ (J, v) ⊨⇩i⇩c⇩s set cs"
proof -
from check_simplex_unsat[OF assms]
show ?thesis unfolding minimal_unsat_core_def by force
qed
hide_const (open) Congruence.eq
fun le_of_constraint :: "constraint ⇒ rat le_constraint" where
"le_of_constraint (LEQ p c) = Le_Constraint Leq_Rel p c"
| "le_of_constraint (LT p c) = Le_Constraint Lt_Rel p c"
| "le_of_constraint (GEQ p c) = Le_Constraint Leq_Rel (-p) (-c)"
| "le_of_constraint (GT p c) = Le_Constraint Lt_Rel (-p) (-c)"
fun poly_of_constraint :: "constraint ⇒ linear_poly" where
"poly_of_constraint (LEQ p c) = p"
| "poly_of_constraint (LT p c) = p"
| "poly_of_constraint (GEQ p c) = (-p)"
| "poly_of_constraint (GT p c) = (-p)"
fun const_of_constraint :: "constraint ⇒ rat" where
"const_of_constraint (LEQ p c) = c"
| "const_of_constraint (LT p c) = c"
| "const_of_constraint (GEQ p c) = (-c)"
| "const_of_constraint (GT p c) = (-c)"
fun is_no_equality :: "constraint ⇒ bool" where
"is_no_equality (EQ p c) = False"
| "is_no_equality _ = True"
fun is_equality :: "constraint ⇒ bool" where
"is_equality (EQ p c) = True"
| "is_equality _ = False"
lemma le_of_constraint: "is_no_equality c ⟹ v ⊨⇩c c ⟷ (v ⊨⇩l⇩e le_of_constraint c)"
by (cases c, auto simp: valuate_uminus)
lemma le_of_constraints: "Ball cs is_no_equality ⟹ v ⊨⇩c⇩s cs ⟷ (∀ c ∈ cs. v ⊨⇩l⇩e le_of_constraint c)"
using le_of_constraint by auto
fun is_strict :: "constraint ⇒ bool" where
"is_strict (GT _ _) = True"
| "is_strict (LT _ _) = True"
| "is_strict _ = False"
fun is_nstrict :: "constraint ⇒ bool" where
"is_nstrict (GEQ _ _) = True"
| "is_nstrict (LEQ _ _) = True"
| "is_nstrict _ = False"
lemma is_equality_iff: "is_equality c = (¬ is_strict c ∧ ¬ is_nstrict c)"
by (cases c, auto)
lemma is_nstrict_iff: "is_nstrict c = (¬ is_strict c ∧ ¬ is_equality c)"
by (cases c, auto)
fun make_strict :: "constraint ⇒ constraint" where
"make_strict (GEQ p c) = GT p c"
| "make_strict (LEQ p c) = LT p c"
| "make_strict c = c"
fun make_equality :: "constraint ⇒ constraint" where
"make_equality (GEQ p c) = EQ p c"
| "make_equality (LEQ p c) = EQ p c"
| "make_equality c = c"
fun make_ineq :: "constraint ⇒ constraint" where
"make_ineq (GEQ p c) = GEQ p c"
| "make_ineq (LEQ p c) = LEQ p c"
| "make_ineq (EQ p c) = LEQ p c"
fun make_flipped_ineq :: "constraint ⇒ constraint" where
"make_flipped_ineq (GEQ p c) = LEQ p c"
| "make_flipped_ineq (LEQ p c) = GEQ p c"
| "make_flipped_ineq (EQ p c) = GEQ p c"
lemma poly_const_repr: assumes "is_nstrict c"
shows "le_of_constraint c = Le_Constraint Leq_Rel (poly_of_constraint c) (const_of_constraint c)"
"le_of_constraint (make_strict c) = Le_Constraint Lt_Rel (poly_of_constraint c) (const_of_constraint c)"
"le_of_constraint (make_flipped_ineq c) = Le_Constraint Leq_Rel (- poly_of_constraint c) (- const_of_constraint c)"
using assms by (cases c, auto)+
lemma poly_const_repr_set: assumes "Ball cs is_nstrict"
shows "le_of_constraint ` cs = (λ c. Le_Constraint Leq_Rel (poly_of_constraint c) (const_of_constraint c)) ` cs"
"le_of_constraint ` (make_strict ` cs) = (λ c. Le_Constraint Lt_Rel (poly_of_constraint c) (const_of_constraint c)) ` cs"
subgoal using assms poly_const_repr(1) by simp
subgoal using assms poly_const_repr(2) unfolding image_comp o_def by auto
done