Section AllPairs.
Variables (S T R : Type) (f : S -> T -> R).
Implicit Types (s : seq S) (t : seq T).
Definition allpairs s t := foldr (fun x => cat (map (f x) t)) [::] s.

Lemma mem_allpairs R (f : S -> T -> R) s1 t1 s2 t2 :
s1 =i s2 -> t1 =i t2 -> allpairs f s1 t1 =i allpairs f s2 t2.