(* This program 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 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program 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      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)


Set Implicit Arguments.
Unset Strict Implicit.
Require Export Parts.
(** Title "Difference of two parts." *)
Section Diff.
Variable E : Setoid.

Definition diff : part_set E -> part_set E -> part_set E.
(* Goal: forall (_ : Carrier (part_set E)) (_ : Carrier (part_set E)), Carrier (part_set E) *)
intros A B.
(* Goal: Carrier (part_set E) *)
apply (Build_Predicate (Pred_fun:=fun x : E => in_part x A /\ ~ in_part x B)).
(* Goal: not (@in_part E x B) *)
red in |- *.
(* Goal: forall (x y : Carrier E) (_ : and (@in_part E x A) (not (@in_part E x B))) (_ : @Equal E y x), and (@in_part E y A) (not (@in_part E y B)) *)
intros x y H' H'0; try assumption.
(* Goal: and (@in_part E y A) (not (@in_part E y B)) *)
elim H'; intros H'1 H'2; try exact H'1; clear H'.
(* Goal: and (@in_part E y A) (not (@in_part E y B)) *)
split; [ try assumption | idtac ].
(* Goal: @in_part E y A *)
(* Goal: not (@in_part E y B) *)
apply in_part_comp_l with x; auto with algebra.
(* Goal: not (@in_part E x B) *)
red in |- *.
(* Goal: forall _ : @in_part E y B, False *)
intros H'; try assumption.
(* Goal: False *)
(* Goal: forall _ : and (@in_part E x A') (not (@in_part E x B')), and (@in_part E x A) (not (@in_part E x B)) *)
absurd (in_part x B); auto with algebra.
(* Goal: @in_part E x B *)
apply in_part_comp_l with y; auto with algebra.
Defined.

Lemma diff_comp :
 forall A A' B B' : part_set E,
 Equal A A' -> Equal B B' -> Equal (diff A B) (diff A' B').
(* Goal: forall (A A' B B' : Carrier (part_set E)) (_ : @Equal (part_set E) A A') (_ : @Equal (part_set E) B B'), @Equal (part_set E) (diff A B) (diff A' B') *)
intros A A' B B'; try assumption.
(* Goal: forall (_ : @Equal (part_set E) A A') (_ : @Equal (part_set E) B B'), @Equal (part_set E) (diff A B) (diff A' B') *)
unfold diff in |- *; simpl in |- *.
(* Goal: forall (_ : @eq_part E A A') (_ : @eq_part E B B'), @eq_part E (@Build_Predicate E (fun x : Carrier E => and (@in_part E x A) (not (@in_part E x B))) (fun (x y : Carrier E) (H' : and (@in_part E x A) (not (@in_part E x B))) (H'0 : @Equal E y x) => @and_ind (@in_part E x A) (not (@in_part E x B)) (and (@in_part E y A) (not (@in_part E y B))) (fun (H'1 : @in_part E x A) (H'2 : not (@in_part E x B)) => @conj (@in_part E y A) (not (@in_part E y B)) (@in_part_comp_l E A x y H'1 H'0) (fun H'3 : @in_part E y B => False_ind False (H'2 (@in_part_comp_l E B y x H'3 (@Sym E y x H'0))))) H')) (@Build_Predicate E (fun x : Carrier E => and (@in_part E x A') (not (@in_part E x B'))) (fun (x y : Carrier E) (H' : and (@in_part E x A') (not (@in_part E x B'))) (H'0 : @Equal E y x) => @and_ind (@in_part E x A') (not (@in_part E x B')) (and (@in_part E y A') (not (@in_part E y B'))) (fun (H'1 : @in_part E x A') (H'2 : not (@in_part E x B')) => @conj (@in_part E y A') (not (@in_part E y B')) (@in_part_comp_l E A' x y H'1 H'0) (fun H'3 : @in_part E y B' => False_ind False (H'2 (@in_part_comp_l E B' y x H'3 (@Sym E y x H'0))))) H')) *)
unfold eq_part in |- *; simpl in |- *.
intros H' H'0 x; split;
 [ intros H'1; split; [ try assumption | idtac ] | idtac ].
elim (H' x); intros H'3 H'4; lapply H'3;
 [ intros H'5; try exact H'5; clear H'3 | clear H'3 ].
(* Goal: @in_part E x A *)
(* Goal: not (@in_part E x B') *)
(* Goal: forall _ : and (@in_part E x A') (not (@in_part E x B')), and (@in_part E x A) (not (@in_part E x B)) *)
elim H'1; intros H'2 H'3; try exact H'2; clear H'1.
(* Goal: not (@in_part E x B) *)
red in |- *.
(* Goal: forall _ : @in_part E x B, False *)
intros H'2; try assumption.
(* Goal: False *)
(* Goal: forall _ : and (@in_part E x A') (not (@in_part E x B')), and (@in_part E x A) (not (@in_part E x B)) *)
absurd (in_part x B); auto with algebra.
(* Goal: not (@in_part E x B') *)
(* Goal: @in_part E x B' *)
elim H'1; intros H'3 H'4; try exact H'4; clear H'1.
elim (H'0 x); intros H'4 H'5; lapply H'5;
 [ intros H'6; try exact H'6; clear H'5 | clear H'5 ].
(* Goal: @in_part E x B' *)
(* Goal: forall _ : and (@in_part E x A') (not (@in_part E x B')), and (@in_part E x A) (not (@in_part E x B)) *)
auto with algebra.
(* Goal: and (@in_part E y A) (not (@in_part E y B)) *)
intros H'1; split; [ try assumption | idtac ].
elim (H' x); intros H'3 H'4; lapply H'4;
 [ intros H'5; try exact H'5; clear H'4 | clear H'4 ].
(* Goal: @in_part E x A' *)
(* Goal: not (@in_part E x B) *)
elim H'1; intros H'2 H'4; try exact H'2; clear H'1.
(* Goal: not (@in_part E x B) *)
red in |- *.
(* Goal: forall _ : @in_part E x B, False *)
intros H'2; try assumption.
(* Goal: @in_part E x B' *)
(* Goal: forall _ : and (@in_part E x A') (not (@in_part E x B')), and (@in_part E x A) (not (@in_part E x B)) *)
absurd (in_part x B'); auto with algebra.
(* Goal: not (@in_part E x B') *)
(* Goal: @in_part E x B' *)
elim H'1; intros H'3 H'4; try exact H'4; clear H'1.
elim (H'0 x); intros H'4 H'5; lapply H'4;
 [ intros H'6; try exact H'6; clear H'4 | clear H'4 ].
(* Goal: @in_part E x B *)
try exact H'2.
Qed.
End Diff.
Hint Resolve diff_comp: algebra.