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)
108 | Con.Term t -> countterm current_size t
109 | Con.ArgProof p -> countp current_size p
110 | Con.ArgMethod s -> (maxsize + 1)) in
111 let size = (countp 0 p) in
115 let is_big = is_big_general (Cexpr2pres.countterm)
118 let make_row items concl =
119 let module P = Mpresentation in
121 P.Mtable _ -> (* big! *)
122 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
123 None,"columnalign","left"],
124 [P.Mtr([],[P.Mtd ([],P.Mrow([],items))]);
125 P.Mtr ([],[P.Mtd ([],P.indented concl)])])
127 P.Mrow([],items@[P.Mspace([None,"width","0.1cm"]);concl]))
130 let make_concl verb concl =
131 let module P = Mpresentation in
133 P.Mtable _ -> (* big! *)
134 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
135 None,"columnalign","left"],
136 [P.Mtr([],[P.Mtd ([],P.Mtext([None,"mathcolor","Red"],verb))]);
137 P.Mtr ([],[P.Mtd ([],P.indented concl)])])
140 [P.Mtext([None,"mathcolor","Red"],verb);
141 P.Mspace([None,"width","0.1cm"]);
145 let make_args_for_apply term2pres args =
146 let module Con = Content in
147 let module P = Mpresentation in
148 let rec make_arg_for_apply is_first arg row =
150 Con.Aux n -> assert false
151 | Con.Premise prem ->
153 (match prem.Con.premise_binder with
160 else P.Mspace([None,"width","0.1cm"])::P.Mi([],"_")::row
163 P.Mspace([None,"width","0.1cm"])::P.Mi([],"_")::row) in
166 make_arg_for_apply true hd
167 (List.fold_right (make_arg_for_apply false) tl [])
168 | _ -> assert false;;
170 let rec justification term2pres p =
171 let module Con = Content in
172 let module P = Mpresentation in
173 if ((p.Con.proof_conclude.Con.conclude_method = "Exact") or
174 ((p.Con.proof_context = []) &
175 (p.Con.proof_apply_context = []) &
176 (p.Con.proof_conclude.Con.conclude_method = "Apply"))) then
178 make_args_for_apply term2pres p.Con.proof_conclude.Con.conclude_args in
180 P.Mtext([None,"mathcolor","Red"],"by")::P.Mspace([None,"width","0.1cm"])::
181 P.Mo([],"(")::pres_args@[P.Mo([],")")])
182 else proof2pres term2pres p
184 and proof2pres term2pres p =
185 let rec proof2pres p =
186 let module Con = Content in
187 let module P = Mpresentation in
192 | `Hypothesis _ -> true
194 ((List.filter is_decl p.Con.proof_context) != []) in
196 (match p.Con.proof_conclude.Con.conclude_conclusion with
198 | Some t -> Some (term2pres t)) in
200 let presconclude = conclude2pres p.Con.proof_conclude indent in
202 acontext2pres p.Con.proof_apply_context presconclude indent in
203 context2pres p.Con.proof_context presacontext in
205 P.Mtable ([("align","baseline 1");("equalrows","false");
206 ("columnalign","left")],
207 (context2pres_old p.Con.proof_context)@
208 (acontext2pres_old p.Con.proof_apply_context indent)@
209 [conclude2pres_old p.Con.proof_conclude indent]) in *)
210 match p.Con.proof_name with
215 None -> P.Mtext([],"NO PROOF!!!")
218 P.Maction([None,"actiontype","toggle"],
219 [(make_concl "proof of" ac);
221 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
222 None,"columnalign","left"],
223 [P.Mtr ([],[P.Mtd ([],P.Mfenced([],[P.Mtext ([],name)]))]);
224 P.Mtr ([],[P.Mtd ([], P.indented action)])])
226 and context2pres c continuation =
227 let module P = Mpresentation in
229 (fun ce continuation ->
230 P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
231 None,"columnalign","left"],
232 [P.Mtr([],[P.Mtd ([],ce2pres ce)]);
233 P.Mtr([],[P.Mtd ([], continuation)])])) c continuation
235 and context2pres_old c =
236 let module P = Mpresentation in
238 (function ce -> P.Mtr ([], [P.Mtd ([], ce2pres ce)])) c
241 let module P = Mpresentation in
242 let module Con = Content in
245 (match d.Con.dec_name with
247 let ty = term2pres d.Con.dec_type in
249 [P.Mtext([None,"mathcolor","Red"],"Assume");
250 P.Mspace([None,"width","0.1cm"]);
255 prerr_endline "NO NAME!!"; assert false)
257 (match h.Con.dec_name with
259 let ty = term2pres h.Con.dec_type in
261 [P.Mtext([None,"mathcolor","Red"],"Suppose");
262 P.Mspace([None,"width","0.1cm"]);
266 P.Mspace([None,"width","0.1cm"]);
269 prerr_endline "NO NAME!!"; assert false)
270 | `Proof p -> proof2pres p
272 (match d.Con.def_name with
274 let term = term2pres d.Con.def_term in
281 prerr_endline "NO NAME!!"; assert false)
283 P.Mtext ([],"jointdef")
285 and acontext2pres ac continuation indent =
286 let module P = Mpresentation in
288 (fun p continuation ->
291 P.indented (proof2pres p)
294 P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
295 None,"columnalign","left"],
296 [P.Mtr([],[P.Mtd ([],hd)]);
297 P.Mtr([],[P.Mtd ([], continuation)])])) ac continuation
299 and acontext2pres_old ac indent =
300 let module P = Mpresentation in
304 P.Mtr ([], [P.Mtd ([], P.indented (proof2pres p))])
307 [P.Mtd ([], proof2pres p)])) ac
309 and conclude2pres conclude indent =
310 let module P = Mpresentation in
312 P.indented (conclude_aux conclude)
314 conclude_aux conclude
316 and conclude2pres_old conclude indent =
317 let module P = Mpresentation in
319 P.Mtr ([], [P.Mtd ([], P.indented (conclude_aux conclude))])
322 [P.Mtd ([], conclude_aux conclude)])
324 and conclude_aux conclude =
325 let module Con = Content in
326 let module P = Mpresentation in
327 if conclude.Con.conclude_method = "TD_Conversion" then
329 (match conclude.Con.conclude_conclusion with
330 None -> P.Mtext([],"NO EXPECTED!!!")
331 | Some c -> term2pres c) in
333 (match conclude.Con.conclude_args with
334 [Con.ArgProof p] -> p
335 | _ -> assert false) in
337 (match subproof.Con.proof_conclude.Con.conclude_conclusion with
338 None -> P.Mtext([],"NO SYNTH!!!")
339 | Some c -> (term2pres c)) in
341 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
342 [P.Mtr([],[P.Mtd([],make_concl "we must prove" expected)]);
343 P.Mtr([],[P.Mtd([],make_concl "or equivalently" synth)]);
344 P.Mtr([],[P.Mtd([],proof2pres subproof)])])
345 else if conclude.Con.conclude_method = "BU_Conversion" then
347 (match conclude.Con.conclude_conclusion with
348 None -> P.Mtext([],"NO Conclusion!!!")
349 | Some c -> term2pres c) in
350 make_concl "that is equivalent to" conclusion
351 else if conclude.Con.conclude_method = "Exact" then
353 (match conclude.Con.conclude_conclusion with
354 None -> P.Mtext([],"NO Conclusion!!!")
355 | Some c -> term2pres c) in
357 (match conclude.Con.conclude_args with
358 [Con.Term t] -> term2pres t
359 | _ -> assert false) in
361 [arg;P.Mspace([None,"width","0.1cm"]);P.Mtext([],"proves")] conclusion
362 else if conclude.Con.conclude_method = "Intros+LetTac" then
364 (match conclude.Con.conclude_conclusion with
365 None -> P.Mtext([],"NO Conclusion!!!")
366 | Some c -> term2pres c) in
367 (match conclude.Con.conclude_args with
370 ([None,"align","baseline 1"; None,"equalrows","false";
371 None,"columnalign","left"],
372 [P.Mtr([],[P.Mtd([],proof2pres p)]);
374 (make_concl "we proved *" conclusion))])]);
376 else if (conclude.Con.conclude_method = "ByInduction") then
378 else if (conclude.Con.conclude_method = "Rewrite") then
380 (match (List.nth conclude.Con.conclude_args 6) with
381 Con.ArgProof p -> justification term2pres p
382 | _ -> assert false) in
384 (match List.nth conclude.Con.conclude_args 2 with
385 Con.Term t -> term2pres t
386 | _ -> assert false) in
388 (match List.nth conclude.Con.conclude_args 5 with
389 Con.Term t -> term2pres t
390 | _ -> assert false) in
392 (match conclude.Con.conclude_conclusion with
393 None -> P.Mtext([],"NO Conclusion!!!")
394 | Some c -> term2pres c) in
395 P.Mtable ([None,"align","baseline 1";None,"equalrows","false";
396 None,"columnalign","left"],
397 [P.Mtr ([],[P.Mtd ([],P.Mrow([],[
398 P.Mtext([None,"mathcolor","Red"],"rewrite");
399 P.Mspace([None,"width","0.1cm"]);term1;
400 P.Mspace([None,"width","0.1cm"]);
401 P.Mtext([None,"mathcolor","Red"],"with");
402 P.Mspace([None,"width","0.1cm"]);term2]))]);
403 P.Mtr ([],[P.Mtd ([],P.indented justif)]);
404 P.Mtr ([],[P.Mtd ([],make_concl "we proved" conclusion)])])
405 else if conclude.Con.conclude_method = "Apply" then
407 make_args_for_apply term2pres conclude.Con.conclude_args in
410 P.Mtext([None,"mathcolor","Red"],"by")::P.Mspace([None,"width","0.1cm"])::
411 P.Mo([],"(")::pres_args@[P.Mo([],")")]) in
412 match conclude.Con.conclude_conclusion with
413 None -> P.Mrow([],[P.Mtext([],"QUA");by])
415 let concl = (term2pres t) in
416 let ann_concl = make_concl "we proved" concl in
417 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
418 None,"columnalign","left"],
419 [P.Mtr ([],[P.Mtd ([],by)]);
420 P.Mtr ([],[P.Mtd ([],ann_concl)])])
423 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
424 [P.Mtr ([],[P.Mtd ([],P.Mtext([],"Apply method" ^ conclude.Con.conclude_method ^ " to"))]);
429 ([None,"align","baseline 1"; None,"equalrows","false";
430 None,"columnalign","left"],
431 args2pres conclude.Con.conclude_args))))])]) in
432 match conclude.Con.conclude_conclusion with
435 let concl = (term2pres t) in
436 let ann_concl = make_concl "we proved" concl in
437 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
438 None,"columnalign","left"],
439 [P.Mtr ([],[P.Mtd ([],body)]);
440 P.Mtr ([],[P.Mtd ([],ann_concl)])])
443 let module P = Mpresentation in
445 (function a -> P.Mtr ([], [P.Mtd ([], arg2pres a)])) l
448 let module P = Mpresentation in
449 let module Con = Content in
452 P.Mtext ([],"aux " ^ n)
453 | Con.Premise prem ->
454 P.Mtext ([],"premise")
460 P.Mtext ([],"method")
462 and byinduction conclude =
463 let module P = Mpresentation in
464 let module Con = Content in
465 let proof_conclusion =
466 (match conclude.Con.conclude_conclusion with
467 None -> P.Mtext([],"No conclusion???")
468 | Some t -> term2pres t) in
469 let inductive_arg,args_for_cases =
470 (match conclude.Con.conclude_args with
472 let l1,l2 = split (int_of_string n) tl in
473 let last_pos = (List.length l2)-1 in
474 List.nth l2 last_pos,l1
475 | _ -> assert false) in
478 (match inductive_arg with
480 P.Mtext ([],"an aux???")
481 | Con.Premise prem ->
482 (match prem.Con.premise_binder with
483 None -> P.Mtext ([],"the previous result")
484 | Some n -> P.Mi([],n))
488 P.Mtext ([],"a proof???")
490 P.Mtext ([],"a method???")) in
491 (make_concl "we proceede by induction on" arg) in
493 (make_concl "to prove" proof_conclusion) in
495 (make_concl "we proved" proof_conclusion) in
497 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
498 P.Mtr ([],[P.Mtd ([],induction_on)])::
499 P.Mtr ([],[P.Mtd ([],to_prove)])::
500 (make_cases args_for_cases) @
501 [P.Mtr ([],[P.Mtd ([],we_proved)])])
503 and make_cases args_for_cases =
504 let module P = Mpresentation in
506 (fun p -> P.Mtr ([],[P.Mtd ([],make_case p)])) args_for_cases
509 let module P = Mpresentation in
510 let module Con = Content in
514 (match p.Con.proof_name with
515 None -> P.Mtext([],"no name for case!!")
516 | Some n -> P.Mi([],n)) in
520 `Hypothesis h -> h.Con.dec_inductive
521 | _ -> false) p.Con.proof_context in
530 (match h.Con.dec_name with
533 [P.Mspace([None,"width","0.1cm"]);
536 (term2pres h.Con.dec_type)]
537 | _ -> [P.Mtext ([],"???")]) in
540 P.Mtr ([],[P.Mtd ([],P.Mrow([],
541 P.Mtext([],"Case")::P.Mspace([None,"width","0.1cm"])::name::pattern_aux@
542 [P.Mspace([None,"width","0.1cm"]);
543 P.Mtext([],"->")]))]) in
545 (match p.Con.proof_conclude.Con.conclude_conclusion with
546 None -> P.Mtext([],"No conclusion!!!")
547 | Some t -> term2pres t) in
550 make_concl "the thesis becomes" subconcl)]) in
551 let induction_hypothesis =
556 P.Mtr([],[P.Mtd([], P.indented
557 (P.Mtext([],"by induction hypothesis we know:")))]) in
562 (match h.Con.dec_name with
565 P.indented (P.Mrow ([],
569 P.Mspace([None,"width","0.1cm"]);
570 term2pres h.Con.dec_type]))
571 | _ -> assert false in
574 (function ce -> P.Mtr ([], [P.Mtd ([], make_hyp ce)]))
578 acontext2pres_old p.Con.proof_apply_context true in *)
579 let body = conclude2pres p.Con.proof_conclude true in
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])]] @
626 [P.Mtext [] "CONJECTURES:"])]) ::
640 | (_,Some (`Declaration d))
641 | (_,Some (`Hypothesis d)) ->
643 { K.dec_name = dec_name ;
644 K.dec_type = ty } = d
653 | (_,Some (`Definition d)) ->
655 { K.def_name = def_name ;
656 K.def_term = bo } = d
665 | (_,Some (`Proof p)) ->
666 let proof_name = p.K.proof_name in
669 (match proof_name with
673 proof2pres term2pres p]
676 [ P.Mi [] (string_of_int n) ;
686 [proof2pres term2pres p])]])
690 let content2pres ~ids_to_inner_sorts =
693 (Cexpr2pres.cexpr2pres_charcount
694 (Content_expressions.acic2cexpr ids_to_inner_sorts p)))