Theory MLSSmf_to_MLSS_Soundness
theory MLSSmf_to_MLSS_Soundness
imports MLSSmf_to_MLSS MLSSmf_Semantics Proper_Venn_Regions MLSSmf_HF_Extras
begin
locale satisfiable_normalized_MLSSmf_clause =
normalized_MLSSmf_clause š for š :: "('v, 'f) MLSSmf_clause" +
fixes Mā©v :: "'v ā hf"
and Mā©f :: "'f ā hf ā hf"
assumes model_for_š: "Iā©cā©l Mā©v Mā©f š"
begin
interpretation proper_Venn_regions V Mā©v
using finite_V by unfold_locales
function ā³ :: "('v, 'f) Composite ā hf" where
"ā³ (Solo x) = Mā©v x"
| "ā³ (vāαā) = proper_Venn_region α"
| "ā³ (UnionOfVennRegions xss) = āØHF ((ā³ ā VennRegion) ` set xss)"
| "ā³ (wāfāālā) = (Mā©f f) (ā³ (UnionOfVennRegions (var_set_set_to_var_set_list l)))"
| "ā³ (UnionOfVars xs) = āØHF (Mā©v ` set xs)"
| "ā³ (InterOfVars xs) = āØ
HF (Mā©v ` set xs)"
| "ā³ (MemAux x) = HF {Mā©v x}"
| "ā³ (InterOfWAux f l m) = ā³ wāfāālā - ā³ wāfāāmā"
| "ā³ (InterOfVarsAux xs) = Mā©v (hd xs) - ā³ (InterOfVars (tl xs))"
by pat_completeness auto
termination
apply (relation "measure (λcomp. case comp of
InterOfVarsAux _ ā Suc 0
| UnionOfVennRegions _ ā Suc 0
| wā_āā_ā ā Suc (Suc 0)
| InterOfWAux _ _ _ ā Suc (Suc (Suc 0))
| _ ā 0)")
apply auto
done
lemma soundness_restriction_on_InterOfVars:
assumes "set xs ā Pā§+ V"
shows "āa ā restriction_on_InterOfVars xs. Iā©sā©a ā³ a"
proof (induction xs rule: restriction_on_InterOfVars.induct)
case (2 x)
{fix a assume "a ā restriction_on_InterOfVars [x]"
then have "a = Var (InterOfVars [x]) =ā©s Var (Solo x)" by simp
then have "Iā©sā©a ā³ a" by (simp add: HInter_singleton)
}
then show ?case by blast
next
case (3 y x xs)
{fix a assume "a ā restriction_on_InterOfVars (y # x # xs) - restriction_on_InterOfVars (x # xs)"
then consider "a = Var (InterOfVarsAux (y # x # xs)) =ā©s Var (Solo y) -ā©s Var (InterOfVars (x # xs))"
| "a = Var (InterOfVars (y # x # xs)) =ā©s Var (Solo y) -ā©s Var (InterOfVarsAux (y # x # xs))"
by fastforce
then have "Iā©sā©a ā³ a"
proof (cases)
case 1
then show ?thesis by simp
next
case 2
have "āØ
HF (insert (Mā©v y) (insert (Mā©v x) (Mā©v ` set xs))) =
āØ
(HF ((insert (Mā©v x) (Mā©v ` set xs))) ā Mā©v y)"
using HF_insert_hinsert by auto
also have "... = Mā©v y ā āØ
HF (insert (Mā©v x) (Mā©v ` set xs))"
by (simp add: HF_nonempty)
also have "... = Mā©v y - (Mā©v y - āØ
HF (insert (Mā©v x) (Mā©v ` set xs)))"
by blast
finally show ?thesis using 2 by simp
qed
}
with "3.IH" show ?case by blast
qed simp
lemma soundness_restriction_on_UnionOfVars:
assumes "set xs ā Pow V"
shows "āa ā restriction_on_UnionOfVars xs. Iā©sā©a ā³ a"
proof (induction xs rule: restriction_on_UnionOfVars.induct)
case 1
then show ?case by auto
next
case (2 x xs)
{fix a assume "a ā restriction_on_UnionOfVars (x # xs) - restriction_on_UnionOfVars xs"
then have a: "a = Var (UnionOfVars (x # xs)) =ā©s Var (Solo x) āā©s Var (UnionOfVars xs)"
by fastforce
have "āØHF (insert (Mā©v x) (Mā©v ` set xs)) = ⨠(HF (Mā©v ` set xs) ā Mā©v x)"
by (simp add: HF_insert_hinsert)
also have "... = Mā©v x ā āØHF (Mā©v ` set xs)" by auto
finally have "Iā©sā©a ā³ a"
using a by simp
}
with "2.IH" show ?case by blast
qed
lemma soundness_introduce_v:
"āfml ā introduce_v. interp Iā©sā©a ā³ fml"
proof -
{fix α assume "α ā Pā§+ V"
have "ā³ vāαā = āØ
HF (Mā©v ` α) - āØHF (Mā©v ` (V - α))"
by simp
also have "... = āØ
HF ((ā³ ā Solo) ` α) - āØHF ((ā³ ā Solo) ` (V - α))"
by simp
finally have "Iā©sā©a ā³ (restriction_on_v α)"
apply (simp add: set_V_list)
using ā¹Ī± ā Pā§+ Vāŗ
by (metis Int_def inf.absorb2 mem_P_plus_subset set_diff_eq)
}
then have "āα ā Pā§+ V. interp Iā©sā©a ā³ (AT (restriction_on_v α))"
by simp
moreover
from soundness_restriction_on_InterOfVars
have "āa ā (restriction_on_InterOfVars ā var_set_to_list) α. Iā©sā©a ā³ a" if "α ā Pā§+ V" for α
by (metis comp_apply mem_P_plus_subset set_var_set_to_list that)
then have "ālt ā AT ` ā ((restriction_on_InterOfVars ā var_set_to_list) ` Pā§+ V). interp Iā©sā©a ā³ lt"
by fastforce
moreover
from soundness_restriction_on_UnionOfVars
have "āa ā (restriction_on_UnionOfVars ā var_set_to_list) α. Iā©sā©a ā³ a" if "α ā Pow V" for α
by (metis Pow_iff comp_apply set_var_set_to_list that)
then have "ālt ā AT ` ā ((restriction_on_UnionOfVars ā var_set_to_list) ` Pow V). interp Iā©sā©a ā³ lt"
by fastforce
ultimately
show ?thesis
unfolding introduce_v_def by blast
qed
lemma soundness_restriction_on_UnionOfVennRegions:
assumes "set αs ā Pow (Pow V)"
shows "āa ā restriction_on_UnionOfVennRegions αs. Iā©sā©a ā³ a"
proof (induction αs rule: restriction_on_UnionOfVennRegions.induct)
case 1
then show ?case by auto
next
case (2 α αs)
{fix a assume "a ā restriction_on_UnionOfVennRegions (α # αs) - restriction_on_UnionOfVennRegions αs"
then have a: "a = Var (UnionOfVennRegions (α # αs)) =ā©s Var vāαā āā©s Var (UnionOfVennRegions αs)"
by fastforce
have "āØHF ((ā³ ā VennRegion) ` set (α # αs)) = āØHF (insert (ā³ vāαā) ((ā³ ā VennRegion) ` set αs))"
by simp
also have "... = ⨠(HF ((ā³ ā VennRegion) ` set αs) ā ā³ vāαā)"
by (simp add: HF_insert_hinsert)
also have "... = ā³ vāαā ā āØHF ((ā³ ā VennRegion) ` set αs)"
by blast
finally have "Iā©sā©a ā³ a" using a by simp
}
with "2.IH" show ?case by blast
qed
lemma soundness_introduce_UnionOfVennRegions:
"ālt ā introduce_UnionOfVennRegions. interp Iā©sā©a ā³ lt"
proof
fix lt assume "lt ā introduce_UnionOfVennRegions"
then obtain αs where "αs ā set all_V_set_lists" "lt ā AT ` restriction_on_UnionOfVennRegions αs"
unfolding introduce_UnionOfVennRegions_def by blast
with soundness_restriction_on_UnionOfVennRegions
show "interp Iā©sā©a ā³ lt"
using set_all_V_set_lists by fastforce
qed
lemma soundness_restriction_on_FunOfUnionOfVennRegions:
assumes l'_l: "l' = var_set_set_to_var_set_list l"
and m'_m: "m' = var_set_set_to_var_set_list m"
shows "ālt ā set (restriction_on_FunOfUnionOfVennRegions l' m' f). interp Iā©sā©a ā³ lt"
proof (cases "ā³ (UnionOfVennRegions l') = ā³ (UnionOfVennRegions m')")
case True
then have "ā³ wāfāālā = ā³ wāfāāmā"
using l'_l m'_m by auto
then have "interp Iā©sā©a ā³ (AT (Var wāfāāset l'ā =ā©s Var wāfāāset m'ā))"
using l'_l m'_m by auto
then show ?thesis by simp
next
case False
then have "interp Iā©sā©a ā³ (AF (Var (UnionOfVennRegions l') =ā©s Var (UnionOfVennRegions m')))"
by fastforce
then show ?thesis by simp
qed
lemma soundness_introduce_w:
"āclause ā introduce_w. ālt ā clause. interp Iā©sā©a ā³ lt"
proof -
let ?f = "Ī»lts. if interp Iā©sā©a ā³ (lts ! 0) then lts ! 0 else lts ! 1"
let ?g = "Ī»(l, m, f). restriction_on_FunOfUnionOfVennRegions l m f"
let ?xs = "List.product all_V_set_lists (List.product all_V_set_lists F_list)"
have "ā(l', m', f) ā set ?xs. ?f (?g (l', m', f)) ā set (?g (l', m', f))"
by fastforce
with valid_choice[where ?f = ?f and ?g = ?g and ?xs = ?xs]
have "map ?f (map ?g ?xs) ā set (choices_from_lists (map ?g ?xs))"
by fast
then have "set (map ?f (map ?g ?xs)) ā introduce_w"
unfolding introduce_w_def
using mem_set_map[where ?x = "map ?f (map ?g ?xs)" and ?f = set]
by blast
moreover
have "{x ā set V_set_list. x ā set l'} = set l'" if "l' ā set all_V_set_lists" for l'
using that set_V_set_list set_all_V_set_lists by auto
then have "interp Iā©sā©a ā³ (?f (restriction_on_FunOfUnionOfVennRegions l' m' f))"
if "l' ā set all_V_set_lists" "m' ā set all_V_set_lists" for l' m' f
using that by auto
then have "ālt ā set (map ?f (map ?g ?xs)). interp Iā©sā©a ā³ lt"
by force
ultimately
show ?thesis by blast
qed
lemma soundness_reduce_literal:
assumes "lt ā set š"
shows "āfml ā reduce_literal lt. interp Iā©sā©a ā³ fml"
proof -
from norm_š ā¹lt ā set šāŗ have "norm_literal lt" by auto
then show ?thesis
proof (cases rule: norm_literal.cases)
case (inc f)
show ?thesis
proof
fix fml assume "fml ā reduce_literal lt"
then have "fml ā reduce_literal (ATā©m (inc(f)))"
using inc by blast
then obtain l m where lm: "l ā Pā§+ V" "m ā Pā§+ V" "l ā m"
and fml: "fml = AT (Var wāfāāmā =ā©s Var wāfāāmā āā©s Var wāfāālā)"
by auto
from model_for_š ā¹lt ā set šāŗ inc have "Iā©a Mā©v Mā©f (inc(f))" by fastforce
then have "ās t. s ⤠t ā¶ (Mā©f f) s ⤠(Mā©f f) t" by simp
moreover
from lm have "āØHF ((ā³ ā VennRegion) ` l) ⤠āØHF ((ā³ ā VennRegion) ` m)"
by (metis HUnion_proper_Venn_region_inter ā³.simps(2) comp_apply image_cong inf.absorb_iff2)
ultimately
have "Mā©f f (āØHF ((ā³ ā VennRegion) ` l)) ⤠Mā©f f (āØHF ((ā³ ā VennRegion) ` m))"
by blast
then have "Mā©f f (āØHF ((ā³ ā VennRegion) ` m)) =
Mā©f f (āØHF ((ā³ ā VennRegion) ` m)) ā Mā©f f (āØHF ((ā³ ā VennRegion) ` l))"
by blast
with fml lm show "interp Iā©sā©a ā³ fml"
by (auto simp only: interp.simps Iā©sā©a.simps Iā©sā©t.simps ā³.simps set_var_set_set_to_var_set_list)
qed
next
case (dec f)
show ?thesis
proof
fix fml assume "fml ā reduce_literal lt"
then have "fml ā reduce_literal (ATā©m (dec(f)))"
using dec by blast
then obtain l m where lm: "l ā Pā§+ V" "m ā Pā§+ V" "l ā m"
and fml: "fml = AT (Var wāfāālā =ā©s Var wāfāālā āā©s Var wāfāāmā)"
by auto
from model_for_š ā¹lt ā set šāŗ dec have "Iā©a Mā©v Mā©f (dec(f))" by fastforce
then have "ās t. s ⤠t ā¶ (Mā©f f) t ⤠(Mā©f f) s" by simp
moreover
from lm have "āØHF ((ā³ ā VennRegion) ` l) ⤠āØHF ((ā³ ā VennRegion) ` m)"
by (metis HUnion_proper_Venn_region_inter ā³.simps(2) comp_apply image_cong inf.absorb_iff2)
ultimately
have "Mā©f f (āØHF ((ā³ ā VennRegion) ` m)) ⤠Mā©f f (āØHF ((ā³ ā VennRegion) ` l))"
by blast
then have "Mā©f f (āØHF ((ā³ ā VennRegion) ` l)) =
Mā©f f (āØHF ((ā³ ā VennRegion) ` l)) ā Mā©f f (āØHF ((ā³ ā VennRegion) ` m))"
by blast
with fml lm show "interp Iā©sā©a ā³ fml"
by (auto simp only: interp.simps Iā©sā©a.simps Iā©sā©t.simps ā³.simps set_var_set_set_to_var_set_list)
qed
next
case (add f)
show ?thesis
proof
fix fml assume "fml ā reduce_literal lt"
then have "fml ā reduce_literal (ATā©m (add(f)))"
using add by blast
then obtain l m where lm: "l ā Pā§+ V" "m ā Pā§+ V"
and fml: "fml = AT (Var wāfāālāŖmā =ā©s Var wāfāālā āā©s Var wāfāāmā)"
by auto
from model_for_š ā¹lt ā set šāŗ add have "Iā©a Mā©v Mā©f (add(f))" by fastforce
then have "ās t. (Mā©f f) (s ā t) = (Mā©f f) s ā (Mā©f f) t" by simp
moreover
have "āØHF ((ā³ ā VennRegion) ` (l āŖ m)) = āØHF ((ā³ ā VennRegion) ` l) ā āØHF ((ā³ ā VennRegion) ` m)"
using HUnion_proper_Venn_region_union ā³.simps(2) lm(1) lm(2) by auto
ultimately
have "Mā©f f (āØHF ((ā³ ā VennRegion) ` (l āŖ m))) =
Mā©f f (āØHF ((ā³ ā VennRegion) ` l)) ā Mā©f f (āØHF ((ā³ ā VennRegion) ` m))"
by auto
with fml lm show "interp Iā©sā©a ā³ fml"
using set_var_set_set_to_var_set_list
apply (simp only: interp.simps Iā©sā©a.simps Iā©sā©t.simps ā³.simps)
by (metis le_sup_iff)
qed
next
case (mul f)
with model_for_š ā¹lt ā set šāŗ have "Iā©a Mā©v Mā©f (mul(f))" by fastforce
then have f_mul: "ās t. (Mā©f f) (s ā t) = (Mā©f f) s ā (Mā©f f) t" by simp
have InterOfWAux: "Iā©sā©a ā³ (Var (InterOfWAux f l m) =ā©s Var wāfāālā -ā©s Var wāfāāmā)" for l m
by auto
{fix l m assume "l ā Pā§+ V" "m ā Pā§+ V"
then have "āØHF ((ā³ ā VennRegion) ` (l ā© m)) = āØHF ((ā³ ā VennRegion) ` l) ā āØHF ((ā³ ā VennRegion) ` m)"
using HUnion_proper_Venn_region_inter by force
then have "ā³ (UnionOfVennRegions (var_set_set_to_var_set_list (l ā© m))) =
ā³ (UnionOfVennRegions (var_set_set_to_var_set_list l)) ā
ā³ (UnionOfVennRegions (var_set_set_to_var_set_list m))"
using set_var_set_set_to_var_set_list ā¹l ā Pā§+ Vāŗ ā¹m ā Pā§+ Vāŗ
by (metis ā³.simps(3) inf.absorb_iff2 inf_left_commute)
with f_mul have "ā³ wāfāālā©mā = ā³ wāfāālā ā ā³ wāfāāmā"
by auto
moreover
from InterOfWAux have "ā³ (InterOfWAux f l m) = ā³ wāfāālā - ā³ wāfāāmā"
by simp
ultimately
have "ā³ wāfāālā©mā = ā³ wāfāālā - ā³ (InterOfWAux f l m)"
by auto
then have "Iā©sā©a ā³ (Var wāfāālā©mā =ā©s Var wāfāālā -ā©s Var (InterOfWAux f l m))"
by auto
}
with InterOfWAux show ?thesis
using mul by auto
next
case (le f g)
show ?thesis
proof
fix fml assume "fml ā reduce_literal lt"
then have "fml ā reduce_literal (ATā©m (f ā¼ā©m g))"
using le by blast
then obtain l where l: "l ā Pā§+ V"
and fml: "fml = AT (Var wāgāālā =ā©s Var wāgāālā āā©s Var wāfāālā)"
by auto
from model_for_š ā¹lt ā set šāŗ le have "Iā©a Mā©v Mā©f (f ā¼ā©m g)" by fastforce
then have "ās. (Mā©f f) s ⤠(Mā©f g) s" by simp
then have "Mā©f f (āØHF ((ā³ ā VennRegion) ` l)) ⤠Mā©f g (āØHF ((ā³ ā VennRegion) ` l))"
by auto
with fml l show "interp Iā©sā©a ā³ fml"
using set_var_set_set_to_var_set_list
by (auto simp only: interp.simps Iā©sā©a.simps Iā©sā©t.simps ā³.simps)
qed
next
case (eq_empty x n)
with ā¹lt ā set šāŗ model_for_š have "Mā©v x = 0" by auto
show ?thesis
proof
fix fml assume "fml ā reduce_literal lt"
with eq_empty have "fml = AT (Var (Solo x) =ā©s ā
n)"
by simp
with ā¹Mā©v x = 0āŗ show "interp Iā©sā©a ā³ fml" by auto
qed
next
case (eq x y)
with ā¹lt ā set šāŗ model_for_š have "Mā©v x = Mā©v y" by auto
show ?thesis
proof
fix fml assume "fml ā reduce_literal lt"
with eq have "fml = AT (Var (Solo x) =ā©s Var (Solo y))"
by simp
with ā¹Mā©v x = Mā©v yāŗ show "interp Iā©sā©a ā³ fml" by auto
qed
next
case (neq x y)
with ā¹lt ā set šāŗ model_for_š have "Mā©v x ā Mā©v y" by auto
show ?thesis
proof
fix fml assume "fml ā reduce_literal lt"
with neq have "fml = AF (Var (Solo x) =ā©s Var (Solo y))"
by simp
with ā¹Mā©v x ā Mā©v yāŗ show "interp Iā©sā©a ā³ fml" by auto
qed
next
case (union x y z)
with ā¹lt ā set šāŗ model_for_š have "Mā©v x = Mā©v y ā Mā©v z" by fastforce
then have "interp Iā©sā©a ā³ (AT (Var (Solo x) =ā©s Var (Solo y) āā©s Var (Solo z)))" by simp
with union show ?thesis by auto
next
case (diff x y z)
with ā¹lt ā set šāŗ model_for_š have "Mā©v x = Mā©v y - Mā©v z" by fastforce
then have "interp Iā©sā©a ā³ (AT (Var (Solo x) =ā©s Var (Solo y) -ā©s Var (Solo z)))" by simp
with diff show ?thesis by auto
next
case (single x y)
with ā¹lt ā set šāŗ model_for_š have "Mā©v x = HF {Mā©v y}" by fastforce
then have "interp Iā©sā©a ā³ (AT (Var (Solo x) =ā©s Single (Var (Solo y))))" by simp
with single show ?thesis by auto
next
case (app x f y)
with ā¹lt ā set šāŗ model_for_š
have "Mā©v x = (Mā©f f) (Mā©v y)" by fastforce
moreover
from app ā¹lt ā set šāŗ have "y ā V"
unfolding V_def by force
with variable_as_composition_of_proper_Venn_regions
have "Mā©v y = āØHF (proper_Venn_region ` ā V y)"
by presburger
then have "Mā©v y = āØHF ((ā³ ā VennRegion) ` ā V y)"
by simp
ultimately
have "ā³ (Solo x) = ā³ wāfāāā V yā"
using ā³.simps set_var_set_set_to_var_set_list ā_subset_P_plus
by metis
with app show ?thesis by simp
qed
qed
lemma soundness_reduce_cl:
"āfml ā reduce_clause. interp Iā©sā©a ā³ fml"
unfolding reduce_clause_def
using soundness_reduce_literal
by fastforce
lemma ā³_is_model_for_reduced_dnf: "is_model_for_reduced_dnf ā³"
unfolding is_model_for_reduced_dnf_def
unfolding reduced_dnf_def
using soundness_introduce_v soundness_introduce_w soundness_introduce_UnionOfVennRegions soundness_reduce_cl
by (metis (no_types, lifting) Un_iff imageI)
end
lemma MLSSmf_to_MLSS_soundness:
assumes š_norm: "norm_clause š"
and š_has_model: "āMā©v Mā©f. Iā©cā©l Mā©v Mā©f š"
shows "āM. normalized_MLSSmf_clause.is_model_for_reduced_dnf š M"
proof -
from š_has_model obtain Mā©v Mā©f where "Iā©cā©l Mā©v Mā©f š" by blast
with š_norm
interpret satisfiable_normalized_MLSSmf_clause š Mā©v Mā©f
by unfold_locales
from ā³_is_model_for_reduced_dnf show ?thesis by auto
qed
end