Section Wrap.
Variable A : Set.
Variable leA : A -> A -> Prop.
Variable leA_dec : forall a a', {leA a a'} + {~ leA a a'}.
(* leA a' a for some a' in second arg *)
Inductive greater : A -> list A -> Prop :=
| Gr0 : forall a a' w, leA a' a -> greater a (a'::w)
| Gr1 : forall a a' w, greater a w -> greater a (a'::w).
(* good sequence - leA a' a, a occurs in arg earlier than a' *)
Inductive good : list A -> Prop :=
| Gd0 : forall a w, greater a w -> good (a::w)
| Gd1 : forall a w, good w -> good (a::w).
Definition bad (l : list A) : Prop := ~ good l.
Fixpoint bad_subsequence (l : list A) : list A :=
match l with
| nil => nil
| a :: l' => let bl := bad_subsequence l' in
match (greater_dec a bl) with
| left _ => bl
| right _ => a :: bl
end
end.

Lemma bad_subsequence_is_bad : forall l, bad (bad_subsequence l).