+ let args = T.list_rev_map2 map tl classes in
+ let args = aux args in
+ if args = [] then hd else C.AAppl ("", hd :: args)
+
+let mk_convert st ?name sty ety note =
+ let e = Cn.hole "" in
+ let csty, cety = H.cic sty, H.cic ety in
+ let script =
+ if debug then
+ let sname = match name with None -> "" | Some (id, _) -> id in
+ let note = Printf.sprintf "%s: %s\nSINTH: %s\nEXP: %s"
+ note sname (Pp.ppterm csty) (Pp.ppterm cety)
+ in
+ [T.Note note]
+ else []
+ in
+ assert (Ut.is_sober st.context csty);
+ assert (Ut.is_sober st.context cety);
+ if Ut.alpha_equivalence csty cety then script else
+ let sty, ety = H.acic_bc st.context sty, H.acic_bc st.context ety in
+ match name with
+ | None -> T.Change (sty, ety, None, e, "") :: script
+ | Some (id, i) ->
+ begin match get_entry st id with
+ | C.Def _ -> assert false (* T.ClearBody (id, "") :: script *)
+ | C.Decl _ ->
+ T.Change (ety, sty, Some (id, Some id), e, "") :: script
+ end
+
+let convert st ?name v =
+ match get_inner_types st v with
+ | None ->
+ if debug then [T.Note "NORMAL: NO INNER TYPES"] else []
+ | Some (sty, ety) -> mk_convert st ?name sty ety "NORMAL"
+
+let convert_elim st ?name t v pattern =
+ match t, get_inner_types st t, get_inner_types st v with
+ | _, None, _
+ | _, _, None -> [(* T.Note "ELIM: NO INNER TYPES"*)]
+ | C.AAppl (_, hd :: tl), Some (tsty, _), Some (vsty, _) ->
+ let where = List.hd (List.rev tl) in
+ let cty = Cn.elim_inferred_type
+ st.context (H.cic vsty) (H.cic where) (H.cic hd) (H.cic pattern)
+ in
+ mk_convert st ?name (Cn.fake_annotate "" st.context cty) tsty "ELIM"
+ | _, Some _, Some _ -> assert false
+
+let get_intro = function
+ | C.Anonymous -> None
+ | C.Name s -> Some s
+
+let mk_preamble st what script =
+ convert st what @ script
+
+let mk_arg st = function
+ | C.ARel (_, _, i, name) as what -> convert st ~name:(name, i) what
+ | _ -> []
+
+let mk_fwd_rewrite st dtext name tl direction v t ity =
+ let compare premise = function
+ | None -> true
+ | Some s -> s = premise
+ in
+ assert (List.length tl = 6);
+ let what, where, predicate = List.nth tl 5, List.nth tl 3, List.nth tl 2 in
+ let e = Cn.mk_pattern 1 predicate in
+ if (Cn.does_not_occur e) then st, [] else