Definition index_not_const l n :=
  filter (fun v => ~~ is_const (nth (Cst 0) l v) n) (iota 0 (size l)).

(* Specifications: *)
Lemma uniq_index_not_const : forall n l, uniq (T:=ssrnat.nat_eqType) (index_not_const l n).
Lemma index_not_const_correct : forall n l (k : nat), not (in_mem k (mem (index_not_const l n))) -> is_const (nth (Cst 0) l k) n = true.
Lemma interp_AppExt_set_nth_not_const : forall k f le l n x, interp (set_nth 0 l n x) (AppExt k f le) = apply k f (foldr (fun v acc i => if ssrnat.eqn i v then interp (set_nth 0 l n x) (nth (Cst 0) le v) else acc i) (nth 0 (map (interp l) le)) (index_not_const le n)).
Lemma D_correct : forall (e : expr) l n, let '(a,b) := D e n in interp_domain l b -> is_derive (fun x => interp (set_nth R0 l n x) e) (nth R0 l n) (interp l a).