]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaProof.ml
first moogle template checkin
[helm.git] / helm / matita / matitaProof.ml
1 (* Copyright (C) 2004, 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://helm.cs.unibo.it/
24  *)
25
26 class proofStatus ~typ ~metasenv ~uri () =
27   object (self)
28     inherit MatitaTypes.subject
29
30     val mutable _proof = (uri, (1, [], typ) :: metasenv, Cic.Meta (1, []), typ)
31     val mutable _goal = Some 1
32
33     method proof = _proof
34     method setProof p = _proof <- p
35     method goal = _goal
36     method setGoal g = _goal <- g
37     method status =
38       _proof,
39       (match _goal with Some g -> g | None -> raise MatitaTypes.No_proof)
40     method setStatus (p, g) =
41       _proof <- p;
42       _goal <- Some g
43
44     method toXml =
45       let (uri, metasenv, bo, ty) = _proof in
46       let currentproof =
47         (* TODO CSC: Wrong: [] is just plainly wrong *)
48         Cic.CurrentProof (UriManager.name_of_uri uri,metasenv, bo, ty, [])
49       in
50       let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
51         Cic2acic.acic_object_of_cic_object ~eta_fix:false currentproof
52       in
53       let xml, bodyxml =
54         match Cic2Xml.print_object uri ~ids_to_inner_sorts
55           ~ask_dtd_to_the_getter:true acurrentproof
56         with
57         | xml, Some bodyxml -> xml, bodyxml
58         | _, None -> assert false
59       in
60       (xml, bodyxml)
61
62     method toString =
63       let (xml, bodyxml) = self#toXml in
64       let buf = Buffer.create 10240 in
65       Buffer.add_string buf "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
66       Buffer.add_string buf "<!DOCTYPE ConstantType SYSTEM \"http://mowgli.cs.unibo.it:58081/getdtd?uri=cic.dtd\">\n";
67       Buffer.add_string buf "<ProofStatus>\n";
68       Buffer.add_string buf (Misc.strip_xml_headings (Xml.pp_to_string xml));
69       Buffer.add_string buf (Misc.strip_xml_headings(Xml.pp_to_string bodyxml));
70       Buffer.add_string buf
71         (match _goal with
72         | None -> "<CurrentGoal />"
73         | Some goal -> Printf.sprintf "<CurrentGoal>%d</CurrentGoal>" goal);
74       Buffer.add_string buf "\n</ProofStatus>";
75       Buffer.contents buf
76
77   end
78
79 let proofStatus ~typ ?(metasenv = []) ?(uri = MatitaTypes.untitled_con_uri) () =
80   new proofStatus ~typ ~metasenv ~uri ()
81
82 let proofStatus_of_string s =
83   MatitaTypes.not_implemented "MatitaProof.proofStatus_of_string"
84
85 class proof ~typ ?metasenv ?uri () =
86   object
87     val mutable _status = proofStatus ~typ ?metasenv ?uri ()
88     method status = _status
89     method setStatus s = _status <- s
90   end
91
92 let proof = new proof
93
94 class tacticCommand ~(tactic:ProofEngineTypes.tactic) (status: proofStatus) =
95   object
96     val statusBackup = status#status
97
98     method execute () =
99       let (new_proof, new_goals) = tactic status#status in
100       status#setProof new_proof;
101       status#setGoal
102         (match new_goals, new_proof with
103         | goal :: _, _ -> Some goal
104         | [], (_, (goal, _, _) :: _, _, _) ->
105             (* the tactic left no open goal: let's choose the first open goal *)
106             (* TODO CSC: here we could implement and use a proof-tree like
107              * notion... *)
108             Some goal
109         | _, _ -> None);
110       status#notify ()
111
112     method undo () =
113       status#setStatus statusBackup;
114       status#notify ()
115   end
116
117 let intros ?namer =
118   new tacticCommand
119     ~tactic:(PrimitiveTactics.intros_tac ?mk_fresh_name_callback:namer ())
120
121 let reflexivity = new tacticCommand ~tactic:EqualityTactics.reflexivity_tac
122 let symmetry =  new tacticCommand ~tactic:EqualityTactics.symmetry_tac
123 let transitivity term =
124   new tacticCommand ~tactic:(EqualityTactics.transitivity_tac ~term)
125
126 let exists = new tacticCommand ~tactic:IntroductionTactics.exists_tac
127 let split = new tacticCommand ~tactic:IntroductionTactics.split_tac
128 let left = new tacticCommand ~tactic:IntroductionTactics.left_tac
129 let right = new tacticCommand ~tactic:IntroductionTactics.right_tac
130
131 let assumption = new tacticCommand ~tactic:VariousTactics.assumption_tac
132