Skip to content
Snippets Groups Projects
Subset_system.v 51.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • Micaela Mayero's avatar
    Micaela Mayero committed
    (**
    This file is part of the Elfic library
    
    Copyright (C) Boldo, Clément, Faissole, Martin, Mayero
    
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 3 of the License, or (at your option) any later version.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    COPYING file for more details.
    *)
    
    (* TODO:
      1. use Ensembles / Powerset formalism?
         Naah, rather use Subset instead.
      2. use setoids?
    
      3. Type classes or canonical structures might help in inheriting properties
    
    François Clément's avatar
    François Clément committed
         of simpler subset systems, e.g. Psyst -> Ring -> Algebra -> Sigma_algebra. *)
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    
    Require Import Subset Subset_finite Subset_seq.
    Require Import Subset_system_base Subset_system_gen.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    
    Variable A0 : U -> Prop. (* Witness (for pi systems). *)
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    
    François Clément's avatar
    François Clément committed
    (* Psyst is the pi-system generated by gen,
    
    Micaela Mayero's avatar
    Micaela Mayero committed
     ie the smallest pi-system containing gen. *)
    
    François Clément's avatar
    François Clément committed
    Inductive Psyst : (U -> Prop) -> Prop :=   (* Unfortunately, Pi was not a good ident *)
      | Psyst_Gen : Incl gen Psyst
      | Psyst_Mem : Psyst A0
      | Psyst_Inter : Inter Psyst.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    (* Ring is the ring (of sets) generated by gen,
     ie the smallest ring containing gen. *)
    Inductive Ring : (U -> Prop) -> Prop :=
      | Ring_Gen : Incl gen Ring
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      | Ring_Diff : Diff Ring
      | Ring_Union : Union Ring.
    
    (* Algebra is the (set) algebra generated by gen,
     ie the smallest algebra containing gen. *)
    Inductive Algebra : (U -> Prop) -> Prop :=
      | Algebra_Gen : Incl gen Algebra
      | Algebra_wEmpty : wEmpty Algebra
      | Algebra_Compl : Compl Algebra
      | Algebra_Union : Union Algebra.
    
    (* Monotone_class is the monotone class generated by gen,
     ie the smallest monotone class containing gen. *)
    Inductive Monotone_class : (U -> Prop) -> Prop :=
      | Monotone_class_Gen : Incl gen Monotone_class
    
    François Clément's avatar
    François Clément committed
      | Monotone_class_Inter_monot_seq : Inter_monot_seq Monotone_class
      | Monotone_class_Union_monot_seq : Union_monot_seq Monotone_class.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    
    François Clément's avatar
    François Clément committed
    (* Lsyst is the lambda-system generated by gen,
    
    Micaela Mayero's avatar
    Micaela Mayero committed
     ie the smallest lambda-system containing gen. *)
    
    François Clément's avatar
    François Clément committed
    Inductive Lsyst : (U -> Prop) -> Prop :=   (* Lambda was an even worse ident! *)
      | Lsyst_Gen : Incl gen Lsyst
      | Lsyst_wFull : wFull Lsyst
      | Lsyst_Compl : Compl Lsyst
    
    François Clément's avatar
    François Clément committed
      | Lsyst_Union_disj_seq : Union_disj_seq Lsyst.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    (* Sigma_ring is the sigma-ring generated by gen,
     ie the smallest sigma-ring containing gen. *)
    Inductive Sigma_ring : (U -> Prop) -> Prop :=
      | Sigma_ring_Gen : Incl gen Sigma_ring
    
      | Sigma_ring_wEmpty : wEmpty Sigma_ring
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      | Sigma_ring_Diff : Diff Sigma_ring
    
    François Clément's avatar
    François Clément committed
      | Sigma_ring_Union_seq : Union_seq Sigma_ring.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    (* Sigma_algebra is the sigma-algebra generated by gen,
     ie the smallest sigma-algebra containing gen. *)
    Inductive Sigma_algebra : (U -> Prop) -> Prop :=
      | Sigma_algebra_Gen : Incl gen Sigma_algebra
      | Sigma_algebra_wEmpty : wEmpty Sigma_algebra
      | Sigma_algebra_Compl : Compl Sigma_algebra
    
    François Clément's avatar
    François Clément committed
      | Sigma_algebra_Union_seq : Union_seq Sigma_algebra.
    
    (* Open is a collection of open subsets of U. *)
    Inductive Open : (U -> Prop) -> Prop :=
      | Open_wEmpty : wEmpty Open
      | Open_wFull : wFull Open
      | Open_Inter_finite : Inter_finite Open
      | Open_Union_any : forall {Idx : Type}, @Union_any Idx U Open.
    
    (* Close is a collection of closed subsets of U. *)
    Inductive Close : (U -> Prop) -> Prop :=
      | Close_wEmpty : wEmpty Close
      | Close_wFull : wFull Close
      | Close_Union_finite : Union_finite Close
      | Close_Inter_any : forall {Idx : Type}, @Inter_any Idx U Close.
    
    *)
    
    End Subset_systems_Def1.
    
    
    Section Subset_systems_Def2.
    
    Context {U : Type}. (* Universe. *)
    
    Variable P : (U -> Prop) -> Prop. (* Subset system. *)
    Variable A0 : U -> Prop. (* Witness. *)
    
    Definition is_Psyst : Prop := Psyst P A0 = P.
    
    Definition is_Semi_ring : Prop :=
      wEmpty P /\ Inter P /\ Part_diff_finite P.
    
    Definition is_Ring : Prop := Ring P = P.
    
    Definition is_Semi_algebra : Prop :=
      wFull P /\ Inter P /\ Part_compl_finite P.
    
    Definition is_Algebra : Prop := Algebra P = P.
    
    Definition is_Monotone_class : Prop := Monotone_class P = P.
    
    Definition is_Lsyst : Prop := Lsyst P = P.
    
    Definition is_Sigma_ring : Prop := Sigma_ring P = P.
    
    Definition is_Sigma_algebra : Prop := Sigma_algebra P = P.
    
    End Subset_systems_Def2.
    
    François Clément's avatar
    François Clément committed
    Hint Constructors Psyst : subset_systems.
    Hint Unfold is_Semi_ring : subset_systems.
    Hint Constructors Ring : subset_systems.
    Hint Unfold is_Semi_algebra : subset_systems.
    Hint Constructors Algebra : subset_systems.
    Hint Constructors Monotone_class : subset_systems.
    Hint Constructors Lsyst : subset_systems.
    
    Hint Constructors Sigma_ring : subset_systems.
    
    François Clément's avatar
    François Clément committed
    Hint Constructors Sigma_algebra : subset_systems.
    (*Print HintDb subset_systems.*)
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Section Subset_systems_Facts1.
    
    Context {U : Type}. (* Universe. *)
    
    Variable P : (U -> Prop) -> Prop. (* Subset system. *)
    
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      forall (A0 : U -> Prop),
    
    François Clément's avatar
    François Clément committed
        is_Psyst P A0 <-> P A0 /\ Inter P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    split.
    (* *)
    
    François Clément's avatar
    François Clément committed
    intros H; rewrite <- H; auto with subset_systems.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros [H1 H2]; apply Ext; split.
    intros H3; induction H3; try easy.
    now apply H2.
    
    François Clément's avatar
    François Clément committed
    apply Psyst_Gen.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
      is_Ring P <-> wEmpty P /\ Diff P /\ Union P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    split.
    (* *)
    
    François Clément's avatar
    François Clément committed
    intros H; rewrite <- H; auto with subset_systems.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros [H1 [H2 H3]]; apply Ext; split.
    
    François Clément's avatar
    François Clément committed
    intros H4; induction H4; try easy; [now apply H2 | now apply H3].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    apply Ring_Gen.
    Qed.
    
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      is_Algebra P <-> wEmpty P /\ Compl P /\ Union P.
    Proof.
    split.
    (* *)
    
    François Clément's avatar
    François Clément committed
    intros H; rewrite <- H; auto with subset_systems.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros [H1 [H2 H3]]; apply Ext; split.
    intros H4; induction H4; try easy; [now apply H2 | now apply H3].
    apply Algebra_Gen.
    Qed.
    
    
    François Clément's avatar
    François Clément committed
      is_Monotone_class P <-> Inter_monot_seq P /\ Union_monot_seq P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    split.
    (* *)
    intros H; split; rewrite <- H.
    
    François Clément's avatar
    François Clément committed
    apply Monotone_class_Inter_monot_seq.
    apply Monotone_class_Union_monot_seq.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros [H1 H2]; apply Ext; split.
    intros H3; induction H3; try easy; [now apply H1 | now apply H2].
    apply Monotone_class_Gen.
    Qed.
    
    
    François Clément's avatar
    François Clément committed
      is_Lsyst P <-> wFull P /\ Compl P /\ Union_disj_seq P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    split.
    (* *)
    intros H; repeat split; rewrite <- H.
    
    François Clément's avatar
    François Clément committed
    apply Lsyst_wFull.
    apply Lsyst_Compl.
    
    François Clément's avatar
    François Clément committed
    apply Lsyst_Union_disj_seq.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros [H1 [H2 H3]]; apply Ext; split.
    intros H4; induction H4; try easy; [now apply H2 | now apply H3].
    
    François Clément's avatar
    François Clément committed
    apply Lsyst_Gen.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
      is_Sigma_ring P <-> wEmpty P /\ Diff P /\ Union_seq P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    split.
    (* *)
    intros H; repeat split; rewrite <- H.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    apply Sigma_ring_Diff.
    
    François Clément's avatar
    François Clément committed
    apply Sigma_ring_Union_seq.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros [H1 [H2 H3]]; apply Ext; split.
    intros H4; induction H4; try easy.
    now apply H2.
    now apply H3.
    apply Sigma_ring_Gen.
    Qed.
    
    
    François Clément's avatar
    François Clément committed
      is_Sigma_algebra P <-> wEmpty P /\ Compl P /\ Union_seq P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    split.
    (* *)
    intros H; repeat split; rewrite <- H.
    apply Sigma_algebra_wEmpty.
    apply Sigma_algebra_Compl.
    
    François Clément's avatar
    François Clément committed
    apply Sigma_algebra_Union_seq.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros [H1 [H2 H3]]; apply Ext; split.
    intros H4; induction H4; try easy; [now apply H2 | now apply H3].
    apply Sigma_algebra_Gen.
    Qed.
    
    End Subset_systems_Facts1.
    
    
    Section Subset_systems_Facts2.
    
    Context {U : Type}. (* Universe. *)
    
    
    Variable gen0 gen1 : (U -> Prop) -> Prop. (* Generators. *)
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Variable A0 : U -> Prop. (* Witness. *)
    
    
      Incl gen0 (Psyst gen1 A0) ->
      Incl (Psyst gen0 A0) (Psyst gen1 A0).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros H A HA; induction HA.
    now apply H.
    
    François Clément's avatar
    François Clément committed
    apply Psyst_Mem.
    now apply Psyst_Inter.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
      Incl gen0 (Ring gen1) ->
      Incl (Ring gen0) (Ring gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros H A HA; induction HA.
    now apply H.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    now apply Ring_Diff.
    now apply Ring_Union.
    Qed.
    
    
      Incl gen0 (Algebra gen1) ->
      Incl (Algebra gen0) (Algebra gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros H A HA; induction HA.
    now apply H.
    apply Algebra_wEmpty.
    now apply Algebra_Compl.
    now apply Algebra_Union.
    Qed.
    
    
      Incl gen0 (Monotone_class gen1) ->
      Incl (Monotone_class gen0) (Monotone_class gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros H A HA; induction HA.
    now apply H.
    
    François Clément's avatar
    François Clément committed
    now apply Monotone_class_Inter_monot_seq.
    now apply Monotone_class_Union_monot_seq.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
      Incl gen0 (Lsyst gen1) ->
      Incl (Lsyst gen0) (Lsyst gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros H A HA; induction HA.
    now apply H.
    
    François Clément's avatar
    François Clément committed
    apply Lsyst_wFull.
    now apply Lsyst_Compl.
    
    François Clément's avatar
    François Clément committed
    now apply Lsyst_Union_disj_seq.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
      Incl gen0 (Sigma_ring gen1) ->
      Incl (Sigma_ring gen0) (Sigma_ring gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros H A HA; induction HA.
    now apply H.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    now apply Sigma_ring_Diff.
    
    François Clément's avatar
    François Clément committed
    now apply Sigma_ring_Union_seq.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
      Incl gen0 (Sigma_algebra gen1) ->
      Incl (Sigma_algebra gen0) (Sigma_algebra gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros H A HA; induction HA.
    now apply H.
    apply Sigma_algebra_wEmpty.
    now apply Sigma_algebra_Compl.
    
    François Clément's avatar
    François Clément committed
    now apply Sigma_algebra_Union_seq.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    End Subset_systems_Facts2.
    
    
    Section Subset_systems_Facts3.
    
    Context {U : Type}. (* Universe. *)
    
    Variable P : (U -> Prop) -> Prop. (* Subset system. *)
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    Variable A0 : U -> Prop. (* Witness. *)
    
    
    François Clément's avatar
    François Clément committed
      is_Psyst P A0 -> Incl gen P -> Incl (Psyst gen A0) P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros H; rewrite <- H; apply Psyst_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
      is_Ring P -> Incl gen P -> Incl (Ring gen) P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros H; rewrite <- H; apply Ring_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      is_Algebra P -> Incl gen P -> Incl (Algebra gen) P.
    Proof.
    
    intros H; rewrite <- H; apply Algebra_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      is_Monotone_class P -> Incl gen P -> Incl (Monotone_class gen) P.
    Proof.
    
    intros H; rewrite <- H; apply Monotone_class_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
      is_Lsyst P -> Incl gen P -> Incl (Lsyst gen) P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros H; rewrite <- H; apply Lsyst_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
      is_Sigma_ring P -> Incl gen P -> Incl (Sigma_ring gen) P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros H; rewrite <- H; apply Sigma_ring_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      is_Sigma_algebra P -> Incl gen P -> Incl (Sigma_algebra gen) P.
    Proof.
    
    intros H; rewrite <- H; apply Sigma_algebra_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    End Subset_systems_Facts3.
    
    
    Section Subset_systems_Facts4.
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    Variable A0 : U -> Prop. (* Witness. *)
    
    
    François Clément's avatar
    François Clément committed
    Lemma Psyst_idem :
      is_Psyst (Psyst gen A0) A0.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    apply Ext_equiv; split; [now apply Psyst_lub_alt | apply Psyst_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Ring_idem :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    apply Ext_equiv; split; [now apply Ring_lub_alt | apply Ring_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Algebra_idem :
      is_Algebra (Algebra gen).
    Proof.
    
    apply Ext_equiv; split; [now apply Algebra_lub_alt | apply Algebra_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Monotone_class_idem :
      is_Monotone_class (Monotone_class gen).
    Proof.
    
    apply Ext_equiv; split; [now apply Monotone_class_lub_alt | apply Monotone_class_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Lsyst_idem :
      is_Lsyst (Lsyst gen).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    apply Ext_equiv; split; [now apply Lsyst_lub_alt | apply Lsyst_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Sigma_ring_idem :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    apply Ext_equiv; split; [now apply Sigma_ring_lub_alt | apply Sigma_ring_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Sigma_algebra_idem :
      is_Sigma_algebra (Sigma_algebra gen).
    Proof.
    
    apply Ext_equiv; split; [now apply Sigma_algebra_lub_alt | apply Sigma_algebra_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    Variable gen0 gen1 : (U -> Prop) -> Prop. (* Generators. *)
    
    François Clément's avatar
    François Clément committed
    Lemma Psyst_monot :
    
      Incl gen0 gen1 -> Incl (Psyst gen0 A0) (Psyst gen1 A0).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Psyst_lub_alt, Incl_trans with gen1; [easy | apply Psyst_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Ring_monot :
    
      Incl gen0 gen1 -> Incl (Ring gen0) (Ring gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ring_lub_alt, Incl_trans with gen1; [easy | apply Ring_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Algebra_monot :
    
      Incl gen0 gen1 -> Incl (Algebra gen0) (Algebra gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Algebra_lub_alt, Incl_trans with gen1; [easy | apply Algebra_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Monotone_class_monot :
    
      Incl gen0 gen1 -> Incl (Monotone_class gen0) (Monotone_class gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Monotone_class_lub_alt, Incl_trans with gen1; [easy | apply Monotone_class_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Lsyst_monot :
    
      Incl gen0 gen1 -> Incl (Lsyst gen0) (Lsyst gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Lsyst_lub_alt, Incl_trans with gen1; [easy | apply Lsyst_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Sigma_ring_monot :
    
      Incl gen0 gen1 -> Incl (Sigma_ring gen0) (Sigma_ring gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Sigma_ring_lub_alt, Incl_trans with gen1; [easy | apply Sigma_ring_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Sigma_algebra_monot :
    
      Incl gen0 gen1 -> Incl (Sigma_algebra gen0) (Sigma_algebra gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Sigma_algebra_lub_alt, Incl_trans with gen1; [easy | apply Sigma_algebra_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Psyst_ext :
    
      Incl gen0 (Psyst gen1 A0) ->
      Incl gen1 (Psyst gen0 A0) ->
      Psyst gen0 A0 = Psyst gen1 A0.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ext_equiv; split; now apply Psyst_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Ring_ext :
    
      Incl gen0 (Ring gen1) ->
      Incl gen1 (Ring gen0) ->
      Ring gen0 = Ring gen1.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ext_equiv; split; now apply Ring_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Algebra_ext :
    
      Incl gen0 (Algebra gen1) ->
      Incl gen1 (Algebra gen0) ->
      Algebra gen0 = Algebra gen1.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ext_equiv; split; now apply Algebra_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Monotone_class_ext :
    
      Incl gen0 (Monotone_class gen1) ->
      Incl gen1 (Monotone_class gen0) ->
      Monotone_class gen0 = Monotone_class gen1.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ext_equiv; split; now apply Monotone_class_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Sigma_ring_ext :
    
      Incl gen0 (Sigma_ring gen1) ->
      Incl gen1 (Sigma_ring gen0) ->
      Sigma_ring gen0 = Sigma_ring gen1.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ext_equiv; split; now apply Sigma_ring_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Lsyst_ext :
    
      Incl gen0 (Lsyst gen1) ->
      Incl gen1 (Lsyst gen0) ->
      Lsyst gen0 = Lsyst gen1.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ext_equiv; split; now apply Lsyst_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Sigma_algebra_ext :
    
      Incl gen0 (Sigma_algebra gen1) ->
      Incl gen1 (Sigma_algebra gen0) ->
      Sigma_algebra gen0 = Sigma_algebra gen1.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ext_equiv; split; now apply Sigma_algebra_lub_alt.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    End Subset_systems_Facts4.
    
    
    Section Subset_system_alt_Facts1.
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      Algebra gen = Gen is_Algebra gen.
    Proof.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    induction HA.
    now apply Gen_ni_gen.
    1,2,3: intros SS HSS1 HSS2; rewrite <- HSS1.
    apply Algebra_wEmpty.
    apply Algebra_Compl; now apply (Algebra_monot gen SS).
    apply Algebra_Union; now apply (Algebra_monot gen SS).
    (* *)
    apply HA.
    apply Algebra_idem.
    apply Algebra_Gen.
    Qed.
    
    End Subset_system_alt_Facts1.
    
    
    Section Subset_system_alt_Facts2.
    
    Context {U : Type}. (* Universe. *)
    
    Lemma is_Algebra_Inter_compat :
    
      @IInter_compat U is_Algebra.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros Idx HIdx; rewrite Algebra_equiv; repeat split.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros SS HSS; rewrite <- (HIdx SS HSS); apply Algebra_wEmpty.
    (* *)
    intros A HA SS HSS; rewrite <- (HIdx SS HSS).
    now apply Algebra_Compl, Algebra_Gen, HA.
    (* *)
    intros A B HA HB SS HSS; rewrite <- (HIdx SS HSS).
    now apply Algebra_Union; apply Algebra_Gen; [apply HA | apply HB].
    Qed.
    
    
    Variable gen0 gen1 : (U -> Prop) -> Prop. (* Generators. *)
    
      Incl gen0 (Algebra gen1) ->
      Incl (Algebra gen0) (Algebra gen1).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; rewrite (Algebra_equiv_alt gen0), (Algebra_equiv_alt gen1).
    apply (Gen_lub_alt is_Algebra).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    apply is_Algebra_Inter_compat.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    End Subset_system_alt_Facts2.
    
    
    
    François Clément's avatar
    François Clément committed
    Section Psyst_Facts.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    Variable A0 : U -> Prop. (* Witness. *)
    
    
    François Clément's avatar
    François Clément committed
    Lemma Psyst_Nonempty :
      Nonempty (Psyst gen A0).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    François Clément's avatar
    François Clément committed
    exists A0; apply Psyst_Mem.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Psyst_Inter_finite :
      Inter_finite (Psyst gen A0).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    François Clément's avatar
    François Clément committed
    apply Inter_finite_equiv, Psyst_Inter.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Psyst_Inter_monot_finite :
      Inter_monot_finite (Psyst gen A0).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    François Clément's avatar
    François Clément committed
    apply Inter_finite_monot, Psyst_Inter_finite.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Psyst_wEmpty :
      Compl (Psyst gen A0) -> wEmpty (Psyst gen A0).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    François Clément's avatar
    François Clément committed
    intros H; apply Nonempty_wEmpty; [easy | apply Psyst_Inter | ].
    exists A0; apply Psyst_Mem.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    Variable P : (U -> Prop) -> Prop. (* Subset system. *)
    
    Lemma is_Psyst_wEmpty :
      is_Psyst P A0 -> is_Psyst (fun A => P A \/ A = emptyset) emptyset.
    Proof.
    
    intros H; rewrite Psyst_equiv in *; split.
    
    François Clément's avatar
    François Clément committed
    End Psyst_Facts.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    
    
    Section is_Semi_ring_Facts.
    
    Context {U : Type}. (* Universe. *)
    
    Variable P : (U -> Prop) -> Prop. (* Subset system. *)
    
    Lemma is_Semi_ring_wEmpty :
      is_Semi_ring P -> wEmpty P.
    Proof.
    
    François Clément's avatar
    François Clément committed
    (* auto with subset_systems. (* is not working! *) *)
    
    (*now unfold is_Semi_ring.*)
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    now intros [H _].
    Qed.
    
    Lemma is_Semi_ring_Inter :
      is_Semi_ring P -> Inter P.
    Proof.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma is_Semi_ring_Part_diff_finite :
      is_Semi_ring P -> Part_diff_finite P.
    Proof.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma is_Semi_ring_is_Psyst :
      is_Semi_ring P -> is_Psyst P emptyset.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    now apply is_Semi_ring_wEmpty.
    now apply is_Semi_ring_Inter.
    Qed.
    
    Lemma is_Semi_ring_Inter_finite :
      is_Semi_ring P -> Inter_finite P.
    Proof.
    
    François Clément's avatar
    François Clément committed
    intros; rewrite <- is_Semi_ring_is_Psyst; try easy.
    apply Psyst_Inter_finite.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma is_Semi_ring_Inter_monot_finite :
      is_Semi_ring P -> Inter_monot_finite P.
    Proof.
    
    François Clément's avatar
    François Clément committed
    intros; rewrite <- is_Semi_ring_is_Psyst; try easy.
    apply Psyst_Inter_monot_finite.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    End is_Semi_ring_Facts.
    
    
    Section Ring_Facts1.
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    
    Lemma Ring_Inter :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    apply Diff_Inter, Ring_Diff.
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Ring_is_Psyst :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    apply Ring_Inter.
    Qed.
    
    Lemma Ring_Inter_finite :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    François Clément's avatar
    François Clément committed
    rewrite <- Ring_is_Psyst; apply Psyst_Inter_finite.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    Lemma Ring_Compl_loc :
      Compl_loc (Ring gen).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Ring_Sym_diff :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    apply Sym_diff_Diff_equiv; [apply Ring_Union | apply Ring_Diff].
    Qed.
    
    Lemma Ring_Union_disj :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    apply Union_Union_disj, Ring_Union.
    Qed.
    
    Lemma Ring_Inter_monot_finite :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    apply Inter_finite_monot, Ring_Inter_finite.
    Qed.
    
    Lemma Ring_Union_finite :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    apply Union_finite_equiv, Ring_Union.
    Qed.
    
    Lemma Ring_Union_monot_finite :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    apply Union_finite_monot, Ring_Union_finite.
    Qed.
    
    Lemma Ring_Union_disj_finite :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    apply Union_finite_disj, Ring_Union_finite.
    Qed.
    
    
    Variable P : (U -> Prop) -> Prop. (* Subset system. *)
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Lemma Ring_equiv_def :
    
      is_Ring P <->
      (Nonempty P \/ wEmpty P) /\
      (Diff P /\ Union P \/
       Diff P /\ Union_disj P \/
       Sym_diff P /\ Inter P \/
    
       Compl_loc P /\ Union_disj P /\ Inter P).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    (* *)
    intros [H1 H2]; repeat split.
    now right.
    now left.
    (* *)
    
    intros [[H1 | H1] [[H2 H3] | [[H2 H3] | [[H2 H3] | [H2 [H3 H4]]]]]]; repeat split; try easy.
    1,2,4,7: apply Nonempty_wEmpty_Diff; try easy.
    1,4,9: now apply Sym_diff_Diff.
    2,5,6,9: apply Union_disj_Union; try easy.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    1,2: now apply Sym_diff_Union.
    Qed.
    
    
    Lemma is_Psyst_Sym_diff_is_Ring :
      forall (A0 : U -> Prop),
        is_Psyst P A0 -> Sym_diff P -> is_Ring P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros A0 H1 H2; rewrite Ring_equiv_def; split.
    
    François Clément's avatar
    François Clément committed
    left; rewrite <- H1; apply Psyst_Nonempty.
    
    right; right; left; split; try easy.
    
    François Clément's avatar
    François Clément committed
    rewrite <- H1; apply Psyst_Inter.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    End Ring_Facts1.
    
    
    Section Ring_Facts2.
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    
    
    François Clément's avatar
    François Clément committed
    Lemma Incl_Psyst_Ring :
    
      Incl (Psyst gen emptyset) (Ring gen).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    rewrite <- Ring_is_Psyst; apply Psyst_monot, Ring_Gen.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Incl_Ring_Psyst :
    
      let P := Psyst gen emptyset in
      Sym_diff P -> Incl (Ring gen) P.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros P H1; assert (H2 : is_Ring P).
    
    François Clément's avatar
    François Clément committed
      apply Psyst_Mem.
      apply Sym_diff_Diff; try easy; apply Psyst_Inter.
      apply Sym_diff_Union; try easy; apply Psyst_Inter.
    
    apply Ring_lub; [easy | apply Psyst_Gen].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Ring_Psyst :
    
      Ring (Psyst gen emptyset) = Ring gen.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros; apply Ext_equiv; split.
    now apply Ring_lub_alt, Incl_Psyst_Ring.
    
    François Clément's avatar
    François Clément committed
    apply Ring_monot, Psyst_Gen.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    End Ring_Facts2.
    
    
    Section Ring_Facts3.
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    
    
    Hypothesis H : is_Semi_ring gen.
    
    (* Explicit_ring represents Union_disj_finite_closure gen. *)
    
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Lemma Explicit_ring_Gen :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros A HA.
    exists (repeat_1 A), 0; repeat split; try easy.
    now rewrite union_finite_0.
    apply disj_finite_0.
    Qed.
    
    Lemma Explicit_ring_wEmpty :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    now apply Explicit_ring_Gen.
    Qed.
    
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    destruct H as [_ [H2 H3]].
    now apply Diff_Union_disj_finite_closure.
    Qed.
    
    Lemma Explicit_ring_Union_disj :
    
    apply Union_disj_Union_disj_finite_closure.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Ring_explicit_aux1 :
    
      Incl (Ring gen) (Union_disj_finite_closure gen).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    apply Ring_equiv_def; split.
    right; apply Explicit_ring_wEmpty.
    right; left; split; [apply Explicit_ring_Diff | apply Explicit_ring_Union_disj].
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    apply Explicit_ring_Gen.
    Qed.
    
    Lemma Ring_explicit_aux2 :
    
      Incl (Union_finite_closure gen) (Ring gen).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    intros A [B [N [HB1 HB2]]].
    rewrite HB2; apply Ring_Union_finite.
    intros; now apply Ring_Gen, HB1.
    Qed.
    
    Lemma Ring_explicit_aux :
    
      Ring gen = Union_disj_finite_closure gen /\
    
      Union_disj_finite_closure gen = Union_finite_closure gen.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    5: apply Incl_trans with (Ring gen).
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    1,6: apply Ring_explicit_aux1.
    
    1,3: apply Union_finite_closure_Incl.
    1,2: apply Ring_explicit_aux2.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    
    Lemma Ring_explicit :
    
      Ring gen = Union_disj_finite_closure gen.
    
    Proof.
    apply Ring_explicit_aux.
    Qed.
    
    
      Ring gen = Union_finite_closure gen.
    
    destruct Ring_explicit_aux as [H1 H2].
    now rewrite H1.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    End Ring_Facts3.
    
    
    Section Semi_algebra_Facts.
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)
    
    
    Lemma is_Semi_algebra_equiv_def_Part_diff_finite :
      is_Semi_algebra gen <-> wFull gen /\ Inter gen /\ Part_diff_finite gen.
    Proof.
    split.
    (* *)
    intros [H1 [H2 H3]]; repeat split; try easy.
    now apply Part_compl_Part_diff_finite.
    (* *)
    intros [H1 [H2 H3]]; repeat split; try easy.
    now apply Part_diff_Part_compl_finite.
    Qed.
    
    Lemma is_Semi_algebra_equiv_def_Semi_ring :
      is_Semi_algebra gen <-> is_Semi_ring gen /\ wFull gen.
    Proof.
    rewrite is_Semi_algebra_equiv_def_Part_diff_finite; unfold is_Semi_ring.
    repeat split; try easy.
    apply wFull_wEmpty_finite; try easy.
    now apply Part_diff_Part_compl_finite.
    Qed.
    
    Lemma is_Semi_algebra_is_Semi_ring :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      is_Semi_algebra gen -> is_Semi_ring gen.
    Proof.
    
    now rewrite is_Semi_algebra_equiv_def_Semi_ring.
    Qed.
    
    François Clément's avatar
    François Clément committed
    Lemma Semi_algebra_is_Psyst_gen :
    
    Micaela Mayero's avatar
    Micaela Mayero committed
      forall (A0 : U -> Prop),
    
    François Clément's avatar
    François Clément committed
        Semi_algebra gen A0 -> is_Psyst (Semi_algebra gen) A0.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    intros A0 HA0; apply Psyst_equiv; split; try easy.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    apply Semi_algebra_Inter.
    Qed.
    
    
    François Clément's avatar
    François Clément committed
    Lemma Semi_algebra_is_Psyst :
      is_Psyst (Semi_algebra gen) fullset.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Proof.
    
    François Clément's avatar
    François Clément committed
    apply Semi_algebra_is_Psyst_gen, Semi_algebra_wFull.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Semi_algebra_Inter_finite :
      Inter_finite (Semi_algebra gen).
    Proof.
    
    François Clément's avatar
    François Clément committed
    rewrite <- Semi_algebra_is_Psyst; apply Psyst_Inter_finite.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Qed.
    
    Lemma Semi_algebra_Part_diff_finite :
      Part_diff_finite (Semi_algebra gen).
    Proof.
    
    François Clément's avatar
    François Clément committed
    Aglopted.
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    *)
    
    End Semi_algebra_Facts.
    
    
    
    Hint Resolve <- Ring_equiv : subset_systems. (* Apparently not working... *)
    
    Micaela Mayero's avatar
    Micaela Mayero committed
    Section Algebra_Facts1.
    
    Context {U : Type}. (* Universe. *)
    
    Variable gen : (U -> Prop) -> Prop. (* Generator. *)