Require terminaison.

Require Relations.

Require term.

Require List.

Require equational_theory.

Require rpo_extension.

Require equational_extension.

Require closure_extension.

Require term_extension.

Require dp.

Require Inclusion.

Require or_ext_generated.

Require ZArith.

Require ring_extention.

Require Zwf.

Require Inverse_Image.

Require matrix.

Require more_list_extention.

Import List.

Import ZArith.

Set Implicit Arguments.

Module algebra.
 Module F
  <:term.Signature.
  Inductive symb  :
   Set := 
     (* id_eq *)
    | id_eq : symb
     (* id_add *)
    | id_add : symb
     (* id_false *)
    | id_false : symb
     (* id_if_rm *)
    | id_if_rm : symb
     (* id_true *)
    | id_true : symb
     (* id_if_min *)
    | id_if_min : symb
     (* id_app *)
    | id_app : symb
     (* id_if_minsort *)
    | id_if_minsort : symb
     (* id_0 *)
    | id_0 : symb
     (* id_min *)
    | id_min : symb
     (* id_le *)
    | id_le : symb
     (* id_minsort *)
    | id_minsort : symb
     (* id_s *)
    | id_s : symb
     (* id_rm *)
    | id_rm : symb
     (* id_nil *)
    | id_nil : symb
  .
  
  
  Definition symb_eq_bool (f1 f2:symb) : bool := 
    match f1,f2 with
      | id_eq,id_eq => true
      | id_add,id_add => true
      | id_false,id_false => true
      | id_if_rm,id_if_rm => true
      | id_true,id_true => true
      | id_if_min,id_if_min => true
      | id_app,id_app => true
      | id_if_minsort,id_if_minsort => true
      | id_0,id_0 => true
      | id_min,id_min => true
      | id_le,id_le => true
      | id_minsort,id_minsort => true
      | id_s,id_s => true
      | id_rm,id_rm => true
      | id_nil,id_nil => true
      | _,_ => false
      end.
  
  
   (* Proof of decidability of equality over symb *)
  Definition symb_eq_bool_ok(f1 f2:symb) :
   match symb_eq_bool f1 f2 with
     | true => f1 = f2
     | false => f1 <> f2
     end.
  Proof.
    intros f1 f2.
    
    refine match f1 as u1,f2 as u2 return 
             match symb_eq_bool u1 u2 return 
               Prop with
               | true => u1 = u2
               | false => u1 <> u2
               end with
             | id_eq,id_eq => refl_equal _
             | id_add,id_add => refl_equal _
             | id_false,id_false => refl_equal _
             | id_if_rm,id_if_rm => refl_equal _
             | id_true,id_true => refl_equal _
             | id_if_min,id_if_min => refl_equal _
             | id_app,id_app => refl_equal _
             | id_if_minsort,id_if_minsort => refl_equal _
             | id_0,id_0 => refl_equal _
             | id_min,id_min => refl_equal _
             | id_le,id_le => refl_equal _
             | id_minsort,id_minsort => refl_equal _
             | id_s,id_s => refl_equal _
             | id_rm,id_rm => refl_equal _
             | id_nil,id_nil => refl_equal _
             | _,_ => _
             end;intros abs;discriminate.
  Defined.
  
  
  Definition arity (f:symb) := 
    match f with
      | id_eq => term.Free 2
      | id_add => term.Free 2
      | id_false => term.Free 0
      | id_if_rm => term.Free 3
      | id_true => term.Free 0
      | id_if_min => term.Free 2
      | id_app => term.Free 2
      | id_if_minsort => term.Free 3
      | id_0 => term.Free 0
      | id_min => term.Free 1
      | id_le => term.Free 2
      | id_minsort => term.Free 2
      | id_s => term.Free 1
      | id_rm => term.Free 2
      | id_nil => term.Free 0
      end.
  
  
  Definition symb_order (f1 f2:symb) : bool := 
    match f1,f2 with
      | id_eq,id_eq => true
      | id_eq,id_add => false
      | id_eq,id_false => false
      | id_eq,id_if_rm => false
      | id_eq,id_true => false
      | id_eq,id_if_min => false
      | id_eq,id_app => false
      | id_eq,id_if_minsort => false
      | id_eq,id_0 => false
      | id_eq,id_min => false
      | id_eq,id_le => false
      | id_eq,id_minsort => false
      | id_eq,id_s => false
      | id_eq,id_rm => false
      | id_eq,id_nil => false
      | id_add,id_eq => true
      | id_add,id_add => true
      | id_add,id_false => false
      | id_add,id_if_rm => false
      | id_add,id_true => false
      | id_add,id_if_min => false
      | id_add,id_app => false
      | id_add,id_if_minsort => false
      | id_add,id_0 => false
      | id_add,id_min => false
      | id_add,id_le => false
      | id_add,id_minsort => false
      | id_add,id_s => false
      | id_add,id_rm => false
      | id_add,id_nil => false
      | id_false,id_eq => true
      | id_false,id_add => true
      | id_false,id_false => true
      | id_false,id_if_rm => false
      | id_false,id_true => false
      | id_false,id_if_min => false
      | id_false,id_app => false
      | id_false,id_if_minsort => false
      | id_false,id_0 => false
      | id_false,id_min => false
      | id_false,id_le => false
      | id_false,id_minsort => false
      | id_false,id_s => false
      | id_false,id_rm => false
      | id_false,id_nil => false
      | id_if_rm,id_eq => true
      | id_if_rm,id_add => true
      | id_if_rm,id_false => true
      | id_if_rm,id_if_rm => true
      | id_if_rm,id_true => false
      | id_if_rm,id_if_min => false
      | id_if_rm,id_app => false
      | id_if_rm,id_if_minsort => false
      | id_if_rm,id_0 => false
      | id_if_rm,id_min => false
      | id_if_rm,id_le => false
      | id_if_rm,id_minsort => false
      | id_if_rm,id_s => false
      | id_if_rm,id_rm => false
      | id_if_rm,id_nil => false
      | id_true,id_eq => true
      | id_true,id_add => true
      | id_true,id_false => true
      | id_true,id_if_rm => true
      | id_true,id_true => true
      | id_true,id_if_min => false
      | id_true,id_app => false
      | id_true,id_if_minsort => false
      | id_true,id_0 => false
      | id_true,id_min => false
      | id_true,id_le => false
      | id_true,id_minsort => false
      | id_true,id_s => false
      | id_true,id_rm => false
      | id_true,id_nil => false
      | id_if_min,id_eq => true
      | id_if_min,id_add => true
      | id_if_min,id_false => true
      | id_if_min,id_if_rm => true
      | id_if_min,id_true => true
      | id_if_min,id_if_min => true
      | id_if_min,id_app => false
      | id_if_min,id_if_minsort => false
      | id_if_min,id_0 => false
      | id_if_min,id_min => false
      | id_if_min,id_le => false
      | id_if_min,id_minsort => false
      | id_if_min,id_s => false
      | id_if_min,id_rm => false
      | id_if_min,id_nil => false
      | id_app,id_eq => true
      | id_app,id_add => true
      | id_app,id_false => true
      | id_app,id_if_rm => true
      | id_app,id_true => true
      | id_app,id_if_min => true
      | id_app,id_app => true
      | id_app,id_if_minsort => false
      | id_app,id_0 => false
      | id_app,id_min => false
      | id_app,id_le => false
      | id_app,id_minsort => false
      | id_app,id_s => false
      | id_app,id_rm => false
      | id_app,id_nil => false
      | id_if_minsort,id_eq => true
      | id_if_minsort,id_add => true
      | id_if_minsort,id_false => true
      | id_if_minsort,id_if_rm => true
      | id_if_minsort,id_true => true
      | id_if_minsort,id_if_min => true
      | id_if_minsort,id_app => true
      | id_if_minsort,id_if_minsort => true
      | id_if_minsort,id_0 => false
      | id_if_minsort,id_min => false
      | id_if_minsort,id_le => false
      | id_if_minsort,id_minsort => false
      | id_if_minsort,id_s => false
      | id_if_minsort,id_rm => false
      | id_if_minsort,id_nil => false
      | id_0,id_eq => true
      | id_0,id_add => true
      | id_0,id_false => true
      | id_0,id_if_rm => true
      | id_0,id_true => true
      | id_0,id_if_min => true
      | id_0,id_app => true
      | id_0,id_if_minsort => true
      | id_0,id_0 => true
      | id_0,id_min => false
      | id_0,id_le => false
      | id_0,id_minsort => false
      | id_0,id_s => false
      | id_0,id_rm => false
      | id_0,id_nil => false
      | id_min,id_eq => true
      | id_min,id_add => true
      | id_min,id_false => true
      | id_min,id_if_rm => true
      | id_min,id_true => true
      | id_min,id_if_min => true
      | id_min,id_app => true
      | id_min,id_if_minsort => true
      | id_min,id_0 => true
      | id_min,id_min => true
      | id_min,id_le => false
      | id_min,id_minsort => false
      | id_min,id_s => false
      | id_min,id_rm => false
      | id_min,id_nil => false
      | id_le,id_eq => true
      | id_le,id_add => true
      | id_le,id_false => true
      | id_le,id_if_rm => true
      | id_le,id_true => true
      | id_le,id_if_min => true
      | id_le,id_app => true
      | id_le,id_if_minsort => true
      | id_le,id_0 => true
      | id_le,id_min => true
      | id_le,id_le => true
      | id_le,id_minsort => false
      | id_le,id_s => false
      | id_le,id_rm => false
      | id_le,id_nil => false
      | id_minsort,id_eq => true
      | id_minsort,id_add => true
      | id_minsort,id_false => true
      | id_minsort,id_if_rm => true
      | id_minsort,id_true => true
      | id_minsort,id_if_min => true
      | id_minsort,id_app => true
      | id_minsort,id_if_minsort => true
      | id_minsort,id_0 => true
      | id_minsort,id_min => true
      | id_minsort,id_le => true
      | id_minsort,id_minsort => true
      | id_minsort,id_s => false
      | id_minsort,id_rm => false
      | id_minsort,id_nil => false
      | id_s,id_eq => true
      | id_s,id_add => true
      | id_s,id_false => true
      | id_s,id_if_rm => true
      | id_s,id_true => true
      | id_s,id_if_min => true
      | id_s,id_app => true
      | id_s,id_if_minsort => true
      | id_s,id_0 => true
      | id_s,id_min => true
      | id_s,id_le => true
      | id_s,id_minsort => true
      | id_s,id_s => true
      | id_s,id_rm => false
      | id_s,id_nil => false
      | id_rm,id_eq => true
      | id_rm,id_add => true
      | id_rm,id_false => true
      | id_rm,id_if_rm => true
      | id_rm,id_true => true
      | id_rm,id_if_min => true
      | id_rm,id_app => true
      | id_rm,id_if_minsort => true
      | id_rm,id_0 => true
      | id_rm,id_min => true
      | id_rm,id_le => true
      | id_rm,id_minsort => true
      | id_rm,id_s => true
      | id_rm,id_rm => true
      | id_rm,id_nil => false
      | id_nil,id_eq => true
      | id_nil,id_add => true
      | id_nil,id_false => true
      | id_nil,id_if_rm => true
      | id_nil,id_true => true
      | id_nil,id_if_min => true
      | id_nil,id_app => true
      | id_nil,id_if_minsort => true
      | id_nil,id_0 => true
      | id_nil,id_min => true
      | id_nil,id_le => true
      | id_nil,id_minsort => true
      | id_nil,id_s => true
      | id_nil,id_rm => true
      | id_nil,id_nil => true
      end.
  
  
  Module Symb.
   Definition A  := symb.
   
   Definition eq_A  := @eq A.
   
   
   Definition eq_proof : equivalence A eq_A.
   Proof.
     constructor.
     red ;reflexivity .
     red ;intros ;transitivity y ;assumption.
     red ;intros ;symmetry ;assumption.
   Defined.
   
   
   Add Relation A eq_A 
  reflexivity proved by (@equiv_refl _ _ eq_proof)
    symmetry proved by (@equiv_sym _ _ eq_proof)
      transitivity proved by (@equiv_trans _ _ eq_proof) as EQA
.
   
   Definition eq_bool  := symb_eq_bool.
   
   Definition eq_bool_ok  := symb_eq_bool_ok.
  End Symb.
  
  Export Symb.
 End F.
 
 Module Alg := term.Make'(F)(term_extension.IntVars).
 
 Module Alg_ext := term_extension.Make(Alg).
 
 Module EQT := equational_theory.Make(Alg).
 
 Module EQT_ext := equational_extension.Make(EQT).
End algebra.

Module R_xml_0_deep_rew.
 Inductive R_xml_0_rules  :
  algebra.Alg.term ->algebra.Alg.term ->Prop := 
    (* eq(0,0) -> true *)
   | R_xml_0_rule_0 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_true nil) 
     (algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Term algebra.F.id_0 
      nil)::(algebra.Alg.Term algebra.F.id_0 nil)::nil))
    (* eq(0,s(x_)) -> false *)
   | R_xml_0_rule_1 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_false nil) 
     (algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Term algebra.F.id_0 
      nil)::(algebra.Alg.Term algebra.F.id_s 
      ((algebra.Alg.Var 1)::nil))::nil))
    (* eq(s(x_),0) -> false *)
   | R_xml_0_rule_2 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_false nil) 
     (algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Term algebra.F.id_s 
      ((algebra.Alg.Var 1)::nil))::(algebra.Alg.Term algebra.F.id_0 
      nil)::nil))
    (* eq(s(x_),s(y_)) -> eq(x_,y_) *)
   | R_xml_0_rule_3 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Var 1)::
                   (algebra.Alg.Var 2)::nil)) 
     (algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Term algebra.F.id_s 
      ((algebra.Alg.Var 1)::nil))::(algebra.Alg.Term algebra.F.id_s 
      ((algebra.Alg.Var 2)::nil))::nil))
    (* le(0,y_) -> true *)
   | R_xml_0_rule_4 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_true nil) 
     (algebra.Alg.Term algebra.F.id_le ((algebra.Alg.Term algebra.F.id_0 
      nil)::(algebra.Alg.Var 2)::nil))
    (* le(s(x_),0) -> false *)
   | R_xml_0_rule_5 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_false nil) 
     (algebra.Alg.Term algebra.F.id_le ((algebra.Alg.Term algebra.F.id_s 
      ((algebra.Alg.Var 1)::nil))::(algebra.Alg.Term algebra.F.id_0 
      nil)::nil))
    (* le(s(x_),s(y_)) -> le(x_,y_) *)
   | R_xml_0_rule_6 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_le ((algebra.Alg.Var 1)::
                   (algebra.Alg.Var 2)::nil)) 
     (algebra.Alg.Term algebra.F.id_le ((algebra.Alg.Term algebra.F.id_s 
      ((algebra.Alg.Var 1)::nil))::(algebra.Alg.Term algebra.F.id_s 
      ((algebra.Alg.Var 2)::nil))::nil))
    (* app(nil,y_) -> y_ *)
   | R_xml_0_rule_7 :
    R_xml_0_rules (algebra.Alg.Var 2) 
     (algebra.Alg.Term algebra.F.id_app ((algebra.Alg.Term algebra.F.id_nil 
      nil)::(algebra.Alg.Var 2)::nil))
    (* app(add(n_,x_),y_) -> add(n_,app(x_,y_)) *)
   | R_xml_0_rule_8 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 3)::
                   (algebra.Alg.Term algebra.F.id_app ((algebra.Alg.Var 1)::
                   (algebra.Alg.Var 2)::nil))::nil)) 
     (algebra.Alg.Term algebra.F.id_app ((algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
      (algebra.Alg.Var 2)::nil))
    (* min(add(n_,nil)) -> n_ *)
   | R_xml_0_rule_9 :
    R_xml_0_rules (algebra.Alg.Var 3) 
     (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 3)::(algebra.Alg.Term algebra.F.id_nil 
      nil)::nil))::nil))
   
    (* min(add(n_,add(m_,x_))) -> if_min(le(n_,m_),add(n_,add(m_,x_))) *)
   | R_xml_0_rule_10 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_if_min ((algebra.Alg.Term 
                   algebra.F.id_le ((algebra.Alg.Var 3)::
                   (algebra.Alg.Var 4)::nil))::(algebra.Alg.Term 
                   algebra.F.id_add ((algebra.Alg.Var 3)::(algebra.Alg.Term 
                   algebra.F.id_add ((algebra.Alg.Var 4)::
                   (algebra.Alg.Var 1)::nil))::nil))::nil)) 
     (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 3)::(algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil))::nil))
   
    (* if_min(true,add(n_,add(m_,x_))) -> min(add(n_,x_)) *)
   | R_xml_0_rule_11 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term 
                   algebra.F.id_add ((algebra.Alg.Var 3)::
                   (algebra.Alg.Var 1)::nil))::nil)) 
     (algebra.Alg.Term algebra.F.id_if_min ((algebra.Alg.Term 
      algebra.F.id_true nil)::(algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 3)::(algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil))::nil))
   
    (* if_min(false,add(n_,add(m_,x_))) -> min(add(m_,x_)) *)
   | R_xml_0_rule_12 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term 
                   algebra.F.id_add ((algebra.Alg.Var 4)::
                   (algebra.Alg.Var 1)::nil))::nil)) 
     (algebra.Alg.Term algebra.F.id_if_min ((algebra.Alg.Term 
      algebra.F.id_false nil)::(algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 3)::(algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil))::nil))
    (* rm(n_,nil) -> nil *)
   | R_xml_0_rule_13 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_nil nil) 
     (algebra.Alg.Term algebra.F.id_rm ((algebra.Alg.Var 3)::
      (algebra.Alg.Term algebra.F.id_nil nil)::nil))
   
    (* rm(n_,add(m_,x_)) -> if_rm(eq(n_,m_),n_,add(m_,x_)) *)
   | R_xml_0_rule_14 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_if_rm ((algebra.Alg.Term 
                   algebra.F.id_eq ((algebra.Alg.Var 3)::
                   (algebra.Alg.Var 4)::nil))::(algebra.Alg.Var 3)::
                   (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 4)::
                   (algebra.Alg.Var 1)::nil))::nil)) 
     (algebra.Alg.Term algebra.F.id_rm ((algebra.Alg.Var 3)::
      (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 4)::
      (algebra.Alg.Var 1)::nil))::nil))
    (* if_rm(true,n_,add(m_,x_)) -> rm(n_,x_) *)
   | R_xml_0_rule_15 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_rm ((algebra.Alg.Var 3)::
                   (algebra.Alg.Var 1)::nil)) 
     (algebra.Alg.Term algebra.F.id_if_rm ((algebra.Alg.Term 
      algebra.F.id_true nil)::(algebra.Alg.Var 3)::(algebra.Alg.Term 
      algebra.F.id_add ((algebra.Alg.Var 4)::
      (algebra.Alg.Var 1)::nil))::nil))
    (* if_rm(false,n_,add(m_,x_)) -> add(m_,rm(n_,x_)) *)
   | R_xml_0_rule_16 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 4)::
                   (algebra.Alg.Term algebra.F.id_rm ((algebra.Alg.Var 3)::
                   (algebra.Alg.Var 1)::nil))::nil)) 
     (algebra.Alg.Term algebra.F.id_if_rm ((algebra.Alg.Term 
      algebra.F.id_false nil)::(algebra.Alg.Var 3)::(algebra.Alg.Term 
      algebra.F.id_add ((algebra.Alg.Var 4)::
      (algebra.Alg.Var 1)::nil))::nil))
    (* minsort(nil,nil) -> nil *)
   | R_xml_0_rule_17 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_nil nil) 
     (algebra.Alg.Term algebra.F.id_minsort ((algebra.Alg.Term 
      algebra.F.id_nil nil)::(algebra.Alg.Term algebra.F.id_nil nil)::nil))
   
    (* minsort(add(n_,x_),y_) -> if_minsort(eq(n_,min(add(n_,x_))),add(n_,x_),y_) *)
   | R_xml_0_rule_18 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_if_minsort 
                   ((algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Var 3)::
                   (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term 
                   algebra.F.id_add ((algebra.Alg.Var 3)::
                   (algebra.Alg.Var 1)::nil))::nil))::nil))::
                   (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 3)::
                   (algebra.Alg.Var 1)::nil))::(algebra.Alg.Var 2)::nil)) 
     (algebra.Alg.Term algebra.F.id_minsort ((algebra.Alg.Term 
      algebra.F.id_add ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
      (algebra.Alg.Var 2)::nil))
   
    (* if_minsort(true,add(n_,x_),y_) -> add(n_,minsort(app(rm(n_,x_),y_),nil)) *)
   | R_xml_0_rule_19 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 3)::
                   (algebra.Alg.Term algebra.F.id_minsort ((algebra.Alg.Term 
                   algebra.F.id_app ((algebra.Alg.Term algebra.F.id_rm 
                   ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
                   (algebra.Alg.Var 2)::nil))::(algebra.Alg.Term 
                   algebra.F.id_nil nil)::nil))::nil)) 
     (algebra.Alg.Term algebra.F.id_if_minsort ((algebra.Alg.Term 
      algebra.F.id_true nil)::(algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
      (algebra.Alg.Var 2)::nil))
   
    (* if_minsort(false,add(n_,x_),y_) -> minsort(x_,add(n_,y_)) *)
   | R_xml_0_rule_20 :
    R_xml_0_rules (algebra.Alg.Term algebra.F.id_minsort 
                   ((algebra.Alg.Var 1)::(algebra.Alg.Term algebra.F.id_add 
                   ((algebra.Alg.Var 3)::(algebra.Alg.Var 2)::nil))::nil)) 
     (algebra.Alg.Term algebra.F.id_if_minsort ((algebra.Alg.Term 
      algebra.F.id_false nil)::(algebra.Alg.Term algebra.F.id_add 
      ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
      (algebra.Alg.Var 2)::nil))
 .
 
 
 Definition R_xml_0_rule_as_list_0  := 
   ((algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Term algebra.F.id_0 
     nil)::(algebra.Alg.Term algebra.F.id_0 nil)::nil)),
    (algebra.Alg.Term algebra.F.id_true nil))::nil.
 
 
 Definition R_xml_0_rule_as_list_1  := 
   ((algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Term algebra.F.id_0 
     nil)::(algebra.Alg.Term algebra.F.id_s 
     ((algebra.Alg.Var 1)::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_false nil))::R_xml_0_rule_as_list_0.
 
 
 Definition R_xml_0_rule_as_list_2  := 
   ((algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Term algebra.F.id_s 
     ((algebra.Alg.Var 1)::nil))::(algebra.Alg.Term algebra.F.id_0 
     nil)::nil)),(algebra.Alg.Term algebra.F.id_false nil))::
    R_xml_0_rule_as_list_1.
 
 
 Definition R_xml_0_rule_as_list_3  := 
   ((algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Term algebra.F.id_s 
     ((algebra.Alg.Var 1)::nil))::(algebra.Alg.Term algebra.F.id_s 
     ((algebra.Alg.Var 2)::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_eq ((algebra.Alg.Var 1)::
     (algebra.Alg.Var 2)::nil)))::R_xml_0_rule_as_list_2.
 
 
 Definition R_xml_0_rule_as_list_4  := 
   ((algebra.Alg.Term algebra.F.id_le ((algebra.Alg.Term algebra.F.id_0 
     nil)::(algebra.Alg.Var 2)::nil)),
    (algebra.Alg.Term algebra.F.id_true nil))::R_xml_0_rule_as_list_3.
 
 
 Definition R_xml_0_rule_as_list_5  := 
   ((algebra.Alg.Term algebra.F.id_le ((algebra.Alg.Term algebra.F.id_s 
     ((algebra.Alg.Var 1)::nil))::(algebra.Alg.Term algebra.F.id_0 
     nil)::nil)),(algebra.Alg.Term algebra.F.id_false nil))::
    R_xml_0_rule_as_list_4.
 
 
 Definition R_xml_0_rule_as_list_6  := 
   ((algebra.Alg.Term algebra.F.id_le ((algebra.Alg.Term algebra.F.id_s 
     ((algebra.Alg.Var 1)::nil))::(algebra.Alg.Term algebra.F.id_s 
     ((algebra.Alg.Var 2)::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_le ((algebra.Alg.Var 1)::
     (algebra.Alg.Var 2)::nil)))::R_xml_0_rule_as_list_5.
 
 
 Definition R_xml_0_rule_as_list_7  := 
   ((algebra.Alg.Term algebra.F.id_app ((algebra.Alg.Term algebra.F.id_nil 
     nil)::(algebra.Alg.Var 2)::nil)),(algebra.Alg.Var 2))::
    R_xml_0_rule_as_list_6.
 
 
 Definition R_xml_0_rule_as_list_8  := 
   ((algebra.Alg.Term algebra.F.id_app ((algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
     (algebra.Alg.Var 2)::nil)),
    (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 3)::
     (algebra.Alg.Term algebra.F.id_app ((algebra.Alg.Var 1)::
     (algebra.Alg.Var 2)::nil))::nil)))::R_xml_0_rule_as_list_7.
 
 
 Definition R_xml_0_rule_as_list_9  := 
   ((algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Term algebra.F.id_nil 
     nil)::nil))::nil)),(algebra.Alg.Var 3))::R_xml_0_rule_as_list_8.
 
 
 Definition R_xml_0_rule_as_list_10  := 
   ((algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_if_min ((algebra.Alg.Term algebra.F.id_le 
     ((algebra.Alg.Var 3)::(algebra.Alg.Var 4)::nil))::(algebra.Alg.Term 
     algebra.F.id_add ((algebra.Alg.Var 3)::(algebra.Alg.Term 
     algebra.F.id_add ((algebra.Alg.Var 4)::
     (algebra.Alg.Var 1)::nil))::nil))::nil)))::R_xml_0_rule_as_list_9.
 
 
 Definition R_xml_0_rule_as_list_11  := 
   ((algebra.Alg.Term algebra.F.id_if_min ((algebra.Alg.Term 
     algebra.F.id_true nil)::(algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::nil)))::
    R_xml_0_rule_as_list_10.
 
 
 Definition R_xml_0_rule_as_list_12  := 
   ((algebra.Alg.Term algebra.F.id_if_min ((algebra.Alg.Term 
     algebra.F.id_false nil)::(algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil)))::
    R_xml_0_rule_as_list_11.
 
 
 Definition R_xml_0_rule_as_list_13  := 
   ((algebra.Alg.Term algebra.F.id_rm ((algebra.Alg.Var 3)::
     (algebra.Alg.Term algebra.F.id_nil nil)::nil)),
    (algebra.Alg.Term algebra.F.id_nil nil))::R_xml_0_rule_as_list_12.
 
 
 Definition R_xml_0_rule_as_list_14  := 
   ((algebra.Alg.Term algebra.F.id_rm ((algebra.Alg.Var 3)::
     (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 4)::
     (algebra.Alg.Var 1)::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_if_rm ((algebra.Alg.Term algebra.F.id_eq 
     ((algebra.Alg.Var 3)::(algebra.Alg.Var 4)::nil))::(algebra.Alg.Var 3)::
     (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 4)::
     (algebra.Alg.Var 1)::nil))::nil)))::R_xml_0_rule_as_list_13.
 
 
 Definition R_xml_0_rule_as_list_15  := 
   ((algebra.Alg.Term algebra.F.id_if_rm ((algebra.Alg.Term 
     algebra.F.id_true nil)::(algebra.Alg.Var 3)::(algebra.Alg.Term 
     algebra.F.id_add ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_rm ((algebra.Alg.Var 3)::
     (algebra.Alg.Var 1)::nil)))::R_xml_0_rule_as_list_14.
 
 
 Definition R_xml_0_rule_as_list_16  := 
   ((algebra.Alg.Term algebra.F.id_if_rm ((algebra.Alg.Term 
     algebra.F.id_false nil)::(algebra.Alg.Var 3)::(algebra.Alg.Term 
     algebra.F.id_add ((algebra.Alg.Var 4)::(algebra.Alg.Var 1)::nil))::nil)),
    (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 4)::
     (algebra.Alg.Term algebra.F.id_rm ((algebra.Alg.Var 3)::
     (algebra.Alg.Var 1)::nil))::nil)))::R_xml_0_rule_as_list_15.
 
 
 Definition R_xml_0_rule_as_list_17  := 
   ((algebra.Alg.Term algebra.F.id_minsort ((algebra.Alg.Term 
     algebra.F.id_nil nil)::(algebra.Alg.Term algebra.F.id_nil nil)::nil)),
    (algebra.Alg.Term algebra.F.id_nil nil))::R_xml_0_rule_as_list_16.
 
 
 Definition R_xml_0_rule_as_list_18  := 
   ((algebra.Alg.Term algebra.F.id_minsort ((algebra.Alg.Term 
     algebra.F.id_add ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
     (algebra.Alg.Var 2)::nil)),
    (algebra.Alg.Term algebra.F.id_if_minsort ((algebra.Alg.Term 
     algebra.F.id_eq ((algebra.Alg.Var 3)::(algebra.Alg.Term 
     algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::nil))::nil))::
     (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 3)::
     (algebra.Alg.Var 1)::nil))::(algebra.Alg.Var 2)::nil)))::
    R_xml_0_rule_as_list_17.
 
 
 Definition R_xml_0_rule_as_list_19  := 
   ((algebra.Alg.Term algebra.F.id_if_minsort ((algebra.Alg.Term 
     algebra.F.id_true nil)::(algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
     (algebra.Alg.Var 2)::nil)),
    (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 3)::
     (algebra.Alg.Term algebra.F.id_minsort ((algebra.Alg.Term 
     algebra.F.id_app ((algebra.Alg.Term algebra.F.id_rm 
     ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
     (algebra.Alg.Var 2)::nil))::(algebra.Alg.Term algebra.F.id_nil 
     nil)::nil))::nil)))::R_xml_0_rule_as_list_18.
 
 
 Definition R_xml_0_rule_as_list_20  := 
   ((algebra.Alg.Term algebra.F.id_if_minsort ((algebra.Alg.Term 
     algebra.F.id_false nil)::(algebra.Alg.Term algebra.F.id_add 
     ((algebra.Alg.Var 3)::(algebra.Alg.Var 1)::nil))::
     (algebra.Alg.Var 2)::nil)),
    (algebra.Alg.Term algebra.F.id_minsort ((algebra.Alg.Var 1)::
     (algebra.Alg.Term algebra.F.id_add ((algebra.Alg.Var 3)::
     (algebra.Alg.Var 2)::nil))::nil)))::R_xml_0_rule_as_list_19.
 
 Definition R_xml_0_rule_as_list  := R_xml_0_rule_as_list_20.
 
 
 Lemma R_xml_0_rules_included :
  forall l r, R_xml_0_rules r l <-> In (l,r) R_xml_0_rule_as_list.
 Proof.
   intros l r.
   constructor.
   intros H.
   
   case H;clear H;
    (apply (more_list.mem_impl_in (@eq (algebra.Alg.term*algebra.Alg.term)));
     [tauto|idtac]);
    match goal with
      |  |- _ _ _ ?t ?l =>
       let u := fresh "u" in 
        (generalize (more_list.mem_bool_ok _ _ 
                      algebra.Alg_ext.eq_term_term_bool_ok t l);
          set (u:=more_list.mem_bool algebra.Alg_ext.eq_term_term_bool t l) in *;
          vm_compute in u|-;unfold u in *;clear u;intros H;refine H)
      end
    .
   intros H.
   vm_compute in H|-.
   rewrite  <- or_ext_generated.or22_equiv in H|-.
   case H;clear H;intros H.
   injection H;intros ;subst;constructor 21.
   injection H;intros ;subst;constructor 20.
   injection H;intros ;subst;constructor 19.
   injection H;intros ;subst;constructor 18.
   injection H;intros ;subst;constructor 17.
   injection H;intros ;subst;constructor 16.
   injection H;intros ;subst;constructor 15.
   injection H;intros ;subst;constructor 14.
   injection H;intros ;subst;constructor 13.
   injection H;intros ;subst;constructor 12.
   injection H;intros ;subst;constructor 11.
   injection H;intros ;subst;constructor 10.
   injection H;intros ;subst;constructor 9.
   injection H;intros ;subst;constructor 8.
   injection H;intros ;subst;constructor 7.
   injection H;intros ;subst;constructor 6.
   injection H;intros ;subst;constructor 5.
   injection H;intros ;subst;constructor 4.
   injection H;intros ;subst;constructor 3.
   injection H;intros ;subst;constructor 2.
   injection H;intros ;subst;constructor 1.
   elim H.
 Qed.
 
 
 Lemma R_xml_0_non_var : forall x t, ~R_xml_0_rules t (algebra.EQT.T.Var x).
 Proof.
   intros x t H.
   inversion H.
 Qed.
 
 
 Lemma R_xml_0_reg :
  forall s t, 
   (R_xml_0_rules s t) ->
    forall x, In x (algebra.Alg.var_list s) ->In x (algebra.Alg.var_list t).
 Proof.
   intros s t H.
   
   inversion H;intros x Hx;
    (apply (more_list.mem_impl_in (@eq algebra.Alg.variable));[tauto|idtac]);
    apply (more_list.in_impl_mem (@eq algebra.Alg.variable)) in Hx;
    vm_compute in Hx|-*;tauto.
 Qed.
 
 
 Inductive and_6 (x6 x7 x8 x9 x10 x11:Prop) :
  Prop := 
   | conj_6 : x6->x7->x8->x9->x10->x11->and_6 x6 x7 x8 x9 x10 x11
 .
 
 
 Lemma are_constuctors_of_R_xml_0 :
  forall t t', 
   (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) t' t) ->
    and_6 (forall x7 x9, 
           t = (algebra.Alg.Term algebra.F.id_add (x7::x9::nil)) ->
            exists x6,
              exists x8,
                t' = (algebra.Alg.Term algebra.F.id_add (x6::x8::nil))/\ 
                (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
                  x6 x7)/\ 
                (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
                  x8 x9)) 
     (t = (algebra.Alg.Term algebra.F.id_false nil) ->
      t' = (algebra.Alg.Term algebra.F.id_false nil)) 
     (t = (algebra.Alg.Term algebra.F.id_true nil) ->
      t' = (algebra.Alg.Term algebra.F.id_true nil)) 
     (t = (algebra.Alg.Term algebra.F.id_0 nil) ->
      t' = (algebra.Alg.Term algebra.F.id_0 nil)) 
     (forall x7, 
      t = (algebra.Alg.Term algebra.F.id_s (x7::nil)) ->
       exists x6,
         t' = (algebra.Alg.Term algebra.F.id_s (x6::nil))/\ 
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) x6 x7)) 
     
     (t = (algebra.Alg.Term algebra.F.id_nil nil) ->
      t' = (algebra.Alg.Term algebra.F.id_nil nil)).
 Proof.
   intros t t' H.
   
   induction H as [|y IH z z_to_y] using 
   closure_extension.refl_trans_clos_ind2.
   constructor 1.
   intros x7 x9 H;exists x7;exists x9;intuition;constructor 1.
   intros H;intuition;constructor 1.
   intros H;intuition;constructor 1.
   intros H;intuition;constructor 1.
   intros x7 H;exists x7;intuition;constructor 1.
   intros H;intuition;constructor 1.
   inversion z_to_y as [t1 t2 H H0 H1|f l1 l2 H0 H H2];clear z_to_y;subst.
   
   inversion H as [t1 t2 sigma H2 H1 H0];clear H IH;subst;inversion H2;
    clear ;constructor;try (intros until 0 );clear ;intros abs;
    discriminate abs.
   destruct IH as [H_id_add H_id_false H_id_true H_id_0 H_id_s H_id_nil].
   constructor.
   
   clear H_id_false H_id_true H_id_0 H_id_s H_id_nil;intros x7 x9 H;
    injection H;clear H;intros ;subst;
    repeat (
    match goal with
      | H:closure.one_step_list (algebra.EQT.one_step _) _ _ |- _ =>
       inversion H;clear H;subst
      end
    ).
   
   match goal with
     | H:algebra.EQT.one_step _ ?y x7 |- _ =>
      destruct (H_id_add y x9 (refl_equal _)) as [x6 [x8]];intros ;intuition;
       exists x6;exists x8;intuition;
       eapply closure_extension.refl_trans_clos_R;eassumption
     end
   .
   
   match goal with
     | H:algebra.EQT.one_step _ ?y x9 |- _ =>
      destruct (H_id_add x7 y (refl_equal _)) as [x6 [x8]];intros ;intuition;
       exists x6;exists x8;intuition;
       eapply closure_extension.refl_trans_clos_R;eassumption
     end
   .
   
   clear H_id_add H_id_true H_id_0 H_id_s H_id_nil;intros H;injection H;
    clear H;intros ;subst;
    repeat (
    match goal with
      | H:closure.one_step_list (algebra.EQT.one_step _) _ _ |- _ =>
       inversion H;clear H;subst
      end
    ).
   
   clear H_id_add H_id_false H_id_0 H_id_s H_id_nil;intros H;injection H;
    clear H;intros ;subst;
    repeat (
    match goal with
      | H:closure.one_step_list (algebra.EQT.one_step _) _ _ |- _ =>
       inversion H;clear H;subst
      end
    ).
   
   clear H_id_add H_id_false H_id_true H_id_s H_id_nil;intros H;injection H;
    clear H;intros ;subst;
    repeat (
    match goal with
      | H:closure.one_step_list (algebra.EQT.one_step _) _ _ |- _ =>
       inversion H;clear H;subst
      end
    ).
   
   clear H_id_add H_id_false H_id_true H_id_0 H_id_nil;intros x7 H;
    injection H;clear H;intros ;subst;
    repeat (
    match goal with
      | H:closure.one_step_list (algebra.EQT.one_step _) _ _ |- _ =>
       inversion H;clear H;subst
      end
    ).
   
   match goal with
     | H:algebra.EQT.one_step _ ?y x7 |- _ =>
      destruct (H_id_s y (refl_equal _)) as [x6];intros ;intuition;exists x6;
       intuition;eapply closure_extension.refl_trans_clos_R;eassumption
     end
   .
   
   clear H_id_add H_id_false H_id_true H_id_0 H_id_s;intros H;injection H;
    clear H;intros ;subst;
    repeat (
    match goal with
      | H:closure.one_step_list (algebra.EQT.one_step _) _ _ |- _ =>
       inversion H;clear H;subst
      end
    ).
 Qed.
 
 
 Lemma id_add_is_R_xml_0_constructor :
  forall t t', 
   (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) t' t) ->
    forall x7 x9, 
     t = (algebra.Alg.Term algebra.F.id_add (x7::x9::nil)) ->
      exists x6,
        exists x8,
          t' = (algebra.Alg.Term algebra.F.id_add (x6::x8::nil))/\ 
          (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) x6 x7)/\
           
          (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) x8 x9).
 Proof.
   intros t t' H.
   destruct (are_constuctors_of_R_xml_0 H).
   assumption.
 Qed.
 
 
 Lemma id_false_is_R_xml_0_constructor :
  forall t t', 
   (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) t' t) ->
    t = (algebra.Alg.Term algebra.F.id_false nil) ->
     t' = (algebra.Alg.Term algebra.F.id_false nil).
 Proof.
   intros t t' H.
   destruct (are_constuctors_of_R_xml_0 H).
   assumption.
 Qed.
 
 
 Lemma id_true_is_R_xml_0_constructor :
  forall t t', 
   (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) t' t) ->
    t = (algebra.Alg.Term algebra.F.id_true nil) ->
     t' = (algebra.Alg.Term algebra.F.id_true nil).
 Proof.
   intros t t' H.
   destruct (are_constuctors_of_R_xml_0 H).
   assumption.
 Qed.
 
 
 Lemma id_0_is_R_xml_0_constructor :
  forall t t', 
   (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) t' t) ->
    t = (algebra.Alg.Term algebra.F.id_0 nil) ->
     t' = (algebra.Alg.Term algebra.F.id_0 nil).
 Proof.
   intros t t' H.
   destruct (are_constuctors_of_R_xml_0 H).
   assumption.
 Qed.
 
 
 Lemma id_s_is_R_xml_0_constructor :
  forall t t', 
   (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) t' t) ->
    forall x7, 
     t = (algebra.Alg.Term algebra.F.id_s (x7::nil)) ->
      exists x6,
        t' = (algebra.Alg.Term algebra.F.id_s (x6::nil))/\ 
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) x6 x7).
 Proof.
   intros t t' H.
   destruct (are_constuctors_of_R_xml_0 H).
   assumption.
 Qed.
 
 
 Lemma id_nil_is_R_xml_0_constructor :
  forall t t', 
   (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) t' t) ->
    t = (algebra.Alg.Term algebra.F.id_nil nil) ->
     t' = (algebra.Alg.Term algebra.F.id_nil nil).
 Proof.
   intros t t' H.
   destruct (are_constuctors_of_R_xml_0 H).
   assumption.
 Qed.
 
 
 Ltac impossible_star_reduction_R_xml_0  :=
  match goal with
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_add (?x7::?x6::nil)) |- _ =>
     let x7 := fresh "x" in 
      (let x6 := fresh "x" in 
        (let Heq := fresh "Heq" in 
          (let Hred1 := fresh "Hred" in 
            (let Hred2 := fresh "Hred" in 
              (destruct (id_add_is_R_xml_0_constructor H (refl_equal _)) as 
               [x7 [x6 [Heq [Hred2 Hred1]]]];
                (discriminate Heq)||
                (injection Heq;intros ;subst;clear Heq;clear H;
                  impossible_star_reduction_R_xml_0 ))))))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_false nil) |- _ =>
     let Heq := fresh "Heq" in 
      (set (Heq:=id_false_is_R_xml_0_constructor H (refl_equal _)) in *;
        (discriminate Heq)||
        (clearbody Heq;try (subst);try (clear Heq);clear H;
          impossible_star_reduction_R_xml_0 ))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_true nil) |- _ =>
     let Heq := fresh "Heq" in 
      (set (Heq:=id_true_is_R_xml_0_constructor H (refl_equal _)) in *;
        (discriminate Heq)||
        (clearbody Heq;try (subst);try (clear Heq);clear H;
          impossible_star_reduction_R_xml_0 ))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_0 nil) |- _ =>
     let Heq := fresh "Heq" in 
      (set (Heq:=id_0_is_R_xml_0_constructor H (refl_equal _)) in *;
        (discriminate Heq)||
        (clearbody Heq;try (subst);try (clear Heq);clear H;
          impossible_star_reduction_R_xml_0 ))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_s (?x6::nil)) |- _ =>
     let x6 := fresh "x" in 
      (let Heq := fresh "Heq" in 
        (let Hred1 := fresh "Hred" in 
          (destruct (id_s_is_R_xml_0_constructor H (refl_equal _)) as 
           [x6 [Heq Hred1]];
            (discriminate Heq)||
            (injection Heq;intros ;subst;clear Heq;clear H;
              impossible_star_reduction_R_xml_0 ))))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_nil nil) |- _ =>
     let Heq := fresh "Heq" in 
      (set (Heq:=id_nil_is_R_xml_0_constructor H (refl_equal _)) in *;
        (discriminate Heq)||
        (clearbody Heq;try (subst);try (clear Heq);clear H;
          impossible_star_reduction_R_xml_0 ))
    end
  .
 
 
 Ltac simplify_star_reduction_R_xml_0  :=
  match goal with
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_add (?x7::?x6::nil)) |- _ =>
     let x7 := fresh "x" in 
      (let x6 := fresh "x" in 
        (let Heq := fresh "Heq" in 
          (let Hred1 := fresh "Hred" in 
            (let Hred2 := fresh "Hred" in 
              (destruct (id_add_is_R_xml_0_constructor H (refl_equal _)) as 
               [x7 [x6 [Heq [Hred2 Hred1]]]];
                (discriminate Heq)||
                (injection Heq;intros ;subst;clear Heq;clear H;
                  try (simplify_star_reduction_R_xml_0 )))))))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_false nil) |- _ =>
     let Heq := fresh "Heq" in 
      (set (Heq:=id_false_is_R_xml_0_constructor H (refl_equal _)) in *;
        (discriminate Heq)||
        (clearbody Heq;try (subst);try (clear Heq);clear H;
          try (simplify_star_reduction_R_xml_0 )))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_true nil) |- _ =>
     let Heq := fresh "Heq" in 
      (set (Heq:=id_true_is_R_xml_0_constructor H (refl_equal _)) in *;
        (discriminate Heq)||
        (clearbody Heq;try (subst);try (clear Heq);clear H;
          try (simplify_star_reduction_R_xml_0 )))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_0 nil) |- _ =>
     let Heq := fresh "Heq" in 
      (set (Heq:=id_0_is_R_xml_0_constructor H (refl_equal _)) in *;
        (discriminate Heq)||
        (clearbody Heq;try (subst);try (clear Heq);clear H;
          try (simplify_star_reduction_R_xml_0 )))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_s (?x6::nil)) |- _ =>
     let x6 := fresh "x" in 
      (let Heq := fresh "Heq" in 
        (let Hred1 := fresh "Hred" in 
          (destruct (id_s_is_R_xml_0_constructor H (refl_equal _)) as 
           [x6 [Heq Hred1]];
            (discriminate Heq)||
            (injection Heq;intros ;subst;clear Heq;clear H;
              try (simplify_star_reduction_R_xml_0 )))))
    | H:closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_rules) 
         _ (algebra.Alg.Term algebra.F.id_nil nil) |- _ =>
     let Heq := fresh "Heq" in 
      (set (Heq:=id_nil_is_R_xml_0_constructor H (refl_equal _)) in *;
        (discriminate Heq)||
        (clearbody Heq;try (subst);try (clear Heq);clear H;
          try (simplify_star_reduction_R_xml_0 )))
    end
  .
End R_xml_0_deep_rew.

Module InterpGen := interp.Interp(algebra.EQT).

Module ddp := dp.MakeDP(algebra.EQT).

Module SymbType. Definition A := algebra.Alg.F.Symb.A. End SymbType.

Module Symb_more_list := more_list_extention.Make(SymbType)(algebra.Alg.F.Symb).

Module SymbSet := list_set.Make(algebra.F.Symb).

Module Interp.
 Section S.
   Require Import interp.
   
   Hypothesis A : Type.
   
   Hypothesis Ale Alt Aeq : A -> A -> Prop.
   
   Hypothesis Aop : interp.ordering_pair Aeq Alt Ale.
   
   Hypothesis A0 : A.
   
   Notation Local "a <= b" := (Ale a b).
   
   Hypothesis P_id_eq : A ->A ->A.
   
   Hypothesis P_id_add : A ->A ->A.
   
   Hypothesis P_id_false : A.
   
   Hypothesis P_id_if_rm : A ->A ->A ->A.
   
   Hypothesis P_id_true : A.
   
   Hypothesis P_id_if_min : A ->A ->A.
   
   Hypothesis P_id_app : A ->A ->A.
   
   Hypothesis P_id_if_minsort : A ->A ->A ->A.
   
   Hypothesis P_id_0 : A.
   
   Hypothesis P_id_min : A ->A.
   
   Hypothesis P_id_le : A ->A ->A.
   
   Hypothesis P_id_minsort : A ->A ->A.
   
   Hypothesis P_id_s : A ->A.
   
   Hypothesis P_id_rm : A ->A ->A.
   
   Hypothesis P_id_nil : A.
   
   Hypothesis P_id_eq_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
   
   Hypothesis P_id_add_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
   
   Hypothesis P_id_if_rm_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (A0 <= x11)/\ (x11 <= x10) ->
      (A0 <= x9)/\ (x9 <= x8) ->
       (A0 <= x7)/\ (x7 <= x6) ->P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
   
   Hypothesis P_id_if_min_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
   
   Hypothesis P_id_app_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
   
   Hypothesis P_id_if_minsort_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (A0 <= x11)/\ (x11 <= x10) ->
      (A0 <= x9)/\ (x9 <= x8) ->
       (A0 <= x7)/\ (x7 <= x6) ->
        P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
   
   Hypothesis P_id_min_monotonic :
    forall x6 x7, (A0 <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
   
   Hypothesis P_id_le_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
   
   Hypothesis P_id_minsort_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_minsort x7 x9 <= P_id_minsort x6 x8.
   
   Hypothesis P_id_s_monotonic :
    forall x6 x7, (A0 <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
   
   Hypothesis P_id_rm_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
   
   Hypothesis P_id_eq_bounded :
    forall x6 x7, (A0 <= x6) ->(A0 <= x7) ->A0 <= P_id_eq x7 x6.
   
   Hypothesis P_id_add_bounded :
    forall x6 x7, (A0 <= x6) ->(A0 <= x7) ->A0 <= P_id_add x7 x6.
   
   Hypothesis P_id_false_bounded : A0 <= P_id_false .
   
   Hypothesis P_id_if_rm_bounded :
    forall x8 x6 x7, 
     (A0 <= x6) ->(A0 <= x7) ->(A0 <= x8) ->A0 <= P_id_if_rm x8 x7 x6.
   
   Hypothesis P_id_true_bounded : A0 <= P_id_true .
   
   Hypothesis P_id_if_min_bounded :
    forall x6 x7, (A0 <= x6) ->(A0 <= x7) ->A0 <= P_id_if_min x7 x6.
   
   Hypothesis P_id_app_bounded :
    forall x6 x7, (A0 <= x6) ->(A0 <= x7) ->A0 <= P_id_app x7 x6.
   
   Hypothesis P_id_if_minsort_bounded :
    forall x8 x6 x7, 
     (A0 <= x6) ->(A0 <= x7) ->(A0 <= x8) ->A0 <= P_id_if_minsort x8 x7 x6.
   
   Hypothesis P_id_0_bounded : A0 <= P_id_0 .
   
   Hypothesis P_id_min_bounded : forall x6, (A0 <= x6) ->A0 <= P_id_min x6.
   
   Hypothesis P_id_le_bounded :
    forall x6 x7, (A0 <= x6) ->(A0 <= x7) ->A0 <= P_id_le x7 x6.
   
   Hypothesis P_id_minsort_bounded :
    forall x6 x7, (A0 <= x6) ->(A0 <= x7) ->A0 <= P_id_minsort x7 x6.
   
   Hypothesis P_id_s_bounded : forall x6, (A0 <= x6) ->A0 <= P_id_s x6.
   
   Hypothesis P_id_rm_bounded :
    forall x6 x7, (A0 <= x6) ->(A0 <= x7) ->A0 <= P_id_rm x7 x6.
   
   Hypothesis P_id_nil_bounded : A0 <= P_id_nil .
   
   Fixpoint measure t { struct t }  := 
     match t with
       | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
        P_id_eq (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
        P_id_add (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
       | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
        P_id_if_rm (measure x8) (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
       | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
        P_id_if_min (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
        P_id_app (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil)) =>
        P_id_if_minsort (measure x8) (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
       | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
        P_id_min (measure x6)
       | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
        P_id_le (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
        P_id_minsort (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_s (x6::nil)) => P_id_s (measure x6)
       | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
        P_id_rm (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
       | _ => A0
       end.
   
   Lemma measure_equation :
    forall t, 
     measure t = match t with
                   | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                    P_id_eq (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                    P_id_add (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
                   | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                    P_id_if_rm (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                   | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                    P_id_if_min (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                    P_id_app (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                      x6::nil)) =>
                    P_id_if_minsort (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                   | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                    P_id_min (measure x6)
                   | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                    P_id_le (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                    P_id_minsort (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                    P_id_s (measure x6)
                   | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                    P_id_rm (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                   | _ => A0
                   end.
   Proof.
     intros t;case t;intros ;apply refl_equal.
   Qed.
   
   Definition Pols f : InterpGen.Pol_type A (InterpGen.get_arity f) := 
     match f with
       | algebra.F.id_eq => P_id_eq
       | algebra.F.id_add => P_id_add
       | algebra.F.id_false => P_id_false
       | algebra.F.id_if_rm => P_id_if_rm
       | algebra.F.id_true => P_id_true
       | algebra.F.id_if_min => P_id_if_min
       | algebra.F.id_app => P_id_app
       | algebra.F.id_if_minsort => P_id_if_minsort
       | algebra.F.id_0 => P_id_0
       | algebra.F.id_min => P_id_min
       | algebra.F.id_le => P_id_le
       | algebra.F.id_minsort => P_id_minsort
       | algebra.F.id_s => P_id_s
       | algebra.F.id_rm => P_id_rm
       | algebra.F.id_nil => P_id_nil
       end.
   
   Lemma same_measure : forall t, measure t = InterpGen.measure A0 Pols t.
   Proof.
     fix 1 .
     intros [a| f l].
     simpl in |-*.
     unfold eq_rect_r, eq_rect, sym_eq in |-*.
     reflexivity .
     
     refine match f with
              | algebra.F.id_eq =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_add =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_false => match l with
                                        | nil => _
                                        | _::_ => _
                                        end
              | algebra.F.id_if_rm =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::nil => _
                 | _::_::_::_::_ => _
                 end
              | algebra.F.id_true => match l with
                                       | nil => _
                                       | _::_ => _
                                       end
              | algebra.F.id_if_min =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_app =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_if_minsort =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::nil => _
                 | _::_::_::_::_ => _
                 end
              | algebra.F.id_0 => match l with
                                    | nil => _
                                    | _::_ => _
                                    end
              | algebra.F.id_min =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::_ => _
                 end
              | algebra.F.id_le =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_minsort =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_s =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::_ => _
                 end
              | algebra.F.id_rm =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_nil => match l with
                                      | nil => _
                                      | _::_ => _
                                      end
              end;simpl in |-*;unfold eq_rect_r, eq_rect, sym_eq in |-*;
      try (reflexivity );f_equal ;auto.
   Qed.
   
   Lemma measure_bounded : forall t, A0 <= measure t.
   Proof.
     intros t.
     rewrite same_measure in |-*.
     apply (InterpGen.measure_bounded Aop).
     intros f.
     case f.
     vm_compute in |-*;intros ;apply P_id_eq_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_add_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_false_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_rm_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_true_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_min_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_app_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_minsort_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_0_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_min_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_le_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_minsort_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_s_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_rm_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_nil_bounded;assumption.
   Qed.
   
   Ltac generate_pos_hyp  :=
    match goal with
      | H:context [measure ?x] |- _ =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      |  |- context [measure ?x] =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      end
    .
   
   Hypothesis rules_monotonic :
    forall l r, 
     (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
      measure r <= measure l.
   
   Lemma measure_star_monotonic :
    forall l r, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                r l) ->measure r <= measure l.
   Proof.
     intros .
     do 2 (rewrite same_measure in |-*).
     
     apply InterpGen.measure_star_monotonic with (1:=Aop) (Pols:=Pols) 
     (rules:=R_xml_0_deep_rew.R_xml_0_rules).
     intros f.
     case f.
     vm_compute in |-*;intros ;apply P_id_eq_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_add_monotonic;assumption.
     vm_compute in |-*;apply (Aop.(le_refl)).
     vm_compute in |-*;intros ;apply P_id_if_rm_monotonic;assumption.
     vm_compute in |-*;apply (Aop.(le_refl)).
     vm_compute in |-*;intros ;apply P_id_if_min_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_app_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_if_minsort_monotonic;assumption.
     vm_compute in |-*;apply (Aop.(le_refl)).
     vm_compute in |-*;intros ;apply P_id_min_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_le_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_minsort_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_s_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_rm_monotonic;assumption.
     vm_compute in |-*;apply (Aop.(le_refl)).
     intros f.
     case f.
     vm_compute in |-*;intros ;apply P_id_eq_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_add_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_false_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_rm_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_true_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_min_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_app_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_minsort_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_0_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_min_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_le_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_minsort_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_s_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_rm_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_nil_bounded;assumption.
     intros .
     do 2 (rewrite  <- same_measure in |-*).
     apply rules_monotonic;assumption.
     assumption.
   Qed.
   
   Hypothesis P_id_LE : A ->A ->A.
   
   Hypothesis P_id_RM : A ->A ->A.
   
   Hypothesis P_id_MIN : A ->A.
   
   Hypothesis P_id_MINSORT : A ->A ->A.
   
   Hypothesis P_id_APP : A ->A ->A.
   
   Hypothesis P_id_IF_RM : A ->A ->A ->A.
   
   Hypothesis P_id_IF_MIN : A ->A ->A.
   
   Hypothesis P_id_IF_MINSORT : A ->A ->A ->A.
   
   Hypothesis P_id_EQ : A ->A ->A.
   
   Hypothesis P_id_LE_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
   
   Hypothesis P_id_RM_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
   
   Hypothesis P_id_MIN_monotonic :
    forall x6 x7, (A0 <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
   
   Hypothesis P_id_MINSORT_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
   
   Hypothesis P_id_APP_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
   
   Hypothesis P_id_IF_RM_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (A0 <= x11)/\ (x11 <= x10) ->
      (A0 <= x9)/\ (x9 <= x8) ->
       (A0 <= x7)/\ (x7 <= x6) ->P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
   
   Hypothesis P_id_IF_MIN_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
   
   Hypothesis P_id_IF_MINSORT_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (A0 <= x11)/\ (x11 <= x10) ->
      (A0 <= x9)/\ (x9 <= x8) ->
       (A0 <= x7)/\ (x7 <= x6) ->
        P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
   
   Hypothesis P_id_EQ_monotonic :
    forall x8 x6 x9 x7, 
     (A0 <= x9)/\ (x9 <= x8) ->
      (A0 <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
   
   Definition marked_measure t := 
     match t with
       | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
        P_id_LE (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
        P_id_RM (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
        P_id_MIN (measure x6)
       | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
        P_id_MINSORT (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
        P_id_APP (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
        P_id_IF_RM (measure x8) (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
        P_id_IF_MIN (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil)) =>
        P_id_IF_MINSORT (measure x8) (measure x7) (measure x6)
       | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
        P_id_EQ (measure x7) (measure x6)
       | _ => measure t
       end.
   
   Definition  Marked_pols :
    forall f, 
     (algebra.EQT.defined R_xml_0_deep_rew.R_xml_0_rules f) ->
      InterpGen.Pol_type A (InterpGen.get_arity f).
   Proof.
     intros f H.
     
     apply ddp.defined_list_complete with (1:=R_xml_0_deep_rew.R_xml_0_rules_included) in H .
     apply (Symb_more_list.change_in algebra.F.symb_order) in H .
     
     set (u := (Symb_more_list.qs algebra.F.symb_order
           (Symb_more_list.XSet.remove_red
              (ddp.defined_list R_xml_0_deep_rew.R_xml_0_rule_as_list)))) in * .
     vm_compute in u .
     unfold u in * .
     clear u .
     unfold more_list.mem_bool in H .
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x7 x6;apply (P_id_RM x7 x6).
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x7 x6;apply (P_id_MINSORT x7 x6).
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x7 x6;apply (P_id_LE x7 x6).
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x6;apply (P_id_MIN x6).
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x8 x7 x6;apply (P_id_IF_MINSORT x8 x7 x6).
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x7 x6;apply (P_id_APP x7 x6).
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x7 x6;apply (P_id_IF_MIN x7 x6).
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x8 x7 x6;apply (P_id_IF_RM x8 x7 x6).
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros x7 x6;apply (P_id_EQ x7 x6).
     discriminate H.
   Defined.
   
   Lemma same_marked_measure :
    forall t, 
     marked_measure t = InterpGen.marked_measure A0 Pols Marked_pols 
                         (ddp.defined_dec _ _ 
                           R_xml_0_deep_rew.R_xml_0_rules_included) t.
   Proof.
     intros [a| f l].
     simpl in |-*.
     unfold eq_rect_r, eq_rect, sym_eq in |-*.
     reflexivity .
     
     refine match f with
              | algebra.F.id_eq =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_add =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_false => match l with
                                        | nil => _
                                        | _::_ => _
                                        end
              | algebra.F.id_if_rm =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::nil => _
                 | _::_::_::_::_ => _
                 end
              | algebra.F.id_true => match l with
                                       | nil => _
                                       | _::_ => _
                                       end
              | algebra.F.id_if_min =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_app =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_if_minsort =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::nil => _
                 | _::_::_::_::_ => _
                 end
              | algebra.F.id_0 => match l with
                                    | nil => _
                                    | _::_ => _
                                    end
              | algebra.F.id_min =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::_ => _
                 end
              | algebra.F.id_le =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_minsort =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_s =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::_ => _
                 end
              | algebra.F.id_rm =>
               match l with
                 | nil => _
                 | _::nil => _
                 | _::_::nil => _
                 | _::_::_::_ => _
                 end
              | algebra.F.id_nil => match l with
                                      | nil => _
                                      | _::_ => _
                                      end
              end.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     
     lazy - [measure InterpGen.measure Pols] in |-* ;f_equal ;
      apply same_measure.
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
     vm_compute in |-*;reflexivity .
   Qed.
   
   Lemma marked_measure_equation :
    forall t, 
     marked_measure t = match t with
                          | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                           P_id_LE (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                           P_id_RM (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                           P_id_MIN (measure x6)
                          | (algebra.Alg.Term algebra.F.id_minsort (x7::
                             x6::nil)) =>
                           P_id_MINSORT (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                           P_id_APP (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                             x6::nil)) =>
                           P_id_IF_RM (measure x8) (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_min (x7::
                             x6::nil)) =>
                           P_id_IF_MIN (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                             x7::x6::nil)) =>
                           P_id_IF_MINSORT (measure x8) (measure x7) 
                            (measure x6)
                          | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                           P_id_EQ (measure x7) (measure x6)
                          | _ => measure t
                          end.
   Proof.
     reflexivity .
   Qed.
   
   Lemma marked_measure_star_monotonic :
    forall f l1 l2, 
     (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                       R_xml_0_deep_rew.R_xml_0_rules)
                                                      ) l1 l2) ->
      marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                 f l2).
   Proof.
     intros .
     do 2 (rewrite same_marked_measure in |-*).
     
     apply InterpGen.marked_measure_star_monotonic with (1:=Aop) (Pols:=
     Pols) (rules:=R_xml_0_deep_rew.R_xml_0_rules).
     clear f.
     intros f.
     case f.
     vm_compute in |-*;intros ;apply P_id_eq_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_add_monotonic;assumption.
     vm_compute in |-*;apply (Aop.(le_refl)).
     vm_compute in |-*;intros ;apply P_id_if_rm_monotonic;assumption.
     vm_compute in |-*;apply (Aop.(le_refl)).
     vm_compute in |-*;intros ;apply P_id_if_min_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_app_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_if_minsort_monotonic;assumption.
     vm_compute in |-*;apply (Aop.(le_refl)).
     vm_compute in |-*;intros ;apply P_id_min_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_le_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_minsort_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_s_monotonic;assumption.
     vm_compute in |-*;intros ;apply P_id_rm_monotonic;assumption.
     vm_compute in |-*;apply (Aop.(le_refl)).
     clear f.
     intros f.
     case f.
     vm_compute in |-*;intros ;apply P_id_eq_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_add_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_false_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_rm_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_true_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_min_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_app_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_if_minsort_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_0_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_min_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_le_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_minsort_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_s_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_rm_bounded;assumption.
     vm_compute in |-*;intros ;apply P_id_nil_bounded;assumption.
     intros .
     do 2 (rewrite  <- same_measure in |-*).
     apply rules_monotonic;assumption.
     clear f.
     intros f.
     clear H.
     intros H.
     generalize H.
     
     apply ddp.defined_list_complete with (1:=R_xml_0_deep_rew.R_xml_0_rules_included) in H .
     apply (Symb_more_list.change_in algebra.F.symb_order) in H .
     
     set (u := (Symb_more_list.qs algebra.F.symb_order
           (Symb_more_list.XSet.remove_red
              (ddp.defined_list R_xml_0_deep_rew.R_xml_0_rule_as_list)))) in * .
     vm_compute in u .
     unfold u in * .
     clear u .
     unfold more_list.mem_bool in H .
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_RM_monotonic;assumption.
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_MINSORT_monotonic;assumption.
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_LE_monotonic;assumption.
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_MIN_monotonic;assumption.
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_IF_MINSORT_monotonic;assumption.
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_APP_monotonic;assumption.
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_IF_MIN_monotonic;assumption.
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_IF_RM_monotonic;assumption.
     
     match type of H with 
       | orb ?a ?b = true => 
         assert (H':{a = true}+{b = true});[
           revert H;case a;[left;reflexivity|simpl;intros h;right;exact h]|
             clear H;destruct H' as [H|H]]
     end .
     
     match type of H with 
       | _ _ ?t = true =>
         generalize (algebra.F.symb_eq_bool_ok f t);
           unfold algebra.Alg.eq_symb_bool in H;
           rewrite H;clear H;intros ;subst
     end .
     vm_compute in |-*;intros ;apply P_id_EQ_monotonic;assumption.
     discriminate H.
     assumption.
   Qed.
   
   End S.
End Interp.

Module InterpZ.
 Section S.
   Open Scope Z_scope.
   
   Hypothesis min_value : Z.
   
   Import ring_extention.
   
   Notation Local "'Alt'" := (Zwf.Zwf min_value).
   
   Notation Local "'Ale'" := Zle.
   
   Notation Local "'Aeq'" := (@eq Z).
   
   Notation Local "a <= b" := (Ale a b).
   
   Notation Local "a < b" := (Alt a b).
   
   Hypothesis P_id_eq : Z ->Z ->Z.
   
   Hypothesis P_id_add : Z ->Z ->Z.
   
   Hypothesis P_id_false : Z.
   
   Hypothesis P_id_if_rm : Z ->Z ->Z ->Z.
   
   Hypothesis P_id_true : Z.
   
   Hypothesis P_id_if_min : Z ->Z ->Z.
   
   Hypothesis P_id_app : Z ->Z ->Z.
   
   Hypothesis P_id_if_minsort : Z ->Z ->Z ->Z.
   
   Hypothesis P_id_0 : Z.
   
   Hypothesis P_id_min : Z ->Z.
   
   Hypothesis P_id_le : Z ->Z ->Z.
   
   Hypothesis P_id_minsort : Z ->Z ->Z.
   
   Hypothesis P_id_s : Z ->Z.
   
   Hypothesis P_id_rm : Z ->Z ->Z.
   
   Hypothesis P_id_nil : Z.
   
   Hypothesis P_id_eq_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
   
   Hypothesis P_id_add_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
   
   Hypothesis P_id_if_rm_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (min_value <= x11)/\ (x11 <= x10) ->
      (min_value <= x9)/\ (x9 <= x8) ->
       (min_value <= x7)/\ (x7 <= x6) ->
        P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
   
   Hypothesis P_id_if_min_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
   
   Hypothesis P_id_app_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
   
   Hypothesis P_id_if_minsort_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (min_value <= x11)/\ (x11 <= x10) ->
      (min_value <= x9)/\ (x9 <= x8) ->
       (min_value <= x7)/\ (x7 <= x6) ->
        P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
   
   Hypothesis P_id_min_monotonic :
    forall x6 x7, (min_value <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
   
   Hypothesis P_id_le_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
   
   Hypothesis P_id_minsort_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->
       P_id_minsort x7 x9 <= P_id_minsort x6 x8.
   
   Hypothesis P_id_s_monotonic :
    forall x6 x7, (min_value <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
   
   Hypothesis P_id_rm_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
   
   Hypothesis P_id_eq_bounded :
    forall x6 x7, 
     (min_value <= x6) ->(min_value <= x7) ->min_value <= P_id_eq x7 x6.
   
   Hypothesis P_id_add_bounded :
    forall x6 x7, 
     (min_value <= x6) ->(min_value <= x7) ->min_value <= P_id_add x7 x6.
   
   Hypothesis P_id_false_bounded : min_value <= P_id_false .
   
   Hypothesis P_id_if_rm_bounded :
    forall x8 x6 x7, 
     (min_value <= x6) ->
      (min_value <= x7) ->
       (min_value <= x8) ->min_value <= P_id_if_rm x8 x7 x6.
   
   Hypothesis P_id_true_bounded : min_value <= P_id_true .
   
   Hypothesis P_id_if_min_bounded :
    forall x6 x7, 
     (min_value <= x6) ->(min_value <= x7) ->min_value <= P_id_if_min x7 x6.
   
   Hypothesis P_id_app_bounded :
    forall x6 x7, 
     (min_value <= x6) ->(min_value <= x7) ->min_value <= P_id_app x7 x6.
   
   Hypothesis P_id_if_minsort_bounded :
    forall x8 x6 x7, 
     (min_value <= x6) ->
      (min_value <= x7) ->
       (min_value <= x8) ->min_value <= P_id_if_minsort x8 x7 x6.
   
   Hypothesis P_id_0_bounded : min_value <= P_id_0 .
   
   Hypothesis P_id_min_bounded :
    forall x6, (min_value <= x6) ->min_value <= P_id_min x6.
   
   Hypothesis P_id_le_bounded :
    forall x6 x7, 
     (min_value <= x6) ->(min_value <= x7) ->min_value <= P_id_le x7 x6.
   
   Hypothesis P_id_minsort_bounded :
    forall x6 x7, 
     (min_value <= x6) ->(min_value <= x7) ->min_value <= P_id_minsort x7 x6.
   
   Hypothesis P_id_s_bounded :
    forall x6, (min_value <= x6) ->min_value <= P_id_s x6.
   
   Hypothesis P_id_rm_bounded :
    forall x6 x7, 
     (min_value <= x6) ->(min_value <= x7) ->min_value <= P_id_rm x7 x6.
   
   Hypothesis P_id_nil_bounded : min_value <= P_id_nil .
   
   Definition measure  := 
     Interp.measure min_value P_id_eq P_id_add P_id_false P_id_if_rm 
      P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
      P_id_le P_id_minsort P_id_s P_id_rm P_id_nil.
   
   Lemma measure_equation :
    forall t, 
     measure t = match t with
                   | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                    P_id_eq (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                    P_id_add (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
                   | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                    P_id_if_rm (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                   | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                    P_id_if_min (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                    P_id_app (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                      x6::nil)) =>
                    P_id_if_minsort (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                   | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                    P_id_min (measure x6)
                   | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                    P_id_le (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                    P_id_minsort (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                    P_id_s (measure x6)
                   | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                    P_id_rm (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                   | _ => min_value
                   end.
   Proof.
     intros t;case t;intros ;apply refl_equal.
   Qed.
   
   Lemma measure_bounded : forall t, min_value <= measure t.
   Proof.
     unfold measure in |-*.
     
     apply Interp.measure_bounded with Alt Aeq;
      (apply interp.o_Z)||
      (cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;auto with zarith).
   Qed.
   
   Ltac generate_pos_hyp  :=
    match goal with
      | H:context [measure ?x] |- _ =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      |  |- context [measure ?x] =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      end
    .
   
   Hypothesis rules_monotonic :
    forall l r, 
     (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
      measure r <= measure l.
   
   Lemma measure_star_monotonic :
    forall l r, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                r l) ->measure r <= measure l.
   Proof.
     unfold measure in *.
     apply Interp.measure_star_monotonic with Alt Aeq.
     
     (apply interp.o_Z)||
     (cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;auto with zarith).
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
   Qed.
   
   Hypothesis P_id_LE : Z ->Z ->Z.
   
   Hypothesis P_id_RM : Z ->Z ->Z.
   
   Hypothesis P_id_MIN : Z ->Z.
   
   Hypothesis P_id_MINSORT : Z ->Z ->Z.
   
   Hypothesis P_id_APP : Z ->Z ->Z.
   
   Hypothesis P_id_IF_RM : Z ->Z ->Z ->Z.
   
   Hypothesis P_id_IF_MIN : Z ->Z ->Z.
   
   Hypothesis P_id_IF_MINSORT : Z ->Z ->Z ->Z.
   
   Hypothesis P_id_EQ : Z ->Z ->Z.
   
   Hypothesis P_id_LE_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
   
   Hypothesis P_id_RM_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
   
   Hypothesis P_id_MIN_monotonic :
    forall x6 x7, (min_value <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
   
   Hypothesis P_id_MINSORT_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->
       P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
   
   Hypothesis P_id_APP_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
   
   Hypothesis P_id_IF_RM_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (min_value <= x11)/\ (x11 <= x10) ->
      (min_value <= x9)/\ (x9 <= x8) ->
       (min_value <= x7)/\ (x7 <= x6) ->
        P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
   
   Hypothesis P_id_IF_MIN_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
   
   Hypothesis P_id_IF_MINSORT_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (min_value <= x11)/\ (x11 <= x10) ->
      (min_value <= x9)/\ (x9 <= x8) ->
       (min_value <= x7)/\ (x7 <= x6) ->
        P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
   
   Hypothesis P_id_EQ_monotonic :
    forall x8 x6 x9 x7, 
     (min_value <= x9)/\ (x9 <= x8) ->
      (min_value <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
   
   Definition marked_measure  := 
     Interp.marked_measure min_value P_id_eq P_id_add P_id_false P_id_if_rm 
      P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
      P_id_le P_id_minsort P_id_s P_id_rm P_id_nil P_id_LE P_id_RM P_id_MIN 
      P_id_MINSORT P_id_APP P_id_IF_RM P_id_IF_MIN P_id_IF_MINSORT P_id_EQ.
   
   Lemma marked_measure_equation :
    forall t, 
     marked_measure t = match t with
                          | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                           P_id_LE (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                           P_id_RM (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                           P_id_MIN (measure x6)
                          | (algebra.Alg.Term algebra.F.id_minsort (x7::
                             x6::nil)) =>
                           P_id_MINSORT (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                           P_id_APP (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                             x6::nil)) =>
                           P_id_IF_RM (measure x8) (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_min (x7::
                             x6::nil)) =>
                           P_id_IF_MIN (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                             x7::x6::nil)) =>
                           P_id_IF_MINSORT (measure x8) (measure x7) 
                            (measure x6)
                          | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                           P_id_EQ (measure x7) (measure x6)
                          | _ => measure t
                          end.
   Proof.
     reflexivity .
   Qed.
   
   Lemma marked_measure_star_monotonic :
    forall f l1 l2, 
     (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                       R_xml_0_deep_rew.R_xml_0_rules)
                                                      ) l1 l2) ->
      marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                 f l2).
   Proof.
     unfold marked_measure in *.
     apply Interp.marked_measure_star_monotonic with Alt Aeq.
     
     (apply interp.o_Z)||
     (cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;auto with zarith).
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
     intros ;apply P_id_LE_monotonic;assumption.
     intros ;apply P_id_RM_monotonic;assumption.
     intros ;apply P_id_MIN_monotonic;assumption.
     intros ;apply P_id_MINSORT_monotonic;assumption.
     intros ;apply P_id_APP_monotonic;assumption.
     intros ;apply P_id_IF_RM_monotonic;assumption.
     intros ;apply P_id_IF_MIN_monotonic;assumption.
     intros ;apply P_id_IF_MINSORT_monotonic;assumption.
     intros ;apply P_id_EQ_monotonic;assumption.
   Qed.
   
   End S.
End InterpZ.

Module WF_R_xml_0_deep_rew.
 Inductive DP_R_xml_0  :
  algebra.Alg.term ->algebra.Alg.term ->Prop := 
    (* <eq(s(x_),s(y_)),eq(x_,y_)> *)
   | DP_R_xml_0_0 :
    forall x2 x6 x1 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_s (x1::nil)) 
       x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_s (x2::nil)) 
        x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_eq (x1::x2::nil)) 
        (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil))
    (* <le(s(x_),s(y_)),le(x_,y_)> *)
   | DP_R_xml_0_1 :
    forall x2 x6 x1 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_s (x1::nil)) 
       x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_s (x2::nil)) 
        x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_le (x1::x2::nil)) 
        (algebra.Alg.Term algebra.F.id_le (x7::x6::nil))
    (* <app(add(n_,x_),y_),app(x_,y_)> *)
   | DP_R_xml_0_2 :
    forall x2 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                
       (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 x2 x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_app (x1::x2::nil)) 
        (algebra.Alg.Term algebra.F.id_app (x7::x6::nil))
   
    (* <min(add(n_,add(m_,x_))),if_min(le(n_,m_),add(n_,add(m_,x_)))> *)
   | DP_R_xml_0_3 :
    forall x4 x6 x1 x3, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                
       (algebra.Alg.Term algebra.F.id_add (x3::(algebra.Alg.Term 
        algebra.F.id_add (x4::x1::nil))::nil)) x6) ->
      DP_R_xml_0 (algebra.Alg.Term algebra.F.id_if_min ((algebra.Alg.Term 
                  algebra.F.id_le (x3::x4::nil))::(algebra.Alg.Term 
                  algebra.F.id_add (x3::(algebra.Alg.Term algebra.F.id_add 
                  (x4::x1::nil))::nil))::nil)) 
       (algebra.Alg.Term algebra.F.id_min (x6::nil))
    (* <min(add(n_,add(m_,x_))),le(n_,m_)> *)
   | DP_R_xml_0_4 :
    forall x4 x6 x1 x3, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                
       (algebra.Alg.Term algebra.F.id_add (x3::(algebra.Alg.Term 
        algebra.F.id_add (x4::x1::nil))::nil)) x6) ->
      DP_R_xml_0 (algebra.Alg.Term algebra.F.id_le (x3::x4::nil)) 
       (algebra.Alg.Term algebra.F.id_min (x6::nil))
    (* <if_min(true,add(n_,add(m_,x_))),min(add(n_,x_))> *)
   | DP_R_xml_0_5 :
    forall x4 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_true nil) 
       x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::(algebra.Alg.Term 
         algebra.F.id_add (x4::x1::nil))::nil)) x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term 
                   algebra.F.id_add (x3::x1::nil))::nil)) 
        (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil))
    (* <if_min(false,add(n_,add(m_,x_))),min(add(m_,x_))> *)
   | DP_R_xml_0_6 :
    forall x4 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_false nil) 
       x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::(algebra.Alg.Term 
         algebra.F.id_add (x4::x1::nil))::nil)) x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term 
                   algebra.F.id_add (x4::x1::nil))::nil)) 
        (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil))
    (* <rm(n_,add(m_,x_)),if_rm(eq(n_,m_),n_,add(m_,x_))> *)
   | DP_R_xml_0_7 :
    forall x4 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                x3 x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_if_rm ((algebra.Alg.Term 
                   algebra.F.id_eq (x3::x4::nil))::x3::(algebra.Alg.Term 
                   algebra.F.id_add (x4::x1::nil))::nil)) 
        (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil))
    (* <rm(n_,add(m_,x_)),eq(n_,m_)> *)
   | DP_R_xml_0_8 :
    forall x4 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                x3 x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_eq (x3::x4::nil)) 
        (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil))
    (* <if_rm(true,n_,add(m_,x_)),rm(n_,x_)> *)
   | DP_R_xml_0_9 :
    forall x8 x4 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_true nil) 
       x8) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 x3 x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
        DP_R_xml_0 (algebra.Alg.Term algebra.F.id_rm (x3::x1::nil)) 
         (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil))
    (* <if_rm(false,n_,add(m_,x_)),rm(n_,x_)> *)
   | DP_R_xml_0_10 :
    forall x8 x4 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_false nil) 
       x8) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 x3 x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
        DP_R_xml_0 (algebra.Alg.Term algebra.F.id_rm (x3::x1::nil)) 
         (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil))
   
    (* <minsort(add(n_,x_),y_),if_minsort(eq(n_,min(add(n_,x_))),add(n_,x_),y_)> *)
   | DP_R_xml_0_11 :
    forall x2 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                
       (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 x2 x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_if_minsort 
                   ((algebra.Alg.Term algebra.F.id_eq (x3::(algebra.Alg.Term 
                   algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add (x3::
                   x1::nil))::nil))::nil))::(algebra.Alg.Term 
                   algebra.F.id_add (x3::x1::nil))::x2::nil)) 
        (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil))
    (* <minsort(add(n_,x_),y_),eq(n_,min(add(n_,x_)))> *)
   | DP_R_xml_0_12 :
    forall x2 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                
       (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 x2 x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_eq (x3::(algebra.Alg.Term 
                   algebra.F.id_min ((algebra.Alg.Term algebra.F.id_add (x3::
                   x1::nil))::nil))::nil)) 
        (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil))
    (* <minsort(add(n_,x_),y_),min(add(n_,x_))> *)
   | DP_R_xml_0_13 :
    forall x2 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                
       (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 x2 x6) ->
       DP_R_xml_0 (algebra.Alg.Term algebra.F.id_min ((algebra.Alg.Term 
                   algebra.F.id_add (x3::x1::nil))::nil)) 
        (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil))
   
    (* <if_minsort(true,add(n_,x_),y_),minsort(app(rm(n_,x_),y_),nil)> *)
   | DP_R_xml_0_14 :
    forall x8 x2 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_true nil) 
       x8) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x2 x6) ->
        DP_R_xml_0 (algebra.Alg.Term algebra.F.id_minsort ((algebra.Alg.Term 
                    algebra.F.id_app ((algebra.Alg.Term algebra.F.id_rm (x3::
                    x1::nil))::x2::nil))::(algebra.Alg.Term algebra.F.id_nil 
                    nil)::nil)) 
         (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
    (* <if_minsort(true,add(n_,x_),y_),app(rm(n_,x_),y_)> *)
   | DP_R_xml_0_15 :
    forall x8 x2 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_true nil) 
       x8) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x2 x6) ->
        DP_R_xml_0 (algebra.Alg.Term algebra.F.id_app ((algebra.Alg.Term 
                    algebra.F.id_rm (x3::x1::nil))::x2::nil)) 
         (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
    (* <if_minsort(true,add(n_,x_),y_),rm(n_,x_)> *)
   | DP_R_xml_0_16 :
    forall x8 x2 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_true nil) 
       x8) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x2 x6) ->
        DP_R_xml_0 (algebra.Alg.Term algebra.F.id_rm (x3::x1::nil)) 
         (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
   
    (* <if_minsort(false,add(n_,x_),y_),minsort(x_,add(n_,y_))> *)
   | DP_R_xml_0_17 :
    forall x8 x2 x6 x1 x3 x7, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                (algebra.Alg.Term algebra.F.id_false nil) 
       x8) ->
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x2 x6) ->
        DP_R_xml_0 (algebra.Alg.Term algebra.F.id_minsort (x1::
                    (algebra.Alg.Term algebra.F.id_add (x3::x2::nil))::nil)) 
         (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
 .
 
 Module ddp := dp.MakeDP(algebra.EQT).
 
 
 Lemma R_xml_0_dp_step_spec :
  forall x y, 
   (ddp.dp_step R_xml_0_deep_rew.R_xml_0_rules x y) ->
    exists f,
      exists l1,
        exists l2,
          y = algebra.Alg.Term f l2/\ 
          (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                            R_xml_0_deep_rew.R_xml_0_rules)
                                                           ) l1 l2)/\ 
          (ddp.dp R_xml_0_deep_rew.R_xml_0_rules x (algebra.Alg.Term f l1)).
 Proof.
   intros x y H.
   induction H.
   inversion H.
   subst.
   destruct t0.
   refine ((False_ind) _ _).
   refine (R_xml_0_deep_rew.R_xml_0_non_var H0).
   simpl in H|-*.
   exists a.
   exists ((List.map) (algebra.Alg.apply_subst sigma) l).
   exists ((List.map) (algebra.Alg.apply_subst sigma) l).
   repeat (constructor).
   assumption.
   exists f.
   exists l2.
   exists l1.
   constructor.
   constructor.
   constructor.
   constructor.
   rewrite  <- closure.rwr_list_trans_clos_one_step_list.
   assumption.
   assumption.
 Qed.
 
 
 Ltac included_dp_tac H :=
  injection H;clear H;intros;subst;
  repeat (match goal with 
  | H: closure.refl_trans_clos (closure.one_step_list _) (_::_) _ |- _=>           
  let x := fresh "x" in 
  let l := fresh "l" in 
  let h1 := fresh "h" in 
  let h2 := fresh "h" in 
  let h3 := fresh "h" in 
  destruct (@algebra.EQT_ext.one_step_list_star_decompose_cons _ _ _ _  H) as [x [l[h1[h2 h3]]]];clear H;subst
  | H: closure.refl_trans_clos (closure.one_step_list _) nil _ |- _ => 
  rewrite (@algebra.EQT_ext.one_step_list_star_decompose_nil _ _ H) in *;clear H
  end
  );simpl;
  econstructor eassumption
 .
 
 
 Ltac dp_concl_tac h2 h cont_tac 
  t :=
  match t with
    | False => let h' := fresh "a" in 
                (set (h':=t) in *;cont_tac h';
                  repeat (
                  let e := type of h in 
                   (match e with
                      | ?t => unfold t in h|-;
                               (case h;
                                [abstract (clear h;intros h;injection h;
                                            clear h;intros ;subst;
                                            included_dp_tac h2)|
                                clear h;intros h;clear t])
                      | ?t => unfold t in h|-;elim h
                      end
                    )
                  ))
    | or ?a ?b => let cont_tac 
                   h' := let h'' := fresh "a" in 
                          (set (h'':=or a h') in *;cont_tac h'') in 
                   (dp_concl_tac h2 h cont_tac b)
    end
  .
 
 
 Module WF_DP_R_xml_0.
  Inductive DP_R_xml_0_scc_1  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <app(add(n_,x_),y_),app(x_,y_)> *)
    | DP_R_xml_0_scc_1_0 :
     forall x2 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x2 x6) ->
        DP_R_xml_0_scc_1 (algebra.Alg.Term algebra.F.id_app (x1::x2::nil)) 
         (algebra.Alg.Term algebra.F.id_app (x7::x6::nil))
  .
  
  
  Module WF_DP_R_xml_0_scc_1.
   Open Scope Z_scope.
   
   Import ring_extention.
   
   Notation Local "a <= b" := (Zle a b).
   
   Notation Local "a < b" := (Zlt a b).
   
   Definition P_id_eq (x6:Z) (x7:Z) := 2.
   
   Definition P_id_add (x6:Z) (x7:Z) := 1 + 1* x6 + 1* x7.
   
   Definition P_id_false  := 2.
   
   Definition P_id_if_rm (x6:Z) (x7:Z) (x8:Z) := 1* x8.
   
   Definition P_id_true  := 0.
   
   Definition P_id_if_min (x6:Z) (x7:Z) := 2* x7.
   
   Definition P_id_app (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_if_minsort (x6:Z) (x7:Z) (x8:Z) := 2* x7 + 2* x8.
   
   Definition P_id_0  := 1.
   
   Definition P_id_min (x6:Z) := 1 + 2* x6.
   
   Definition P_id_le (x6:Z) (x7:Z) := 3* x7.
   
   Definition P_id_minsort (x6:Z) (x7:Z) := 2* x6 + 2* x7.
   
   Definition P_id_s (x6:Z) := 3* x6.
   
   Definition P_id_rm (x6:Z) (x7:Z) := 1* x7.
   
   Definition P_id_nil  := 0.
   
   Lemma P_id_eq_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_minsort x7 x9 <= P_id_minsort x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_eq_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_eq x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_add x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_false_bounded : 0 <= P_id_false .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_rm x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_true_bounded : 0 <= P_id_true .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_if_min x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_app x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_minsort x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_0_bounded : 0 <= P_id_0 .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_bounded : forall x6, (0 <= x6) ->0 <= P_id_min x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_le x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_minsort x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_bounded : forall x6, (0 <= x6) ->0 <= P_id_s x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_rm x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_nil_bounded : 0 <= P_id_nil .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition measure  := 
     InterpZ.measure 0 P_id_eq P_id_add P_id_false P_id_if_rm P_id_true 
      P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min P_id_le 
      P_id_minsort P_id_s P_id_rm P_id_nil.
   
   Lemma measure_equation :
    forall t, 
     measure t = match t with
                   | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                    P_id_eq (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                    P_id_add (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
                   | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                    P_id_if_rm (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                   | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                    P_id_if_min (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                    P_id_app (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                      x6::nil)) =>
                    P_id_if_minsort (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                   | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                    P_id_min (measure x6)
                   | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                    P_id_le (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                    P_id_minsort (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                    P_id_s (measure x6)
                   | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                    P_id_rm (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                   | _ => 0
                   end.
   Proof.
     intros t;case t;intros ;apply refl_equal.
   Qed.
   
   Lemma measure_bounded : forall t, 0 <= measure t.
   Proof.
     unfold measure in |-*.
     
     apply InterpZ.measure_bounded;
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Ltac generate_pos_hyp  :=
    match goal with
      | H:context [measure ?x] |- _ =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      |  |- context [measure ?x] =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      end
    .
   
   Lemma rules_monotonic :
    forall l r, 
     (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
      measure r <= measure l.
   Proof.
     intros l r H.
     fold measure in |-*.
     
     inversion H;clear H;subst;inversion H0;clear H0;subst;
      simpl algebra.EQT.T.apply_subst in |-*;
      repeat (
      match goal with
        |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
         rewrite (measure_equation (algebra.Alg.Term f t))
        end
      );repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma measure_star_monotonic :
    forall l r, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                r l) ->measure r <= measure l.
   Proof.
     unfold measure in *.
     apply InterpZ.measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
   Qed.
   
   Definition P_id_LE (x6:Z) (x7:Z) := 0.
   
   Definition P_id_RM (x6:Z) (x7:Z) := 0.
   
   Definition P_id_MIN (x6:Z) := 0.
   
   Definition P_id_MINSORT (x6:Z) (x7:Z) := 0.
   
   Definition P_id_APP (x6:Z) (x7:Z) := 2* x6.
   
   Definition P_id_IF_RM (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_IF_MIN (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_MINSORT (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_EQ (x6:Z) (x7:Z) := 0.
   
   Lemma P_id_LE_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_RM_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MIN_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MINSORT_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_APP_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_RM_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MIN_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MINSORT_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_EQ_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition marked_measure  := 
     InterpZ.marked_measure 0 P_id_eq P_id_add P_id_false P_id_if_rm 
      P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
      P_id_le P_id_minsort P_id_s P_id_rm P_id_nil P_id_LE P_id_RM P_id_MIN 
      P_id_MINSORT P_id_APP P_id_IF_RM P_id_IF_MIN P_id_IF_MINSORT P_id_EQ.
   
   Lemma marked_measure_equation :
    forall t, 
     marked_measure t = match t with
                          | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                           P_id_LE (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                           P_id_RM (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                           P_id_MIN (measure x6)
                          | (algebra.Alg.Term algebra.F.id_minsort (x7::
                             x6::nil)) =>
                           P_id_MINSORT (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                           P_id_APP (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                             x6::nil)) =>
                           P_id_IF_RM (measure x8) (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_min (x7::
                             x6::nil)) =>
                           P_id_IF_MIN (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                             x7::x6::nil)) =>
                           P_id_IF_MINSORT (measure x8) (measure x7) 
                            (measure x6)
                          | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                           P_id_EQ (measure x7) (measure x6)
                          | _ => measure t
                          end.
   Proof.
     reflexivity .
   Qed.
   
   Lemma marked_measure_star_monotonic :
    forall f l1 l2, 
     (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                       R_xml_0_deep_rew.R_xml_0_rules)
                                                      ) l1 l2) ->
      marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                 f l2).
   Proof.
     unfold marked_measure in *.
     apply InterpZ.marked_measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
     intros ;apply P_id_LE_monotonic;assumption.
     intros ;apply P_id_RM_monotonic;assumption.
     intros ;apply P_id_MIN_monotonic;assumption.
     intros ;apply P_id_MINSORT_monotonic;assumption.
     intros ;apply P_id_APP_monotonic;assumption.
     intros ;apply P_id_IF_RM_monotonic;assumption.
     intros ;apply P_id_IF_MIN_monotonic;assumption.
     intros ;apply P_id_IF_MINSORT_monotonic;assumption.
     intros ;apply P_id_EQ_monotonic;assumption.
   Qed.
   
   Ltac rewrite_and_unfold  :=
    do 2 (rewrite marked_measure_equation);
     repeat (
     match goal with
       |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
        rewrite (measure_equation (algebra.Alg.Term f t))
       | H:context [measure (algebra.Alg.Term ?f ?t)] |- _ =>
        rewrite (measure_equation (algebra.Alg.Term f t)) in H|-
       end
     ).
   
   
   Lemma wf : well_founded WF_DP_R_xml_0.DP_R_xml_0_scc_1.
   Proof.
     intros x.
     
     apply well_founded_ind with
       (R:=fun x y => (Zwf.Zwf 0) (marked_measure x) (marked_measure y)).
     apply Inverse_Image.wf_inverse_image with  (B:=Z).
     apply Zwf.Zwf_well_founded.
     clear x.
     intros x IHx.
     
     repeat (
     constructor;inversion 1;subst;
      full_prove_ineq algebra.Alg.Term 
      ltac:(algebra.Alg_ext.find_replacement ) 
      algebra.EQT_ext.one_step_list_refl_trans_clos marked_measure 
      marked_measure_star_monotonic (Zwf.Zwf 0) (interp.o_Z 0) 
      ltac:(fun _ => R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 ) 
      ltac:(fun _ => rewrite_and_unfold ) ltac:(fun _ => generate_pos_hyp ) 
      ltac:(fun _ => cbv beta iota zeta delta - [Zplus Zmult Zle Zlt] in * ;
                      try (constructor))
       IHx
     ).
   Qed.
  End WF_DP_R_xml_0_scc_1.
  
  Definition wf_DP_R_xml_0_scc_1  := WF_DP_R_xml_0_scc_1.wf.
  
  
  Lemma acc_DP_R_xml_0_scc_1 :
   forall x y, (DP_R_xml_0_scc_1 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x.
    pattern x.
    apply (@Acc_ind _ DP_R_xml_0_scc_1).
    intros x' _ Hrec y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply Hrec;econstructor eassumption)||
      ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
       (eapply Hrec;econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))).
    apply wf_DP_R_xml_0_scc_1.
  Qed.
  
  
  Inductive DP_R_xml_0_non_scc_2  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <if_minsort(true,add(n_,x_),y_),app(rm(n_,x_),y_)> *)
    | DP_R_xml_0_non_scc_2_0 :
     forall x8 x2 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_true nil) 
        x8) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   x2 x6) ->
         DP_R_xml_0_non_scc_2 (algebra.Alg.Term algebra.F.id_app 
                               ((algebra.Alg.Term algebra.F.id_rm (x3::
                               x1::nil))::x2::nil)) 
          (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
  .
  
  
  Lemma acc_DP_R_xml_0_non_scc_2 :
   forall x y, 
    (DP_R_xml_0_non_scc_2 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply acc_DP_R_xml_0_scc_1;
        econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
      ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
       (eapply Hrec;econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))).
  Qed.
  
  
  Inductive DP_R_xml_0_scc_3  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <le(s(x_),s(y_)),le(x_,y_)> *)
    | DP_R_xml_0_scc_3_0 :
     forall x2 x6 x1 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_s (x1::nil)) 
        x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_s (x2::nil)) x6) ->
        DP_R_xml_0_scc_3 (algebra.Alg.Term algebra.F.id_le (x1::x2::nil)) 
         (algebra.Alg.Term algebra.F.id_le (x7::x6::nil))
  .
  
  
  Module WF_DP_R_xml_0_scc_3.
   Open Scope Z_scope.
   
   Import ring_extention.
   
   Notation Local "a <= b" := (Zle a b).
   
   Notation Local "a < b" := (Zlt a b).
   
   Definition P_id_eq (x6:Z) (x7:Z) := 2* x6.
   
   Definition P_id_add (x6:Z) (x7:Z) := 2* x6 + 1* x7.
   
   Definition P_id_false  := 0.
   
   Definition P_id_if_rm (x6:Z) (x7:Z) (x8:Z) := 1* x8.
   
   Definition P_id_true  := 3.
   
   Definition P_id_if_min (x6:Z) (x7:Z) := 1 + 2* x7.
   
   Definition P_id_app (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_if_minsort (x6:Z) (x7:Z) (x8:Z) := 1* x7 + 1* x8.
   
   Definition P_id_0  := 2.
   
   Definition P_id_min (x6:Z) := 1 + 2* x6.
   
   Definition P_id_le (x6:Z) (x7:Z) := 2 + 3* x6 + 2* x7.
   
   Definition P_id_minsort (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_s (x6:Z) := 1 + 2* x6.
   
   Definition P_id_rm (x6:Z) (x7:Z) := 1* x7.
   
   Definition P_id_nil  := 0.
   
   Lemma P_id_eq_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_minsort x7 x9 <= P_id_minsort x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_eq_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_eq x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_add x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_false_bounded : 0 <= P_id_false .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_rm x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_true_bounded : 0 <= P_id_true .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_if_min x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_app x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_minsort x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_0_bounded : 0 <= P_id_0 .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_bounded : forall x6, (0 <= x6) ->0 <= P_id_min x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_le x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_minsort x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_bounded : forall x6, (0 <= x6) ->0 <= P_id_s x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_rm x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_nil_bounded : 0 <= P_id_nil .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition measure  := 
     InterpZ.measure 0 P_id_eq P_id_add P_id_false P_id_if_rm P_id_true 
      P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min P_id_le 
      P_id_minsort P_id_s P_id_rm P_id_nil.
   
   Lemma measure_equation :
    forall t, 
     measure t = match t with
                   | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                    P_id_eq (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                    P_id_add (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
                   | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                    P_id_if_rm (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                   | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                    P_id_if_min (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                    P_id_app (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                      x6::nil)) =>
                    P_id_if_minsort (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                   | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                    P_id_min (measure x6)
                   | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                    P_id_le (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                    P_id_minsort (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                    P_id_s (measure x6)
                   | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                    P_id_rm (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                   | _ => 0
                   end.
   Proof.
     intros t;case t;intros ;apply refl_equal.
   Qed.
   
   Lemma measure_bounded : forall t, 0 <= measure t.
   Proof.
     unfold measure in |-*.
     
     apply InterpZ.measure_bounded;
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Ltac generate_pos_hyp  :=
    match goal with
      | H:context [measure ?x] |- _ =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      |  |- context [measure ?x] =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      end
    .
   
   Lemma rules_monotonic :
    forall l r, 
     (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
      measure r <= measure l.
   Proof.
     intros l r H.
     fold measure in |-*.
     
     inversion H;clear H;subst;inversion H0;clear H0;subst;
      simpl algebra.EQT.T.apply_subst in |-*;
      repeat (
      match goal with
        |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
         rewrite (measure_equation (algebra.Alg.Term f t))
        end
      );repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma measure_star_monotonic :
    forall l r, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                r l) ->measure r <= measure l.
   Proof.
     unfold measure in *.
     apply InterpZ.measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
   Qed.
   
   Definition P_id_LE (x6:Z) (x7:Z) := 1* x6.
   
   Definition P_id_RM (x6:Z) (x7:Z) := 0.
   
   Definition P_id_MIN (x6:Z) := 0.
   
   Definition P_id_MINSORT (x6:Z) (x7:Z) := 0.
   
   Definition P_id_APP (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_RM (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_IF_MIN (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_MINSORT (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_EQ (x6:Z) (x7:Z) := 0.
   
   Lemma P_id_LE_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_RM_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MIN_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MINSORT_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_APP_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_RM_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MIN_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MINSORT_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_EQ_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition marked_measure  := 
     InterpZ.marked_measure 0 P_id_eq P_id_add P_id_false P_id_if_rm 
      P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
      P_id_le P_id_minsort P_id_s P_id_rm P_id_nil P_id_LE P_id_RM P_id_MIN 
      P_id_MINSORT P_id_APP P_id_IF_RM P_id_IF_MIN P_id_IF_MINSORT P_id_EQ.
   
   Lemma marked_measure_equation :
    forall t, 
     marked_measure t = match t with
                          | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                           P_id_LE (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                           P_id_RM (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                           P_id_MIN (measure x6)
                          | (algebra.Alg.Term algebra.F.id_minsort (x7::
                             x6::nil)) =>
                           P_id_MINSORT (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                           P_id_APP (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                             x6::nil)) =>
                           P_id_IF_RM (measure x8) (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_min (x7::
                             x6::nil)) =>
                           P_id_IF_MIN (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                             x7::x6::nil)) =>
                           P_id_IF_MINSORT (measure x8) (measure x7) 
                            (measure x6)
                          | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                           P_id_EQ (measure x7) (measure x6)
                          | _ => measure t
                          end.
   Proof.
     reflexivity .
   Qed.
   
   Lemma marked_measure_star_monotonic :
    forall f l1 l2, 
     (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                       R_xml_0_deep_rew.R_xml_0_rules)
                                                      ) l1 l2) ->
      marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                 f l2).
   Proof.
     unfold marked_measure in *.
     apply InterpZ.marked_measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
     intros ;apply P_id_LE_monotonic;assumption.
     intros ;apply P_id_RM_monotonic;assumption.
     intros ;apply P_id_MIN_monotonic;assumption.
     intros ;apply P_id_MINSORT_monotonic;assumption.
     intros ;apply P_id_APP_monotonic;assumption.
     intros ;apply P_id_IF_RM_monotonic;assumption.
     intros ;apply P_id_IF_MIN_monotonic;assumption.
     intros ;apply P_id_IF_MINSORT_monotonic;assumption.
     intros ;apply P_id_EQ_monotonic;assumption.
   Qed.
   
   Ltac rewrite_and_unfold  :=
    do 2 (rewrite marked_measure_equation);
     repeat (
     match goal with
       |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
        rewrite (measure_equation (algebra.Alg.Term f t))
       | H:context [measure (algebra.Alg.Term ?f ?t)] |- _ =>
        rewrite (measure_equation (algebra.Alg.Term f t)) in H|-
       end
     ).
   
   
   Lemma wf : well_founded WF_DP_R_xml_0.DP_R_xml_0_scc_3.
   Proof.
     intros x.
     
     apply well_founded_ind with
       (R:=fun x y => (Zwf.Zwf 0) (marked_measure x) (marked_measure y)).
     apply Inverse_Image.wf_inverse_image with  (B:=Z).
     apply Zwf.Zwf_well_founded.
     clear x.
     intros x IHx.
     
     repeat (
     constructor;inversion 1;subst;
      full_prove_ineq algebra.Alg.Term 
      ltac:(algebra.Alg_ext.find_replacement ) 
      algebra.EQT_ext.one_step_list_refl_trans_clos marked_measure 
      marked_measure_star_monotonic (Zwf.Zwf 0) (interp.o_Z 0) 
      ltac:(fun _ => R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 ) 
      ltac:(fun _ => rewrite_and_unfold ) ltac:(fun _ => generate_pos_hyp ) 
      ltac:(fun _ => cbv beta iota zeta delta - [Zplus Zmult Zle Zlt] in * ;
                      try (constructor))
       IHx
     ).
   Qed.
  End WF_DP_R_xml_0_scc_3.
  
  Definition wf_DP_R_xml_0_scc_3  := WF_DP_R_xml_0_scc_3.wf.
  
  
  Lemma acc_DP_R_xml_0_scc_3 :
   forall x y, (DP_R_xml_0_scc_3 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x.
    pattern x.
    apply (@Acc_ind _ DP_R_xml_0_scc_3).
    intros x' _ Hrec y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply Hrec;econstructor eassumption)||
      ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
       (eapply Hrec;econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))).
    apply wf_DP_R_xml_0_scc_3.
  Qed.
  
  
  Inductive DP_R_xml_0_non_scc_4  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <min(add(n_,add(m_,x_))),le(n_,m_)> *)
    | DP_R_xml_0_non_scc_4_0 :
     forall x4 x6 x1 x3, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::(algebra.Alg.Term 
         algebra.F.id_add (x4::x1::nil))::nil)) x6) ->
       DP_R_xml_0_non_scc_4 (algebra.Alg.Term algebra.F.id_le (x3::x4::nil)) 
        (algebra.Alg.Term algebra.F.id_min (x6::nil))
  .
  
  
  Lemma acc_DP_R_xml_0_non_scc_4 :
   forall x y, 
    (DP_R_xml_0_non_scc_4 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply acc_DP_R_xml_0_scc_3;
        econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
      ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
       (eapply Hrec;econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))).
  Qed.
  
  
  Inductive DP_R_xml_0_scc_5  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <min(add(n_,add(m_,x_))),if_min(le(n_,m_),add(n_,add(m_,x_)))> *)
    | DP_R_xml_0_scc_5_0 :
     forall x4 x6 x1 x3, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::(algebra.Alg.Term 
         algebra.F.id_add (x4::x1::nil))::nil)) x6) ->
       DP_R_xml_0_scc_5 (algebra.Alg.Term algebra.F.id_if_min 
                         ((algebra.Alg.Term algebra.F.id_le (x3::x4::nil))::
                         (algebra.Alg.Term algebra.F.id_add (x3::
                         (algebra.Alg.Term algebra.F.id_add (x4::
                         x1::nil))::nil))::nil)) 
        (algebra.Alg.Term algebra.F.id_min (x6::nil))
    
     (* <if_min(true,add(n_,add(m_,x_))),min(add(n_,x_))> *)
    | DP_R_xml_0_scc_5_1 :
     forall x4 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_true nil) 
        x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x3::(algebra.Alg.Term 
          algebra.F.id_add (x4::x1::nil))::nil)) x6) ->
        DP_R_xml_0_scc_5 (algebra.Alg.Term algebra.F.id_min 
                          ((algebra.Alg.Term algebra.F.id_add (x3::
                          x1::nil))::nil)) 
         (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil))
    
     (* <if_min(false,add(n_,add(m_,x_))),min(add(m_,x_))> *)
    | DP_R_xml_0_scc_5_2 :
     forall x4 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_false nil) 
        x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x3::(algebra.Alg.Term 
          algebra.F.id_add (x4::x1::nil))::nil)) x6) ->
        DP_R_xml_0_scc_5 (algebra.Alg.Term algebra.F.id_min 
                          ((algebra.Alg.Term algebra.F.id_add (x4::
                          x1::nil))::nil)) 
         (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil))
  .
  
  
  Module WF_DP_R_xml_0_scc_5.
   Open Scope Z_scope.
   
   Import ring_extention.
   
   Notation Local "a <= b" := (Zle a b).
   
   Notation Local "a < b" := (Zlt a b).
   
   Definition P_id_eq (x6:Z) (x7:Z) := 0.
   
   Definition P_id_add (x6:Z) (x7:Z) := 2 + 2* x6 + 1* x7.
   
   Definition P_id_false  := 0.
   
   Definition P_id_if_rm (x6:Z) (x7:Z) (x8:Z) := 1* x8.
   
   Definition P_id_true  := 0.
   
   Definition P_id_if_min (x6:Z) (x7:Z) := 1* x7.
   
   Definition P_id_app (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_if_minsort (x6:Z) (x7:Z) (x8:Z) := 1* x7 + 1* x8.
   
   Definition P_id_0  := 0.
   
   Definition P_id_min (x6:Z) := 2 + 1* x6.
   
   Definition P_id_le (x6:Z) (x7:Z) := 0.
   
   Definition P_id_minsort (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_s (x6:Z) := 0.
   
   Definition P_id_rm (x6:Z) (x7:Z) := 1* x7.
   
   Definition P_id_nil  := 0.
   
   Lemma P_id_eq_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_minsort x7 x9 <= P_id_minsort x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_eq_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_eq x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_add x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_false_bounded : 0 <= P_id_false .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_rm x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_true_bounded : 0 <= P_id_true .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_if_min x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_app x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_minsort x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_0_bounded : 0 <= P_id_0 .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_bounded : forall x6, (0 <= x6) ->0 <= P_id_min x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_le x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_minsort x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_bounded : forall x6, (0 <= x6) ->0 <= P_id_s x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_rm x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_nil_bounded : 0 <= P_id_nil .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition measure  := 
     InterpZ.measure 0 P_id_eq P_id_add P_id_false P_id_if_rm P_id_true 
      P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min P_id_le 
      P_id_minsort P_id_s P_id_rm P_id_nil.
   
   Lemma measure_equation :
    forall t, 
     measure t = match t with
                   | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                    P_id_eq (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                    P_id_add (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
                   | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                    P_id_if_rm (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                   | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                    P_id_if_min (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                    P_id_app (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                      x6::nil)) =>
                    P_id_if_minsort (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                   | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                    P_id_min (measure x6)
                   | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                    P_id_le (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                    P_id_minsort (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                    P_id_s (measure x6)
                   | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                    P_id_rm (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                   | _ => 0
                   end.
   Proof.
     intros t;case t;intros ;apply refl_equal.
   Qed.
   
   Lemma measure_bounded : forall t, 0 <= measure t.
   Proof.
     unfold measure in |-*.
     
     apply InterpZ.measure_bounded;
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Ltac generate_pos_hyp  :=
    match goal with
      | H:context [measure ?x] |- _ =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      |  |- context [measure ?x] =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      end
    .
   
   Lemma rules_monotonic :
    forall l r, 
     (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
      measure r <= measure l.
   Proof.
     intros l r H.
     fold measure in |-*.
     
     inversion H;clear H;subst;inversion H0;clear H0;subst;
      simpl algebra.EQT.T.apply_subst in |-*;
      repeat (
      match goal with
        |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
         rewrite (measure_equation (algebra.Alg.Term f t))
        end
      );repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma measure_star_monotonic :
    forall l r, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                r l) ->measure r <= measure l.
   Proof.
     unfold measure in *.
     apply InterpZ.measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
   Qed.
   
   Definition P_id_LE (x6:Z) (x7:Z) := 0.
   
   Definition P_id_RM (x6:Z) (x7:Z) := 0.
   
   Definition P_id_MIN (x6:Z) := 3 + 2* x6.
   
   Definition P_id_MINSORT (x6:Z) (x7:Z) := 0.
   
   Definition P_id_APP (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_RM (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_IF_MIN (x6:Z) (x7:Z) := 2* x7.
   
   Definition P_id_IF_MINSORT (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_EQ (x6:Z) (x7:Z) := 0.
   
   Lemma P_id_LE_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_RM_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MIN_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MINSORT_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_APP_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_RM_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MIN_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MINSORT_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_EQ_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition marked_measure  := 
     InterpZ.marked_measure 0 P_id_eq P_id_add P_id_false P_id_if_rm 
      P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
      P_id_le P_id_minsort P_id_s P_id_rm P_id_nil P_id_LE P_id_RM P_id_MIN 
      P_id_MINSORT P_id_APP P_id_IF_RM P_id_IF_MIN P_id_IF_MINSORT P_id_EQ.
   
   Lemma marked_measure_equation :
    forall t, 
     marked_measure t = match t with
                          | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                           P_id_LE (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                           P_id_RM (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                           P_id_MIN (measure x6)
                          | (algebra.Alg.Term algebra.F.id_minsort (x7::
                             x6::nil)) =>
                           P_id_MINSORT (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                           P_id_APP (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                             x6::nil)) =>
                           P_id_IF_RM (measure x8) (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_min (x7::
                             x6::nil)) =>
                           P_id_IF_MIN (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                             x7::x6::nil)) =>
                           P_id_IF_MINSORT (measure x8) (measure x7) 
                            (measure x6)
                          | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                           P_id_EQ (measure x7) (measure x6)
                          | _ => measure t
                          end.
   Proof.
     reflexivity .
   Qed.
   
   Lemma marked_measure_star_monotonic :
    forall f l1 l2, 
     (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                       R_xml_0_deep_rew.R_xml_0_rules)
                                                      ) l1 l2) ->
      marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                 f l2).
   Proof.
     unfold marked_measure in *.
     apply InterpZ.marked_measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
     intros ;apply P_id_LE_monotonic;assumption.
     intros ;apply P_id_RM_monotonic;assumption.
     intros ;apply P_id_MIN_monotonic;assumption.
     intros ;apply P_id_MINSORT_monotonic;assumption.
     intros ;apply P_id_APP_monotonic;assumption.
     intros ;apply P_id_IF_RM_monotonic;assumption.
     intros ;apply P_id_IF_MIN_monotonic;assumption.
     intros ;apply P_id_IF_MINSORT_monotonic;assumption.
     intros ;apply P_id_EQ_monotonic;assumption.
   Qed.
   
   Ltac rewrite_and_unfold  :=
    do 2 (rewrite marked_measure_equation);
     repeat (
     match goal with
       |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
        rewrite (measure_equation (algebra.Alg.Term f t))
       | H:context [measure (algebra.Alg.Term ?f ?t)] |- _ =>
        rewrite (measure_equation (algebra.Alg.Term f t)) in H|-
       end
     ).
   
   
   Lemma wf : well_founded WF_DP_R_xml_0.DP_R_xml_0_scc_5.
   Proof.
     intros x.
     
     apply well_founded_ind with
       (R:=fun x y => (Zwf.Zwf 0) (marked_measure x) (marked_measure y)).
     apply Inverse_Image.wf_inverse_image with  (B:=Z).
     apply Zwf.Zwf_well_founded.
     clear x.
     intros x IHx.
     
     repeat (
     constructor;inversion 1;subst;
      full_prove_ineq algebra.Alg.Term 
      ltac:(algebra.Alg_ext.find_replacement ) 
      algebra.EQT_ext.one_step_list_refl_trans_clos marked_measure 
      marked_measure_star_monotonic (Zwf.Zwf 0) (interp.o_Z 0) 
      ltac:(fun _ => R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 ) 
      ltac:(fun _ => rewrite_and_unfold ) ltac:(fun _ => generate_pos_hyp ) 
      ltac:(fun _ => cbv beta iota zeta delta - [Zplus Zmult Zle Zlt] in * ;
                      try (constructor))
       IHx
     ).
   Qed.
  End WF_DP_R_xml_0_scc_5.
  
  Definition wf_DP_R_xml_0_scc_5  := WF_DP_R_xml_0_scc_5.wf.
  
  
  Lemma acc_DP_R_xml_0_scc_5 :
   forall x y, (DP_R_xml_0_scc_5 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x.
    pattern x.
    apply (@Acc_ind _ DP_R_xml_0_scc_5).
    intros x' _ Hrec y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply Hrec;econstructor eassumption)||
      ((eapply acc_DP_R_xml_0_non_scc_4;
         econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
       ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
        (eapply Hrec;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' )))).
    apply wf_DP_R_xml_0_scc_5.
  Qed.
  
  
  Inductive DP_R_xml_0_non_scc_6  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <minsort(add(n_,x_),y_),min(add(n_,x_))> *)
    | DP_R_xml_0_non_scc_6_0 :
     forall x2 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x2 x6) ->
        DP_R_xml_0_non_scc_6 (algebra.Alg.Term algebra.F.id_min 
                              ((algebra.Alg.Term algebra.F.id_add (x3::
                              x1::nil))::nil)) 
         (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil))
  .
  
  
  Lemma acc_DP_R_xml_0_non_scc_6 :
   forall x y, 
    (DP_R_xml_0_non_scc_6 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply acc_DP_R_xml_0_scc_5;
        econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
      ((eapply acc_DP_R_xml_0_non_scc_4;
         econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
       ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
        (eapply Hrec;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' )))).
  Qed.
  
  
  Inductive DP_R_xml_0_scc_7  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <eq(s(x_),s(y_)),eq(x_,y_)> *)
    | DP_R_xml_0_scc_7_0 :
     forall x2 x6 x1 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_s (x1::nil)) 
        x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_s (x2::nil)) x6) ->
        DP_R_xml_0_scc_7 (algebra.Alg.Term algebra.F.id_eq (x1::x2::nil)) 
         (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil))
  .
  
  
  Module WF_DP_R_xml_0_scc_7.
   Open Scope Z_scope.
   
   Import ring_extention.
   
   Notation Local "a <= b" := (Zle a b).
   
   Notation Local "a < b" := (Zlt a b).
   
   Definition P_id_eq (x6:Z) (x7:Z) := 2* x6.
   
   Definition P_id_add (x6:Z) (x7:Z) := 2* x6 + 1* x7.
   
   Definition P_id_false  := 0.
   
   Definition P_id_if_rm (x6:Z) (x7:Z) (x8:Z) := 1* x8.
   
   Definition P_id_true  := 3.
   
   Definition P_id_if_min (x6:Z) (x7:Z) := 1 + 2* x7.
   
   Definition P_id_app (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_if_minsort (x6:Z) (x7:Z) (x8:Z) := 1* x7 + 1* x8.
   
   Definition P_id_0  := 2.
   
   Definition P_id_min (x6:Z) := 1 + 2* x6.
   
   Definition P_id_le (x6:Z) (x7:Z) := 2 + 3* x6 + 2* x7.
   
   Definition P_id_minsort (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_s (x6:Z) := 1 + 2* x6.
   
   Definition P_id_rm (x6:Z) (x7:Z) := 1* x7.
   
   Definition P_id_nil  := 0.
   
   Lemma P_id_eq_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_minsort x7 x9 <= P_id_minsort x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_eq_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_eq x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_add x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_false_bounded : 0 <= P_id_false .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_rm x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_true_bounded : 0 <= P_id_true .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_if_min x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_app x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_minsort x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_0_bounded : 0 <= P_id_0 .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_bounded : forall x6, (0 <= x6) ->0 <= P_id_min x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_le x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_minsort x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_bounded : forall x6, (0 <= x6) ->0 <= P_id_s x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_rm x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_nil_bounded : 0 <= P_id_nil .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition measure  := 
     InterpZ.measure 0 P_id_eq P_id_add P_id_false P_id_if_rm P_id_true 
      P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min P_id_le 
      P_id_minsort P_id_s P_id_rm P_id_nil.
   
   Lemma measure_equation :
    forall t, 
     measure t = match t with
                   | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                    P_id_eq (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                    P_id_add (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
                   | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                    P_id_if_rm (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                   | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                    P_id_if_min (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                    P_id_app (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                      x6::nil)) =>
                    P_id_if_minsort (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                   | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                    P_id_min (measure x6)
                   | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                    P_id_le (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                    P_id_minsort (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                    P_id_s (measure x6)
                   | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                    P_id_rm (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                   | _ => 0
                   end.
   Proof.
     intros t;case t;intros ;apply refl_equal.
   Qed.
   
   Lemma measure_bounded : forall t, 0 <= measure t.
   Proof.
     unfold measure in |-*.
     
     apply InterpZ.measure_bounded;
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Ltac generate_pos_hyp  :=
    match goal with
      | H:context [measure ?x] |- _ =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      |  |- context [measure ?x] =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      end
    .
   
   Lemma rules_monotonic :
    forall l r, 
     (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
      measure r <= measure l.
   Proof.
     intros l r H.
     fold measure in |-*.
     
     inversion H;clear H;subst;inversion H0;clear H0;subst;
      simpl algebra.EQT.T.apply_subst in |-*;
      repeat (
      match goal with
        |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
         rewrite (measure_equation (algebra.Alg.Term f t))
        end
      );repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma measure_star_monotonic :
    forall l r, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                r l) ->measure r <= measure l.
   Proof.
     unfold measure in *.
     apply InterpZ.measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
   Qed.
   
   Definition P_id_LE (x6:Z) (x7:Z) := 0.
   
   Definition P_id_RM (x6:Z) (x7:Z) := 0.
   
   Definition P_id_MIN (x6:Z) := 0.
   
   Definition P_id_MINSORT (x6:Z) (x7:Z) := 0.
   
   Definition P_id_APP (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_RM (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_IF_MIN (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_MINSORT (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_EQ (x6:Z) (x7:Z) := 1* x6.
   
   Lemma P_id_LE_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_RM_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MIN_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MINSORT_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_APP_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_RM_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MIN_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MINSORT_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_EQ_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition marked_measure  := 
     InterpZ.marked_measure 0 P_id_eq P_id_add P_id_false P_id_if_rm 
      P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
      P_id_le P_id_minsort P_id_s P_id_rm P_id_nil P_id_LE P_id_RM P_id_MIN 
      P_id_MINSORT P_id_APP P_id_IF_RM P_id_IF_MIN P_id_IF_MINSORT P_id_EQ.
   
   Lemma marked_measure_equation :
    forall t, 
     marked_measure t = match t with
                          | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                           P_id_LE (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                           P_id_RM (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                           P_id_MIN (measure x6)
                          | (algebra.Alg.Term algebra.F.id_minsort (x7::
                             x6::nil)) =>
                           P_id_MINSORT (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                           P_id_APP (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                             x6::nil)) =>
                           P_id_IF_RM (measure x8) (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_min (x7::
                             x6::nil)) =>
                           P_id_IF_MIN (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                             x7::x6::nil)) =>
                           P_id_IF_MINSORT (measure x8) (measure x7) 
                            (measure x6)
                          | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                           P_id_EQ (measure x7) (measure x6)
                          | _ => measure t
                          end.
   Proof.
     reflexivity .
   Qed.
   
   Lemma marked_measure_star_monotonic :
    forall f l1 l2, 
     (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                       R_xml_0_deep_rew.R_xml_0_rules)
                                                      ) l1 l2) ->
      marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                 f l2).
   Proof.
     unfold marked_measure in *.
     apply InterpZ.marked_measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
     intros ;apply P_id_LE_monotonic;assumption.
     intros ;apply P_id_RM_monotonic;assumption.
     intros ;apply P_id_MIN_monotonic;assumption.
     intros ;apply P_id_MINSORT_monotonic;assumption.
     intros ;apply P_id_APP_monotonic;assumption.
     intros ;apply P_id_IF_RM_monotonic;assumption.
     intros ;apply P_id_IF_MIN_monotonic;assumption.
     intros ;apply P_id_IF_MINSORT_monotonic;assumption.
     intros ;apply P_id_EQ_monotonic;assumption.
   Qed.
   
   Ltac rewrite_and_unfold  :=
    do 2 (rewrite marked_measure_equation);
     repeat (
     match goal with
       |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
        rewrite (measure_equation (algebra.Alg.Term f t))
       | H:context [measure (algebra.Alg.Term ?f ?t)] |- _ =>
        rewrite (measure_equation (algebra.Alg.Term f t)) in H|-
       end
     ).
   
   
   Lemma wf : well_founded WF_DP_R_xml_0.DP_R_xml_0_scc_7.
   Proof.
     intros x.
     
     apply well_founded_ind with
       (R:=fun x y => (Zwf.Zwf 0) (marked_measure x) (marked_measure y)).
     apply Inverse_Image.wf_inverse_image with  (B:=Z).
     apply Zwf.Zwf_well_founded.
     clear x.
     intros x IHx.
     
     repeat (
     constructor;inversion 1;subst;
      full_prove_ineq algebra.Alg.Term 
      ltac:(algebra.Alg_ext.find_replacement ) 
      algebra.EQT_ext.one_step_list_refl_trans_clos marked_measure 
      marked_measure_star_monotonic (Zwf.Zwf 0) (interp.o_Z 0) 
      ltac:(fun _ => R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 ) 
      ltac:(fun _ => rewrite_and_unfold ) ltac:(fun _ => generate_pos_hyp ) 
      ltac:(fun _ => cbv beta iota zeta delta - [Zplus Zmult Zle Zlt] in * ;
                      try (constructor))
       IHx
     ).
   Qed.
  End WF_DP_R_xml_0_scc_7.
  
  Definition wf_DP_R_xml_0_scc_7  := WF_DP_R_xml_0_scc_7.wf.
  
  
  Lemma acc_DP_R_xml_0_scc_7 :
   forall x y, (DP_R_xml_0_scc_7 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x.
    pattern x.
    apply (@Acc_ind _ DP_R_xml_0_scc_7).
    intros x' _ Hrec y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply Hrec;econstructor eassumption)||
      ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
       (eapply Hrec;econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))).
    apply wf_DP_R_xml_0_scc_7.
  Qed.
  
  
  Inductive DP_R_xml_0_non_scc_8  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <minsort(add(n_,x_),y_),eq(n_,min(add(n_,x_)))> *)
    | DP_R_xml_0_non_scc_8_0 :
     forall x2 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x2 x6) ->
        DP_R_xml_0_non_scc_8 (algebra.Alg.Term algebra.F.id_eq (x3::
                              (algebra.Alg.Term algebra.F.id_min 
                              ((algebra.Alg.Term algebra.F.id_add (x3::
                              x1::nil))::nil))::nil)) 
         (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil))
  .
  
  
  Lemma acc_DP_R_xml_0_non_scc_8 :
   forall x y, 
    (DP_R_xml_0_non_scc_8 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply acc_DP_R_xml_0_scc_7;
        econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
      ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
       (eapply Hrec;econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))).
  Qed.
  
  
  Inductive DP_R_xml_0_non_scc_9  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <rm(n_,add(m_,x_)),eq(n_,m_)> *)
    | DP_R_xml_0_non_scc_9_0 :
     forall x4 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 x3 x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
        DP_R_xml_0_non_scc_9 (algebra.Alg.Term algebra.F.id_eq (x3::x4::nil)) 
         (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil))
  .
  
  
  Lemma acc_DP_R_xml_0_non_scc_9 :
   forall x y, 
    (DP_R_xml_0_non_scc_9 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply acc_DP_R_xml_0_scc_7;
        econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
      ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
       (eapply Hrec;econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))).
  Qed.
  
  
  Inductive DP_R_xml_0_scc_10  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <rm(n_,add(m_,x_)),if_rm(eq(n_,m_),n_,add(m_,x_))> *)
    | DP_R_xml_0_scc_10_0 :
     forall x4 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 x3 x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
        DP_R_xml_0_scc_10 (algebra.Alg.Term algebra.F.id_if_rm 
                           ((algebra.Alg.Term algebra.F.id_eq (x3::
                           x4::nil))::x3::(algebra.Alg.Term algebra.F.id_add 
                           (x4::x1::nil))::nil)) 
         (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil))
     (* <if_rm(true,n_,add(m_,x_)),rm(n_,x_)> *)
    | DP_R_xml_0_scc_10_1 :
     forall x8 x4 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_true nil) 
        x8) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x3 x7) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   
          (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
         DP_R_xml_0_scc_10 (algebra.Alg.Term algebra.F.id_rm (x3::x1::nil)) 
          (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil))
     (* <if_rm(false,n_,add(m_,x_)),rm(n_,x_)> *)
    | DP_R_xml_0_scc_10_2 :
     forall x8 x4 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_false nil) 
        x8) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x3 x7) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   
          (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
         DP_R_xml_0_scc_10 (algebra.Alg.Term algebra.F.id_rm (x3::x1::nil)) 
          (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil))
  .
  
  
  Module WF_DP_R_xml_0_scc_10.
   Inductive DP_R_xml_0_scc_10_large  :
    algebra.Alg.term ->algebra.Alg.term ->Prop := 
      (* <rm(n_,add(m_,x_)),if_rm(eq(n_,m_),n_,add(m_,x_))> *)
     | DP_R_xml_0_scc_10_large_0 :
      forall x4 x6 x1 x3 x7, 
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x3 x7) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   
          (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
         DP_R_xml_0_scc_10_large (algebra.Alg.Term algebra.F.id_if_rm 
                                  ((algebra.Alg.Term algebra.F.id_eq (x3::
                                  x4::nil))::x3::(algebra.Alg.Term 
                                  algebra.F.id_add (x4::x1::nil))::nil)) 
          (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil))
   .
   
   
   Inductive DP_R_xml_0_scc_10_strict  :
    algebra.Alg.term ->algebra.Alg.term ->Prop := 
      (* <if_rm(true,n_,add(m_,x_)),rm(n_,x_)> *)
     | DP_R_xml_0_scc_10_strict_0 :
      forall x8 x4 x6 x1 x3 x7, 
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  (algebra.Alg.Term algebra.F.id_true nil) 
         x8) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   x3 x7) ->
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                    
           (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
          DP_R_xml_0_scc_10_strict (algebra.Alg.Term algebra.F.id_rm (x3::
                                    x1::nil)) 
           (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil))
     
      (* <if_rm(false,n_,add(m_,x_)),rm(n_,x_)> *)
     | DP_R_xml_0_scc_10_strict_1 :
      forall x8 x4 x6 x1 x3 x7, 
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  (algebra.Alg.Term algebra.F.id_false nil) 
         x8) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   x3 x7) ->
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                    
           (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
          DP_R_xml_0_scc_10_strict (algebra.Alg.Term algebra.F.id_rm (x3::
                                    x1::nil)) 
           (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil))
   .
   
   
   Module WF_DP_R_xml_0_scc_10_large.
    Inductive DP_R_xml_0_scc_10_large_non_scc_1  :
     algebra.Alg.term ->algebra.Alg.term ->Prop := 
       (* <rm(n_,add(m_,x_)),if_rm(eq(n_,m_),n_,add(m_,x_))> *)
      | DP_R_xml_0_scc_10_large_non_scc_1_0 :
       forall x4 x6 x1 x3 x7, 
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   x3 x7) ->
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                    
           (algebra.Alg.Term algebra.F.id_add (x4::x1::nil)) x6) ->
          DP_R_xml_0_scc_10_large_non_scc_1 (algebra.Alg.Term 
                                             algebra.F.id_if_rm 
                                             ((algebra.Alg.Term 
                                             algebra.F.id_eq (x3::x4::nil))::
                                             x3::(algebra.Alg.Term 
                                             algebra.F.id_add (x4::
                                             x1::nil))::nil)) 
           (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil))
    .
    
    
    Lemma acc_DP_R_xml_0_scc_10_large_non_scc_1 :
     forall x y, 
      (DP_R_xml_0_scc_10_large_non_scc_1 x y) ->
       Acc WF_DP_R_xml_0_scc_10.DP_R_xml_0_scc_10_large x.
    Proof.
      intros x y h.
      
      inversion h;clear h;subst;
       constructor;intros _y _h;inversion _h;clear _h;subst;
        (R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
        (eapply Hrec;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' )).
    Qed.
    
    
    Lemma wf : well_founded WF_DP_R_xml_0_scc_10.DP_R_xml_0_scc_10_large.
    Proof.
      constructor;intros _y _h;inversion _h;clear _h;subst;
       (eapply acc_DP_R_xml_0_scc_10_large_non_scc_1;
         econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
       ((eapply acc_DP_R_xml_0_scc_10_large_non_scc_0;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
        ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||(fail))).
    Qed.
   End WF_DP_R_xml_0_scc_10_large.
   
   Open Scope Z_scope.
   
   Import ring_extention.
   
   Notation Local "a <= b" := (Zle a b).
   
   Notation Local "a < b" := (Zlt a b).
   
   Definition P_id_eq (x6:Z) (x7:Z) := 0.
   
   Definition P_id_add (x6:Z) (x7:Z) := 2 + 2* x6 + 1* x7.
   
   Definition P_id_false  := 0.
   
   Definition P_id_if_rm (x6:Z) (x7:Z) (x8:Z) := 1* x7 + 1* x8.
   
   Definition P_id_true  := 0.
   
   Definition P_id_if_min (x6:Z) (x7:Z) := 1 + 2* x7.
   
   Definition P_id_app (x6:Z) (x7:Z) := 1 + 1* x6 + 1* x7.
   
   Definition P_id_if_minsort (x6:Z) (x7:Z) (x8:Z) := 2* x7 + 2* x8.
   
   Definition P_id_0  := 0.
   
   Definition P_id_min (x6:Z) := 2 + 2* x6.
   
   Definition P_id_le (x6:Z) (x7:Z) := 0.
   
   Definition P_id_minsort (x6:Z) (x7:Z) := 2* x6 + 2* x7.
   
   Definition P_id_s (x6:Z) := 0.
   
   Definition P_id_rm (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_nil  := 0.
   
   Lemma P_id_eq_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_minsort x7 x9 <= P_id_minsort x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_eq_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_eq x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_add x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_false_bounded : 0 <= P_id_false .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_rm x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_true_bounded : 0 <= P_id_true .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_if_min x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_app x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_minsort x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_0_bounded : 0 <= P_id_0 .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_bounded : forall x6, (0 <= x6) ->0 <= P_id_min x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_le x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_minsort x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_bounded : forall x6, (0 <= x6) ->0 <= P_id_s x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_rm x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_nil_bounded : 0 <= P_id_nil .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition measure  := 
     InterpZ.measure 0 P_id_eq P_id_add P_id_false P_id_if_rm P_id_true 
      P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min P_id_le 
      P_id_minsort P_id_s P_id_rm P_id_nil.
   
   Lemma measure_equation :
    forall t, 
     measure t = match t with
                   | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                    P_id_eq (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                    P_id_add (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
                   | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                    P_id_if_rm (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                   | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                    P_id_if_min (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                    P_id_app (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                      x6::nil)) =>
                    P_id_if_minsort (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                   | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                    P_id_min (measure x6)
                   | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                    P_id_le (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                    P_id_minsort (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                    P_id_s (measure x6)
                   | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                    P_id_rm (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                   | _ => 0
                   end.
   Proof.
     intros t;case t;intros ;apply refl_equal.
   Qed.
   
   Lemma measure_bounded : forall t, 0 <= measure t.
   Proof.
     unfold measure in |-*.
     
     apply InterpZ.measure_bounded;
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Ltac generate_pos_hyp  :=
    match goal with
      | H:context [measure ?x] |- _ =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      |  |- context [measure ?x] =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      end
    .
   
   Lemma rules_monotonic :
    forall l r, 
     (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
      measure r <= measure l.
   Proof.
     intros l r H.
     fold measure in |-*.
     
     inversion H;clear H;subst;inversion H0;clear H0;subst;
      simpl algebra.EQT.T.apply_subst in |-*;
      repeat (
      match goal with
        |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
         rewrite (measure_equation (algebra.Alg.Term f t))
        end
      );repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma measure_star_monotonic :
    forall l r, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                r l) ->measure r <= measure l.
   Proof.
     unfold measure in *.
     apply InterpZ.measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
   Qed.
   
   Definition P_id_LE (x6:Z) (x7:Z) := 0.
   
   Definition P_id_RM (x6:Z) (x7:Z) := 1* x7.
   
   Definition P_id_MIN (x6:Z) := 0.
   
   Definition P_id_MINSORT (x6:Z) (x7:Z) := 0.
   
   Definition P_id_APP (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_RM (x6:Z) (x7:Z) (x8:Z) := 1* x8.
   
   Definition P_id_IF_MIN (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_MINSORT (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_EQ (x6:Z) (x7:Z) := 0.
   
   Lemma P_id_LE_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_RM_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MIN_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MINSORT_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_APP_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_RM_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MIN_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MINSORT_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_EQ_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition marked_measure  := 
     InterpZ.marked_measure 0 P_id_eq P_id_add P_id_false P_id_if_rm 
      P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
      P_id_le P_id_minsort P_id_s P_id_rm P_id_nil P_id_LE P_id_RM P_id_MIN 
      P_id_MINSORT P_id_APP P_id_IF_RM P_id_IF_MIN P_id_IF_MINSORT P_id_EQ.
   
   Lemma marked_measure_equation :
    forall t, 
     marked_measure t = match t with
                          | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                           P_id_LE (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                           P_id_RM (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                           P_id_MIN (measure x6)
                          | (algebra.Alg.Term algebra.F.id_minsort (x7::
                             x6::nil)) =>
                           P_id_MINSORT (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                           P_id_APP (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                             x6::nil)) =>
                           P_id_IF_RM (measure x8) (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_min (x7::
                             x6::nil)) =>
                           P_id_IF_MIN (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                             x7::x6::nil)) =>
                           P_id_IF_MINSORT (measure x8) (measure x7) 
                            (measure x6)
                          | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                           P_id_EQ (measure x7) (measure x6)
                          | _ => measure t
                          end.
   Proof.
     reflexivity .
   Qed.
   
   Lemma marked_measure_star_monotonic :
    forall f l1 l2, 
     (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                       R_xml_0_deep_rew.R_xml_0_rules)
                                                      ) l1 l2) ->
      marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                 f l2).
   Proof.
     unfold marked_measure in *.
     apply InterpZ.marked_measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
     intros ;apply P_id_LE_monotonic;assumption.
     intros ;apply P_id_RM_monotonic;assumption.
     intros ;apply P_id_MIN_monotonic;assumption.
     intros ;apply P_id_MINSORT_monotonic;assumption.
     intros ;apply P_id_APP_monotonic;assumption.
     intros ;apply P_id_IF_RM_monotonic;assumption.
     intros ;apply P_id_IF_MIN_monotonic;assumption.
     intros ;apply P_id_IF_MINSORT_monotonic;assumption.
     intros ;apply P_id_EQ_monotonic;assumption.
   Qed.
   
   Ltac rewrite_and_unfold  :=
    do 2 (rewrite marked_measure_equation);
     repeat (
     match goal with
       |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
        rewrite (measure_equation (algebra.Alg.Term f t))
       | H:context [measure (algebra.Alg.Term ?f ?t)] |- _ =>
        rewrite (measure_equation (algebra.Alg.Term f t)) in H|-
       end
     ).
   
   Definition lt a b := (Zwf.Zwf 0) (marked_measure a) (marked_measure b).
   
   Definition le a b := marked_measure a <= marked_measure b.
   
   Lemma lt_le_compat : forall a b c, (lt a b) ->(le b c) ->lt a c.
   Proof.
     unfold lt, le in *.
     intros a b c.
     apply (interp.le_lt_compat_right (interp.o_Z 0)).
   Qed.
   
   Lemma wf_lt : well_founded lt.
   Proof.
     unfold lt in *.
     apply Inverse_Image.wf_inverse_image with  (B:=Z).
     apply Zwf.Zwf_well_founded.
   Qed.
   
   Lemma DP_R_xml_0_scc_10_strict_in_lt :
    Relation_Definitions.inclusion _ DP_R_xml_0_scc_10_strict lt.
   Proof.
     unfold Relation_Definitions.inclusion, lt in *.
     
     intros a b H;destruct H;
      match goal with
        |  |- (Zwf.Zwf 0) _ (marked_measure (algebra.Alg.Term ?f ?l)) =>
         let l'' := algebra.Alg_ext.find_replacement l  in 
          ((apply (interp.le_lt_compat_right (interp.o_Z 0)) with
             (marked_measure (algebra.Alg.Term f l''));[idtac|
            apply marked_measure_star_monotonic;
             repeat (apply algebra.EQT_ext.one_step_list_refl_trans_clos);
             (assumption)||(constructor 1)]))
        end
      ;clear ;rewrite_and_unfold ;repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma DP_R_xml_0_scc_10_large_in_le :
    Relation_Definitions.inclusion _ DP_R_xml_0_scc_10_large le.
   Proof.
     unfold Relation_Definitions.inclusion, le, Zwf.Zwf in *.
     
     intros a b H;destruct H;
      match goal with
        |  |- _ <= marked_measure (algebra.Alg.Term ?f ?l) =>
         let l'' := algebra.Alg_ext.find_replacement l  in 
          ((apply (interp.le_trans (interp.o_Z 0)) with
             (marked_measure (algebra.Alg.Term f l''));[idtac|
            apply marked_measure_star_monotonic;
             repeat (apply algebra.EQT_ext.one_step_list_refl_trans_clos);
             (assumption)||(constructor 1)]))
        end
      ;clear ;rewrite_and_unfold ;repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition wf_DP_R_xml_0_scc_10_large  := WF_DP_R_xml_0_scc_10_large.wf.
   
   
   Lemma wf : well_founded WF_DP_R_xml_0.DP_R_xml_0_scc_10.
   Proof.
     intros x.
     apply (well_founded_ind wf_lt).
     clear x.
     intros x.
     pattern x.
     apply (@Acc_ind _ DP_R_xml_0_scc_10_large).
     clear x.
     intros x _ IHx IHx'.
     constructor.
     intros y H.
     
     destruct H;
      (apply IHx';apply DP_R_xml_0_scc_10_strict_in_lt;
        econstructor eassumption)||
      ((apply IHx;[econstructor eassumption|
        intros y' Hlt;apply IHx';apply lt_le_compat with (1:=Hlt) ;
         apply DP_R_xml_0_scc_10_large_in_le;econstructor eassumption])).
     apply wf_DP_R_xml_0_scc_10_large.
   Qed.
  End WF_DP_R_xml_0_scc_10.
  
  Definition wf_DP_R_xml_0_scc_10  := WF_DP_R_xml_0_scc_10.wf.
  
  
  Lemma acc_DP_R_xml_0_scc_10 :
   forall x y, (DP_R_xml_0_scc_10 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x.
    pattern x.
    apply (@Acc_ind _ DP_R_xml_0_scc_10).
    intros x' _ Hrec y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply Hrec;econstructor eassumption)||
      ((eapply acc_DP_R_xml_0_non_scc_9;
         econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
       ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
        (eapply Hrec;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' )))).
    apply wf_DP_R_xml_0_scc_10.
  Qed.
  
  
  Inductive DP_R_xml_0_non_scc_11  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <if_minsort(true,add(n_,x_),y_),rm(n_,x_)> *)
    | DP_R_xml_0_non_scc_11_0 :
     forall x8 x2 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_true nil) 
        x8) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   x2 x6) ->
         DP_R_xml_0_non_scc_11 (algebra.Alg.Term algebra.F.id_rm (x3::
                                x1::nil)) 
          (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
  .
  
  
  Lemma acc_DP_R_xml_0_non_scc_11 :
   forall x y, 
    (DP_R_xml_0_non_scc_11 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply acc_DP_R_xml_0_scc_10;
        econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
      ((eapply acc_DP_R_xml_0_non_scc_9;
         econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
       ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
        (eapply Hrec;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' )))).
  Qed.
  
  
  Inductive DP_R_xml_0_scc_12  :
   algebra.Alg.term ->algebra.Alg.term ->Prop := 
     (* <if_minsort(true,add(n_,x_),y_),minsort(app(rm(n_,x_),y_),nil)> *)
    | DP_R_xml_0_scc_12_0 :
     forall x8 x2 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_true nil) 
        x8) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   x2 x6) ->
         DP_R_xml_0_scc_12 (algebra.Alg.Term algebra.F.id_minsort 
                            ((algebra.Alg.Term algebra.F.id_app 
                            ((algebra.Alg.Term algebra.F.id_rm (x3::
                            x1::nil))::x2::nil))::(algebra.Alg.Term 
                            algebra.F.id_nil nil)::nil)) 
          (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
    
     (* <minsort(add(n_,x_),y_),if_minsort(eq(n_,min(add(n_,x_))),add(n_,x_),y_)> *)
    | DP_R_xml_0_scc_12_1 :
     forall x2 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 
        (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  x2 x6) ->
        DP_R_xml_0_scc_12 (algebra.Alg.Term algebra.F.id_if_minsort 
                           ((algebra.Alg.Term algebra.F.id_eq (x3::
                           (algebra.Alg.Term algebra.F.id_min 
                           ((algebra.Alg.Term algebra.F.id_add (x3::
                           x1::nil))::nil))::nil))::(algebra.Alg.Term 
                           algebra.F.id_add (x3::x1::nil))::x2::nil)) 
         (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil))
    
     (* <if_minsort(false,add(n_,x_),y_),minsort(x_,add(n_,y_))> *)
    | DP_R_xml_0_scc_12_2 :
     forall x8 x2 x6 x1 x3 x7, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 (algebra.Alg.Term algebra.F.id_false nil) 
        x8) ->
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   x2 x6) ->
         DP_R_xml_0_scc_12 (algebra.Alg.Term algebra.F.id_minsort (x1::
                            (algebra.Alg.Term algebra.F.id_add (x3::
                            x2::nil))::nil)) 
          (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
  .
  
  
  Module WF_DP_R_xml_0_scc_12.
   Inductive DP_R_xml_0_scc_12_large  :
    algebra.Alg.term ->algebra.Alg.term ->Prop := 
      (* <minsort(add(n_,x_),y_),if_minsort(eq(n_,min(add(n_,x_))),add(n_,x_),y_)> *)
     | DP_R_xml_0_scc_12_large_0 :
      forall x2 x6 x1 x3 x7, 
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  
         (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   x2 x6) ->
         DP_R_xml_0_scc_12_large (algebra.Alg.Term algebra.F.id_if_minsort 
                                  ((algebra.Alg.Term algebra.F.id_eq (x3::
                                  (algebra.Alg.Term algebra.F.id_min 
                                  ((algebra.Alg.Term algebra.F.id_add (x3::
                                  x1::nil))::nil))::nil))::(algebra.Alg.Term 
                                  algebra.F.id_add (x3::x1::nil))::x2::nil)) 
          (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil))
     
      (* <if_minsort(false,add(n_,x_),y_),minsort(x_,add(n_,y_))> *)
     | DP_R_xml_0_scc_12_large_1 :
      forall x8 x2 x6 x1 x3 x7, 
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  (algebra.Alg.Term algebra.F.id_false nil) 
         x8) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   
          (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                    x2 x6) ->
          DP_R_xml_0_scc_12_large (algebra.Alg.Term algebra.F.id_minsort 
                                   (x1::(algebra.Alg.Term algebra.F.id_add 
                                   (x3::x2::nil))::nil)) 
           (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
   .
   
   
   Inductive DP_R_xml_0_scc_12_strict  :
    algebra.Alg.term ->algebra.Alg.term ->Prop := 
      (* <if_minsort(true,add(n_,x_),y_),minsort(app(rm(n_,x_),y_),nil)> *)
     | DP_R_xml_0_scc_12_strict_0 :
      forall x8 x2 x6 x1 x3 x7, 
       (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                  (algebra.Alg.Term algebra.F.id_true nil) 
         x8) ->
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   
          (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                    x2 x6) ->
          DP_R_xml_0_scc_12_strict (algebra.Alg.Term algebra.F.id_minsort 
                                    ((algebra.Alg.Term algebra.F.id_app 
                                    ((algebra.Alg.Term algebra.F.id_rm (x3::
                                    x1::nil))::x2::nil))::(algebra.Alg.Term 
                                    algebra.F.id_nil nil)::nil)) 
           (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
   .
   
   
   Module WF_DP_R_xml_0_scc_12_large.
    Inductive DP_R_xml_0_scc_12_large_large  :
     algebra.Alg.term ->algebra.Alg.term ->Prop := 
       (* <if_minsort(false,add(n_,x_),y_),minsort(x_,add(n_,y_))> *)
      | DP_R_xml_0_scc_12_large_large_0 :
       forall x8 x2 x6 x1 x3 x7, 
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   (algebra.Alg.Term algebra.F.id_false nil) 
          x8) ->
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                    
           (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
          (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                     x2 x6) ->
           DP_R_xml_0_scc_12_large_large (algebra.Alg.Term 
                                          algebra.F.id_minsort (x1::
                                          (algebra.Alg.Term algebra.F.id_add 
                                          (x3::x2::nil))::nil)) 
            (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
    .
    
    
    Inductive DP_R_xml_0_scc_12_large_strict  :
     algebra.Alg.term ->algebra.Alg.term ->Prop := 
       (* <minsort(add(n_,x_),y_),if_minsort(eq(n_,min(add(n_,x_))),add(n_,x_),y_)> *)
      | DP_R_xml_0_scc_12_large_strict_0 :
       forall x2 x6 x1 x3 x7, 
        (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                   
          (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                    x2 x6) ->
          DP_R_xml_0_scc_12_large_strict (algebra.Alg.Term 
                                          algebra.F.id_if_minsort 
                                          ((algebra.Alg.Term algebra.F.id_eq 
                                          (x3::(algebra.Alg.Term 
                                          algebra.F.id_min 
                                          ((algebra.Alg.Term 
                                          algebra.F.id_add (x3::
                                          x1::nil))::nil))::nil))::
                                          (algebra.Alg.Term algebra.F.id_add 
                                          (x3::x1::nil))::x2::nil)) 
           (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil))
    .
    
    
    Module WF_DP_R_xml_0_scc_12_large_large.
     Inductive DP_R_xml_0_scc_12_large_large_non_scc_1  :
      algebra.Alg.term ->algebra.Alg.term ->Prop := 
        (* <if_minsort(false,add(n_,x_),y_),minsort(x_,add(n_,y_))> *)
       | DP_R_xml_0_scc_12_large_large_non_scc_1_0 :
        forall x8 x2 x6 x1 x3 x7, 
         (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                    
           (algebra.Alg.Term algebra.F.id_false nil) x8) ->
          (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                     
            (algebra.Alg.Term algebra.F.id_add (x3::x1::nil)) x7) ->
           (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                      x2 x6) ->
            DP_R_xml_0_scc_12_large_large_non_scc_1 (algebra.Alg.Term 
                                                     algebra.F.id_minsort 
                                                     (x1::(algebra.Alg.Term 
                                                     algebra.F.id_add (x3::
                                                     x2::nil))::nil)) 
             (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::x6::nil))
     .
     
     
     Lemma acc_DP_R_xml_0_scc_12_large_large_non_scc_1 :
      forall x y, 
       (DP_R_xml_0_scc_12_large_large_non_scc_1 x y) ->
        Acc WF_DP_R_xml_0_scc_12_large.DP_R_xml_0_scc_12_large_large x.
     Proof.
       intros x y h.
       
       inversion h;clear h;subst;
        constructor;intros _y _h;inversion _h;clear _h;subst;
         (R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
         (eapply Hrec;
           econstructor (eassumption)||(algebra.Alg_ext.star_refl' )).
     Qed.
     
     
     Lemma wf :
      well_founded WF_DP_R_xml_0_scc_12_large.DP_R_xml_0_scc_12_large_large.
     Proof.
       constructor;intros _y _h;inversion _h;clear _h;subst;
        (eapply acc_DP_R_xml_0_scc_12_large_large_non_scc_1;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
        ((eapply acc_DP_R_xml_0_scc_12_large_large_non_scc_0;
           econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
         ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||(fail))).
     Qed.
    End WF_DP_R_xml_0_scc_12_large_large.
    
    Open Scope Z_scope.
    
    Import ring_extention.
    
    Notation Local "a <= b" := (Zle a b).
    
    Notation Local "a < b" := (Zlt a b).
    
    Definition P_id_eq (x6:Z) (x7:Z) := 0.
    
    Definition P_id_add (x6:Z) (x7:Z) := 1 + 1* x6 + 1* x7.
    
    Definition P_id_false  := 0.
    
    Definition P_id_if_rm (x6:Z) (x7:Z) (x8:Z) := 1* x8.
    
    Definition P_id_true  := 0.
    
    Definition P_id_if_min (x6:Z) (x7:Z) := 2* x7.
    
    Definition P_id_app (x6:Z) (x7:Z) := 1* x6 + 1* x7.
    
    Definition P_id_if_minsort (x6:Z) (x7:Z) (x8:Z) := 2* x7 + 2* x8.
    
    Definition P_id_0  := 0.
    
    Definition P_id_min (x6:Z) := 2* x6.
    
    Definition P_id_le (x6:Z) (x7:Z) := 3* x6.
    
    Definition P_id_minsort (x6:Z) (x7:Z) := 2* x6 + 2* x7.
    
    Definition P_id_s (x6:Z) := 2* x6.
    
    Definition P_id_rm (x6:Z) (x7:Z) := 1* x7.
    
    Definition P_id_nil  := 0.
    
    Lemma P_id_eq_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_add_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_if_rm_monotonic :
     forall x8 x10 x6 x9 x11 x7, 
      (0 <= x11)/\ (x11 <= x10) ->
       (0 <= x9)/\ (x9 <= x8) ->
        (0 <= x7)/\ (x7 <= x6) ->P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
    Proof.
      intros x11 x10 x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      intros [H_5 H_4].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_if_min_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_app_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_if_minsort_monotonic :
     forall x8 x10 x6 x9 x11 x7, 
      (0 <= x11)/\ (x11 <= x10) ->
       (0 <= x9)/\ (x9 <= x8) ->
        (0 <= x7)/\ (x7 <= x6) ->
         P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
    Proof.
      intros x11 x10 x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      intros [H_5 H_4].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_min_monotonic :
     forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
    Proof.
      intros x7 x6.
      intros [H_1 H_0].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_le_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_minsort_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_minsort x7 x9 <= P_id_minsort x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_s_monotonic :
     forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
    Proof.
      intros x7 x6.
      intros [H_1 H_0].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_rm_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_eq_bounded :
     forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_eq x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_add_bounded :
     forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_add x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_false_bounded : 0 <= P_id_false .
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_if_rm_bounded :
     forall x8 x6 x7, 
      (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_rm x8 x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_true_bounded : 0 <= P_id_true .
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_if_min_bounded :
     forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_if_min x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_app_bounded :
     forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_app x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_if_minsort_bounded :
     forall x8 x6 x7, 
      (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_minsort x8 x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_0_bounded : 0 <= P_id_0 .
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_min_bounded : forall x6, (0 <= x6) ->0 <= P_id_min x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_le_bounded :
     forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_le x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_minsort_bounded :
     forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_minsort x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_s_bounded : forall x6, (0 <= x6) ->0 <= P_id_s x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_rm_bounded :
     forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_rm x7 x6.
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_nil_bounded : 0 <= P_id_nil .
    Proof.
      intros .
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Definition measure  := 
      InterpZ.measure 0 P_id_eq P_id_add P_id_false P_id_if_rm P_id_true 
       P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min P_id_le 
       P_id_minsort P_id_s P_id_rm P_id_nil.
    
    Lemma measure_equation :
     forall t, 
      measure t = match t with
                    | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                     P_id_eq (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                     P_id_add (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_false nil) =>
                     P_id_false 
                    | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                     P_id_if_rm (measure x8) (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                    | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                     P_id_if_min (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                     P_id_app (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                       x6::nil)) =>
                     P_id_if_minsort (measure x8) (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                    | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                     P_id_min (measure x6)
                    | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                     P_id_le (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                     P_id_minsort (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                     P_id_s (measure x6)
                    | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                     P_id_rm (measure x7) (measure x6)
                    | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                    | _ => 0
                    end.
    Proof.
      intros t;case t;intros ;apply refl_equal.
    Qed.
    
    Lemma measure_bounded : forall t, 0 <= measure t.
    Proof.
      unfold measure in |-*.
      
      apply InterpZ.measure_bounded;
       cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
        (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Ltac generate_pos_hyp  :=
     match goal with
       | H:context [measure ?x] |- _ =>
        let v := fresh "v" in 
         (let H := fresh "h" in 
           (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
             clearbody H;clearbody v))
       |  |- context [measure ?x] =>
        let v := fresh "v" in 
         (let H := fresh "h" in 
           (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
             clearbody H;clearbody v))
       end
     .
    
    Lemma rules_monotonic :
     forall l r, 
      (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
       measure r <= measure l.
    Proof.
      intros l r H.
      fold measure in |-*.
      
      inversion H;clear H;subst;inversion H0;clear H0;subst;
       simpl algebra.EQT.T.apply_subst in |-*;
       repeat (
       match goal with
         |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
          rewrite (measure_equation (algebra.Alg.Term f t))
         end
       );repeat (generate_pos_hyp );
       cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
        (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma measure_star_monotonic :
     forall l r, 
      (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                 r l) ->measure r <= measure l.
    Proof.
      unfold measure in *.
      apply InterpZ.measure_star_monotonic.
      intros ;apply P_id_eq_monotonic;assumption.
      intros ;apply P_id_add_monotonic;assumption.
      intros ;apply P_id_if_rm_monotonic;assumption.
      intros ;apply P_id_if_min_monotonic;assumption.
      intros ;apply P_id_app_monotonic;assumption.
      intros ;apply P_id_if_minsort_monotonic;assumption.
      intros ;apply P_id_min_monotonic;assumption.
      intros ;apply P_id_le_monotonic;assumption.
      intros ;apply P_id_minsort_monotonic;assumption.
      intros ;apply P_id_s_monotonic;assumption.
      intros ;apply P_id_rm_monotonic;assumption.
      intros ;apply P_id_eq_bounded;assumption.
      intros ;apply P_id_add_bounded;assumption.
      intros ;apply P_id_false_bounded;assumption.
      intros ;apply P_id_if_rm_bounded;assumption.
      intros ;apply P_id_true_bounded;assumption.
      intros ;apply P_id_if_min_bounded;assumption.
      intros ;apply P_id_app_bounded;assumption.
      intros ;apply P_id_if_minsort_bounded;assumption.
      intros ;apply P_id_0_bounded;assumption.
      intros ;apply P_id_min_bounded;assumption.
      intros ;apply P_id_le_bounded;assumption.
      intros ;apply P_id_minsort_bounded;assumption.
      intros ;apply P_id_s_bounded;assumption.
      intros ;apply P_id_rm_bounded;assumption.
      intros ;apply P_id_nil_bounded;assumption.
      apply rules_monotonic.
    Qed.
    
    Definition P_id_LE (x6:Z) (x7:Z) := 0.
    
    Definition P_id_RM (x6:Z) (x7:Z) := 0.
    
    Definition P_id_MIN (x6:Z) := 0.
    
    Definition P_id_MINSORT (x6:Z) (x7:Z) := 2 + 1* x6.
    
    Definition P_id_APP (x6:Z) (x7:Z) := 0.
    
    Definition P_id_IF_RM (x6:Z) (x7:Z) (x8:Z) := 0.
    
    Definition P_id_IF_MIN (x6:Z) (x7:Z) := 0.
    
    Definition P_id_IF_MINSORT (x6:Z) (x7:Z) (x8:Z) := 1 + 1* x7.
    
    Definition P_id_EQ (x6:Z) (x7:Z) := 0.
    
    Lemma P_id_LE_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_RM_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_MIN_monotonic :
     forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
    Proof.
      intros x7 x6.
      intros [H_1 H_0].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_MINSORT_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_APP_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_IF_RM_monotonic :
     forall x8 x10 x6 x9 x11 x7, 
      (0 <= x11)/\ (x11 <= x10) ->
       (0 <= x9)/\ (x9 <= x8) ->
        (0 <= x7)/\ (x7 <= x6) ->P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
    Proof.
      intros x11 x10 x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      intros [H_5 H_4].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_IF_MIN_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_IF_MINSORT_monotonic :
     forall x8 x10 x6 x9 x11 x7, 
      (0 <= x11)/\ (x11 <= x10) ->
       (0 <= x9)/\ (x9 <= x8) ->
        (0 <= x7)/\ (x7 <= x6) ->
         P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
    Proof.
      intros x11 x10 x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      intros [H_5 H_4].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma P_id_EQ_monotonic :
     forall x8 x6 x9 x7, 
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
    Proof.
      intros x9 x8 x7 x6.
      intros [H_1 H_0].
      intros [H_3 H_2].
      
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Definition marked_measure  := 
      InterpZ.marked_measure 0 P_id_eq P_id_add P_id_false P_id_if_rm 
       P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
       P_id_le P_id_minsort P_id_s P_id_rm P_id_nil P_id_LE P_id_RM P_id_MIN 
       P_id_MINSORT P_id_APP P_id_IF_RM P_id_IF_MIN P_id_IF_MINSORT P_id_EQ.
    
    Lemma marked_measure_equation :
     forall t, 
      marked_measure t = match t with
                           | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                            P_id_LE (measure x7) (measure x6)
                           | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                            P_id_RM (measure x7) (measure x6)
                           | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                            P_id_MIN (measure x6)
                           | (algebra.Alg.Term algebra.F.id_minsort (x7::
                              x6::nil)) =>
                            P_id_MINSORT (measure x7) (measure x6)
                           | (algebra.Alg.Term algebra.F.id_app (x7::
                              x6::nil)) =>
                            P_id_APP (measure x7) (measure x6)
                           | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                              x6::nil)) =>
                            P_id_IF_RM (measure x8) (measure x7) (measure x6)
                           | (algebra.Alg.Term algebra.F.id_if_min (x7::
                              x6::nil)) =>
                            P_id_IF_MIN (measure x7) (measure x6)
                           | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                              x7::x6::nil)) =>
                            P_id_IF_MINSORT (measure x8) (measure x7) 
                             (measure x6)
                           | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                            P_id_EQ (measure x7) (measure x6)
                           | _ => measure t
                           end.
    Proof.
      reflexivity .
    Qed.
    
    Lemma marked_measure_star_monotonic :
     forall f l1 l2, 
      (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                        R_xml_0_deep_rew.R_xml_0_rules)
                                                       ) l1 l2) ->
       marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                  f l2).
    Proof.
      unfold marked_measure in *.
      apply InterpZ.marked_measure_star_monotonic.
      intros ;apply P_id_eq_monotonic;assumption.
      intros ;apply P_id_add_monotonic;assumption.
      intros ;apply P_id_if_rm_monotonic;assumption.
      intros ;apply P_id_if_min_monotonic;assumption.
      intros ;apply P_id_app_monotonic;assumption.
      intros ;apply P_id_if_minsort_monotonic;assumption.
      intros ;apply P_id_min_monotonic;assumption.
      intros ;apply P_id_le_monotonic;assumption.
      intros ;apply P_id_minsort_monotonic;assumption.
      intros ;apply P_id_s_monotonic;assumption.
      intros ;apply P_id_rm_monotonic;assumption.
      intros ;apply P_id_eq_bounded;assumption.
      intros ;apply P_id_add_bounded;assumption.
      intros ;apply P_id_false_bounded;assumption.
      intros ;apply P_id_if_rm_bounded;assumption.
      intros ;apply P_id_true_bounded;assumption.
      intros ;apply P_id_if_min_bounded;assumption.
      intros ;apply P_id_app_bounded;assumption.
      intros ;apply P_id_if_minsort_bounded;assumption.
      intros ;apply P_id_0_bounded;assumption.
      intros ;apply P_id_min_bounded;assumption.
      intros ;apply P_id_le_bounded;assumption.
      intros ;apply P_id_minsort_bounded;assumption.
      intros ;apply P_id_s_bounded;assumption.
      intros ;apply P_id_rm_bounded;assumption.
      intros ;apply P_id_nil_bounded;assumption.
      apply rules_monotonic.
      intros ;apply P_id_LE_monotonic;assumption.
      intros ;apply P_id_RM_monotonic;assumption.
      intros ;apply P_id_MIN_monotonic;assumption.
      intros ;apply P_id_MINSORT_monotonic;assumption.
      intros ;apply P_id_APP_monotonic;assumption.
      intros ;apply P_id_IF_RM_monotonic;assumption.
      intros ;apply P_id_IF_MIN_monotonic;assumption.
      intros ;apply P_id_IF_MINSORT_monotonic;assumption.
      intros ;apply P_id_EQ_monotonic;assumption.
    Qed.
    
    Ltac rewrite_and_unfold  :=
     do 2 (rewrite marked_measure_equation);
      repeat (
      match goal with
        |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
         rewrite (measure_equation (algebra.Alg.Term f t))
        | H:context [measure (algebra.Alg.Term ?f ?t)] |- _ =>
         rewrite (measure_equation (algebra.Alg.Term f t)) in H|-
        end
      ).
    
    Definition lt a b := (Zwf.Zwf 0) (marked_measure a) (marked_measure b).
    
    Definition le a b := marked_measure a <= marked_measure b.
    
    Lemma lt_le_compat : forall a b c, (lt a b) ->(le b c) ->lt a c.
    Proof.
      unfold lt, le in *.
      intros a b c.
      apply (interp.le_lt_compat_right (interp.o_Z 0)).
    Qed.
    
    Lemma wf_lt : well_founded lt.
    Proof.
      unfold lt in *.
      apply Inverse_Image.wf_inverse_image with  (B:=Z).
      apply Zwf.Zwf_well_founded.
    Qed.
    
    Lemma DP_R_xml_0_scc_12_large_strict_in_lt :
     Relation_Definitions.inclusion _ DP_R_xml_0_scc_12_large_strict lt.
    Proof.
      unfold Relation_Definitions.inclusion, lt in *.
      
      intros a b H;destruct H;
       match goal with
         |  |- (Zwf.Zwf 0) _ (marked_measure (algebra.Alg.Term ?f ?l)) =>
          let l'' := algebra.Alg_ext.find_replacement l  in 
           ((apply (interp.le_lt_compat_right (interp.o_Z 0)) with
              (marked_measure (algebra.Alg.Term f l''));[idtac|
             apply marked_measure_star_monotonic;
              repeat (apply algebra.EQT_ext.one_step_list_refl_trans_clos);
              (assumption)||(constructor 1)]))
         end
       ;clear ;rewrite_and_unfold ;repeat (generate_pos_hyp );
       cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
        (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Lemma DP_R_xml_0_scc_12_large_large_in_le :
     Relation_Definitions.inclusion _ DP_R_xml_0_scc_12_large_large le.
    Proof.
      unfold Relation_Definitions.inclusion, le, Zwf.Zwf in *.
      
      intros a b H;destruct H;
       match goal with
         |  |- _ <= marked_measure (algebra.Alg.Term ?f ?l) =>
          let l'' := algebra.Alg_ext.find_replacement l  in 
           ((apply (interp.le_trans (interp.o_Z 0)) with
              (marked_measure (algebra.Alg.Term f l''));[idtac|
             apply marked_measure_star_monotonic;
              repeat (apply algebra.EQT_ext.one_step_list_refl_trans_clos);
              (assumption)||(constructor 1)]))
         end
       ;clear ;rewrite_and_unfold ;repeat (generate_pos_hyp );
       cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
        (auto with zarith)||(repeat (translate_vars );prove_ineq ).
    Qed.
    
    Definition wf_DP_R_xml_0_scc_12_large_large  := 
      WF_DP_R_xml_0_scc_12_large_large.wf.
    
    
    Lemma wf : well_founded WF_DP_R_xml_0_scc_12.DP_R_xml_0_scc_12_large.
    Proof.
      intros x.
      apply (well_founded_ind wf_lt).
      clear x.
      intros x.
      pattern x.
      apply (@Acc_ind _ DP_R_xml_0_scc_12_large_large).
      clear x.
      intros x _ IHx IHx'.
      constructor.
      intros y H.
      
      destruct H;
       (apply IHx';apply DP_R_xml_0_scc_12_large_strict_in_lt;
         econstructor eassumption)||
       ((apply IHx;[econstructor eassumption|
         intros y' Hlt;apply IHx';apply lt_le_compat with (1:=Hlt) ;
          apply DP_R_xml_0_scc_12_large_large_in_le;econstructor eassumption])).
      apply wf_DP_R_xml_0_scc_12_large_large.
    Qed.
   End WF_DP_R_xml_0_scc_12_large.
   
   Open Scope Z_scope.
   
   Import ring_extention.
   
   Notation Local "a <= b" := (Zle a b).
   
   Notation Local "a < b" := (Zlt a b).
   
   Definition P_id_eq (x6:Z) (x7:Z) := 0.
   
   Definition P_id_add (x6:Z) (x7:Z) := 2 + 2* x6 + 1* x7.
   
   Definition P_id_false  := 0.
   
   Definition P_id_if_rm (x6:Z) (x7:Z) (x8:Z) := 1* x7 + 1* x8.
   
   Definition P_id_true  := 0.
   
   Definition P_id_if_min (x6:Z) (x7:Z) := 1* x7.
   
   Definition P_id_app (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_if_minsort (x6:Z) (x7:Z) (x8:Z) := 2* x7 + 2* x8.
   
   Definition P_id_0  := 3.
   
   Definition P_id_min (x6:Z) := 1* x6.
   
   Definition P_id_le (x6:Z) (x7:Z) := 3* x6 + 3* x7.
   
   Definition P_id_minsort (x6:Z) (x7:Z) := 2* x6 + 2* x7.
   
   Definition P_id_s (x6:Z) := 3 + 2* x6.
   
   Definition P_id_rm (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_nil  := 0.
   
   Lemma P_id_eq_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_eq x7 x9 <= P_id_eq x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_add x7 x9 <= P_id_add x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_if_rm x7 x9 x11 <= P_id_if_rm x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_if_min x7 x9 <= P_id_if_min x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_app x7 x9 <= P_id_app x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_if_minsort x7 x9 x11 <= P_id_if_minsort x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_min x7 <= P_id_min x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_le x7 x9 <= P_id_le x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_minsort x7 x9 <= P_id_minsort x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_s x7 <= P_id_s x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_rm x7 x9 <= P_id_rm x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_eq_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_eq x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_add_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_add x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_false_bounded : 0 <= P_id_false .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_rm_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_rm x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_true_bounded : 0 <= P_id_true .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_min_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_if_min x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_app_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_app x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_if_minsort_bounded :
    forall x8 x6 x7, 
     (0 <= x6) ->(0 <= x7) ->(0 <= x8) ->0 <= P_id_if_minsort x8 x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_0_bounded : 0 <= P_id_0 .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_min_bounded : forall x6, (0 <= x6) ->0 <= P_id_min x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_le_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_le x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_minsort_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_minsort x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_s_bounded : forall x6, (0 <= x6) ->0 <= P_id_s x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_rm_bounded :
    forall x6 x7, (0 <= x6) ->(0 <= x7) ->0 <= P_id_rm x7 x6.
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_nil_bounded : 0 <= P_id_nil .
   Proof.
     intros .
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition measure  := 
     InterpZ.measure 0 P_id_eq P_id_add P_id_false P_id_if_rm P_id_true 
      P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min P_id_le 
      P_id_minsort P_id_s P_id_rm P_id_nil.
   
   Lemma measure_equation :
    forall t, 
     measure t = match t with
                   | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                    P_id_eq (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_add (x7::x6::nil)) =>
                    P_id_add (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_false nil) => P_id_false 
                   | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::x6::nil)) =>
                    P_id_if_rm (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_true nil) => P_id_true 
                   | (algebra.Alg.Term algebra.F.id_if_min (x7::x6::nil)) =>
                    P_id_if_min (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                    P_id_app (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_if_minsort (x8::x7::
                      x6::nil)) =>
                    P_id_if_minsort (measure x8) (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_0 nil) => P_id_0 
                   | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                    P_id_min (measure x6)
                   | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                    P_id_le (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_minsort (x7::x6::nil)) =>
                    P_id_minsort (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_s (x6::nil)) =>
                    P_id_s (measure x6)
                   | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                    P_id_rm (measure x7) (measure x6)
                   | (algebra.Alg.Term algebra.F.id_nil nil) => P_id_nil 
                   | _ => 0
                   end.
   Proof.
     intros t;case t;intros ;apply refl_equal.
   Qed.
   
   Lemma measure_bounded : forall t, 0 <= measure t.
   Proof.
     unfold measure in |-*.
     
     apply InterpZ.measure_bounded;
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Ltac generate_pos_hyp  :=
    match goal with
      | H:context [measure ?x] |- _ =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      |  |- context [measure ?x] =>
       let v := fresh "v" in 
        (let H := fresh "h" in 
          (set (H:=measure_bounded x) in *;set (v:=measure x) in *;
            clearbody H;clearbody v))
      end
    .
   
   Lemma rules_monotonic :
    forall l r, 
     (algebra.EQT.axiom R_xml_0_deep_rew.R_xml_0_rules r l) ->
      measure r <= measure l.
   Proof.
     intros l r H.
     fold measure in |-*.
     
     inversion H;clear H;subst;inversion H0;clear H0;subst;
      simpl algebra.EQT.T.apply_subst in |-*;
      repeat (
      match goal with
        |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
         rewrite (measure_equation (algebra.Alg.Term f t))
        end
      );repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma measure_star_monotonic :
    forall l r, 
     (closure.refl_trans_clos (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules)
                                r l) ->measure r <= measure l.
   Proof.
     unfold measure in *.
     apply InterpZ.measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
   Qed.
   
   Definition P_id_LE (x6:Z) (x7:Z) := 0.
   
   Definition P_id_RM (x6:Z) (x7:Z) := 0.
   
   Definition P_id_MIN (x6:Z) := 0.
   
   Definition P_id_MINSORT (x6:Z) (x7:Z) := 1* x6 + 1* x7.
   
   Definition P_id_APP (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_RM (x6:Z) (x7:Z) (x8:Z) := 0.
   
   Definition P_id_IF_MIN (x6:Z) (x7:Z) := 0.
   
   Definition P_id_IF_MINSORT (x6:Z) (x7:Z) (x8:Z) := 1* x7 + 1* x8.
   
   Definition P_id_EQ (x6:Z) (x7:Z) := 0.
   
   Lemma P_id_LE_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_LE x7 x9 <= P_id_LE x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_RM_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_RM x7 x9 <= P_id_RM x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MIN_monotonic :
    forall x6 x7, (0 <= x7)/\ (x7 <= x6) ->P_id_MIN x7 <= P_id_MIN x6.
   Proof.
     intros x7 x6.
     intros [H_1 H_0].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_MINSORT_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_MINSORT x7 x9 <= P_id_MINSORT x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_APP_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_APP x7 x9 <= P_id_APP x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_RM_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->P_id_IF_RM x7 x9 x11 <= P_id_IF_RM x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MIN_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_IF_MIN x7 x9 <= P_id_IF_MIN x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_IF_MINSORT_monotonic :
    forall x8 x10 x6 x9 x11 x7, 
     (0 <= x11)/\ (x11 <= x10) ->
      (0 <= x9)/\ (x9 <= x8) ->
       (0 <= x7)/\ (x7 <= x6) ->
        P_id_IF_MINSORT x7 x9 x11 <= P_id_IF_MINSORT x6 x8 x10.
   Proof.
     intros x11 x10 x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     intros [H_5 H_4].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma P_id_EQ_monotonic :
    forall x8 x6 x9 x7, 
     (0 <= x9)/\ (x9 <= x8) ->
      (0 <= x7)/\ (x7 <= x6) ->P_id_EQ x7 x9 <= P_id_EQ x6 x8.
   Proof.
     intros x9 x8 x7 x6.
     intros [H_1 H_0].
     intros [H_3 H_2].
     
     cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
      (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition marked_measure  := 
     InterpZ.marked_measure 0 P_id_eq P_id_add P_id_false P_id_if_rm 
      P_id_true P_id_if_min P_id_app P_id_if_minsort P_id_0 P_id_min 
      P_id_le P_id_minsort P_id_s P_id_rm P_id_nil P_id_LE P_id_RM P_id_MIN 
      P_id_MINSORT P_id_APP P_id_IF_RM P_id_IF_MIN P_id_IF_MINSORT P_id_EQ.
   
   Lemma marked_measure_equation :
    forall t, 
     marked_measure t = match t with
                          | (algebra.Alg.Term algebra.F.id_le (x7::x6::nil)) =>
                           P_id_LE (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_rm (x7::x6::nil)) =>
                           P_id_RM (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_min (x6::nil)) =>
                           P_id_MIN (measure x6)
                          | (algebra.Alg.Term algebra.F.id_minsort (x7::
                             x6::nil)) =>
                           P_id_MINSORT (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_app (x7::x6::nil)) =>
                           P_id_APP (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_rm (x8::x7::
                             x6::nil)) =>
                           P_id_IF_RM (measure x8) (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_min (x7::
                             x6::nil)) =>
                           P_id_IF_MIN (measure x7) (measure x6)
                          | (algebra.Alg.Term algebra.F.id_if_minsort (x8::
                             x7::x6::nil)) =>
                           P_id_IF_MINSORT (measure x8) (measure x7) 
                            (measure x6)
                          | (algebra.Alg.Term algebra.F.id_eq (x7::x6::nil)) =>
                           P_id_EQ (measure x7) (measure x6)
                          | _ => measure t
                          end.
   Proof.
     reflexivity .
   Qed.
   
   Lemma marked_measure_star_monotonic :
    forall f l1 l2, 
     (closure.refl_trans_clos (closure.one_step_list (algebra.EQT.one_step 
                                                       R_xml_0_deep_rew.R_xml_0_rules)
                                                      ) l1 l2) ->
      marked_measure (algebra.Alg.Term f l1) <= marked_measure (algebra.Alg.Term 
                                                                 f l2).
   Proof.
     unfold marked_measure in *.
     apply InterpZ.marked_measure_star_monotonic.
     intros ;apply P_id_eq_monotonic;assumption.
     intros ;apply P_id_add_monotonic;assumption.
     intros ;apply P_id_if_rm_monotonic;assumption.
     intros ;apply P_id_if_min_monotonic;assumption.
     intros ;apply P_id_app_monotonic;assumption.
     intros ;apply P_id_if_minsort_monotonic;assumption.
     intros ;apply P_id_min_monotonic;assumption.
     intros ;apply P_id_le_monotonic;assumption.
     intros ;apply P_id_minsort_monotonic;assumption.
     intros ;apply P_id_s_monotonic;assumption.
     intros ;apply P_id_rm_monotonic;assumption.
     intros ;apply P_id_eq_bounded;assumption.
     intros ;apply P_id_add_bounded;assumption.
     intros ;apply P_id_false_bounded;assumption.
     intros ;apply P_id_if_rm_bounded;assumption.
     intros ;apply P_id_true_bounded;assumption.
     intros ;apply P_id_if_min_bounded;assumption.
     intros ;apply P_id_app_bounded;assumption.
     intros ;apply P_id_if_minsort_bounded;assumption.
     intros ;apply P_id_0_bounded;assumption.
     intros ;apply P_id_min_bounded;assumption.
     intros ;apply P_id_le_bounded;assumption.
     intros ;apply P_id_minsort_bounded;assumption.
     intros ;apply P_id_s_bounded;assumption.
     intros ;apply P_id_rm_bounded;assumption.
     intros ;apply P_id_nil_bounded;assumption.
     apply rules_monotonic.
     intros ;apply P_id_LE_monotonic;assumption.
     intros ;apply P_id_RM_monotonic;assumption.
     intros ;apply P_id_MIN_monotonic;assumption.
     intros ;apply P_id_MINSORT_monotonic;assumption.
     intros ;apply P_id_APP_monotonic;assumption.
     intros ;apply P_id_IF_RM_monotonic;assumption.
     intros ;apply P_id_IF_MIN_monotonic;assumption.
     intros ;apply P_id_IF_MINSORT_monotonic;assumption.
     intros ;apply P_id_EQ_monotonic;assumption.
   Qed.
   
   Ltac rewrite_and_unfold  :=
    do 2 (rewrite marked_measure_equation);
     repeat (
     match goal with
       |  |- context [measure (algebra.Alg.Term ?f ?t)] =>
        rewrite (measure_equation (algebra.Alg.Term f t))
       | H:context [measure (algebra.Alg.Term ?f ?t)] |- _ =>
        rewrite (measure_equation (algebra.Alg.Term f t)) in H|-
       end
     ).
   
   Definition lt a b := (Zwf.Zwf 0) (marked_measure a) (marked_measure b).
   
   Definition le a b := marked_measure a <= marked_measure b.
   
   Lemma lt_le_compat : forall a b c, (lt a b) ->(le b c) ->lt a c.
   Proof.
     unfold lt, le in *.
     intros a b c.
     apply (interp.le_lt_compat_right (interp.o_Z 0)).
   Qed.
   
   Lemma wf_lt : well_founded lt.
   Proof.
     unfold lt in *.
     apply Inverse_Image.wf_inverse_image with  (B:=Z).
     apply Zwf.Zwf_well_founded.
   Qed.
   
   Lemma DP_R_xml_0_scc_12_strict_in_lt :
    Relation_Definitions.inclusion _ DP_R_xml_0_scc_12_strict lt.
   Proof.
     unfold Relation_Definitions.inclusion, lt in *.
     
     intros a b H;destruct H;
      match goal with
        |  |- (Zwf.Zwf 0) _ (marked_measure (algebra.Alg.Term ?f ?l)) =>
         let l'' := algebra.Alg_ext.find_replacement l  in 
          ((apply (interp.le_lt_compat_right (interp.o_Z 0)) with
             (marked_measure (algebra.Alg.Term f l''));[idtac|
            apply marked_measure_star_monotonic;
             repeat (apply algebra.EQT_ext.one_step_list_refl_trans_clos);
             (assumption)||(constructor 1)]))
        end
      ;clear ;rewrite_and_unfold ;repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Lemma DP_R_xml_0_scc_12_large_in_le :
    Relation_Definitions.inclusion _ DP_R_xml_0_scc_12_large le.
   Proof.
     unfold Relation_Definitions.inclusion, le, Zwf.Zwf in *.
     
     intros a b H;destruct H;
      match goal with
        |  |- _ <= marked_measure (algebra.Alg.Term ?f ?l) =>
         let l'' := algebra.Alg_ext.find_replacement l  in 
          ((apply (interp.le_trans (interp.o_Z 0)) with
             (marked_measure (algebra.Alg.Term f l''));[idtac|
            apply marked_measure_star_monotonic;
             repeat (apply algebra.EQT_ext.one_step_list_refl_trans_clos);
             (assumption)||(constructor 1)]))
        end
      ;clear ;rewrite_and_unfold ;repeat (generate_pos_hyp );
      cbv beta iota zeta delta - [Zle Zlt Zplus Zmult] ;intuition;
       (auto with zarith)||(repeat (translate_vars );prove_ineq ).
   Qed.
   
   Definition wf_DP_R_xml_0_scc_12_large  := WF_DP_R_xml_0_scc_12_large.wf.
   
   
   Lemma wf : well_founded WF_DP_R_xml_0.DP_R_xml_0_scc_12.
   Proof.
     intros x.
     apply (well_founded_ind wf_lt).
     clear x.
     intros x.
     pattern x.
     apply (@Acc_ind _ DP_R_xml_0_scc_12_large).
     clear x.
     intros x _ IHx IHx'.
     constructor.
     intros y H.
     
     destruct H;
      (apply IHx';apply DP_R_xml_0_scc_12_strict_in_lt;
        econstructor eassumption)||
      ((apply IHx;[econstructor eassumption|
        intros y' Hlt;apply IHx';apply lt_le_compat with (1:=Hlt) ;
         apply DP_R_xml_0_scc_12_large_in_le;econstructor eassumption])).
     apply wf_DP_R_xml_0_scc_12_large.
   Qed.
  End WF_DP_R_xml_0_scc_12.
  
  Definition wf_DP_R_xml_0_scc_12  := WF_DP_R_xml_0_scc_12.wf.
  
  
  Lemma acc_DP_R_xml_0_scc_12 :
   forall x y, (DP_R_xml_0_scc_12 x y) ->Acc WF_R_xml_0_deep_rew.DP_R_xml_0 x.
  Proof.
    intros x.
    pattern x.
    apply (@Acc_ind _ DP_R_xml_0_scc_12).
    intros x' _ Hrec y h.
    
    inversion h;clear h;subst;
     constructor;intros _y _h;inversion _h;clear _h;subst;
      (eapply Hrec;econstructor eassumption)||
      ((eapply acc_DP_R_xml_0_non_scc_11;
         econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
       ((eapply acc_DP_R_xml_0_non_scc_8;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
        ((eapply acc_DP_R_xml_0_non_scc_6;
           econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
         ((eapply acc_DP_R_xml_0_non_scc_2;
            econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
          ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
           (eapply Hrec;
             econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))))))).
    apply wf_DP_R_xml_0_scc_12.
  Qed.
  
  
  Lemma wf : well_founded WF_R_xml_0_deep_rew.DP_R_xml_0.
  Proof.
    constructor;intros _y _h;inversion _h;clear _h;subst;
     (eapply acc_DP_R_xml_0_non_scc_11;
       econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
     ((eapply acc_DP_R_xml_0_non_scc_10;
        econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
      ((eapply acc_DP_R_xml_0_non_scc_9;
         econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
       ((eapply acc_DP_R_xml_0_non_scc_8;
          econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
        ((eapply acc_DP_R_xml_0_non_scc_7;
           econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
         ((eapply acc_DP_R_xml_0_non_scc_6;
            econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
          ((eapply acc_DP_R_xml_0_non_scc_5;
             econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
           ((eapply acc_DP_R_xml_0_non_scc_4;
              econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
            ((eapply acc_DP_R_xml_0_non_scc_3;
               econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
             ((eapply acc_DP_R_xml_0_non_scc_2;
                econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
              ((eapply acc_DP_R_xml_0_non_scc_1;
                 econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
               ((eapply acc_DP_R_xml_0_non_scc_0;
                  econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
                ((eapply acc_DP_R_xml_0_scc_12;
                   econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
                 ((eapply acc_DP_R_xml_0_scc_11;
                    econstructor (eassumption)||(algebra.Alg_ext.star_refl' ))||
                  ((eapply acc_DP_R_xml_0_scc_10;
                     econstructor 
                     (eassumption)||(algebra.Alg_ext.star_refl' ))||
                   ((eapply acc_DP_R_xml_0_scc_9;
                      econstructor 
                      (eassumption)||(algebra.Alg_ext.star_refl' ))||
                    ((eapply acc_DP_R_xml_0_scc_8;
                       econstructor 
                       (eassumption)||(algebra.Alg_ext.star_refl' ))||
                     ((eapply acc_DP_R_xml_0_scc_7;
                        econstructor 
                        (eassumption)||(algebra.Alg_ext.star_refl' ))||
                      ((eapply acc_DP_R_xml_0_scc_6;
                         econstructor 
                         (eassumption)||(algebra.Alg_ext.star_refl' ))||
                       ((eapply acc_DP_R_xml_0_scc_5;
                          econstructor 
                          (eassumption)||(algebra.Alg_ext.star_refl' ))||
                        ((eapply acc_DP_R_xml_0_scc_4;
                           econstructor 
                           (eassumption)||(algebra.Alg_ext.star_refl' ))||
                         ((eapply acc_DP_R_xml_0_scc_3;
                            econstructor 
                            (eassumption)||(algebra.Alg_ext.star_refl' ))||
                          ((eapply acc_DP_R_xml_0_scc_2;
                             econstructor 
                             (eassumption)||(algebra.Alg_ext.star_refl' ))||
                           ((eapply acc_DP_R_xml_0_scc_1;
                              econstructor 
                              (eassumption)||(algebra.Alg_ext.star_refl' ))||
                            ((eapply acc_DP_R_xml_0_scc_0;
                               econstructor 
                               (eassumption)||(algebra.Alg_ext.star_refl' ))||
                             ((R_xml_0_deep_rew.impossible_star_reduction_R_xml_0 )||
                              (fail)))))))))))))))))))))))))).
  Qed.
 End WF_DP_R_xml_0.
 
 Definition wf_H  := WF_DP_R_xml_0.wf.
 
 Lemma wf :
  well_founded (algebra.EQT.one_step R_xml_0_deep_rew.R_xml_0_rules).
 Proof.
   apply ddp.dp_criterion.
   apply R_xml_0_deep_rew.R_xml_0_non_var.
   apply R_xml_0_deep_rew.R_xml_0_reg.
   
   intros ;
    apply (ddp.constructor_defined_dec _ _ 
            R_xml_0_deep_rew.R_xml_0_rules_included).
   refine (Inclusion.wf_incl _ _ _ _ wf_H).
   intros x y H.
   destruct (R_xml_0_dp_step_spec H) as [f [l1 [l2 [H1 [H2 H3]]]]].
   
   destruct (ddp.dp_list_complete _ _ 
              R_xml_0_deep_rew.R_xml_0_rules_included _ _ H3)
    as [x' [y' [sigma [h1 [h2 h3]]]]].
   clear H3.
   subst.
   vm_compute in h3|-.
   let e := type of h3 in (dp_concl_tac h2 h3 ltac:(fun _ => idtac) e).
 Qed.
End WF_R_xml_0_deep_rew.


(* 
*** Local Variables: ***
*** coq-prog-name: "coqtop" ***
*** coq-prog-args: ("-emacs-U" "-I" "$COCCINELLE/examples" "-I" "$COCCINELLE/term_algebra" "-I" "$COCCINELLE/term_orderings" "-I" "$COCCINELLE/basis" "-I" "$COCCINELLE/list_extensions" "-I" "$COCCINELLE/examples/cime_trace/") ***
*** compile-command: "coqc -I $COCCINELLE/term_algebra -I $COCCINELLE/term_orderings -I $COCCINELLE/basis -I $COCCINELLE/list_extensions -I $COCCINELLE/examples/cime_trace/ -I $COCCINELLE/examples/  c_output/strat/tpdb-5.0___TRS___AG01___3.10.trs/a3pat.v" ***
*** End: ***
 *)