2 : simpl; ring.
unfold step.
generalize (nil : expr); elim e; simpl; auto.
intros; ring.
intros (c,l1) e1 IH e2.
rewrite IH, iter_split_c, lrev_c; simpl; auto.
ring.
Qed.
Inductive rp (T : Type) := Stop (_ : T) | More (_ : T).
Definition rp_val (T : Type) (x : rp T) :=
match x with Stop _ y => y | More _ y => y end.
Fixpoint iter_rp (T : Type) n f (v : rp T) := match v with
| More _ r => match n with
| O => f r
| S n1 => iter_rp T n1 f (iter_rp T n1 f v)
end
| _ => v
end.
Definition iter_step (k : nat) (e : expr) :=
iter_rp _ k (fun e => let e1 := step e in
match ecompare e e1 with
Eq => @Stop _ e
| _ => More _ e1
end) (More _ e).

(* Specifications: *)
Lemma iter_step_c k e : {e[rp_val _ (iter_step k e)]} = {e[e]}.
Fixpoint inter_elim (cc : coef) (x a b c d: tvar) (l : list tuple)
(accu: list tuple) e : expr :=
match l with
| nil =>  einsert cc (rev _ accu l) e
| t :: l1 =>
if tin x t then
let (c1,t1) := tsort (tsubst x a t) in
let (c2,t2) := tsort (Tuple b c d) in
let (c3,t3) := tsort (tsubst x b t) in
let (c4,t4) := tsort (Tuple a c d) in
einsert0
(scmp (sopp (smult c1 c2)) cc)
(linsert t1 (linsert t2 (rev _ accu l1)))
(einsert0
(scmp (smult c3 c4) cc)
(linsert t3 (linsert t4 (rev _ accu l1)))
e)
else inter_elim cc x a b c d l1 (t ::accu) e
end.