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