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 None,"selection","1"],
220 [(make_concl "proof of" ac);
222 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
223 None,"columnalign","left"],
224 [P.Mtr ([],[P.Mtd ([],P.Mfenced([],[P.Mtext ([],name)]))]);
225 P.Mtr ([],[P.Mtd ([], P.indented action)])])
227 and context2pres c continuation =
228 let module P = Mpresentation in
230 (fun ce continuation ->
231 P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
232 None,"columnalign","left"],
233 [P.Mtr([],[P.Mtd ([],ce2pres ce)]);
234 P.Mtr([],[P.Mtd ([], continuation)])])) c continuation
236 and context2pres_old c =
237 let module P = Mpresentation in
239 (function ce -> P.Mtr ([], [P.Mtd ([], ce2pres ce)])) c
242 let module P = Mpresentation in
243 let module Con = Content in
246 (match d.Con.dec_name with
248 let ty = term2pres d.Con.dec_type in
250 [P.Mtext([None,"mathcolor","Red"],"Assume");
251 P.Mspace([None,"width","0.1cm"]);
256 prerr_endline "NO NAME!!"; assert false)
258 (match h.Con.dec_name with
260 let ty = term2pres h.Con.dec_type in
262 [P.Mtext([None,"mathcolor","Red"],"Suppose");
263 P.Mspace([None,"width","0.1cm"]);
267 P.Mspace([None,"width","0.1cm"]);
270 prerr_endline "NO NAME!!"; assert false)
271 | `Proof p -> proof2pres p
273 (match d.Con.def_name with
275 let term = term2pres d.Con.def_term in
282 prerr_endline "NO NAME!!"; assert false)
284 P.Mtext ([],"jointdef")
286 and acontext2pres ac continuation indent =
287 let module P = Mpresentation in
289 (fun p continuation ->
292 P.indented (proof2pres p)
295 P.Mtable([None,"align","baseline 1"; None,"equalrows","false";
296 None,"columnalign","left"],
297 [P.Mtr([],[P.Mtd ([],hd)]);
298 P.Mtr([],[P.Mtd ([], continuation)])])) ac continuation
300 and acontext2pres_old ac indent =
301 let module P = Mpresentation in
305 P.Mtr ([], [P.Mtd ([], P.indented (proof2pres p))])
308 [P.Mtd ([], proof2pres p)])) ac
310 and conclude2pres conclude indent =
311 let module P = Mpresentation in
313 P.indented (conclude_aux conclude)
315 conclude_aux conclude
317 and conclude2pres_old conclude indent =
318 let module P = Mpresentation in
320 P.Mtr ([], [P.Mtd ([], P.indented (conclude_aux conclude))])
323 [P.Mtd ([], conclude_aux conclude)])
325 and conclude_aux conclude =
326 let module Con = Content in
327 let module P = Mpresentation in
328 if conclude.Con.conclude_method = "TD_Conversion" then
330 (match conclude.Con.conclude_conclusion with
331 None -> P.Mtext([],"NO EXPECTED!!!")
332 | Some c -> term2pres c) in
334 (match conclude.Con.conclude_args with
335 [Con.ArgProof p] -> p
336 | _ -> assert false) in
338 (match subproof.Con.proof_conclude.Con.conclude_conclusion with
339 None -> P.Mtext([],"NO SYNTH!!!")
340 | Some c -> (term2pres c)) in
342 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
343 [P.Mtr([],[P.Mtd([],make_concl "we must prove" expected)]);
344 P.Mtr([],[P.Mtd([],make_concl "or equivalently" synth)]);
345 P.Mtr([],[P.Mtd([],proof2pres subproof)])])
346 else if conclude.Con.conclude_method = "BU_Conversion" then
348 (match conclude.Con.conclude_conclusion with
349 None -> P.Mtext([],"NO Conclusion!!!")
350 | Some c -> term2pres c) in
351 make_concl "that is equivalent to" conclusion
352 else if conclude.Con.conclude_method = "Exact" then
354 (match conclude.Con.conclude_conclusion with
355 None -> P.Mtext([],"NO Conclusion!!!")
356 | Some c -> term2pres c) in
358 (match conclude.Con.conclude_args with
359 [Con.Term t] -> term2pres t
360 | _ -> assert false) in
362 [arg;P.Mspace([None,"width","0.1cm"]);P.Mtext([],"proves")] conclusion
363 else if conclude.Con.conclude_method = "Intros+LetTac" then
365 (match conclude.Con.conclude_conclusion with
366 None -> P.Mtext([],"NO Conclusion!!!")
367 | Some c -> term2pres c) in
368 (match conclude.Con.conclude_args with
371 ([None,"align","baseline 1"; None,"equalrows","false";
372 None,"columnalign","left"],
373 [P.Mtr([],[P.Mtd([],proof2pres p)]);
375 (make_concl "we proved *" conclusion))])]);
377 else if (conclude.Con.conclude_method = "ByInduction") then
379 else if (conclude.Con.conclude_method = "Rewrite") then
381 (match (List.nth conclude.Con.conclude_args 6) with
382 Con.ArgProof p -> justification term2pres p
383 | _ -> assert false) in
385 (match List.nth conclude.Con.conclude_args 2 with
386 Con.Term t -> term2pres t
387 | _ -> assert false) in
389 (match List.nth conclude.Con.conclude_args 5 with
390 Con.Term t -> term2pres t
391 | _ -> assert false) in
393 (match conclude.Con.conclude_conclusion with
394 None -> P.Mtext([],"NO Conclusion!!!")
395 | Some c -> term2pres c) in
396 P.Mtable ([None,"align","baseline 1";None,"equalrows","false";
397 None,"columnalign","left"],
398 [P.Mtr ([],[P.Mtd ([],P.Mrow([],[
399 P.Mtext([None,"mathcolor","Red"],"rewrite");
400 P.Mspace([None,"width","0.1cm"]);term1;
401 P.Mspace([None,"width","0.1cm"]);
402 P.Mtext([None,"mathcolor","Red"],"with");
403 P.Mspace([None,"width","0.1cm"]);term2]))]);
404 P.Mtr ([],[P.Mtd ([],P.indented justif)]);
405 P.Mtr ([],[P.Mtd ([],make_concl "we proved" conclusion)])])
406 else if conclude.Con.conclude_method = "Apply" then
408 make_args_for_apply term2pres conclude.Con.conclude_args in
411 P.Mtext([None,"mathcolor","Red"],"by")::P.Mspace([None,"width","0.1cm"])::
412 P.Mo([],"(")::pres_args@[P.Mo([],")")]) in
413 match conclude.Con.conclude_conclusion with
414 None -> P.Mrow([],[P.Mtext([],"QUA");by])
416 let concl = (term2pres t) in
417 let ann_concl = make_concl "we proved" concl in
418 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
419 None,"columnalign","left"],
420 [P.Mtr ([],[P.Mtd ([],by)]);
421 P.Mtr ([],[P.Mtd ([],ann_concl)])])
424 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
425 [P.Mtr ([],[P.Mtd ([],P.Mtext([],"Apply method" ^ conclude.Con.conclude_method ^ " to"))]);
430 ([None,"align","baseline 1"; None,"equalrows","false";
431 None,"columnalign","left"],
432 args2pres conclude.Con.conclude_args))))])]) in
433 match conclude.Con.conclude_conclusion with
436 let concl = (term2pres t) in
437 let ann_concl = make_concl "we proved" concl in
438 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
439 None,"columnalign","left"],
440 [P.Mtr ([],[P.Mtd ([],body)]);
441 P.Mtr ([],[P.Mtd ([],ann_concl)])])
444 let module P = Mpresentation in
446 (function a -> P.Mtr ([], [P.Mtd ([], arg2pres a)])) l
449 let module P = Mpresentation in
450 let module Con = Content in
453 P.Mtext ([],"aux " ^ n)
454 | Con.Premise prem ->
455 P.Mtext ([],"premise")
461 P.Mtext ([],"method")
463 and byinduction conclude =
464 let module P = Mpresentation in
465 let module Con = Content in
466 let proof_conclusion =
467 (match conclude.Con.conclude_conclusion with
468 None -> P.Mtext([],"No conclusion???")
469 | Some t -> term2pres t) in
470 let inductive_arg,args_for_cases =
471 (match conclude.Con.conclude_args with
473 let l1,l2 = split (int_of_string n) tl in
474 let last_pos = (List.length l2)-1 in
475 List.nth l2 last_pos,l1
476 | _ -> assert false) in
479 (match inductive_arg with
481 P.Mtext ([],"an aux???")
482 | Con.Premise prem ->
483 (match prem.Con.premise_binder with
484 None -> P.Mtext ([],"the previous result")
485 | Some n -> P.Mi([],n))
489 P.Mtext ([],"a proof???")
491 P.Mtext ([],"a method???")) in
492 (make_concl "we proceede by induction on" arg) in
494 (make_concl "to prove" proof_conclusion) in
496 (make_concl "we proved" proof_conclusion) in
498 ([None,"align","baseline 1"; None,"equalrows","false"; None,"columnalign","left"],
499 P.Mtr ([],[P.Mtd ([],induction_on)])::
500 P.Mtr ([],[P.Mtd ([],to_prove)])::
501 (make_cases args_for_cases) @
502 [P.Mtr ([],[P.Mtd ([],we_proved)])])
504 and make_cases args_for_cases =
505 let module P = Mpresentation in
507 (fun p -> P.Mtr ([],[P.Mtd ([],make_case p)])) args_for_cases
510 let module P = Mpresentation in
511 let module Con = Content in
515 (match p.Con.proof_name with
516 None -> P.Mtext([],"no name for case!!")
517 | Some n -> P.Mi([],n)) in
521 `Hypothesis h -> h.Con.dec_inductive
522 | _ -> false) p.Con.proof_context in
531 (match h.Con.dec_name with
534 [P.Mspace([None,"width","0.1cm"]);
537 (term2pres h.Con.dec_type)]
538 | _ -> [P.Mtext ([],"???")]) in
541 P.Mtr ([],[P.Mtd ([],P.Mrow([],
542 P.Mtext([],"Case")::P.Mspace([None,"width","0.1cm"])::name::pattern_aux@
543 [P.Mspace([None,"width","0.1cm"]);
544 P.Mtext([],"->")]))]) in
546 (match p.Con.proof_conclude.Con.conclude_conclusion with
547 None -> P.Mtext([],"No conclusion!!!")
548 | Some t -> term2pres t) in
551 make_concl "the thesis becomes" subconcl)]) in
552 let induction_hypothesis =
557 P.Mtr([],[P.Mtd([], P.indented
558 (P.Mtext([],"by induction hypothesis we know:")))]) in
563 (match h.Con.dec_name with
566 P.indented (P.Mrow ([],
570 P.Mspace([None,"width","0.1cm"]);
571 term2pres h.Con.dec_type]))
572 | _ -> assert false in
575 (function ce -> P.Mtr ([], [P.Mtd ([], make_hyp ce)]))
579 acontext2pres_old p.Con.proof_apply_context true in *)
580 let body = conclude2pres p.Con.proof_conclude true in
582 acontext2pres p.Con.proof_apply_context body true in
583 P.Mtable ([None,"align","baseline 1"; None,"equalrows","false";
584 None,"columnalign","left"],
585 pattern::asubconcl::induction_hypothesis@
586 [P.Mtr([],[P.Mtd([],presacontext)])])
587 | _ -> assert false in
594 let content2pres term2pres (id,params,metasenv,obj) =
595 let module K = Content in
596 let module P = Mpresentation in
598 `Def (K.Const,thesis,`Proof p) ->
600 [None,"align","baseline 1";
601 None,"equalrows","false";
602 None,"columnalign","left";
603 None,"helm:xref","id"]
608 ("UNFINISHED PROOF" ^ id ^"(" ^
609 String.concat " ; " (List.map UriManager.string_of_uri params)^
614 [P.Mtext [] "THESIS:"])] ;
620 term2pres thesis])]] @
626 (* Conjectures are in their own table to make *)
627 (* diffing the DOM trees easier. *)
629 [None,"align","baseline 1";
630 None,"equalrows","false";
631 None,"columnalign","left"]
635 [P.Mtext [] "CONJECTURES:"])])::
649 | (_,Some (`Declaration d))
650 | (_,Some (`Hypothesis d)) ->
652 { K.dec_name = dec_name ;
653 K.dec_type = ty } = d
662 | (_,Some (`Definition d)) ->
664 { K.def_name = def_name ;
665 K.def_term = bo } = d
674 | (_,Some (`Proof p)) ->
675 let proof_name = p.K.proof_name in
678 (match proof_name with
682 proof2pres term2pres p]
685 [ P.Mi [] (string_of_int n) ;
696 [proof2pres term2pres p])]])
700 let content2pres ~ids_to_inner_sorts =
703 (Cexpr2pres.cexpr2pres_charcount
704 (Content_expressions.acic2cexpr ids_to_inner_sorts p)))