Fixpoint freshmax_expr (e: expr) : var :=
  match e with
  | Nil => minid
  | Var v => v
  end.Definition var_max (x y : var) : var :=
 match Ident.compare x y with Lt => y | _ => x end.Definition freshmax_pn_atom (a: pn_atom) : var :=
  match a with
  | Equ e1 e2 => var_max (freshmax_expr e1) (freshmax_expr e2)
  | Nequ e1 e2 => var_max (freshmax_expr e1) (freshmax_expr e2)
  end.Definition freshmax_space_atom (a: space_atom) : var :=
  match a with
  | Next e1 e2 =>  var_max (freshmax_expr e1) (freshmax_expr e2)
  | Lseg e1 e2 =>  var_max (freshmax_expr e1) (freshmax_expr e2)
 end.Definition freshmax_list {A} (f: A -> var) (l: list A) : var :=
  fold_right (fun a i => var_max (f a) i) minid l.Definition freshmax_assertion (a: assertion) : var :=
  match a with
  | Assertion pi sigma =>
     var_max (freshmax_list freshmax_pn_atom pi)
            (freshmax_list freshmax_space_atom sigma)
  end.Definition freshmax_pure_atom (a: pure_atom) : var :=
  match a with
  | Eqv e1 e2 => var_max (freshmax_expr e1) (freshmax_expr e2)
  end.Definition freshmax_clause (c : clause) : var :=
 match c with
 | PureClause pi pi' _ _ =>  var_max (freshmax_list freshmax_pure_atom pi)
                                     (freshmax_list freshmax_pure_atom pi')
 | PosSpaceClause pi pi' sigma =>
     var_max (var_max (freshmax_list freshmax_pure_atom pi)
                                     (freshmax_list freshmax_pure_atom pi'))
                       (freshmax_list freshmax_space_atom sigma)
 | NegSpaceClause pi sigma pi' =>
     var_max (var_max (freshmax_list freshmax_pure_atom pi)
                                     (freshmax_list freshmax_pure_atom pi'))
                       (freshmax_list freshmax_space_atom sigma)
 end.

(* Specifications: *)
Lemma varmax_minid: forall x, var_max minid x = x.
Lemma varmax_minid': forall x, var_max x minid = x.
Lemma var_max_intro: forall a b c, Ident.lt a c -> Ident.lt b c -> Ident.lt (var_max a b) c.
Lemma Ile_var_max1: forall a b, Ile a (var_max a b).
Lemma Ile_var_max2: forall a b, Ile b (var_max a b).
Lemma Ile_trans: forall a b c, Ile a b -> Ile b c -> Ile a c.
Lemma Ile_minid: forall m, Ile minid m.
Lemma var_max_intro': forall a b c, Ile a c -> Ile b c -> Ile (var_max a b) c.
Lemma var_max_split': forall a b c, Ile (var_max a b) c -> Ile a c /\ Ile b c.
Lemma id_compare_refl: forall z, Ident.compare z z = Eq.
Lemma id_compare_lt: forall x y, Ident.lt x y -> Ident.compare x y = Lt.
Lemma id_compare_gt: forall x y, Ident.lt y x -> Ident.compare x y = Gt.
Lemma var_max_assoc: forall x y z, var_max x (var_max y z) = var_max (var_max x y) z.
Lemma var_max_com: forall x y, var_max x y = var_max y x.
Lemma var_max_split: forall a b c, Ident.lt (var_max a b) c -> Ident.lt a c /\ Ident.lt b c.
Lemma freshmax_list_app: forall {A} (f: A -> var) l1 l2, freshmax_list f (l1++l2) = var_max (freshmax_list f l1) (freshmax_list f l2).
Lemma freshmax_list_rev: forall {A} (f: A -> var) l, freshmax_list f (rev l) = freshmax_list f l.
Lemma Ile_freshmax_i3: forall s m, (forall x, M.In x s -> Ile (freshmax_clause x) m) -> Ile (freshmax_list freshmax_clause (M.elements s)) m.
Lemma merge_nil1: forall {A} (f: A -> A -> comparison) l, merge f nil l = l.
Lemma freshmax_list_merge: forall m al bl, Ile (freshmax_list freshmax_pure_atom al) m -> Ile (freshmax_list freshmax_pure_atom bl) m -> Ile (freshmax_list freshmax_pure_atom (merge pure_atom_cmp al bl)) m.
Lemma Ile_freshmax_list: forall A (f: A -> var) m (s: list A), Ile (freshmax_list f s) m <-> (forall x, List.In x s -> Ile (f x) m).
Lemma freshmax_list_insu: forall A (f: A -> var) (cmp: A -> A -> comparison) (CMP_EQ: forall a b, a=b <-> Eq = cmp a b) a s, freshmax_list f (insert_uniq cmp a s) = var_max (f a) (freshmax_list f s).
Lemma freshmax_list_sort: forall A (f: A -> var) (cmp: A -> A -> comparison) (CMP_EQ: forall a b, a=b <-> Eq = cmp a b) (s: list A), freshmax_list f (rsort_uniq cmp s) = freshmax_list f s.
Lemma freshmax_insu: forall m a pi, Ile (freshmax_pure_atom a) m -> Ile (freshmax_list freshmax_pure_atom pi) m -> Ile (freshmax_list freshmax_pure_atom (insert_uniq pure_atom_cmp a pi)) m.