]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaProof.ml
snapshot
[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 ~uri ~typ =
27   object
28     inherit MatitaTypes.subject
29
30     val mutable _proof = (uri, [ 1, [], typ ], 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 to_xml =
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   end
63
64 class proof ~uri ~typ =
65   object
66     val mutable _status = new proofStatus ~uri ~typ
67     method status = _status
68     method setStatus s = _status <- s
69   end
70
71 class tacticCommand ~(tactic:ProofEngineTypes.tactic) (status: proofStatus) =
72   object
73     val statusBackup = status#status
74
75     method execute () =
76       let (new_proof, new_goals) = tactic status#status in
77       status#setProof new_proof;
78       status#setGoal
79         (match new_goals, new_proof with
80         | goal :: _, _ -> Some goal
81         | [], (_, (goal, _, _) :: _, _, _) ->
82             (* the tactic left no open goal: let's choose the first open goal *)
83             (* TODO CSC: here we could implement and use a proof-tree like
84              * notion... *)
85             Some goal
86         | _, _ -> None);
87       status#notify ()
88
89     method undo () =
90       status#setStatus statusBackup;
91       status#notify ()
92   end
93
94 let intros ?namer =
95   new tacticCommand
96     ~tactic:(PrimitiveTactics.intros_tac ?mk_fresh_name_callback:namer ())
97
98 let reflexivity = new tacticCommand ~tactic:EqualityTactics.reflexivity_tac
99 let symmetry =  new tacticCommand ~tactic:EqualityTactics.symmetry_tac
100 let transitivity term =
101   new tacticCommand ~tactic:(EqualityTactics.transitivity_tac ~term)
102
103 let exists = new tacticCommand ~tactic:IntroductionTactics.exists_tac
104 let split = new tacticCommand ~tactic:IntroductionTactics.split_tac
105 let left = new tacticCommand ~tactic:IntroductionTactics.left_tac
106 let right = new tacticCommand ~tactic:IntroductionTactics.right_tac
107
108 let assumption = new tacticCommand ~tactic:VariousTactics.assumption_tac
109