+(* functions to be moved ****************************************************)
+
+let rec list_split n l =
+ if n = 0 then [],l else
+ let l1, l2 = list_split (pred n) (List.tl l) in
+ List.hd l :: l1, l2
+
+(****************************************************************************)
+
+type name = string
+type what = Cic.annterm
+type using = Cic.annterm
+type count = int
+type note = string
+
+type step = Note of note
+ | Theorem of name * what * note
+ | Qed of note
+ | Intros of count option * name list * note
+ | Elim of what * using option * note
+ | Exact of what * note
+ | Branch of step list list * note
+
+(* level 2 transformation ***************************************************)
+
+let mk_name = function
+ | Some name -> name
+ | None -> "_"
+
+let mk_intros_arg = function
+ | `Declaration {C.dec_name = name}
+ | `Hypothesis {C.dec_name = name}
+ | `Definition {C.def_name = name} -> mk_name name
+ | `Joint _ -> assert false
+ | `Proof _ -> assert false
+
+let mk_intros_args pc = List.map mk_intros_arg pc
+
+let split_inductive n tl =
+ let l1, l2 = list_split (int_of_string n) tl in
+ List.hd (List.rev l2), l1
+
+let mk_what rpac = function
+ | C.Premise {C.premise_n = Some i; C.premise_binder = Some b} ->
+ Cic.ARel ("", "", i, b)
+ | C.Premise {C.premise_n = None; C.premise_binder = None} ->
+ Cic.ARel ("", "", 1, "COMPOUND")
+ | C.Term t -> t
+ | C.Premise _ -> assert false
+ | C.ArgMethod _ -> assert false
+ | C.ArgProof _ -> assert false
+ | C.Lemma _ -> assert false
+ | C.Aux _ -> assert false
+
+let rec mk_proof p =
+ let names = mk_intros_args p.C.proof_context in
+ let count = List.length names in
+ if count > 0 then Intros (Some count, names, "") :: mk_proof_body p
+ else mk_proof_body p
+
+and mk_proof_body p =
+ let cmethod = p.C.proof_conclude.C.conclude_method in
+ let cargs = p.C.proof_conclude.C.conclude_args in
+ let capply = p.C.proof_apply_context in
+ match cmethod, cargs with
+ | "Intros+LetTac", [C.ArgProof p] -> mk_proof p
+ | "ByInduction", C.Aux n :: C.Term (Cic.AAppl (_, using :: _)) :: tl ->
+ let rpac = List.rev capply in
+ let whatm, ms = split_inductive n tl in (* actual rx params here *)
+ let what, qs = mk_what rpac whatm, List.map mk_subproof ms in
+ [Elim (what, Some using, ""); Branch (qs, "")]
+ | _ ->
+ [Note (Printf.sprintf "%s %u" cmethod (List.length cargs))]
+
+and mk_subproof = function
+ | C.ArgProof ({C.proof_name = Some n} as p) -> Note n :: mk_proof p
+ | C.ArgProof ({C.proof_name = None} as p) -> Note "" :: mk_proof p
+ | _ -> assert false
+
+let mk_obj ids_to_inner_sorts prefix (_, params, xmenv, obj) =
+ if List.length params > 0 || xmenv <> None then assert false;
+ match obj with
+ | `Def (C.Const, t, `Proof ({C.proof_name = Some name} as p)) ->
+ Theorem (name, t, "") :: mk_proof p @ [Qed ""]
+ | _ -> assert false
+