(* Copyright 2012-2015 by Adam Petcher.				* * Use of this source code is governed by the license described	* * in the LICENSE file at the root of the source tree.		*)
Set Implicit Arguments.
Local Open Scope list_scope.
induction ls; intuition; simpl in *.
intuition; subst.
destruct (EqDec_dec eqd a0 a0); intuition.
destruct (EqDec_dec eqd a0 a); subst.
trivial.
simpl.
rewrite IHls.
destruct ls; simpl in *; intuition.
trivial.
Qed.
Fixpoint addInAllLocations(A : Type)(a : A)(ls : list A) :=
match ls with
| nil =>  (a :: nil) :: nil
| a' :: ls' =>
(a :: ls) :: map (fun x => a' :: x) (addInAllLocations a ls')
end.
Fixpoint getAllPermutations(A : Type)(ls : list A) :=
match ls with
| nil => nil :: nil
| a :: ls' =>
let perms' := getAllPermutations ls' in
flatten (map (addInAllLocations a) perms')
end.
induction l; intuition; unfold addInAllLocations in *; simpl in *.
inversion H.
inversion H.
Qed.
induction ls; intuition; simpl in *.
inversion H.
case_eq (getAllPermutations ls); intuition.
rewrite H0 in H.
simpl in *.
apply app_eq_nil in H.
intuition.
eapply addInAllLocations_not_nil; eauto.
Qed.
induction x0; intuition; simpl in *.
intuition; subst.
eapply Permutation_refl.
intuition; subst.
eapply Permutation_refl.
eapply in_map_iff in H0.
destruct H0.
intuition; subst.
eapply perm_trans.
2:{
eapply perm_swap.
}
eapply perm_skip.
eapply IHx0.
trivial.
Qed.

Theorem getAllPermutations_perms :
forall (A : Set)(ls1 ls2 : list A),
In ls2 (getAllPermutations ls1) ->
Permutation ls1 ls2.