(**************************************************************)
(*   Copyright Dominique Larchey-Wendling [*]                 *)
(*             Ralph Matthes [+]                              *)
(*                                                            *)
(*                             [*] Affiliation LORIA -- CNRS  *)
(*                             [+] Affiliation IRIT -- CNRS   *)
(**************************************************************)
(*      This file is distributed under the terms of the       *)
(*         CeCILL v2 FREE SOFTWARE LICENSE AGREEMENT          *)
(**************************************************************)
(** ** Pidgeon hole principle *)
Set Implicit Arguments.
Local Infix "~p" := (@Permutation _) (at level 70, no associativity).
Section incl.
Variable X : Type.
Implicit Type l : list X.
Fact incl_cons_linv l m x : incl (x::m) l -> In x l /\ incl m l.
Fact incl_app_rinv l m p : incl m (l++p) -> exists m1 m2, m ~p m1++m2 /\ incl m1 l /\ incl m2 p.
Fact incl_cons_rinv x l m : incl m (x::l) -> exists m1 m2, m ~p m1 ++ m2 /\ Forall (eq x) m1 /\ incl m2 l.
Fact incl_right_cons_choose x l m : incl m (x::l) -> In x m \/ incl m l.
Fact incl_left_right_cons x l y m : incl (x::l) (y::m) -> y = x  /\ In y l
\/ y = x  /\ incl l m
\/ In x m /\ incl l (y::m).
Fact perm_incl_left m1 m2 l: m1 ~p m2 -> incl m2 l -> incl m1 l.
End incl.
Section Permutation_tools.
Variable X : Type.
Implicit Types (l : list X).

Theorem Permutation_In_inv l1 l2: l1 ~p l2 -> forall x, In x l1 -> exists l, exists r, l2 = l++x::r.
End Permutation_tools.