Proof with try solve[simpl; auto].
apply main_ind.
intros. inversion H1. split; solve[apply setd_empty_set|subst; auto].
intros. inversion H1. split; solve[apply setd_empty_set|subst; auto].
intros; inversion H1; subst; clear H1.
assert (H3 : listd clause_denote inter TT l' s).
unfold l'. apply listd_filter_pred. autounfold with DEBUG_UNFOLD.
apply listd_partition_pred with (f := clause_denote) (s0 := s) in e1...
destruct e1. apply listd_map_pred with (f := clause_denote)...
intros; apply simplify_sound...
unfold us'; apply cclose_sound...
apply partial_mod_sound1 with (s:=s) in e2...
split; unfold clause_list2set; [apply setd_fold_left|]...
2: apply setd_empty_set.
solve[intros; apply setd_add; auto].
assert (H4 : listd clause_denote inter TT us s /\
listd clause_denote inter TT rs s)
by (eapply listd_partition_pred; eauto).
destruct H4 as [H4 H5].
apply cclose_sound...
rewrite listd_app, (@listd_unfold_inter _ state); split...
unfold us'; apply cclose_sound...
intros until r0; intros IH H1 H2; apply IH...
autounfold with DEBUG_UNFOLD.
rewrite (@listd_sort_inter _ state).
assert (H3 : listd clause_denote inter TT l' s).
unfold l'. apply listd_filter_pred. autounfold with DEBUG_UNFOLD.
apply listd_partition_pred with (f := clause_denote) (s0 := s) in e1...
destruct e1. apply listd_map_pred with (f := clause_denote)...
intros; apply simplify_sound...
unfold us'; apply cclose_sound...
rewrite listd_app, (@listd_unfold_inter _ state); split...
apply infer_list_sound...
apply partial_mod_sound2 with (R:=nil)(R':=R)(acc:=nil)(l:=l')(ce:=cty)...
apply cclose_sound.
rewrite listd_app, (@listd_unfold_inter _ state); split...
apply listd_partition_pred with (h := is_unit_clause) (xs:=us)(ys:=rs) in H1...
destruct H1... unfold us'; apply cclose_sound...
Qed.

(* Specifications: *)
Lemma main_Cexample_sound n l R sel units given unselected s :
listd clause_denote inter TT l s ->
main n nil l = (C_example R sel, units, given, unselected) ->
setd clause_denote inter TT sel s.