(* This tactic applies whichever of the above three lemmas is applicable. *)
Ltac subst_idx :=
first [
rewrite @subst_idx_identity by omega
| rewrite @subst_idx_miss_1 by omega
| rewrite @subst_idx_miss_2 by omega
].
Ltac subst_idx_in h :=
first [
rewrite @subst_idx_identity in h by omega
| rewrite @subst_idx_miss_1 in h by omega
| rewrite @subst_idx_miss_2 in h by omega
].
Ltac subst_idx_all :=
first [
rewrite @subst_idx_identity in * by omega
| rewrite @subst_idx_miss_1 in * by omega
| rewrite @subst_idx_miss_2 in * by omega
].
(* A little lemma: replacing a variable with a variable always yields a variable. *)

Lemma subst_idx_var:
forall `{Var V},
forall v k x,
subst_idx (var v) k x =
var (subst_idx v k x).