Set Implicit Arguments.
Unset Strict Implicit.
From Undecidability.HOU Require Import std.decidable std.lists.basics std.lists.advanced std.tactics.
Notation "( A × B × .. × C )" :=
(list_prod .. (list_prod A B) .. C) (at level 0, left associativity).
Notation "[ s | p ∈ A ',' P ]" :=
(map (fun p => s) (filter (fun p => decb P) A)) (p pattern).
Notation "[ s | p ∈ A ]" :=
(map (fun p => s) A) (p pattern).
Notation "[ s 'where' H ':' P ]" := (match dec P with
| left H => s :: nil
| right _ => nil
end) (H pattern).
Notation "[ s | p ∈ A 'where' H ':' P ]" :=
(flat_map (fun p => [s where H : P]) A) (p pattern, H pattern).
Notation "[ s | p ∈ A '&' q ∈ B ]" :=
(flat_map (fun q => map (fun p => s) A) B) (p pattern, q pattern).
Notation "[ s | p ∈ A '&' q ∈ B 'where' H ':' P ]" :=
(flat_map (fun q => map (fun p => [s where H : P]) A) B) (p pattern, q pattern).
Ltac in_collect a :=
eapply in_map_iff; exists a; split; [ eauto | match goal with [ |- _ ∈ filter _ _ ] =>  eapply filter_In; split; [ try (rewrite !in_prod_iff; repeat split) | repeat split; eauto ] | _ => try (rewrite !in_prod_iff; repeat split) end ].
Ltac in_app n :=
(match goal with
| [ |- _ ∈ _ ++ _ ] =>
match n with
| 0 => idtac
| 1 => eapply in_app_iff; left
| S ?n => eapply in_app_iff; right; in_app n
end
| [ |- _ ∈  _ :: _ ] => match n with 0 => idtac | 1 => left | S ?n => right; in_app n end
end) || (repeat (try right; eapply in_app_iff; right)).

Lemma in_concat_iff A l (a:A) : a ∈ concat l <-> exists l', a ∈ l' /\ l' ∈ l.