1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (***************************************************************************)
30 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (***************************************************************************)
38 split (n-1) (List.tl l) in
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
49 let c1 = (countcontext current_size p.Con.proof_context) in
50 if c1 > maxsize then c1
52 let c2 = (countapplycontext c1 p.Con.proof_apply_context) in
53 if c2 > maxsize then c2
55 countconclude c2 p.Con.proof_conclude
58 countcontext current_size c =
59 List.fold_left countcontextitem current_size c
61 countcontextitem current_size e =
62 if current_size > maxsize then maxsize
66 (match d.Con.dec_name with
67 Some s -> current_size + 4 + (String.length s)
68 | None -> prerr_endline "NO NAME!!"; assert false)
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
75 (match d.Con.def_name with
77 let c1 = (current_size + 4 + (String.length s)) in
78 (countterm c1 d.Con.def_term)
80 prerr_endline "NO NAME!!"; assert false)
81 | `Joint ho -> maxsize + 1) (* we assume is big *)
83 countapplycontext current_size ac =
84 List.fold_left countp current_size ac
86 countconclude current_size co =
87 if current_size > maxsize then current_size
89 let c1 = countargs current_size co.Con.conclude_args in
90 if c1 > maxsize then c1
92 (match co.Con.conclude_conclusion with
93 Some concl -> countterm c1 concl
96 countargs current_size args =
97 List.fold_left countarg current_size args
99 countarg current_size arg =
100 if current_size > maxsize then current_size
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)
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
117 let is_big = is_big_general (Cexpr2pres.countterm)
121 let module Con = Content in
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
130 let make_row ?(attrs=[]) items concl =
131 let module P = Mpresentation in
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)])])
139 P.Mrow(attrs,items@[P.Mspace([None,"width","0.1cm"]);concl]))
142 let make_concl ?(attrs=[]) verb concl =
143 let module P = Mpresentation in
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)])])
152 [P.Mtext([None,"mathcolor","Red"],verb);
153 P.Mspace([None,"width","0.1cm"]);
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 =
162 Con.Aux n -> assert false
163 | Con.Premise prem ->
165 (match prem.Con.premise_binder with
168 P.smallskip::P.Mi([],name)::row
170 P.smallskip::P.Mi([],lemma.Con.lemma_name)::row
174 else P.smallskip::P.Mi([],"_")::row
177 P.smallskip::P.Mi([],"_")::row) in
180 make_arg_for_apply true hd
181 (List.fold_right (make_arg_for_apply false) tl [])
182 | _ -> assert false;;
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
192 make_args_for_apply term2pres p.Con.proof_conclude.Con.conclude_args in
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
198 and proof2pres term2pres p =
199 let rec proof2pres p =
200 let module Con = Content in
201 let module P = Mpresentation in
206 | `Hypothesis _ -> true
208 ((List.filter is_decl p.Con.proof_context) != []) in
210 (match p.Con.proof_conclude.Con.conclude_conclusion with
212 | Some t -> Some (term2pres t)) in
214 let presconclude = conclude2pres p.Con.proof_conclude indent in
216 acontext2pres p.Con.proof_apply_context presconclude indent in
217 context2pres p.Con.proof_context presacontext in
218 match p.Con.proof_name with
223 None -> P.Mtext([],"NO PROOF!!!")
226 P.Maction([None,"actiontype","toggle" ;
227 None,"selection","1"],
228 [(make_concl "proof of" ac);
230 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
231 None,"columnalign","left";Some "helm", "xref", p.Con.proof_id],
232 [P.Mtr ([],[P.Mtd ([],P.Mfenced([],[P.Mtext ([],name)]))]);
233 P.Mtr ([],[P.Mtd ([], P.indented action)])])
235 and context2pres c continuation =
236 (* we generate a subtable for each context element, for selection
238 let module P = Mpresentation in
240 (fun ce continuation ->
241 let xref = get_xref ce in
242 P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
243 None,"columnalign","left"; Some "helm", "xref", xref ],
244 [P.Mtr([Some "helm", "xref", "ce_"^xref],[P.Mtd ([],ce2pres ce)]);
245 P.Mtr([],[P.Mtd ([], continuation)])])) c continuation
248 let module P = Mpresentation in
249 let module Con = Content in
252 (match d.Con.dec_name with
254 let ty = term2pres d.Con.dec_type in
256 [P.Mtext([None,"mathcolor","Red"],"Assume");
257 P.Mspace([None,"width","0.1cm"]);
262 prerr_endline "NO NAME!!"; assert false)
264 (match h.Con.dec_name with
266 let ty = term2pres h.Con.dec_type in
268 [P.Mtext([None,"mathcolor","Red"],"Suppose");
269 P.Mspace([None,"width","0.1cm"]);
273 P.Mspace([None,"width","0.1cm"]);
276 prerr_endline "NO NAME!!"; assert false)
277 | `Proof p -> proof2pres p
279 (match d.Con.def_name with
281 let term = term2pres d.Con.def_term in
288 prerr_endline "NO NAME!!"; assert false)
290 P.Mtext ([],"jointdef")
292 and acontext2pres ac continuation indent =
293 let module Con = Content in
294 let module P = Mpresentation in
296 (fun p continuation ->
299 P.indented (proof2pres p)
302 P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
303 None,"columnalign","left"; Some "helm","xref",p.Con.proof_id],
304 [P.Mtr([Some "helm","xref","ace_"^p.Con.proof_id],[P.Mtd ([],hd)]);
305 P.Mtr([],[P.Mtd ([], continuation)])])) ac continuation
307 and conclude2pres conclude indent =
308 let module P = Mpresentation in
310 P.indented (conclude_aux conclude)
312 conclude_aux conclude
314 and conclude_aux conclude =
315 let module Con = Content in
316 let module P = Mpresentation in
317 if conclude.Con.conclude_method = "TD_Conversion" then
319 (match conclude.Con.conclude_conclusion with
320 None -> P.Mtext([],"NO EXPECTED!!!")
321 | Some c -> term2pres c) in
323 (match conclude.Con.conclude_args with
324 [Con.ArgProof p] -> p
325 | _ -> assert false) in
327 (match subproof.Con.proof_conclude.Con.conclude_conclusion with
328 None -> P.Mtext([],"NO SYNTH!!!")
329 | Some c -> (term2pres c)) in
331 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"; Some "helm", "xref", conclude.Con.conclude_id],
332 [P.Mtr([],[P.Mtd([],make_concl "we must prove" expected)]);
333 P.Mtr([],[P.Mtd([],make_concl "or equivalently" synth)]);
334 P.Mtr([],[P.Mtd([],proof2pres subproof)])])
335 else if conclude.Con.conclude_method = "BU_Conversion" then
337 (match conclude.Con.conclude_conclusion with
338 None -> P.Mtext([],"NO Conclusion!!!")
339 | Some c -> term2pres c) in
341 ~attrs:[Some "helm", "xref", conclude.Con.conclude_id]
342 "that is equivalent to" conclusion
343 else if conclude.Con.conclude_method = "Exact" then
345 (match conclude.Con.conclude_conclusion with
346 None -> P.Mtext([],"NO Conclusion!!!")
347 | Some c -> term2pres c) in
349 (match conclude.Con.conclude_args with
350 [Con.Term t] -> term2pres t
351 | _ -> assert false) in
352 make_row ~attrs:[Some "helm", "xref", conclude.Con.conclude_id]
353 [arg;P.Mspace([None,"width","0.1cm"]);P.Mtext([],"proves")] conclusion
354 else if conclude.Con.conclude_method = "Intros+LetTac" then
356 (match conclude.Con.conclude_conclusion with
357 None -> P.Mtext([],"NO Conclusion!!!")
358 | Some c -> term2pres c) in
359 (match conclude.Con.conclude_args with
362 ([None,"align","baseline 1"; None,"equalrows","false";
363 None,"columnalign","left";
364 Some "helm", "xref", conclude.Con.conclude_id],
365 [P.Mtr([],[P.Mtd([],proof2pres p)]);
367 (make_concl "we proved *" conclusion))])]);
369 else if (conclude.Con.conclude_method = "ByInduction") then
371 else if (conclude.Con.conclude_method = "Rewrite") then
373 (match (List.nth conclude.Con.conclude_args 6) with
374 Con.ArgProof p -> justification term2pres p
375 | _ -> assert false) in
377 (match List.nth conclude.Con.conclude_args 2 with
378 Con.Term t -> term2pres t
379 | _ -> assert false) in
381 (match List.nth conclude.Con.conclude_args 5 with
382 Con.Term t -> term2pres t
383 | _ -> assert false) in
385 (match conclude.Con.conclude_conclusion with
386 None -> P.Mtext([],"NO Conclusion!!!")
387 | Some c -> term2pres c) in
388 P.Mtable ([None,"align","baseline 1";None,"equalrows","false";
389 None,"columnalign","left";
390 Some "helm", "xref", conclude.Con.conclude_id],
391 [P.Mtr ([],[P.Mtd ([],P.Mrow([],[
392 P.Mtext([None,"mathcolor","Red"],"rewrite");
393 P.Mspace([None,"width","0.1cm"]);term1;
394 P.Mspace([None,"width","0.1cm"]);
395 P.Mtext([None,"mathcolor","Red"],"with");
396 P.Mspace([None,"width","0.1cm"]);term2]))]);
397 P.Mtr ([],[P.Mtd ([],P.indented justif)]);
398 P.Mtr ([],[P.Mtd ([],make_concl "we proved" conclusion)])])
399 else if conclude.Con.conclude_method = "Apply" then
401 make_args_for_apply term2pres conclude.Con.conclude_args in
404 P.Mtext([None,"mathcolor","Red"],"by")::P.Mspace([None,"width","0.1cm"])::
405 P.Mo([],"(")::pres_args@[P.Mo([],")")]) in
406 match conclude.Con.conclude_conclusion with
407 None -> P.Mrow([],[P.Mtext([],"QUA");by])
409 let concl = (term2pres t) in
410 let ann_concl = make_concl "we proved" concl in
411 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
412 None,"columnalign","left";
413 Some "helm", "xref", conclude.Con.conclude_id],
414 [P.Mtr ([],[P.Mtd ([],by)]);
415 P.Mtr ([],[P.Mtd ([],ann_concl)])])
418 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"; Some "helm", "xref", conclude.Con.conclude_id],
419 [P.Mtr ([],[P.Mtd ([],P.Mtext([],"Apply method" ^ conclude.Con.conclude_method ^ " to"))]);
424 ([None,"align","baseline 1"; None,"equalrows","false";
425 None,"columnalign","left"],
426 args2pres conclude.Con.conclude_args))))])]) in
427 match conclude.Con.conclude_conclusion with
430 let concl = (term2pres t) in
431 let ann_concl = make_concl "we proved" concl in
432 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
433 None,"columnalign","left"],
434 [P.Mtr ([],[P.Mtd ([],body)]);
435 P.Mtr ([],[P.Mtd ([],ann_concl)])])
438 let module P = Mpresentation in
440 (function a -> P.Mtr ([], [P.Mtd ([], arg2pres a)])) l
443 let module P = Mpresentation in
444 let module Con = Content in
447 P.Mtext ([],"aux " ^ n)
448 | Con.Premise prem ->
449 P.Mtext ([],"premise")
457 P.Mtext ([],"method")
459 and byinduction conclude =
460 let module P = Mpresentation in
461 let module Con = Content in
462 let proof_conclusion =
463 (match conclude.Con.conclude_conclusion with
464 None -> P.Mtext([],"No conclusion???")
465 | Some t -> term2pres t) in
466 let inductive_arg,args_for_cases =
467 (match conclude.Con.conclude_args with
469 let l1,l2 = split (int_of_string n) tl in
470 let last_pos = (List.length l2)-1 in
471 List.nth l2 last_pos,l1
472 | _ -> assert false) in
475 (match inductive_arg with
477 P.Mtext ([],"an aux???")
478 | Con.Premise prem ->
479 (match prem.Con.premise_binder with
480 None -> P.Mtext ([],"the previous result")
481 | Some n -> P.Mi([],n))
482 | Con.Lemma lemma -> P.Mi([],lemma.Con.lemma_name)
486 P.Mtext ([],"a proof???")
488 P.Mtext ([],"a method???")) in
489 (make_concl "we proceede by induction on" arg) in
491 (make_concl "to prove" proof_conclusion) in
493 (make_concl "we proved" proof_conclusion) in
495 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
496 P.Mtr ([],[P.Mtd ([],induction_on)])::
497 P.Mtr ([],[P.Mtd ([],to_prove)])::
498 (make_cases args_for_cases) @
499 [P.Mtr ([],[P.Mtd ([],we_proved)])])
501 and make_cases args_for_cases =
502 let module P = Mpresentation in
504 (fun p -> P.Mtr ([],[P.Mtd ([],make_case p)])) args_for_cases
507 let module P = Mpresentation in
508 let module Con = Content in
512 (match p.Con.proof_name with
513 None -> P.Mtext([],"no name for case!!")
514 | Some n -> P.Mi([],n)) in
518 `Hypothesis h -> h.Con.dec_inductive
519 | _ -> false) p.Con.proof_context in
528 (match h.Con.dec_name with
531 [P.Mspace([None,"width","0.1cm"]);
534 (term2pres h.Con.dec_type)]
535 | _ -> [P.Mtext ([],"???")]) in
538 P.Mtr ([],[P.Mtd ([],P.Mrow([],
539 P.Mtext([],"Case")::P.Mspace([None,"width","0.1cm"])::name::pattern_aux@
540 [P.Mspace([None,"width","0.1cm"]);
541 P.Mtext([],"->")]))]) in
543 (match p.Con.proof_conclude.Con.conclude_conclusion with
544 None -> P.Mtext([],"No conclusion!!!")
545 | Some t -> term2pres t) in
548 P.indented (make_concl "the thesis becomes" subconcl))]) in
549 let induction_hypothesis =
554 P.Mtr([],[P.Mtd([], P.indented
555 (P.Mtext([],"by induction hypothesis we know:")))]) in
560 (match h.Con.dec_name with
563 P.indented (P.Mrow ([],
567 P.Mspace([None,"width","0.1cm"]);
568 term2pres h.Con.dec_type]))
569 | _ -> assert false in
572 (function ce -> P.Mtr ([], [P.Mtd ([], make_hyp ce)]))
576 acontext2pres_old p.Con.proof_apply_context true in *)
577 let body = conclude2pres p.Con.proof_conclude true in
579 P.Maction([None,"actiontype","toggle" ; None,"selection","1"],
580 [P.indented (P.Mtext([None,"mathcolor","Red"],"Proof"));
581 acontext2pres p.Con.proof_apply_context body true]) in
582 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
583 None,"columnalign","left"],
584 pattern::asubconcl::induction_hypothesis@
585 [P.Mtr([],[P.Mtd([],presacontext)])])
586 | _ -> assert false in
593 let content2pres term2pres (id,params,metasenv,obj) =
594 let module K = Content in
595 let module P = Mpresentation in
597 `Def (K.Const,thesis,`Proof p) ->
599 [None,"align","baseline 1";
600 None,"equalrows","false";
601 None,"columnalign","left";
602 None,"helm:xref","id"]
607 ("UNFINISHED PROOF" ^ id ^"(" ^
608 String.concat " ; " (List.map UriManager.string_of_uri params)^
613 [P.Mtext [] "THESIS:"])] ;
619 term2pres thesis])]] @
625 (* Conjectures are in their own table to make *)
626 (* diffing the DOM trees easier. *)
628 [None,"align","baseline 1";
629 None,"equalrows","false";
630 None,"columnalign","left"]
634 [P.Mtext [] "CONJECTURES:"])])::
648 | (_,Some (`Declaration d))
649 | (_,Some (`Hypothesis d)) ->
651 { K.dec_name = dec_name ;
652 K.dec_type = ty } = d
661 | (_,Some (`Definition d)) ->
663 { K.def_name = def_name ;
664 K.def_term = bo } = d
673 | (_,Some (`Proof p)) ->
674 let proof_name = p.K.proof_name in
677 (match proof_name with
681 proof2pres term2pres p]
684 [ P.Mi [] (string_of_int n) ;
695 [proof2pres term2pres p])]])
699 let content2pres ~ids_to_inner_sorts =
702 (Cexpr2pres.cexpr2pres_charcount
703 (Content_expressions.acic2cexpr ids_to_inner_sorts p)))