Ltac fresh_tac :=
   solve [auto]
 || rewrite freshmax_norm in *
 || match goal with
  | H : List.In _ (match ?D with | PureClause _ _ _ _ => _
          | PosSpaceClause _ _ _ => _ | NegSpaceClause _ _ _ => _ end)
     |- _  => destruct D
  | H : List.In _ (match ?D with nil => _ | _ :: _ => _ end) |- _  => destruct D
  | H : List.In _ (match ?D with Eqv _ _ => _ end) |- _  => destruct D
  | H : List.In _ (if ?D then _ else _) |- _ =>
      let H' := fresh in revert H; case_eq D; intros H' H;
           repeat rewrite <- andb_assoc in H';
           try (rewrite andb_true_iff in H'; destruct H' as [H' _])
  | H : expr_eq _ ?e1 = true |- _ => symmetry in H; apply expr_eq_eq' in H;
                                        subst e1
  | H : Ile _ _ |- _ => apply var_max_split' in H; destruct H
  | H : List.In ?c (_ :: _) |- _ => destruct H; [ subst c | ]
  | |- Ile (freshmax_pure_atom (norm_pure_atom _)) _ => unfold norm_pure_atom
  | |- Ile (freshmax_pure_atom (if ?D then _ else _)) _ => destruct D
  end
 || apply freshmax_list_merge
 || simpl freshmax_clause
 || apply Ile_minid
 || apply var_max_intro'
 || (rewrite comp_refl in *; auto)
 || (rewrite freshmax_list_sort; [auto | apply pure_atom_cmp_eq])
 || apply freshmax_insu.

Lemma freshmax_demodulate: forall a c m, Ile (freshmax_clause a) m -> Ile (freshmax_clause c) m -> Ile (freshmax_clause (demodulate a c)) m.