]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_transformations/content2pres.ml
* the transformations have been ported so to generate BoxML + MathML
[helm.git] / helm / ocaml / cic_transformations / content2pres.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (***************************************************************************)
27 (*                                                                         *)
28 (*                            PROJECT HELM                                 *)
29 (*                                                                         *)
30 (*                Andrea Asperti <asperti@cs.unibo.it>                     *)
31 (*                              17/06/2003                                 *)
32 (*                                                                         *)
33 (***************************************************************************)
34
35 module P = Mpresentation
36 module B = Box
37
38 let p_mtr a b = Mpresentation.Mtr(a,b)
39 let p_mtd a b = Mpresentation.Mtd(a,b)
40 let p_mtable a b = Mpresentation.Mtable(a,b)
41 let p_mtext a b = Mpresentation.Mtext(a,b)
42 let p_mi a b = Mpresentation.Mi(a,b)
43 let p_mo a b = Mpresentation.Mo(a,b)
44 let p_mrow a b = Mpresentation.Mrow(a,b)
45 let p_mphantom a b = Mpresentation.Mphantom(a,b)
46
47 let rec split n l =
48   if n = 0 then [],l
49   else let l1,l2 = 
50     split (n-1) (List.tl l) in
51     (List.hd l)::l1,l2
52 ;;
53   
54
55 let is_big_general countterm p =
56   let maxsize = Cexpr2pres.maxsize in
57   let module Con = Content in
58   let rec countp current_size p =
59     if current_size > maxsize then current_size
60     else 
61       let c1 = (countcontext current_size p.Con.proof_context) in
62       if c1 > maxsize then c1
63     else 
64       let c2 = (countapplycontext c1 p.Con.proof_apply_context) in
65       if c2 > maxsize then c2
66     else 
67       countconclude c2 p.Con.proof_conclude
68
69   and 
70     countcontext current_size c =
71       List.fold_left countcontextitem current_size c
72   and
73     countcontextitem current_size e =
74       if current_size > maxsize then maxsize
75       else 
76         (match e with
77           `Declaration d -> 
78             (match d.Con.dec_name with
79                Some s -> current_size + 4 + (String.length s)
80              | None -> prerr_endline "NO NAME!!"; assert false)
81         | `Hypothesis h ->
82             (match h.Con.dec_name with
83                 Some s -> current_size + 4 + (String.length s)
84               | None -> prerr_endline "NO NAME!!"; assert false) 
85         | `Proof p -> countp current_size p
86         | `Definition d -> 
87             (match d.Con.def_name with
88                 Some s -> 
89                   let c1 = (current_size + 4 + (String.length s)) in
90                   (countterm c1 d.Con.def_term)
91               | None -> 
92                   prerr_endline "NO NAME!!"; assert false) 
93         | `Joint ho -> maxsize + 1) (* we assume is big *)
94   and 
95     countapplycontext current_size ac =
96       List.fold_left countp current_size ac
97   and 
98     countconclude current_size co =
99       if current_size > maxsize then current_size
100       else
101         let c1 = countargs current_size co.Con.conclude_args in
102         if c1 > maxsize then c1 
103       else 
104         (match co.Con.conclude_conclusion with
105            Some concl ->  countterm c1 concl
106         | None -> c1)
107   and 
108     countargs current_size args =
109       List.fold_left countarg current_size args
110   and
111     countarg current_size arg =
112       if current_size > maxsize then current_size
113       else 
114         (match arg with 
115            Con.Aux _ -> current_size
116          | Con.Premise prem -> 
117              (match prem.Con.premise_binder with
118                 Some s -> current_size + (String.length s)
119               | None -> current_size + 7) 
120          | Con.Lemma lemma -> 
121              current_size + (String.length lemma.Con.lemma_name)
122          | Con.Term t -> countterm current_size t
123          | Con.ArgProof p -> countp current_size p
124          | Con.ArgMethod s -> (maxsize + 1)) in
125   let size = (countp 0 p) in
126   (size > maxsize)
127 ;;
128
129 let is_big = is_big_general (Cexpr2pres.countterm)
130 ;;
131
132 let get_xref =
133     let module Con = Content in
134       function
135         `Declaration d  
136       | `Hypothesis d -> d.Con.dec_id
137       | `Proof p -> p.Con.proof_id
138       | `Definition d -> d.Con.def_id
139       | `Joint jo -> jo.Con.joint_id
140 ;;
141
142 let make_row ?(attrs=[]) items concl =
143   match concl with 
144       B.V _ -> (* big! *)
145         B.b_v attrs [B.b_h [] items; B.b_indent concl]
146     | _ ->  (* small *)
147         B.b_h attrs (items@[B.b_space; concl])
148 ;;
149
150 let make_concl ?(attrs=[]) verb concl =
151   match concl with 
152       B.V _ -> (* big! *)
153         B.b_v attrs [ B.b_kw verb; B.b_indent concl]
154     | _ ->  (* small *)
155         B.b_h attrs [ B.b_kw verb; B.b_space; concl ]
156 ;;
157
158 let make_args_for_apply term2pres args =
159  let module Con = Content in
160  let make_arg_for_apply is_first arg row = 
161   let res =
162    match arg with 
163       Con.Aux n -> assert false
164     | Con.Premise prem -> 
165         let name = 
166           (match prem.Con.premise_binder with
167              None -> "previous"
168            | Some s -> s) in
169         (B.b_object (P.Mi ([], name)))::row
170     | Con.Lemma lemma -> 
171         (B.b_object (P.Mi([],lemma.Con.lemma_name)))::row 
172     | Con.Term t -> 
173         if is_first then
174           (term2pres t)::row
175         else (B.b_object (P.Mi([],"_")))::row
176     | Con.ArgProof _ 
177     | Con.ArgMethod _ -> 
178         (B.b_object (P.Mi([],"_")))::row
179   in
180    if is_first then res else B.skip::res
181  in
182   match args with 
183     hd::tl -> 
184       make_arg_for_apply true hd 
185         (List.fold_right (make_arg_for_apply false) tl [])
186   | _ -> assert false
187 ;;
188
189 let rec justification term2pres p = 
190   let module Con = Content in
191   let module P = Mpresentation in
192   if ((p.Con.proof_conclude.Con.conclude_method = "Exact") or
193      ((p.Con.proof_context = []) &
194       (p.Con.proof_apply_context = []) &
195       (p.Con.proof_conclude.Con.conclude_method = "Apply"))) then
196     let pres_args = 
197       make_args_for_apply term2pres p.Con.proof_conclude.Con.conclude_args in
198     B.H([],
199       (B.b_kw "by")::B.b_space::
200       B.Text([],"(")::pres_args@[B.Text([],")")]) 
201   else proof2pres term2pres p 
202      
203 and proof2pres term2pres p =
204   let rec proof2pres p =
205     let module Con = Content in
206       let indent = 
207         let is_decl e = 
208           (match e with 
209              `Declaration _
210            | `Hypothesis _ -> true
211            | _ -> false) in
212         ((List.filter is_decl p.Con.proof_context) != []) in 
213       let omit_conclusion = (not indent) && (p.Con.proof_context != []) in
214       let concl = 
215         (match p.Con.proof_conclude.Con.conclude_conclusion with
216            None -> None
217          | Some t -> Some (term2pres t)) in
218       let body =
219           let presconclude = 
220             conclude2pres p.Con.proof_conclude indent omit_conclusion in
221           let presacontext = 
222             acontext2pres p.Con.proof_apply_context presconclude indent in
223           context2pres p.Con.proof_context presacontext in
224       match p.Con.proof_name with
225         None -> body
226       | Some name ->
227           let action = 
228            match concl with
229               None -> body
230             | Some ac ->
231                B.Action
232                  ([None,"type","toggle"],
233                   [(make_concl ~attrs:[Some "helm", "xref", p.Con.proof_id]
234                      "proof of" ac); body])
235           in
236           B.V ([],
237             [B.Text ([],"(" ^ name ^ ")");
238              B.indent action])
239
240   and context2pres c continuation =
241     (* we generate a subtable for each context element, for selection
242        purposes 
243        The table generated by the head-element does not have an xref;
244        the whole context-proof is already selectable *)
245     match c with
246       [] -> continuation
247     | hd::tl -> 
248         let continuation' =
249           List.fold_right
250             (fun ce continuation ->
251               let xref = get_xref ce in
252               B.V([Some "helm", "xref", xref ],
253                 [B.H([Some "helm", "xref", "ce_"^xref],[ce2pres ce]);
254                  continuation])) tl continuation in
255          let hd_xref= get_xref hd in
256          B.V([],
257              [B.H([Some "helm", "xref", "ce_"^hd_xref],
258                [ce2pres hd]);
259              continuation'])
260          
261   and ce2pres =
262     let module Con = Content in
263       function
264         `Declaration d -> 
265           (match d.Con.dec_name with
266               Some s ->
267                 let ty = term2pres d.Con.dec_type in
268                 B.H ([],
269                   [(B.b_kw "Assume");
270                    B.b_space;
271                    B.Object ([], P.Mi([],s));
272                    B.Text([],":");
273                    ty])
274             | None -> 
275                 prerr_endline "NO NAME!!"; assert false)
276       | `Hypothesis h ->
277           (match h.Con.dec_name with
278               Some s ->
279                 let ty = term2pres h.Con.dec_type in
280                 B.H ([],
281                   [(B.b_kw "Suppose");
282                    B.b_space;
283                    B.Text([],"(");
284                    B.Object ([], P.Mi ([],s));
285                    B.Text([],")");
286                    B.b_space;
287                    ty])
288             | None -> 
289                 prerr_endline "NO NAME!!"; assert false) 
290       | `Proof p -> 
291            proof2pres p 
292       | `Definition d -> 
293            (match d.Con.def_name with
294               Some s ->
295                 let term = term2pres d.Con.def_term in
296                 B.H ([],
297                   [B.Text([],"Let ");
298                    B.Object ([], P.Mi([],s));
299                    B.Text([]," = ");
300                    term])
301             | None -> 
302                 prerr_endline "NO NAME!!"; assert false) 
303       | `Joint ho -> 
304             B.Text ([],"jointdef")
305
306   and acontext2pres ac continuation indent =
307     let module Con = Content in
308     List.fold_right
309       (fun p continuation ->
310          let hd = 
311            if indent then
312              B.indent (proof2pres p)
313            else 
314              proof2pres p in
315          B.V([Some "helm","xref",p.Con.proof_id],
316            [B.H([Some "helm","xref","ace_"^p.Con.proof_id],[hd]);
317             continuation])) ac continuation 
318
319   and conclude2pres conclude indent omit_conclusion =
320     let module Con = Content in
321     let module P = Mpresentation in
322     let tconclude_body = 
323       match conclude.Con.conclude_conclusion with
324         Some t when
325          not omit_conclusion or
326          (* CSC: I ignore the omit_conclusion flag in this case.   *)
327          (* CSC: Is this the correct behaviour? In the stylesheets *)
328          (* CSC: we simply generated nothing (i.e. the output type *)
329          (* CSC: of the function should become an option.          *)
330          conclude.Con.conclude_method = "BU_Conversion" ->
331           let concl = (term2pres t) in 
332           if conclude.Con.conclude_method = "BU_Conversion" then
333             make_concl "that is equivalent to" concl
334           else if conclude.Con.conclude_method = "FalseInd" then
335            (* false ind is in charge to add the conclusion *)
336            falseind conclude
337           else  
338             let conclude_body = conclude_aux conclude in
339             let ann_concl = 
340               if conclude.Con.conclude_method = "TD_Conversion" then
341                  make_concl "that is equivalent to" concl 
342               else make_concl "we conclude" concl in
343             B.V ([], [conclude_body; ann_concl])
344       | _ -> conclude_aux conclude in
345     if indent then 
346       B.indent (B.H ([Some "helm", "xref", conclude.Con.conclude_id],
347                     [tconclude_body]))
348     else 
349       B.H ([Some "helm", "xref", conclude.Con.conclude_id],[tconclude_body])
350
351
352   and conclude_aux conclude =
353     let module Con = Content in
354     let module P = Mpresentation in
355     if conclude.Con.conclude_method = "TD_Conversion" then
356       let expected = 
357         (match conclude.Con.conclude_conclusion with 
358            None -> B.Text([],"NO EXPECTED!!!")
359          | Some c -> term2pres c) in
360       let subproof = 
361         (match conclude.Con.conclude_args with
362           [Con.ArgProof p] -> p
363          | _ -> assert false) in
364       let synth = 
365         (match subproof.Con.proof_conclude.Con.conclude_conclusion with
366            None -> B.Text([],"NO SYNTH!!!")
367          | Some c -> (term2pres c)) in
368       B.V 
369         ([],
370         [make_concl "we must prove" expected;
371          make_concl "or equivalently" synth;
372          proof2pres subproof])
373     else if conclude.Con.conclude_method = "BU_Conversion" then
374       assert false
375     else if conclude.Con.conclude_method = "Exact" then
376       let arg = 
377         (match conclude.Con.conclude_args with 
378            [Con.Term t] -> term2pres t
379          | _ -> assert false) in
380       (match conclude.Con.conclude_conclusion with 
381          None ->
382           B.b_h [] [B.b_kw "Consider"; B.b_space; arg]
383        | Some c -> let conclusion = term2pres c in
384           make_row 
385             [arg; B.b_space; B.Text([],"proves")]
386             conclusion
387        )
388     else if conclude.Con.conclude_method = "Intros+LetTac" then
389       (match conclude.Con.conclude_args with
390          [Con.ArgProof p] -> proof2pres p
391        | _ -> assert false)
392 (* OLD CODE 
393       let conclusion = 
394       (match conclude.Con.conclude_conclusion with 
395          None -> B.Text([],"NO Conclusion!!!")
396        | Some c -> term2pres c) in
397       (match conclude.Con.conclude_args with
398          [Con.ArgProof p] -> 
399            B.V 
400             ([None,"align","baseline 1"; None,"equalrows","false";
401               None,"columnalign","left"],
402               [B.H([],[B.Object([],proof2pres p)]);
403                B.H([],[B.Object([],
404                 (make_concl "we proved 1" conclusion))])]);
405        | _ -> assert false)
406 *)
407     else if (conclude.Con.conclude_method = "Case") then
408       case conclude
409     else if (conclude.Con.conclude_method = "ByInduction") then
410       byinduction conclude
411     else if (conclude.Con.conclude_method = "Exists") then
412       exists conclude
413     else if (conclude.Con.conclude_method = "AndInd") then
414       andind conclude
415     else if (conclude.Con.conclude_method = "FalseInd") then
416       falseind conclude
417     else if (conclude.Con.conclude_method = "Rewrite") then
418       let justif = 
419         (match (List.nth conclude.Con.conclude_args 6) with
420            Con.ArgProof p -> justification term2pres p
421          | _ -> assert false) in
422       let term1 = 
423         (match List.nth conclude.Con.conclude_args 2 with
424            Con.Term t -> term2pres t
425          | _ -> assert false) in 
426       let term2 = 
427         (match List.nth conclude.Con.conclude_args 5 with
428            Con.Term t -> term2pres t
429          | _ -> assert false) in
430       B.V ([], 
431          [B.H ([],[
432           (B.b_kw "rewrite");
433           B.b_space; term1;
434           B.b_space; (B.b_kw "with");
435           B.b_space; term2;
436           B.indent justif])])
437     else if conclude.Con.conclude_method = "Apply" then
438       let pres_args = 
439         make_args_for_apply term2pres conclude.Con.conclude_args in
440       B.H([],
441         (B.b_kw "by")::
442         B.b_space::
443         B.Text([],"(")::pres_args@[B.Text([],")")])
444     else 
445       B.V 
446         ([],
447          [B.Text([],"Apply method" ^ conclude.Con.conclude_method ^ " to");
448           (B.indent 
449              (B.V 
450                 ([],
451                  args2pres conclude.Con.conclude_args)))]) 
452
453   and args2pres l = List.map arg2pres l
454
455   and arg2pres =
456     let module Con = Content in
457     function
458         Con.Aux n -> 
459           B.Text ([],"aux " ^ n)
460       | Con.Premise prem -> 
461           B.Text ([],"premise")
462       | Con.Lemma lemma ->
463           B.Text ([],"lemma")
464       | Con.Term t -> 
465           term2pres t
466       | Con.ArgProof p ->
467         proof2pres p 
468       | Con.ArgMethod s -> 
469          B.Text ([],"method") 
470  
471    and case conclude =
472      let module Con = Content in
473      let proof_conclusion = 
474        (match conclude.Con.conclude_conclusion with
475           None -> B.Text([],"No conclusion???")
476         | Some t -> term2pres t) in
477      let arg,args_for_cases = 
478        (match conclude.Con.conclude_args with
479            Con.Aux(_)::Con.Aux(_)::Con.Term(_)::arg::tl ->
480              arg,tl
481          | _ -> assert false) in
482      let case_on =
483        let case_arg = 
484          (match arg with
485             Con.Aux n -> 
486               B.Text ([],"an aux???")
487            | Con.Premise prem ->
488               (match prem.Con.premise_binder with
489                  None -> B.Text ([],"the previous result")
490                | Some n -> B.Object ([], P.Mi([],n)))
491            | Con.Lemma lemma -> B.Object ([], P.Mi([],lemma.Con.lemma_name))
492            | Con.Term t -> 
493                term2pres t
494            | Con.ArgProof p ->
495                B.Text ([],"a proof???")
496            | Con.ArgMethod s -> 
497                B.Text ([],"a method???")) in
498         (make_concl "we proceede by cases on" case_arg) in
499      let to_prove =
500         (make_concl "to prove" proof_conclusion) in
501      B.V 
502        ([],
503           case_on::to_prove::(make_cases args_for_cases))
504
505    and byinduction conclude =
506      let module Con = Content in
507      let proof_conclusion = 
508        (match conclude.Con.conclude_conclusion with
509           None -> B.Text([],"No conclusion???")
510         | Some t -> term2pres t) in
511      let inductive_arg,args_for_cases = 
512        (match conclude.Con.conclude_args with
513            Con.Aux(n)::_::tl ->
514              let l1,l2 = split (int_of_string n) tl in
515              let last_pos = (List.length l2)-1 in
516              List.nth l2 last_pos,l1
517          | _ -> assert false) in
518      let induction_on =
519        let arg = 
520          (match inductive_arg with
521             Con.Aux n -> 
522               B.Text ([],"an aux???")
523            | Con.Premise prem ->
524               (match prem.Con.premise_binder with
525                  None -> B.Text ([],"the previous result")
526                | Some n -> B.Object ([], P.Mi([],n)))
527            | Con.Lemma lemma -> B.Object ([], P.Mi([],lemma.Con.lemma_name))
528            | Con.Term t -> 
529                term2pres t
530            | Con.ArgProof p ->
531                B.Text ([],"a proof???")
532            | Con.ArgMethod s -> 
533                B.Text ([],"a method???")) in
534         (make_concl "we proceede by induction on" arg) in
535      let to_prove =
536         (make_concl "to prove" proof_conclusion) in
537      B.V 
538        ([],
539           induction_on::to_prove::
540           (make_cases args_for_cases))
541
542     and make_cases l = List.map make_case l
543
544     and make_case =  
545       let module Con = Content in
546       function 
547         Con.ArgProof p ->
548           let name =
549             (match p.Con.proof_name with
550                None -> B.Text([],"no name for case!!")
551              | Some n -> B.Object ([], P.Mi([],n))) in
552           let indhyps,args =
553              List.partition 
554                (function
555                    `Hypothesis h -> h.Con.dec_inductive
556                  | _ -> false) p.Con.proof_context in
557           let pattern_aux =
558              List.fold_right
559                (fun e p -> 
560                   let dec  = 
561                     (match e with 
562                        `Declaration h 
563                      | `Hypothesis h -> 
564                          let name = 
565                            (match h.Con.dec_name with
566                               None -> "NO NAME???"
567                            | Some n ->n) in
568                          [B.b_space;
569                           B.Object ([], P.Mi ([],name));
570                           B.Text([],":");
571                           (term2pres h.Con.dec_type)]
572                      | _ -> [B.Text ([],"???")]) in
573                   dec@p) args [] in
574           let pattern = 
575             B.H ([],
576                (B.Text([],"Case")::B.b_space::name::pattern_aux)@
577                 [B.b_space;
578                  B.Text([],"->")]) in
579           let subconcl = 
580             (match p.Con.proof_conclude.Con.conclude_conclusion with
581                None -> B.Text([],"No conclusion!!!") 
582              | Some t -> term2pres t) in
583           let asubconcl = B.indent (make_concl "the thesis becomes" subconcl) in
584           let induction_hypothesis = 
585             (match indhyps with
586               [] -> []
587             | _ -> 
588                let text =
589                  B.indent (B.Text([],"by induction hypothesis we know:")) in
590                let make_hyp =
591                  function 
592                    `Hypothesis h ->
593                      let name = 
594                        (match h.Con.dec_name with
595                           None -> "no name"
596                         | Some s -> s) in
597                      B.indent (B.H ([],
598                        [B.Text([],"(");
599                         B.Object ([], P.Mi ([],name));
600                         B.Text([],")");
601                         B.b_space;
602                         term2pres h.Con.dec_type]))
603                    | _ -> assert false in
604                let hyps = List.map make_hyp indhyps in
605                text::hyps) in          
606           (* let acontext = 
607                acontext2pres_old p.Con.proof_apply_context true in *)
608           let body = conclude2pres p.Con.proof_conclude true false in
609           let presacontext = 
610            let acontext_id =
611             match p.Con.proof_apply_context with
612                [] -> p.Con.proof_conclude.Con.conclude_id
613              | {Con.proof_id = id}::_ -> id
614            in
615             B.Action([None,"type","toggle"],
616               [B.indent
617                (B.Text
618                  ([None,"color","red" ;
619                    Some "helm", "xref", acontext_id],"Proof")) ;
620                acontext2pres p.Con.proof_apply_context body true]) in
621           B.V ([], pattern::asubconcl::induction_hypothesis@[presacontext])
622        | _ -> assert false 
623
624      and falseind conclude =
625        let module P = Mpresentation in
626        let module Con = Content in
627        let proof_conclusion = 
628          (match conclude.Con.conclude_conclusion with
629             None -> B.Text([],"No conclusion???")
630           | Some t -> term2pres t) in
631        let case_arg = 
632          (match conclude.Con.conclude_args with
633              [Con.Aux(n);_;case_arg] -> case_arg
634            | _ -> assert false;
635              (* 
636              List.map (ContentPp.parg 0) conclude.Con.conclude_args;
637              assert false *)) in
638        let arg = 
639          (match case_arg with
640              Con.Aux n -> assert false
641            | Con.Premise prem ->
642               (match prem.Con.premise_binder with
643                  None -> [B.Text([],"Contradiction, hence")]
644                | Some n -> 
645                   [B.Object ([],P.Mi([],n)); B.skip;B.Text([],"is contradictory, hence")])
646            | Con.Lemma lemma -> 
647                [B.Object ([], P.Mi([],lemma.Con.lemma_name)); B.skip; B.Text([],"is contradictory, hence")]
648            | _ -> assert false) in
649             (* let body = proof2pres {proof with Con.proof_context = tl} in *)
650        make_row arg proof_conclusion
651
652      and andind conclude =
653        let module P = Mpresentation in
654        let module Con = Content in
655        let proof_conclusion = 
656          (match conclude.Con.conclude_conclusion with
657             None -> B.Text([],"No conclusion???")
658           | Some t -> term2pres t) in
659        let proof,case_arg = 
660          (match conclude.Con.conclude_args with
661              [Con.Aux(n);_;Con.ArgProof proof;case_arg] -> proof,case_arg
662            | _ -> assert false;
663              (* 
664              List.map (ContentPp.parg 0) conclude.Con.conclude_args;
665              assert false *)) in
666        let arg = 
667          (match case_arg with
668              Con.Aux n -> assert false
669            | Con.Premise prem ->
670               (match prem.Con.premise_binder with
671                  None -> []
672                | Some n -> [(B.b_kw "by"); B.b_space; B.Object([], P.Mi([],n))])
673            | Con.Lemma lemma -> 
674                [(B.b_kw "by");B.skip; B.Object([], P.Mi([],lemma.Con.lemma_name))]
675            | _ -> assert false) in
676        match proof.Con.proof_context with
677          `Hypothesis hyp1::`Hypothesis hyp2::tl ->
678             let get_name hyp =
679               (match hyp.Con.dec_name with
680                 None -> "_"
681               | Some s -> s) in
682             let preshyp1 = 
683               B.H ([],
684                [B.Text([],"(");
685                 B.Object ([], P.Mi([],get_name hyp1));
686                 B.Text([],")");
687                 B.skip;
688                 term2pres hyp1.Con.dec_type]) in
689             let preshyp2 = 
690               B.H ([],
691                [B.Text([],"(");
692                 B.Object ([], P.Mi([],get_name hyp2));
693                 B.Text([],")");
694                 B.skip;
695                 term2pres hyp2.Con.dec_type]) in
696             (* let body = proof2pres {proof with Con.proof_context = tl} in *)
697             let body = conclude2pres proof.Con.proof_conclude false true in
698             let presacontext = 
699               acontext2pres proof.Con.proof_apply_context body false in
700             B.V 
701               ([],
702                [B.H ([],arg@[B.skip; B.Text([],"we have")]);
703                 preshyp1;
704                 B.Text([],"and");
705                 preshyp2;
706                 presacontext]);
707          | _ -> assert false
708
709      and exists conclude =
710        let module P = Mpresentation in
711        let module Con = Content in
712        let proof_conclusion = 
713          (match conclude.Con.conclude_conclusion with
714             None -> B.Text([],"No conclusion???")
715           | Some t -> term2pres t) in
716        let proof = 
717          (match conclude.Con.conclude_args with
718              [Con.Aux(n);_;Con.ArgProof proof;_] -> proof
719            | _ -> assert false;
720              (* 
721              List.map (ContentPp.parg 0) conclude.Con.conclude_args;
722              assert false *)) in
723        match proof.Con.proof_context with
724            `Declaration decl::`Hypothesis hyp::tl
725          | `Hypothesis decl::`Hypothesis hyp::tl ->
726            let get_name decl =
727              (match decl.Con.dec_name with
728                 None -> "_"
729               | Some s -> s) in
730            let presdecl = 
731              B.H ([],
732                [(B.b_kw "let");
733                 B.skip;
734                 B.Object ([], P.Mi([],get_name decl));
735                 B.Text([],":"); term2pres decl.Con.dec_type]) in
736            let suchthat =
737              B.H ([],
738                [(B.b_kw "such that");
739                 B.skip;
740                 B.Text([],"(");
741                 B.Object ([], P.Mi([],get_name hyp));
742                 B.Text([],")");
743                 B.skip;
744                 term2pres hyp.Con.dec_type]) in
745             (* let body = proof2pres {proof with Con.proof_context = tl} in *)
746             let body = conclude2pres proof.Con.proof_conclude false true in
747             let presacontext = 
748               acontext2pres proof.Con.proof_apply_context body false in
749             B.V 
750               ([],
751                [presdecl;
752                 suchthat;
753                 presacontext]);
754          | _ -> assert false in
755
756 proof2pres p
757 ;;
758
759 exception ToDo;;
760
761 let aaa = ref 0
762
763 let content2pres term2pres (id,params,metasenv,obj) =
764   let module K = Content in
765     match obj with
766         `Def (K.Const,thesis,`Proof p) ->
767           B.b_v
768           [None,"helm:xref","id"]
769           ([B.b_text [] ("UNFINISHED PROOF " ^ id ^"(" ^ String.concat " ; " (List.map UriManager.string_of_uri params)^ ")") ;
770             B.b_text [] "THESIS:" ;
771             B.indent (term2pres thesis)] @
772            (match metasenv with
773                 None -> []
774               | Some metasenv' ->
775                     (* Conjectures are in their own table to make *)
776                     (* diffing the DOM trees easier.              *)
777                     (B.b_v []
778                        ((B.b_text [] ("CONJECTURES:" ^ (let _ = incr aaa; in (string_of_int !aaa))))::
779                        (List.map
780                           (function
781                                (id,n,context,ty) ->
782                                  (B.b_h [Some "helm", "xref", id]
783                                     (((List.map
784                                          (function
785                                               None ->
786                                                 B.b_h []
787                                                 [ B.b_object (p_mi [] "_") ;
788                                                   B.b_object (p_mo [] ":?") ;
789                                                   B.b_object (p_mi [] "_")]
790                                             | Some (`Declaration d)
791                                             | Some (`Hypothesis d) ->
792                                                 let
793                                                   { K.dec_name = dec_name ;
794                                                     K.dec_type = ty } = d
795                                                 in
796                                                   B.b_h []
797                                                     [ B.b_object (p_mi []
798                                                                      (match dec_name with
799                                                                           None -> "_"
800                                                                         | Some n -> n)) ;
801                                                       B.b_text [] ":" ;
802                                                       term2pres ty]
803                                             | Some (`Definition d) ->
804                                                 let
805                                                   { K.def_name = def_name ;
806                                                     K.def_term = bo } = d
807                                                 in
808                                                   B.b_h []
809                                                     [ B.b_object (p_mi []
810                                                                      (match def_name with
811                                                                           None -> "_"
812                                                                         | Some n -> n)) ;
813                                                       B.b_text [] ":=" ;
814                                                       term2pres bo]
815                                             | Some (`Proof p) ->
816                                                 let proof_name = p.K.proof_name in
817                                                   B.b_h []
818                                                     [ B.b_object (p_mi []
819                                                                      (match proof_name with
820                                                                           None -> "_"
821                                                                         | Some n -> n)) ;
822                                                       B.b_text [] ":=" ;
823                                                       proof2pres term2pres p]
824                                          ) (List.rev context)) @
825                                       [ B.b_text [] "|-" ;
826                                         B.b_object (p_mi [] (string_of_int n)) ;
827                                         B.b_text [] ":" ;
828                                         term2pres ty ])
829                                     ))
830                           ) metasenv'))
831                     )::[proof2pres term2pres p]
832            )
833           )
834       | _ -> raise ToDo
835 ;;
836
837 let content2pres ~ids_to_inner_sorts =
838  content2pres 
839   (function p -> 
840      (Cexpr2pres.cexpr2pres_charcount 
841                     (Content_expressions.acic2cexpr ids_to_inner_sorts p)))
842 ;;
843