(* This is a really crazy diamond lemma that says, roughly, if the equation [insert x1 a1 e1 = insert x2 a2 e2] holds, then [e1] and [e2] can be constructed out of a common environment [e]. We would like to conclude [e1 = insert x2 a2 e /\ e2 = insert x1 a1 e], but this is false, because one of the indices is off-by-one in one way or the other. We need to adjust, and the arithmetic is a bit painful. *)

Lemma insert_eq_insert_3:
forall A x1 x2 a1 a2 (e1 e2 : env A),
insert x1 a1 e1 = insert x2 a2 e2 ->
x1 <> x2 ->
exists e y1 y2,
e1 = insert y1 a2 e /\
e2 = insert y2 a1 e /\
shift x1 y1 = x2 /\
y2 = (if le_gt_dec x1 y1 then x1 else x1 - 1).