(* 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                                                     *)
(** %\subsection*{ support :  cast\_between\_subsets.v }%*)
Set Implicit Arguments.
Unset Strict Implicit.
Require Export Map_embed.
Require Export algebra_omissions.
(** - Various casting functions between equal but non-convertible types *)
(** - This one maps elements of a subset to the same subset under a different name %\label{mapbetweenequalsubsets}% *)
Definition map_between_equal_subsets :
forall (A : Setoid) (X Y : part_set A), X =' Y in _ -> X -> Y.
intros A X Y H x.
inversion_clear x.
apply (Build_subtype (E:=A) (P:=Y) (subtype_elt:=subtype_elt)).
simpl in H.
red in H.
generalize (H subtype_elt).
intro H'.
inversion_clear H'.
apply H0; auto with algebra.
Defined.
intros.
elim x.
simpl in |- *.
auto with algebra.
Qed.
Hint Resolve subtype_elt_eats_map_between_equal_subsets: algebra.
simpl in |- *.
unfold subtype_image_equal in |- *; simpl in |- *.
intros.
apply Trans with (subtype_elt (map_between_equal_subsets H x));
auto with algebra.
apply Trans with (subtype_elt (map_between_equal_subsets H' x'));
auto with algebra.
Qed.
(** - This one turns $f:A\to X$ into $A\to Y$ whenever $X='Y$ *)
(** %\label{Maptoequalsubsets}% *)
Definition Map_to_equal_subsets :
forall (A B : Setoid) (X Y : part_set A), X =' Y in _ -> MAP B X -> MAP B Y.
intros.
apply (Build_Map (Ap:=fun b : B => map_between_equal_subsets H (X0 b))).
red in |- *; simpl in |- *; red in |- *.
intros.
unfold map_between_equal_subsets in |- *.
generalize (Map_compatible_prf X0 H0).
case (X0 x); case (X0 y).
simpl in |- *.
auto.
Defined.
intros.
simpl in |- *.
case (M b).
simpl in |- *.
auto with algebra.
Qed.
Hint Resolve subtype_elt_eats_Map_to_equal_subsets: algebra.

Lemma Map_embed_eats_Map_to_equal_subsets :
forall (A B : Setoid) (X Y : part_set A) (H : X =' Y in _) (M : Map B X),
Map_embed (Map_to_equal_subsets H M) =' Map_embed M in _.