1 (* Copyright (C) 2003-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (***************************************************************************)
30 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (***************************************************************************)
37 module P = Mpresentation
41 let p_mtr a b = Mpresentation.Mtr(a,b)
42 let p_mtd a b = Mpresentation.Mtd(a,b)
43 let p_mtable a b = Mpresentation.Mtable(a,b)
44 let p_mtext a b = Mpresentation.Mtext(a,b)
45 let p_mi a b = Mpresentation.Mi(a,b)
46 let p_mo a b = Mpresentation.Mo(a,b)
47 let p_mrow a b = Mpresentation.Mrow(a,b)
48 let p_mphantom a b = Mpresentation.Mphantom(a,b)
53 split (n-1) (List.tl l) in
56 let get_xref = function
58 | `Hypothesis d -> d.Con.dec_id
59 | `Proof p -> p.Con.proof_id
60 | `Definition d -> d.Con.def_id
61 | `Joint jo -> jo.Con.joint_id
64 RenderingAttrs.spacing_attributes `BoxML
65 @ RenderingAttrs.indent_attributes `BoxML
67 let make_row items concl =
68 B.b_hv hv_attrs (items @ [ concl ])
71 B.b_v attrs [B.b_h [] items; B.b_indent concl]
73 B.b_h attrs (items@[B.b_space; concl]) *)
75 let make_concl ?(attrs=[]) verb concl =
76 B.b_hv (hv_attrs @ attrs) [ B.b_kw verb; concl ]
79 B.b_v attrs [ B.b_kw verb; B.b_indent concl]
81 B.b_h attrs [ B.b_kw verb; B.b_space; concl ] *)
83 let make_args_for_apply term2pres args =
84 let make_arg_for_apply is_first arg row =
87 Con.Aux n -> assert false
90 (match prem.Con.premise_binder with
93 (B.b_object (P.Mi ([], name)))::row
96 Some "helm", "xref", lemma.Con.lemma_id;
97 Some "xlink", "href", lemma.Con.lemma_uri ]
99 (B.b_object (P.Mi(lemma_attrs,lemma.Con.lemma_name)))::row
101 if is_first || (not b) then
103 else (B.b_object (P.Mi([],"?")))::row
106 (B.b_object (P.Mi([],"?")))::row
108 if is_first then res else B.skip::res
112 make_arg_for_apply true hd
113 (List.fold_right (make_arg_for_apply false) tl [])
116 let get_name ?(default="_") = function
120 let add_xref id = function
121 | B.Text (attrs, t) -> B.Text (((Some "helm", "xref", id) :: attrs), t)
122 | _ -> assert false (* TODO, add_xref is meaningful for all boxes *)
124 let rec justification ~for_rewriting_step ~ignore_atoms term2pres p =
125 if p.Con.proof_conclude.Con.conclude_method = "Exact" &&
130 (p.Con.proof_conclude.Con.conclude_method = "Exact" && not ignore_atoms) ||
131 (p.Con.proof_context = [] &&
132 p.Con.proof_apply_context = [] &&
133 p.Con.proof_conclude.Con.conclude_method = "Apply")
136 make_args_for_apply term2pres p.Con.proof_conclude.Con.conclude_args
139 (if for_rewriting_step then (B.b_kw "exact") else (B.b_kw "by"))::
141 B.Text([],"(")::pres_args@[B.Text([],")")])], None
144 if for_rewriting_step then
147 [B.b_kw "by"; B.b_space; B.b_kw "proof"]
149 Some (B.b_toggle [B.b_kw "proof";B.indent (proof2pres true term2pres p)])
151 and proof2pres ?skip_initial_lambdas is_top_down term2pres p =
152 let rec proof2pres ?skip_initial_lambdas_internal is_top_down p in_bu_conversion =
157 | `Hypothesis _ -> true
159 ((List.filter is_decl p.Con.proof_context) != []) in
160 let omit_conclusion = (not indent) && (p.Con.proof_context != []) in
162 (match p.Con.proof_conclude.Con.conclude_conclusion with
164 | Some t -> Some (term2pres t)) in
168 ?skip_initial_lambdas_internal:
169 (match skip_initial_lambdas_internal with
170 Some (`Later s) -> Some (`Now s)
172 is_top_down p.Con.proof_name p.Con.proof_conclude indent
173 omit_conclusion in_bu_conversion in
176 (if p.Con.proof_conclude.Con.conclude_method = "BU_Conversion" then
180 p.Con.proof_apply_context
182 (p.Con.proof_conclude.Con.conclude_method = "BU_Conversion")
185 (match skip_initial_lambdas_internal with
186 Some (`Now n) -> snd (HExtlib.split_nth n p.Con.proof_context)
187 | _ -> p.Con.proof_context)
191 let body = B.V([],[B.b_kw ("(*<<" ^ p.Con.proof_conclude.Con.conclude_method ^ (if is_top_down then "(TD)" else "(NTD)") ^ "*)"); body; B.b_kw "(*>>*)"]) in
193 match p.Con.proof_name with
201 make_concl ~attrs:[ Some "helm", "xref", p.Con.proof_id ]
203 B.b_toggle [ B.H ([], [concl; B.skip ; B.Text([],"(");
204 B.Object ([], P.Mi ([],name));
205 B.Text([],")") ]) ; body ]
209 and context2pres c continuation =
210 (* we generate a subtable for each context element, for selection
212 The table generated by the head-element does not have an xref;
213 the whole context-proof is already selectable *)
219 (fun ce continuation ->
220 let xref = get_xref ce in
221 B.V([Some "helm", "xref", xref ],
222 [B.H([Some "helm", "xref", "ce_"^xref],
223 [ce2pres_in_proof_context_element ce]);
224 continuation])) tl continuation in
225 let hd_xref= get_xref hd in
227 [B.H([Some "helm", "xref", "ce_"^hd_xref],
228 [ce2pres_in_proof_context_element hd]);
231 and ce2pres_in_joint_context_element = function
232 | `Inductive _ -> assert false (* TODO *)
233 | (`Declaration _) as x -> ce2pres x
234 | (`Hypothesis _) as x -> ce2pres x
235 | (`Proof _) as x -> ce2pres x
236 | (`Definition _) as x -> ce2pres x
238 and ce2pres_in_proof_context_element = function
240 B.H ([],(List.map ce2pres_in_joint_context_element ho.Content.joint_defs))
241 | (`Declaration _) as x -> ce2pres x
242 | (`Hypothesis _) as x -> ce2pres x
243 | (`Proof _) as x -> ce2pres x
244 | (`Definition _) as x -> ce2pres x
249 let ty = term2pres d.Con.dec_type in
253 B.Object ([], P.Mi([],get_name d.Con.dec_name));
258 let ty = term2pres h.Con.dec_type in
265 B.Object ([], P.Mi ([],get_name h.Con.dec_name));
269 proof2pres false p false
271 let term = term2pres d.Con.def_term in
273 [ B.b_kw "let"; B.b_space;
274 B.Object ([], P.Mi([],get_name d.Con.def_name));
275 B.Text([],Utf8Macro.unicode_of_tex "\\def");
278 and acontext2pres is_top_down ac continuation indent in_bu_conversion =
283 let continuation = aux tl in
284 (* Applicative context get flattened and the "body" of a BU_Conversion
285 is put in the applicative context. Thus two different situations
287 {method = "BU_Conversion"; applicative_context=[p1; ...; pn]}
288 {method = xxx; applicative_context =
289 [ p1; ...; pn; {method="BU_Conversion"} ; p_{n+1}; ... ; pm ]}
290 In both situations only pn must be processed in in_bu_conversion
293 let in_bu_conversion =
295 [] -> in_bu_conversion
296 | p::_ -> p.Con.proof_conclude.Con.conclude_method = "BU_Conversion"
298 let hd = proof2pres is_top_down p in_bu_conversion in
299 let hd = if indent then B.indent hd else hd in
300 B.V([Some "helm","xref",p.Con.proof_id],
301 [B.H([Some "helm","xref","ace_"^p.Con.proof_id],[hd]);
305 and conclude2pres ?skip_initial_lambdas_internal is_top_down name conclude indent omit_conclusion in_bu_conversion =
307 match conclude.Con.conclude_conclusion with
308 Some t (*when not omit_conclusion or
309 (* CSC: I ignore the omit_conclusion flag in this case. *)
310 (* CSC: Is this the correct behaviour? In the stylesheets *)
311 (* CSC: we simply generated nothing (i.e. the output type *)
312 (* CSC: of the function should become an option. *)
313 conclude.Con.conclude_method = "BU_Conversion" *) ->
314 let concl = term2pres t in
315 if conclude.Con.conclude_method = "BU_Conversion" then
317 (make_concl "that is equivalent to" concl ::
318 if is_top_down then [B.b_space ; B.b_kw "done";
319 B.Text([],".")] else [B.Text([],".")])
320 else if conclude.Con.conclude_method = "FalseInd" then
321 (* false ind is in charge to add the conclusion *)
327 conclude.Con.conclude_method = "Intros+LetTac"
329 let name = get_name name in
333 (match conclude.Con.conclude_conclusion with
334 None -> B.Text([],"NO EXPECTED!!!")
335 | Some c -> term2pres c)
337 [make_concl "we need to prove" expected;
340 B.Object ([], P.Mi ([],name));
347 conclude_aux ?skip_initial_lambdas_internal is_top_down conclude in
349 if conclude.Con.conclude_method = "Intros+LetTac"
350 || conclude.Con.conclude_method = "ByInduction"
351 || conclude.Con.conclude_method = "TD_Conversion"
352 || conclude.Con.conclude_method = "Eq_chain"
355 else if omit_conclusion then
356 B.H([], [B.b_kw "done" ; B.Text([],".") ])
359 ((if not is_top_down || in_bu_conversion then
360 (make_concl "we proved" concl) ::
361 if not is_top_down then
362 let name = get_name ~default:"previous" name in
363 [B.b_space; B.Text([],"(" ^ name ^ ")")]
366 ) @ if not in_bu_conversion then [B.Text([],".")] else [])
368 B.V ([], prequel @ [conclude_body; ann_concl])
369 | _ -> conclude_aux ?skip_initial_lambdas_internal is_top_down conclude
372 B.indent (B.H ([Some "helm", "xref", conclude.Con.conclude_id],
375 B.H ([Some "helm", "xref", conclude.Con.conclude_id],[tconclude_body])
377 and conclude_aux ?skip_initial_lambdas_internal is_top_down conclude =
378 if conclude.Con.conclude_method = "TD_Conversion" then
380 (match conclude.Con.conclude_conclusion with
381 None -> B.Text([],"NO EXPECTED!!!")
382 | Some c -> term2pres c) in
384 (match conclude.Con.conclude_args with
385 [Con.ArgProof p] -> p
386 | _ -> assert false) in
388 (match subproof.Con.proof_conclude.Con.conclude_conclusion with
389 None -> B.Text([],"NO SYNTH!!!")
390 | Some c -> (term2pres c)) in
393 [make_concl "we need to prove" expected;
394 B.H ([],[make_concl "or equivalently" synth; B.Text([],".")]);
395 proof2pres true subproof false])
396 else if conclude.Con.conclude_method = "BU_Conversion" then
398 else if conclude.Con.conclude_method = "Exact" then
400 (match conclude.Con.conclude_args with
401 [Con.Term (b,t)] -> assert (not b);term2pres t
403 (match p.Con.premise_binder with
404 | None -> assert false; (* unnamed hypothesis ??? *)
405 | Some s -> B.Text([],s))
406 | err -> assert false) in
407 (match conclude.Con.conclude_conclusion with
409 B.b_h [] [B.b_kw "by"; B.b_space; arg]
411 B.b_h [] [B.b_kw "by"; B.b_space; arg]
413 else if conclude.Con.conclude_method = "Intros+LetTac" then
414 (match conclude.Con.conclude_args with
416 (match conclude.Con.conclude_args with
418 proof2pres ?skip_initial_lambdas_internal true p false
423 (match conclude.Con.conclude_conclusion with
424 None -> B.Text([],"NO Conclusion!!!")
425 | Some c -> term2pres c) in
426 (match conclude.Con.conclude_args with
429 ([None,"align","baseline 1"; None,"equalrows","false";
430 None,"columnalign","left"],
431 [B.H([],[B.Object([],proof2pres p false)]);
433 (make_concl "we proved 1" conclusion))])]);
436 else if (conclude.Con.conclude_method = "Case") then
438 else if (conclude.Con.conclude_method = "ByInduction") then
440 else if (conclude.Con.conclude_method = "Exists") then
442 else if (conclude.Con.conclude_method = "AndInd") then
444 else if (conclude.Con.conclude_method = "FalseInd") then
446 else if conclude.Con.conclude_method = "RewriteLR"
447 || conclude.Con.conclude_method = "RewriteRL" then
448 let justif1,justif2 =
449 (match (List.nth conclude.Con.conclude_args 6) with
451 justification ~for_rewriting_step:true ~ignore_atoms:true
453 | _ -> assert false) in
459 let index_term1, index_term2 =
460 if conclude.Con.conclude_method = "RewriteLR" then 2,5 else 5,2
463 (match List.nth conclude.Con.conclude_args index_term1 with
464 Con.Term (_,t) -> term2pres t
465 | _ -> assert false) in
467 (match List.nth conclude.Con.conclude_args index_term2 with
468 Con.Term (_,t) -> term2pres t
469 | _ -> assert false) in
476 [B.b_kw "we proved (" ;
479 term2; B.b_kw ") (equality)."])]
486 B.b_space; (B.b_kw "with");
488 B.b_space; justif1])::
489 match justif2 with None -> [] | Some j -> [B.indent j])
491 B.V([], justif @ [B.b_kw "by _"])
492 else if conclude.Con.conclude_method = "Eq_chain" then
493 let justification p =
495 justification ~for_rewriting_step:true ~ignore_atoms:false term2pres p
497 j1, match j2 with Some j -> [j] | None -> []
502 | (Con.ArgProof p)::(Con.Term (_,t))::tl ->
503 let justif1,justif2 = justification p in
504 B.HOV(RenderingAttrs.indent_attributes `BoxML,([B.b_kw
505 "=";B.b_space;term2pres t;B.b_space]@justif1@
506 (if tl <> [] then [B.Text ([],".")] else [B.b_space; B.b_kw "done" ; B.Text([],".")])@
511 match List.hd conclude.Con.conclude_args with
512 | Con.Term (_,t) -> t
517 [B.b_kw "conclude";B.b_space;term2pres hd;
518 B.V ([],aux (List.tl conclude.Con.conclude_args))])
521 [B.b_kw "obtain";B.b_space;B.b_kw "FIXMEXX"; B.b_space;term2pres hd;
522 B.V ([],aux (List.tl conclude.Con.conclude_args))])
523 else if conclude.Con.conclude_method = "Apply" then
525 make_args_for_apply term2pres conclude.Con.conclude_args in
529 B.Text([],"(")::pres_args@[B.Text([],")")])
532 B.b_kw ("Apply method" ^ conclude.Con.conclude_method ^ " to");
533 (B.indent (B.V ([], args2pres conclude.Con.conclude_args)))])
535 and args2pres l = List.map arg2pres l
539 Con.Aux n -> B.b_kw ("aux " ^ n)
540 | Con.Premise prem -> B.b_kw "premise"
541 | Con.Lemma lemma -> B.b_kw "lemma"
542 | Con.Term (_,t) -> term2pres t
543 | Con.ArgProof p -> proof2pres true p false
544 | Con.ArgMethod s -> B.b_kw "method"
547 let proof_conclusion =
548 (match conclude.Con.conclude_conclusion with
549 None -> B.b_kw "No conclusion???"
550 | Some t -> term2pres t) in
551 let arg,args_for_cases =
552 (match conclude.Con.conclude_args with
553 Con.Aux(_)::Con.Aux(_)::Con.Term(_)::arg::tl ->
555 | _ -> assert false) in
559 Con.Aux n -> B.b_kw "an aux???"
560 | Con.Premise prem ->
561 (match prem.Con.premise_binder with
562 None -> B.b_kw "previous"
563 | Some n -> B.Object ([], P.Mi([],n)))
564 | Con.Lemma lemma -> B.Object ([], P.Mi([],lemma.Con.lemma_name))
567 | Con.ArgProof p -> B.b_kw "a proof???"
568 | Con.ArgMethod s -> B.b_kw "a method???")
570 (make_concl "we proceed by cases on" case_arg) in
572 (make_concl "to prove" proof_conclusion) in
573 B.V ([], case_on::to_prove::(make_cases args_for_cases))
575 and byinduction conclude =
576 let proof_conclusion =
577 (match conclude.Con.conclude_conclusion with
578 None -> B.b_kw "No conclusion???"
579 | Some t -> term2pres t) in
580 let inductive_arg,args_for_cases =
581 (match conclude.Con.conclude_args with
583 let l1,l2 = split (int_of_string n) tl in
584 let last_pos = (List.length l2)-1 in
585 List.nth l2 last_pos,l1
586 | _ -> assert false) in
589 (match inductive_arg with
590 Con.Aux n -> B.b_kw "an aux???"
591 | Con.Premise prem ->
592 (match prem.Con.premise_binder with
593 None -> B.b_kw "previous"
594 | Some n -> B.Object ([], P.Mi([],n)))
595 | Con.Lemma lemma -> B.Object ([], P.Mi([],lemma.Con.lemma_name))
598 | Con.ArgProof p -> B.b_kw "a proof???"
599 | Con.ArgMethod s -> B.b_kw "a method???") in
600 (make_concl "we proceed by induction on" arg) in
602 B.H ([], [make_concl "to prove" proof_conclusion ; B.Text([],".")]) in
603 B.V ([], induction_on::to_prove::(make_cases args_for_cases))
605 and make_cases l = List.map make_case l
611 (match p.Con.proof_name with
612 None -> B.b_kw "no name for case!!"
613 | Some n -> B.Object ([], P.Mi([],n))) in
617 `Hypothesis h -> h.Con.dec_inductive
618 | _ -> false) p.Con.proof_context in
626 let name = get_name h.Con.dec_name in
629 B.Object ([], P.Mi ([],name));
631 (term2pres h.Con.dec_type);
633 | _ -> assert false (*[B.Text ([],"???")]*)) in
637 (B.b_kw "case"::B.b_space::name::pattern_aux)@
641 (match p.Con.proof_conclude.Con.conclude_conclusion with
642 None -> B.b_kw "No conclusion!!!"
643 | Some t -> term2pres t) in
644 let asubconcl = B.indent (make_concl "the thesis becomes" subconcl) in
645 let induction_hypothesis =
649 let text = B.indent (B.b_kw "by induction hypothesis we know") in
654 (match h.Con.dec_name with
658 [term2pres h.Con.dec_type;
661 B.Object ([], P.Mi ([],name));
664 | _ -> assert false in
665 let hyps = List.map make_hyp indhyps in
668 conclude2pres true p.Con.proof_name p.Con.proof_conclude true true false in
671 match p.Con.proof_apply_context with
672 [] -> p.Con.proof_conclude.Con.conclude_id
673 | {Con.proof_id = id}::_ -> id
675 B.Action([None,"type","toggle"],
676 [ B.indent (add_xref acontext_id (B.b_kw "Proof"));
678 (p.Con.proof_conclude.Con.conclude_method = "BU_Conversion")
679 p.Con.proof_apply_context body true
680 (p.Con.proof_conclude.Con.conclude_method = "BU_Conversion")
682 B.V ([], pattern::induction_hypothesis@[B.H ([],[asubconcl;B.Text([],".")]);presacontext])
685 and falseind conclude =
686 let proof_conclusion =
687 (match conclude.Con.conclude_conclusion with
688 None -> B.b_kw "No conclusion???"
689 | Some t -> term2pres t) in
691 (match conclude.Con.conclude_args with
692 [Con.Aux(n);_;case_arg] -> case_arg
695 List.map (ContentPp.parg 0) conclude.Con.conclude_args;
699 Con.Aux n -> assert false
700 | Con.Premise prem ->
701 (match prem.Con.premise_binder with
702 None -> [B.b_kw "Contradiction, hence"]
704 [ B.Object ([],P.Mi([],n)); B.skip;
705 B.b_kw "is contradictory, hence"])
707 [ B.Object ([], P.Mi([],lemma.Con.lemma_name)); B.skip;
708 B.b_kw "is contradictory, hence" ]
709 | _ -> assert false) in
710 make_row arg proof_conclusion
712 and andind conclude =
714 (match conclude.Con.conclude_args with
715 [Con.Aux(n);_;Con.ArgProof proof;case_arg] -> proof,case_arg
718 List.map (ContentPp.parg 0) conclude.Con.conclude_args;
722 Con.Aux n -> assert false
723 | Con.Premise prem ->
724 (match prem.Con.premise_binder with
726 | Some n -> [(B.b_kw "by"); B.b_space; B.Object([], P.Mi([],n))])
728 [(B.b_kw "by");B.skip;
729 B.Object([], P.Mi([],lemma.Con.lemma_name))]
730 | _ -> assert false) in
731 match proof.Con.proof_context with
732 `Hypothesis hyp1::`Hypothesis hyp2::tl ->
736 B.Object ([], P.Mi([],get_name hyp1.Con.dec_name));
739 term2pres hyp1.Con.dec_type]) in
743 B.Object ([], P.Mi([],get_name hyp2.Con.dec_name));
746 term2pres hyp2.Con.dec_type]) in
748 conclude2pres false proof.Con.proof_name proof.Con.proof_conclude
751 acontext2pres false proof.Con.proof_apply_context body false false
755 [B.H ([],arg@[B.skip; B.b_kw "we have"]);
762 and exists conclude =
764 (match conclude.Con.conclude_args with
765 [Con.Aux(n);_;Con.ArgProof proof;_] -> proof
768 List.map (ContentPp.parg 0) conclude.Con.conclude_args;
770 match proof.Con.proof_context with
771 `Declaration decl::`Hypothesis hyp::tl
772 | `Hypothesis decl::`Hypothesis hyp::tl ->
777 B.Object ([], P.Mi([],get_name decl.Con.dec_name));
778 B.Text([],":"); term2pres decl.Con.dec_type]) in
781 [(B.b_kw "such that");
784 B.Object ([], P.Mi([],get_name hyp.Con.dec_name));
787 term2pres hyp.Con.dec_type]) in
789 conclude2pres false proof.Con.proof_name proof.Con.proof_conclude
792 acontext2pres false proof.Con.proof_apply_context body false false
803 ?skip_initial_lambdas_internal:
804 (match skip_initial_lambdas with
805 None -> Some (`Later 0) (* we already printed theorem: *)
806 | Some n -> Some (`Later n))
813 let conjecture2pres term2pres (id, n, context, ty) =
815 (B.b_hv [Some "helm", "xref", id]
817 B.b_h [] [B.b_text [] "{...}"; B.b_space];
818 B.b_hv [] (HExtlib.list_concat ~sep:[B.b_text [] ";"; B.b_space]
819 (List.map (fun x -> [x])
824 [ B.b_object (p_mi [] "_") ;
825 B.b_object (p_mo [] ":?") ;
826 B.b_object (p_mi [] "_")]
827 | Some (`Declaration d)
828 | Some (`Hypothesis d) ->
829 let { Content.dec_name =
830 dec_name ; Content.dec_type = ty } = d
838 B.b_text [] ":"; B.b_space;
840 | Some (`Definition d) ->
842 { Content.def_name = def_name ;
843 Content.def_term = bo } = d
846 [ B.b_object (p_mi []
850 B.b_text [] (Utf8Macro.unicode_of_tex "\\Assign");
854 let proof_name = p.Content.proof_name in
856 [ B.b_object (p_mi []
857 (match proof_name with
860 B.b_text [] (Utf8Macro.unicode_of_tex "\\Assign");
862 proof2pres true term2pres p])
863 (List.rev context)))) ] ::
866 B.b_text [] (Utf8Macro.unicode_of_tex "\\vdash");
868 B.b_object (p_mi [] (string_of_int n)) ;
873 let metasenv2pres term2pres = function
876 (* Conjectures are in their own table to make *)
877 (* diffing the DOM trees easier. *)
879 ((B.b_kw ("Conjectures:" ^
880 (let _ = incr counter; in (string_of_int !counter)))) ::
881 (List.map (conjecture2pres term2pres) metasenv'))]
883 let params2pres params =
885 B.b_text [Some "xlink", "href", UriManager.string_of_uri uri]
886 (UriManager.name_of_uri uri)
888 let rec spatiate = function
891 | hd :: tl -> hd :: B.b_text [] ", " :: spatiate tl
896 let params = spatiate (List.map param2pres p) in
898 B.b_h [] (B.b_text [] "[" :: params @ [ B.b_text [] "]" ])]
900 let recursion_kind2pres params kind =
903 | `Recursive _ -> "Recursive definition"
904 | `CoRecursive -> "CoRecursive definition"
906 "Inductive definition with "^string_of_int i^" fixed parameter(s)"
908 "Co-Inductive definition with "^string_of_int i^" fixed parameter(s)"
910 B.b_h [] (B.b_kw kind :: params2pres params)
912 let inductive2pres term2pres ind =
913 let constructor2pres decl =
915 B.b_text [] ("| " ^ get_name decl.Content.dec_name ^ ":");
917 term2pres decl.Content.dec_type
922 B.b_kw (ind.Content.inductive_name ^ " of arity");
924 term2pres ind.Content.inductive_type ]
925 :: List.map constructor2pres ind.Content.inductive_constructors)
927 let joint_def2pres term2pres def =
929 | `Inductive ind -> inductive2pres term2pres ind
930 | _ -> assert false (* ZACK or raise ToDo? *)
933 ?skip_initial_lambdas ?(skip_thm_and_qed=false) term2pres
934 (id,params,metasenv,obj)
937 | `Def (Content.Const, thesis, `Proof p) ->
938 let name = get_name p.Content.proof_name in
939 let proof = proof2pres true term2pres ?skip_initial_lambdas p in
940 if skip_thm_and_qed then
944 [Some "helm","xref","id"]
945 ([ B.b_h [] (B.b_kw ("theorem " ^ name) ::
946 params2pres params @ [B.b_kw ":"]);
947 B.H ([],[B.indent (term2pres thesis) ; B.b_kw "." ])] @
948 metasenv2pres term2pres metasenv @
949 [proof ; B.b_kw "qed."])
950 | `Def (_, ty, `Definition body) ->
951 let name = get_name body.Content.def_name in
953 [Some "helm","xref","id"]
955 (B.b_kw ("definition " ^ name) :: params2pres params @ [B.b_kw ":"]);
956 B.indent (term2pres ty)] @
957 metasenv2pres term2pres metasenv @
959 B.indent (term2pres body.Content.def_term);
961 | `Decl (_, `Declaration decl)
962 | `Decl (_, `Hypothesis decl) ->
963 let name = get_name decl.Content.dec_name in
965 [Some "helm","xref","id"]
966 ([B.b_h [] (B.b_kw ("Axiom " ^ name) :: params2pres params);
968 B.indent (term2pres decl.Content.dec_type)] @
969 metasenv2pres term2pres metasenv)
972 (recursion_kind2pres params joint.Content.joint_kind
973 :: List.map (joint_def2pres term2pres) joint.Content.joint_defs)
977 ?skip_initial_lambdas ?skip_thm_and_qed ~ids_to_inner_sorts
979 content2pres ?skip_initial_lambdas ?skip_thm_and_qed
980 (fun ?(prec=90) annterm ->
981 let ast, ids_to_uris =
982 TermAcicContent.ast_of_acic ~output_type:`Term ids_to_inner_sorts annterm
984 CicNotationPres.box_of_mpres
985 (CicNotationPres.render ids_to_uris ~prec
986 (TermContentPres.pp_ast ast)))