Section split_interval.
(* [0,i[ U {i} U ]i,n] ~~ [0,n[ U {n} *)
Variables (n i : nat) (Hi : i <= n).
Let g j := if le_lt_dec (S n) j then j else     (* j > n  *)
if le_lt_dec i j then
if le_lt_dec j i then n              (* j = i *)
else j-1                             (* i < j <= n *)
else j.                              (* j < i *)
Let h j := if le_lt_dec (S n) j then j else     (* j > n  *)
if le_lt_dec n j then i else         (* j = n  *)
if le_lt_dec i j then j+1            (* i <= j < n *)
else j.                              (* j < i *)
Let Hg1 : forall j, j <= n -> g j <= n.
Let Hg2 j : n < j -> g j = j.
Let Hh1 : forall j, j <= n -> h j <= n.
Let Hh2 j : n < j -> h j = j.
Ltac mydestruct H :=
match goal with
|- if ?c then _ else _ = _ => destruct c as [ H | H ]; try lia; auto
end.

Theorem split_interval : { g : nat -> nat & { h | (forall j, j <= n -> g j <= n)
/\ (forall j, j <= n -> h j <= n)
/\ (forall j, g (h j) = j)
/\ (forall j, h (g j) = j)
/\ g i = n } }.