Theory Proper_Venn_Regions

theory Proper_Venn_Regions
  imports MLSSmf_Semantics MLSSmf_to_MLSS MLSSmf_HF_Extras
begin

locale proper_Venn_regions =
    fixes V :: "'a set"
      and π’œ :: "'a β‡’ hf"
  assumes finite_V: "finite V"
begin

fun proper_Venn_region :: "'a set β‡’ hf" where
  "proper_Venn_region Ξ± = β¨…HF (π’œ ` Ξ±) - ⨆HF (π’œ ` (V - Ξ±))"

lemma proper_Venn_region_nonempty_iff[iff]:
  "c ∈ proper_Venn_region Ξ± ∧ Ξ± βŠ† V ⟷ Ξ± = {x ∈ V. c ∈ π’œ x} ∧ Ξ± β‰  {}"
proof(standard, goal_cases)
  case 1
  then have "c ∈ proper_Venn_region Ξ±" "Ξ± βŠ† V" by blast+
  show ?case
  proof(standard, standard, goal_cases)
    case 1
    then show ?case
    proof
      fix x assume "x ∈ α"
      have "c ∈ β¨…HF (π’œ ` Ξ±)"
        using β€Ήc ∈ proper_Venn_region Ξ±β€Ί by auto
      then have "c ∈ π’œ x"
        using β€Ήx ∈ Ξ±β€Ί
        by (metis (mono_tags, opaque_lifting) HInter_hempty HInter_iff hempty_iff hmem_HF_iff imageI)
      then show "x ∈ {x ∈ V. c ∈ π’œ x}"
        using β€ΉΞ± βŠ† Vβ€Ί β€Ήx ∈ Ξ±β€Ί by blast
    qed
  next
    case 2
    then show ?case
    proof
      fix x assume "x ∈ {x ∈ V. c ∈ π’œ x}"
      then have "x ∈ V" "c ∈ π’œ x" by blast+
      show "x ∈ α"
      proof (rule ccontr)
        assume "x βˆ‰ Ξ±"
        then have "x ∈ V - α"
          using β€ΉΞ± βŠ† Vβ€Ί β€Ήx ∈ Vβ€Ί by blast
        then have "c ∈ ⨆HF (π’œ ` (V - Ξ±))"
          using β€Ήc ∈ π’œ xβ€Ί finite_V by auto
        then have "c βˆ‰ proper_Venn_region Ξ±" by simp
        then show False
          using β€Ήc ∈ proper_Venn_region Ξ±β€Ί by blast
      qed
    qed
  next
    case 3
    then show ?case
    proof (rule ccontr)
      assume "Β¬ Ξ± β‰  {}"
      then have "Ξ± = {}" by fast
      then have "proper_Venn_region Ξ± = 0"
        using Zero_hf_def by auto
      then show False
        using β€Ήc ∈ proper_Venn_region Ξ±β€Ί by simp
    qed
  qed
next
  case 2
  then have "Ξ± = {x ∈ V. c ∈ π’œ x}" "Ξ± β‰  {}" by simp+
  then have "Ξ± βŠ† V" by blast
  moreover
  from 2 finite_V have "finite Ξ±" by force
  then have "finite (π’œ ` Ξ±)" by blast
  then have "finite (π’œ ` (V - Ξ±))"
    using finite_V by fast
  from β€ΉΞ± β‰  {}β€Ί have "π’œ ` Ξ± β‰  {}" by blast
  from 2 have "βˆ€x ∈ Ξ±. c ∈ π’œ x" by simp
  then have "βˆ€x ∈ π’œ ` Ξ±. c ∈ x" by blast
  then have "c ∈ β¨…HF (π’œ ` Ξ±)"
    using β€Ήfinite (π’œ ` Ξ±)β€Ί β€Ήπ’œ ` Ξ± β‰  {}β€Ί
    by (metis HInter_iff hfset_0 hfset_HF hmem_HF_iff)
  moreover
  have "c βˆ‰ ⨆HF (π’œ ` (V - Ξ±))"
  proof
    assume "c ∈ ⨆HF (π’œ ` (V - Ξ±))"
    then obtain x where "c ∈ x" "x ∈ π’œ ` (V - Ξ±)" by auto
    then have "x ∈ π’œ ` (V) - π’œ ` Ξ±"
      using 2 by fastforce
    then have "x βˆ‰ π’œ ` Ξ±" by blast
    then show False
      using β€Ήc ∈ xβ€Ί 2 β€Ήx ∈ π’œ ` (V - Ξ±)β€Ί by blast 
  qed
  ultimately show ?case by auto
qed

lemma proper_Venn_region_strongly_injective:
  assumes "proper_Venn_region Ξ± βŠ“ proper_Venn_region Ξ² β‰  0"
      and "Ξ± βŠ† V"
      and "Ξ² βŠ† V"
    shows "Ξ± = Ξ²"
proof -
  from β€Ήproper_Venn_region Ξ± βŠ“ proper_Venn_region Ξ² β‰  0β€Ί
  obtain c where c: "c ∈ proper_Venn_region α" "c ∈ proper_Venn_region β"
    by blast
  then have "Ξ± = {x ∈ V. c ∈ π’œ x}" "Ξ² = {x ∈ V. c ∈ π’œ x}"
    using β€ΉΞ± βŠ† Vβ€Ί β€ΉΞ² βŠ† Vβ€Ί
    using proper_Venn_region_nonempty_iff by (metis (mono_tags, lifting))+
  then show "Ξ± = Ξ²" by presburger
qed

lemma proper_Venn_region_disjoint:
  "Ξ± β‰  Ξ² ⟹ Ξ± βŠ† V ⟹ Ξ² βŠ† V ⟹ proper_Venn_region Ξ± βŠ“ proper_Venn_region Ξ² = 0"
  using proper_Venn_region_strongly_injective by meson

lemma HUnion_proper_Venn_region_union:
  assumes "l βŠ† P+ V"
      and "m βŠ† P+ V"
    shows "⨆HF (proper_Venn_region ` (l βˆͺ m)) = ⨆HF (proper_Venn_region ` l) βŠ” ⨆HF(proper_Venn_region ` m)"
  by (metis HUnion_hunion P_plus_finite assms(1) assms(2) finite_V finite_imageI finite_subset image_Un union_hunion)

lemma HUnion_proper_Venn_region_inter:
  assumes "l βŠ† P+ V"
      and "m βŠ† P+ V"
    shows "⨆HF (proper_Venn_region ` (l ∩ m)) = ⨆HF (proper_Venn_region ` l) βŠ“ ⨆HF(proper_Venn_region ` m)"
proof -
  from β€Ήl βŠ† P+ Vβ€Ί have "finite l"
    using finite_V P_plus_finite by (metis finite_subset)
  from β€Ήm βŠ† P+ Vβ€Ί have "finite m"
    using finite_V P_plus_finite by (metis finite_subset)
  
  have "⨆HF (proper_Venn_region ` (l ∩ m)) ≀ ⨆HF (proper_Venn_region ` l) βŠ“ ⨆HF (proper_Venn_region ` m)"
    using proper_Venn_region_disjoint β€Ήfinite lβ€Ί β€Ήfinite mβ€Ί
    by auto
  moreover
  have "c ∈ ⨆HF (proper_Venn_region ` (l ∩ m))" if "c ∈ ⨆HF (proper_Venn_region ` l) βŠ“ ⨆HF (proper_Venn_region ` m)" for c
  proof -
    from that have "c ∈ ⨆HF (proper_Venn_region ` l)" "c ∈ ⨆HF (proper_Venn_region ` m)" by blast+
    then obtain α β where "α ∈ l" "β ∈ m" and c_mem: "c ∈ proper_Venn_region α" "c ∈ proper_Venn_region β" by auto
    with β€Ήl βŠ† P+ Vβ€Ί β€Ήm βŠ† P+ Vβ€Ί finite_V have "Ξ± βŠ† V" "Ξ² βŠ† V" by auto
    with proper_Venn_region_strongly_injective c_mem have "Ξ± = Ξ²" by blast
    with β€ΉΞ± ∈ lβ€Ί β€ΉΞ² ∈ mβ€Ί have "Ξ± ∈ l ∩ m" by blast
    with c_mem show ?thesis
      using HUnion_iff β€Ήfinite lβ€Ί hmem_def by auto 
  qed
  then have "⨆HF (proper_Venn_region ` l) βŠ“ ⨆HF (proper_Venn_region ` m) ≀ ⨆HF (proper_Venn_region ` (l ∩ m))" by blast
  ultimately show ?thesis by order
qed

text ‹⋃_{α∈L_y} v_Ξ± = yβ€Ί
lemma variable_as_composition_of_proper_Venn_regions:
  assumes "y ∈ V"
    shows "⨆HF (proper_Venn_region ` β„’ V y) = π’œ y"
proof(standard; standard)
  fix c assume c: "c ∈ ⨆HF (proper_Venn_region ` (β„’ V y))"
  then obtain Ξ± where Ξ±: "Ξ± ∈ β„’ V y" "c ∈ proper_Venn_region Ξ±"
    by auto
  then have "y ∈ Ξ±" using β€Ήy ∈ Vβ€Ί by fastforce
  then have "π’œ y ∈ π’œ ` Ξ±" by blast
  from finite_V β€ΉΞ± ∈ β„’ V yβ€Ί β€Ήy ∈ Vβ€Ί have "finite Ξ±" "Ξ± β‰  {}" by auto
  then have "finite (π’œ ` Ξ±)" "π’œ ` Ξ± β‰  {}" by simp+
  with β€Ήπ’œ y ∈ π’œ ` Ξ±β€Ί have "β¨…(HF (π’œ ` Ξ±)) ≀ π’œ y"
    by (metis HInter_iff hfset_0 hfset_HF hmem_HF_iff hsubsetI)
  then show "c ∈ π’œ y"
    using Ξ± by fastforce
next
  fix c assume "c ∈ π’œ y"
  let ?Ξ± = "{x ∈ V. c ∈ π’œ x}"
  from β€Ήc ∈ π’œ yβ€Ί β€Ήy ∈ Vβ€Ί have "y ∈ ?Ξ±" by blast
  then have "?Ξ± ∈ β„’ V y" by auto
  then have "?Ξ± β‰  {}" by auto
  then have "c ∈ proper_Venn_region ?α"
    using proper_Venn_region_nonempty_iff
    by (metis (mono_tags, lifting))
  moreover
  from β€Ή?Ξ± ∈ β„’ V yβ€Ί have "proper_Venn_region ?Ξ± ∈ proper_Venn_region ` β„’ V y" by fast
  moreover
  have "finite (β„’ V y)" using finite_V by simp
  ultimately
  show "c ∈ ⨆HF (proper_Venn_region ` (β„’ V y))"
    by (smt (verit, best) HUnion_iff finite_imageI hmem_HF_iff)
qed

lemma proper_Venn_region_subset_variable_iff:
  assumes "Ξ± βŠ† V"
      and "x ∈ V"
      and "proper_Venn_region Ξ± β‰  0"
    shows "x ∈ Ξ± ⟷ proper_Venn_region Ξ± ≀ π’œ x"
proof
  assume "x ∈ α"
  then have "β¨…HF (π’œ ` Ξ±) ≀ π’œ x" using β€ΉΞ± βŠ† Vβ€Ί finite_V
    by (smt (verit, ccfv_SIG) HInter_iff ball_imageD finite_imageI hemptyE hmem_HF_iff hsubsetI rev_finite_subset)
  then show "proper_Venn_region Ξ± ≀ π’œ x" by auto
next
  assume "proper_Venn_region Ξ± ≀ π’œ x"
  moreover
  from variable_as_composition_of_proper_Venn_regions β€Ήx ∈ Vβ€Ί
  have "π’œ x = ⨆HF (proper_Venn_region ` β„’ V x)"
    by presburger
  ultimately
  have "proper_Venn_region Ξ± ≀ ⨆HF (proper_Venn_region ` β„’ V x)"
    by argo
  show "x ∈ α"
  proof (rule ccontr)
    assume "x βˆ‰ Ξ±"
    then have "Ξ± βˆ‰ β„’ V x" by simp
    moreover
    from β€Ήproper_Venn_region Ξ± ≀ ⨆HF (proper_Venn_region ` β„’ V x)β€Ί β€Ήproper_Venn_region Ξ± β‰  0β€Ί
    have "proper_Venn_region Ξ± βŠ“ ⨆HF (proper_Venn_region ` β„’ V x) β‰  0" by fast
    then obtain Ξ² where "Ξ² ∈ β„’ V x" "proper_Venn_region Ξ± βŠ“ proper_Venn_region Ξ² β‰  0"
      by auto
    with proper_Venn_region_strongly_injective have "Ξ± = Ξ²"
      using β€ΉΞ² ∈ β„’ V xβ€Ί β€ΉΞ± βŠ† Vβ€Ί by auto
    with β€ΉΞ² ∈ β„’ V xβ€Ί have "Ξ± ∈ β„’ V x" by blast
    ultimately
    show False by blast
  qed
qed

end

end