]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_transformations/content2pres.ml
1616c21c8273d0bf15b9fc4ba39948a3e328e8c4
[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 action = 
224            match concl with
225               None -> body
226 (*
227                P.Maction
228                  ([None,"actiontype","toggle" ; None,"selection","1"],
229                   [P.Mtext [] "proof" ; body])
230 *)
231             | Some ac ->
232                P.Maction
233                  ([None,"actiontype","toggle" ; None,"selection","1"],
234                   [(make_concl "proof of" ac); body])
235           in
236           P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
237               None,"columnalign","left"],
238             [P.Mtr ([],[P.Mtd ([],P.Mfenced([],[P.Mtext ([],name)]))]);
239              P.Mtr ([],[P.Mtd ([], P.indented action)])])
240 (*
241           P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
242               None,"columnalign","left";Some "helm", "xref", p.Con.proof_id],
243             [P.Mtr ([],[P.Mtd ([],P.Mfenced([],[P.Mtext ([],name)]))]);
244              P.Mtr ([],[P.Mtd ([], P.indented action)])]) *)
245
246   and context2pres c continuation =
247     (* we generate a subtable for each context element, for selection
248        purposes 
249        The table generated by the head-element does not have an xref;
250        the whole context-proof is already selectable *)
251     let module P = Mpresentation in
252     match c with
253       [] -> continuation
254     | hd::tl -> 
255         let continuation' =
256           List.fold_right
257             (fun ce continuation ->
258               let xref = get_xref ce in
259               P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
260                None,"columnalign","left"; Some "helm", "xref", xref ],
261                 [P.Mtr([Some "helm", "xref", "ce_"^xref],[P.Mtd ([],ce2pres ce)]);
262                  P.Mtr([],[P.Mtd ([], continuation)])])) tl continuation in
263          let hd_xref= get_xref hd in
264          P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
265            None,"columnalign","left"],
266              [P.Mtr([Some "helm", "xref", "ce_"^hd_xref],
267                [P.Mtd ([],ce2pres hd)]);
268              P.Mtr([],[P.Mtd ([], continuation')])])
269          
270   and ce2pres =
271     let module P = Mpresentation in
272     let module Con = Content in
273       function
274         `Declaration d -> 
275           (match d.Con.dec_name with
276               Some s ->
277                 let ty = term2pres d.Con.dec_type in
278                 P.Mrow ([],
279                   [P.Mtext([None,"mathcolor","Red"],"Assume");
280                    P.Mspace([None,"width","0.1cm"]);
281                    P.Mi([],s);
282                    P.Mtext([],":");
283                    ty])
284             | None -> 
285                 prerr_endline "NO NAME!!"; assert false)
286       | `Hypothesis h ->
287           (match h.Con.dec_name with
288               Some s ->
289                 let ty = term2pres h.Con.dec_type in
290                 P.Mrow ([],
291                   [P.Mtext([None,"mathcolor","Red"],"Suppose");
292                    P.Mspace([None,"width","0.1cm"]);
293                    P.Mtext([],"(");
294                    P.Mi ([],s);
295                    P.Mtext([],")");
296                    P.Mspace([None,"width","0.1cm"]);
297                    ty])
298             | None -> 
299                 prerr_endline "NO NAME!!"; assert false) 
300       | `Proof p -> proof2pres p
301       | `Definition d -> 
302            (match d.Con.def_name with
303               Some s ->
304                 let term = term2pres d.Con.def_term in
305                 P.Mrow ([],
306                   [P.Mtext([],"Let ");
307                    P.Mi([],s);
308                    P.Mtext([]," = ");
309                    term])
310             | None -> 
311                 prerr_endline "NO NAME!!"; assert false) 
312       | `Joint ho -> 
313             P.Mtext ([],"jointdef")
314
315   and acontext2pres ac continuation indent =
316     let module Con = Content in
317     let module P = Mpresentation in
318     List.fold_right
319       (fun p continuation ->
320          let hd = 
321            if indent then
322              P.indented (proof2pres p)
323            else 
324              proof2pres p in
325          P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
326           None,"columnalign","left"; Some "helm","xref",p.Con.proof_id],
327            [P.Mtr([Some "helm","xref","ace_"^p.Con.proof_id],[P.Mtd ([],hd)]);
328             P.Mtr([],[P.Mtd ([], continuation)])])) ac continuation 
329
330   and conclude2pres conclude indent omit_conclusion =
331     let module Con = Content in
332     let module P = Mpresentation in
333     let tconclude_body = 
334       match conclude.Con.conclude_conclusion with
335         Some t when not omit_conclusion ->
336           let concl = (term2pres t) in 
337           if conclude.Con.conclude_method = "BU_Conversion" then
338             make_concl "that is equivalent to" concl
339           else  
340             let conclude_body = conclude_aux conclude in
341             let ann_concl = make_concl "we conclude" concl in
342             P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
343               None,"columnalign","left"],
344                 [P.Mtr ([],[P.Mtd ([],conclude_body)]);
345                  P.Mtr ([],[P.Mtd ([],ann_concl)])])
346       | _ -> conclude_aux conclude in
347     if indent then 
348       P.indented (P.Mrow ([Some "helm", "xref", conclude.Con.conclude_id],
349                     [tconclude_body]))
350     else 
351       P.Mrow ([Some "helm", "xref", conclude.Con.conclude_id],[tconclude_body])
352
353
354   and conclude_aux conclude =
355     let module Con = Content in
356     let module P = Mpresentation in
357     if conclude.Con.conclude_method = "TD_Conversion" then
358       let expected = 
359         (match conclude.Con.conclude_conclusion with 
360            None -> P.Mtext([],"NO EXPECTED!!!")
361          | Some c -> term2pres c) in
362       let subproof = 
363         (match conclude.Con.conclude_args with
364           [Con.ArgProof p] -> p
365          | _ -> assert false) in
366       let synth = 
367         (match subproof.Con.proof_conclude.Con.conclude_conclusion with
368            None -> P.Mtext([],"NO SYNTH!!!")
369          | Some c -> (term2pres c)) in
370       P.Mtable 
371         ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
372         [P.Mtr([],[P.Mtd([],make_concl "we must prove" expected)]);
373          P.Mtr([],[P.Mtd([],make_concl "or equivalently" synth)]);
374          P.Mtr([],[P.Mtd([],proof2pres subproof)])])
375     else if conclude.Con.conclude_method = "BU_Conversion" then
376       assert false
377     else if conclude.Con.conclude_method = "Exact" then
378       let arg = 
379         (match conclude.Con.conclude_args with 
380            [Con.Term t] -> term2pres t
381          | _ -> assert false) in
382       (match conclude.Con.conclude_conclusion with 
383          None ->
384           P.Mrow []
385            [P.Mtext [None, "mathcolor", "red"] "Consider" ; P.smallskip; arg]
386        | Some c -> let conclusion = term2pres c in
387           make_row 
388             [arg; P.Mspace([None,"width","0.1cm"]);P.Mtext([],"proves")]
389             conclusion
390        )
391     else if conclude.Con.conclude_method = "Intros+LetTac" then
392       (match conclude.Con.conclude_args with
393          [Con.ArgProof p] -> proof2pres p
394        | _ -> assert false)
395 (* OLD CODE 
396       let conclusion = 
397       (match conclude.Con.conclude_conclusion with 
398          None -> P.Mtext([],"NO Conclusion!!!")
399        | Some c -> term2pres c) in
400       (match conclude.Con.conclude_args with
401          [Con.ArgProof p] -> 
402            P.Mtable 
403             ([None,"align","baseline 1"; None,"equalrows","false";
404               None,"columnalign","left"],
405               [P.Mtr([],[P.Mtd([],proof2pres p)]);
406                P.Mtr([],[P.Mtd([],
407                 (make_concl "we proved 1" conclusion))])]);
408        | _ -> assert false)
409 *)
410     else if (conclude.Con.conclude_method = "ByInduction") then
411       byinduction conclude
412     else if (conclude.Con.conclude_method = "Rewrite") then
413       let justif = 
414         (match (List.nth conclude.Con.conclude_args 6) with
415            Con.ArgProof p -> justification term2pres p
416          | _ -> assert false) in
417       let term1 = 
418         (match List.nth conclude.Con.conclude_args 2 with
419            Con.Term t -> term2pres t
420          | _ -> assert false) in 
421       let term2 = 
422         (match List.nth conclude.Con.conclude_args 5 with
423            Con.Term t -> term2pres t
424          | _ -> assert false) in
425       P.Mtable ([None,"align","baseline 1";None,"equalrows","false";
426         None,"columnalign","left"], 
427          [P.Mtr ([],[P.Mtd ([],P.Mrow([],[
428           P.Mtext([None,"mathcolor","Red"],"rewrite");
429           P.Mspace([None,"width","0.1cm"]);term1;
430           P.Mspace([None,"width","0.1cm"]);
431           P.Mtext([None,"mathcolor","Red"],"with");
432           P.Mspace([None,"width","0.1cm"]);term2]))]);
433           P.Mtr ([],[P.Mtd ([],P.indented justif)])]);
434 (* OLD CODE   
435       let conclusion = 
436         (match conclude.Con.conclude_conclusion with 
437            None -> P.Mtext([],"NO Conclusion!!!")
438          | Some c -> term2pres c) in
439       P.Mtable ([None,"align","baseline 1";None,"equalrows","false";
440             None,"columnalign","left"],
441              [P.Mtr ([],[P.Mtd ([],P.Mrow([],[
442                P.Mtext([None,"mathcolor","Red"],"rewrite");
443                P.Mspace([None,"width","0.1cm"]);term1;
444                P.Mspace([None,"width","0.1cm"]);
445                P.Mtext([None,"mathcolor","Red"],"with");
446                P.Mspace([None,"width","0.1cm"]);term2]))]);
447               P.Mtr ([],[P.Mtd ([],P.indented justif)]);
448               P.Mtr ([],[P.Mtd ([],make_concl "we proved 2" conclusion)])]) *)
449     else if conclude.Con.conclude_method = "Apply" then
450       let pres_args = 
451         make_args_for_apply term2pres conclude.Con.conclude_args in
452       P.Mrow([],
453         P.Mtext([None,"mathcolor","Red"],"by")::
454         P.Mspace([None,"width","0.1cm"])::
455         P.Mo([],"(")::pres_args@[P.Mo([],")")])
456 (* OLD CODE 
457       let by = 
458          P.Mrow([],
459            P.Mtext([None,"mathcolor","Red"],"by")::P.Mspace([None,"width","0.1cm"])::
460            P.Mo([],"(")::pres_args@[P.Mo([],")")]) in 
461       match conclude.Con.conclude_conclusion with
462         None -> P.Mrow([],[P.Mtext([],"QUA");by])
463       | Some t ->
464          let concl = (term2pres t) in
465          let ann_concl = make_concl "we proved 3" concl in
466          P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
467             None,"columnalign","left"; 
468             Some "helm", "xref", conclude.Con.conclude_id],
469              [P.Mtr ([],[P.Mtd ([],by)]);
470               P.Mtr ([],[P.Mtd ([],ann_concl)])]) *)
471     else 
472       P.Mtable 
473         ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
474          [P.Mtr ([],[P.Mtd ([],P.Mtext([],"Apply method" ^ conclude.Con.conclude_method ^ " to"))]);
475           P.Mtr ([],
476            [P.Mtd ([], 
477              (P.indented 
478                (P.Mtable 
479                  ([None,"align","baseline 1"; None,"equalrows","false";
480                    None,"columnalign","left"],
481                   args2pres conclude.Con.conclude_args))))])]) 
482 (* OLD CODE 
483      match conclude.Con.conclude_conclusion with
484        None -> body
485      | Some t ->
486          let concl = (term2pres t) in
487          let ann_concl = make_concl "we proved 4" concl in
488          P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
489             None,"columnalign","left"],
490              [P.Mtr ([],[P.Mtd ([],body)]);
491               P.Mtr ([],[P.Mtd ([],ann_concl)])]) *)
492
493   and args2pres l =
494     let module P = Mpresentation in
495     List.map 
496      (function a -> P.Mtr ([], [P.Mtd ([], arg2pres a)])) l
497
498   and arg2pres =
499     let module P = Mpresentation in
500     let module Con = Content in
501     function
502         Con.Aux n -> 
503           P.Mtext ([],"aux " ^ n)
504       | Con.Premise prem -> 
505           P.Mtext ([],"premise")
506       | Con.Lemma lemma ->
507           P.Mtext ([],"lemma")
508       | Con.Term t -> 
509           term2pres t
510       | Con.ArgProof p ->
511         proof2pres p 
512       | Con.ArgMethod s -> 
513          P.Mtext ([],"method") 
514  
515    and byinduction conclude =
516      let module P = Mpresentation in
517      let module Con = Content in
518      let proof_conclusion = 
519        (match conclude.Con.conclude_conclusion with
520           None -> P.Mtext([],"No conclusion???")
521         | Some t -> term2pres t) in
522      let inductive_arg,args_for_cases = 
523        (match conclude.Con.conclude_args with
524            Con.Aux(n)::_::tl ->
525              let l1,l2 = split (int_of_string n) tl in
526              let last_pos = (List.length l2)-1 in
527              List.nth l2 last_pos,l1
528          | _ -> assert false) in
529      let induction_on =
530        let arg = 
531          (match inductive_arg with
532             Con.Aux n -> 
533               P.Mtext ([],"an aux???")
534            | Con.Premise prem ->
535               (match prem.Con.premise_binder with
536                  None -> P.Mtext ([],"the previous result")
537                | Some n -> P.Mi([],n))
538            | Con.Lemma lemma -> P.Mi([],lemma.Con.lemma_name)
539            | Con.Term t -> 
540                term2pres t
541            | Con.ArgProof p ->
542                P.Mtext ([],"a proof???")
543            | Con.ArgMethod s -> 
544                P.Mtext ([],"a method???")) in
545         (make_concl "we proceede by induction on" arg) in
546      let to_prove =
547         (make_concl "to prove" proof_conclusion) in
548      P.Mtable 
549        ([None,"align","baseline 1"; None,"equalrows","false"; 
550          None,"columnalign","left"],
551           P.Mtr ([],[P.Mtd ([],induction_on)])::
552           P.Mtr ([],[P.Mtd ([],to_prove)])::
553           (make_cases args_for_cases))
554 (* OLD CODE   
555      let we_proved = 
556         (make_concl "we proved 5" proof_conclusion) in 
557      P.Mtable 
558        ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
559           P.Mtr ([],[P.Mtd ([],induction_on)])::
560           P.Mtr ([],[P.Mtd ([],to_prove)])::
561           (make_cases args_for_cases) @
562           [P.Mtr ([],[P.Mtd ([],we_proved)])]) *)
563     
564     and make_cases args_for_cases =
565     let module P = Mpresentation in
566     List.map 
567       (fun p -> P.Mtr ([],[P.Mtd ([],make_case p)])) args_for_cases
568
569     and make_case =  
570       let module P = Mpresentation in
571       let module Con = Content in
572       function 
573         Con.ArgProof p ->
574           let name =
575             (match p.Con.proof_name with
576                None -> P.Mtext([],"no name for case!!")
577              | Some n -> P.Mi([],n)) in
578           let indhyps,args =
579              List.partition 
580                (function
581                    `Hypothesis h -> h.Con.dec_inductive
582                  | _ -> false) p.Con.proof_context in
583           let pattern_aux =
584              List.fold_right
585                (fun e p -> 
586                   let dec  = 
587                     (match e with 
588                        `Declaration h 
589                      | `Hypothesis h -> 
590                          let name = 
591                            (match h.Con.dec_name with
592                               None -> "NO NAME???"
593                            | Some n ->n) in
594                          [P.Mspace([None,"width","0.1cm"]);
595                           P.Mi ([],name);
596                           P.Mtext([],":");
597                           (term2pres h.Con.dec_type)]
598                      | _ -> [P.Mtext ([],"???")]) in
599                   dec@p) args [] in
600           let pattern = 
601             P.Mtr ([],[P.Mtd ([],P.Mrow([],
602                P.Mtext([],"Case")::P.Mspace([None,"width","0.1cm"])::name::pattern_aux@
603                 [P.Mspace([None,"width","0.1cm"]);
604                  P.Mtext([],"->")]))]) in
605           let subconcl = 
606             (match p.Con.proof_conclude.Con.conclude_conclusion with
607                None -> P.Mtext([],"No conclusion!!!") 
608              | Some t -> term2pres t) in
609           let asubconcl =
610              P.Mtr([],[P.Mtd([],
611               P.indented (make_concl "the thesis becomes" subconcl))]) in
612           let induction_hypothesis = 
613             (match indhyps with
614               [] -> []
615             | _ -> 
616                let text =
617                  P.Mtr([],[P.Mtd([], P.indented 
618                  (P.Mtext([],"by induction hypothesis we know:")))]) in
619                let make_hyp =
620                  function 
621                    `Hypothesis h ->
622                      let name = 
623                        (match h.Con.dec_name with
624                           None -> "no name"
625                         | Some s -> s) in
626                      P.indented (P.Mrow ([],
627                        [P.Mtext([],"(");
628                         P.Mi ([],name);
629                         P.Mtext([],")");
630                         P.Mspace([None,"width","0.1cm"]);
631                         term2pres h.Con.dec_type]))
632                    | _ -> assert false in
633                let hyps = 
634                  List.map 
635                    (function ce -> P.Mtr ([], [P.Mtd ([], make_hyp ce)])) 
636                     indhyps in
637                text::hyps) in          
638           (* let acontext = 
639                acontext2pres_old p.Con.proof_apply_context true in *)
640           let body = conclude2pres p.Con.proof_conclude true false in
641           let presacontext = 
642             P.Maction([None,"actiontype","toggle" ; None,"selection","1"],
643               [P.indented (P.Mtext([None,"mathcolor","Red"],"Proof"));
644                acontext2pres p.Con.proof_apply_context body true]) in
645           P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
646              None,"columnalign","left"],
647              pattern::asubconcl::induction_hypothesis@
648               [P.Mtr([],[P.Mtd([],presacontext)])])
649       | _ -> assert false in
650
651 proof2pres p
652 ;;
653
654 exception ToDo;;
655
656 let content2pres term2pres (id,params,metasenv,obj) =
657  let module K = Content in
658  let module P = Mpresentation in
659   match obj with
660      `Def (K.Const,thesis,`Proof p) ->
661        P.Mtable
662         [None,"align","baseline 1";
663          None,"equalrows","false";
664          None,"columnalign","left";
665          None,"helm:xref","id"]
666         ([P.Mtr []
667            [P.Mtd []
668             (P.Mrow []
669              [P.Mtext []
670                ("UNFINISHED PROOF" ^ id ^"(" ^
671                  String.concat " ; " (List.map UriManager.string_of_uri params)^
672                 ")")])] ;
673          P.Mtr []
674           [P.Mtd []
675             (P.Mrow []
676               [P.Mtext [] "THESIS:"])] ;
677          P.Mtr []
678           [P.Mtd []
679             (P.Mrow []
680               [P.Mphantom []
681                 (P.Mtext [] "__") ;
682               term2pres thesis])]] @
683          (match metasenv with
684              None -> []
685            | Some metasenv' ->
686               [P.Mtr []
687                 [P.Mtd []
688                   (* Conjectures are in their own table to make *)
689                   (* diffing the DOM trees easier.              *)
690                   (P.Mtable
691                     [None,"align","baseline 1";
692                      None,"equalrows","false";
693                      None,"columnalign","left"]
694                    ((P.Mtr []
695                       [P.Mtd []
696                        (P.Mrow []
697                          [P.Mtext [] "CONJECTURES:"])])::
698                     List.map
699                      (function
700                        (id,n,context,ty) ->
701                          P.Mtr []
702                           [P.Mtd []
703                            (P.Mrow [Some "helm", "xref", id]
704                              (List.map
705                                (function
706                                    (_,None) ->
707                                      P.Mrow []
708                                       [ P.Mi [] "_" ;
709                                         P.Mo [] ":?" ;
710                                         P.Mi [] "_"]
711                                  | (_,Some (`Declaration d))
712                                  | (_,Some (`Hypothesis d)) ->
713                                     let
714                                      { K.dec_name = dec_name ;
715                                        K.dec_type = ty } = d
716                                      in
717                                       P.Mrow []
718                                        [ P.Mi []
719                                           (match dec_name with
720                                               None -> "_"
721                                             | Some n -> n) ;
722                                          P.Mo [] ":" ;
723                                          term2pres ty]
724                                  | (_,Some (`Definition d)) ->
725                                     let
726                                      { K.def_name = def_name ;
727                                        K.def_term = bo } = d
728                                      in
729                                       P.Mrow []
730                                        [ P.Mi []
731                                           (match def_name with
732                                               None -> "_"
733                                             | Some n -> n) ;
734                                          P.Mo [] ":=" ;
735                                          term2pres bo]
736                                  | (_,Some (`Proof p)) ->
737                                     let proof_name = p.K.proof_name in
738                                      P.Mrow []
739                                       [ P.Mi []
740                                          (match proof_name with
741                                              None -> "_"
742                                            | Some n -> n) ;
743                                         P.Mo [] ":=" ;
744                                         proof2pres term2pres p]
745                                ) context @
746                              [ P.Mo [] "|-" ] @
747                              [ P.Mi [] (string_of_int n) ;
748                                P.Mo [] ":" ;
749                                term2pres ty ]
750                            ))
751                           ]
752                      ) metasenv'
753                   ))]]
754          )  @
755         [P.Mtr []
756           [P.Mtd []
757             (P.Mrow []
758               [proof2pres term2pres p])]])
759    | _ -> raise ToDo
760 ;;
761
762 let content2pres ~ids_to_inner_sorts =
763  content2pres 
764   (function p -> 
765    (Cexpr2pres.cexpr2pres_charcount 
766     (Content_expressions.acic2cexpr ids_to_inner_sorts p)))
767 ;;