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