1 (* Copyright (C) 2005, 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://helm.cs.unibo.it/
28 module PEH = ProofEngineHelpers
31 (* mo file name, ma file name *)
32 exception IncludedFileNotCompiled of string * string
35 (Cic.context -> GrafiteTypes.status * (Cic.term,Cic.lazy_term) GrafiteAst.macro)
36 exception NMacro of GrafiteAst.loc * GrafiteAst.nmacro
38 type 'a disambiguator_input = string * int * 'a
41 do_heavy_checks: bool ;
44 let concat_nuris uris nuris =
46 | `New uris, `New nuris -> `New (nuris@uris)
49 (** create a ProofEngineTypes.mk_fresh_name_type function which uses given
50 * names as long as they are available, then it fallbacks to name generation
51 * using FreshNamesGenerator module *)
53 let len = List.length names in
55 fun metasenv context name ~typ ->
56 if !count < len then begin
57 let name = match List.nth names !count with
58 | Some s -> Cic.Name s
59 | None -> Cic.Anonymous
64 FreshNamesGenerator.mk_fresh_name ~subst:[] metasenv context name ~typ
66 let rec tactic_of_ast status ast =
67 let module PET = ProofEngineTypes in
69 (* Higher order tactics *)
70 | GrafiteAst.Do (loc, n, tactic) ->
71 Tacticals.do_tactic n (tactic_of_ast status tactic)
72 | GrafiteAst.Seq (loc, tactics) -> (* tac1; tac2; ... *)
73 Tacticals.seq (List.map (tactic_of_ast status) tactics)
74 | GrafiteAst.Repeat (loc, tactic) ->
75 Tacticals.repeat_tactic (tactic_of_ast status tactic)
76 | GrafiteAst.Then (loc, tactic, tactics) -> (* tac; [ tac1 | ... ] *)
78 (tactic_of_ast status tactic)
79 (List.map (tactic_of_ast status) tactics)
80 | GrafiteAst.First (loc, tactics) ->
81 Tacticals.first (List.map (tactic_of_ast status) tactics)
82 | GrafiteAst.Try (loc, tactic) ->
83 Tacticals.try_tactic (tactic_of_ast status tactic)
84 | GrafiteAst.Solve (loc, tactics) ->
85 Tacticals.solve_tactics (List.map (tactic_of_ast status) tactics)
86 | GrafiteAst.Progress (loc, tactic) ->
87 Tacticals.progress_tactic (tactic_of_ast status tactic)
88 (* First order tactics *)
89 | GrafiteAst.Absurd (_, term) -> Tactics.absurd term
90 | GrafiteAst.Apply (_, term) -> Tactics.apply term
91 | GrafiteAst.ApplyRule (_, term) -> Tactics.apply term
92 | GrafiteAst.ApplyP (_, term) -> Tactics.applyP term
93 | GrafiteAst.ApplyS (_, term, params) ->
94 Tactics.applyS ~term ~params ~dbd:(LibraryDb.instance ())
95 ~automation_cache:status#automation_cache
96 | GrafiteAst.Assumption _ -> Tactics.assumption
97 | GrafiteAst.AutoBatch (_,params) ->
98 Tactics.auto ~params ~dbd:(LibraryDb.instance ())
99 ~automation_cache:status#automation_cache
100 | GrafiteAst.Cases (_, what, pattern, (howmany, names)) ->
101 Tactics.cases_intros ?howmany ~mk_fresh_name_callback:(namer_of names)
103 | GrafiteAst.Change (_, pattern, with_what) ->
104 Tactics.change ~pattern with_what
105 | GrafiteAst.Clear (_,id) -> Tactics.clear id
106 | GrafiteAst.ClearBody (_,id) -> Tactics.clearbody id
107 | GrafiteAst.Compose (_,t1,t2,times,(howmany, names)) ->
108 Tactics.compose times t1 t2 ?howmany
109 ~mk_fresh_name_callback:(namer_of names)
110 | GrafiteAst.Contradiction _ -> Tactics.contradiction
111 | GrafiteAst.Constructor (_, n) -> Tactics.constructor n
112 | GrafiteAst.Cut (_, ident, term) ->
113 let names = match ident with None -> [] | Some id -> [Some id] in
114 Tactics.cut ~mk_fresh_name_callback:(namer_of names) term
115 | GrafiteAst.Decompose (_, names) ->
116 let mk_fresh_name_callback = namer_of names in
117 Tactics.decompose ~mk_fresh_name_callback ()
118 | GrafiteAst.Demodulate (_, params) ->
120 ~dbd:(LibraryDb.instance ()) ~params
121 ~automation_cache:status#automation_cache
122 | GrafiteAst.Destruct (_,xterms) -> Tactics.destruct xterms
123 | GrafiteAst.Elim (_, what, using, pattern, (depth, names)) ->
124 Tactics.elim_intros ?using ?depth ~mk_fresh_name_callback:(namer_of names)
126 | GrafiteAst.ElimType (_, what, using, (depth, names)) ->
127 Tactics.elim_type ?using ?depth ~mk_fresh_name_callback:(namer_of names)
129 | GrafiteAst.Exact (_, term) -> Tactics.exact term
130 | GrafiteAst.Exists _ -> Tactics.exists
131 | GrafiteAst.Fail _ -> Tactics.fail
132 | GrafiteAst.Fold (_, reduction_kind, term, pattern) ->
134 match reduction_kind with
136 PET.const_lazy_reduction
137 (CicReduction.normalize ~delta:false ~subst:[])
138 | `Simpl -> PET.const_lazy_reduction ProofEngineReduction.simpl
140 PET.const_lazy_reduction (ProofEngineReduction.unfold ?what:None)
141 | `Unfold (Some lazy_term) ->
142 (fun context metasenv ugraph ->
143 let what, metasenv, ugraph = lazy_term context metasenv ugraph in
144 ProofEngineReduction.unfold ~what, metasenv, ugraph)
146 PET.const_lazy_reduction (CicReduction.whd ~delta:false ~subst:[])
148 Tactics.fold ~reduction ~term ~pattern
149 | GrafiteAst.Fourier _ -> Tactics.fourier
150 | GrafiteAst.FwdSimpl (_, hyp, names) ->
151 Tactics.fwd_simpl ~mk_fresh_name_callback:(namer_of names)
152 ~dbd:(LibraryDb.instance ()) hyp
153 | GrafiteAst.Generalize (_,pattern,ident) ->
154 let names = match ident with None -> [] | Some id -> [Some id] in
155 Tactics.generalize ~mk_fresh_name_callback:(namer_of names) pattern
156 | GrafiteAst.IdTac _ -> Tactics.id
157 | GrafiteAst.Intros (_, (howmany, names)) ->
158 PrimitiveTactics.intros_tac ?howmany
159 ~mk_fresh_name_callback:(namer_of names) ()
160 | GrafiteAst.Inversion (_, term) ->
161 Tactics.inversion term
162 | GrafiteAst.LApply (_, linear, how_many, to_what, what, ident) ->
163 let names = match ident with None -> [] | Some id -> [Some id] in
164 Tactics.lapply ~mk_fresh_name_callback:(namer_of names)
165 ~linear ?how_many ~to_what what
166 | GrafiteAst.Left _ -> Tactics.left
167 | GrafiteAst.LetIn (loc,term,name) ->
168 Tactics.letin term ~mk_fresh_name_callback:(namer_of [Some name])
169 | GrafiteAst.Reduce (_, reduction_kind, pattern) ->
170 (match reduction_kind with
171 | `Normalize -> Tactics.normalize ~pattern
172 | `Simpl -> Tactics.simpl ~pattern
173 | `Unfold what -> Tactics.unfold ~pattern what
174 | `Whd -> Tactics.whd ~pattern)
175 | GrafiteAst.Reflexivity _ -> Tactics.reflexivity
176 | GrafiteAst.Replace (_, pattern, with_what) ->
177 Tactics.replace ~pattern ~with_what
178 | GrafiteAst.Rewrite (_, direction, t, pattern, names) ->
179 EqualityTactics.rewrite_tac ~direction ~pattern t
180 (* to be replaced with ~mk_fresh_name_callback:(namer_of names) *)
181 (List.map (function Some s -> s | None -> assert false) names)
182 | GrafiteAst.Right _ -> Tactics.right
183 | GrafiteAst.Ring _ -> Tactics.ring
184 | GrafiteAst.Split _ -> Tactics.split
185 | GrafiteAst.Symmetry _ -> Tactics.symmetry
186 | GrafiteAst.Transitivity (_, term) -> Tactics.transitivity term
187 (* Implementazioni Aggiunte *)
188 | GrafiteAst.Assume (_, id, t) -> Declarative.assume id t
189 | GrafiteAst.Suppose (_, t, id, t1) -> Declarative.suppose t id t1
190 | GrafiteAst.By_just_we_proved (_, just, ty, id, t1) ->
191 Declarative.by_just_we_proved ~dbd:(LibraryDb.instance())
192 ~automation_cache:status#automation_cache just ty id t1
193 | GrafiteAst.We_need_to_prove (_, t, id, t2) ->
194 Declarative.we_need_to_prove t id t2
195 | GrafiteAst.Bydone (_, t) ->
196 Declarative.bydone ~dbd:(LibraryDb.instance())
197 ~automation_cache:status#automation_cache t
198 | GrafiteAst.We_proceed_by_cases_on (_, t, t1) ->
199 Declarative.we_proceed_by_cases_on t t1
200 | GrafiteAst.We_proceed_by_induction_on (_, t, t1) ->
201 Declarative.we_proceed_by_induction_on t t1
202 | GrafiteAst.Byinduction (_, t, id) -> Declarative.byinduction t id
203 | GrafiteAst.Thesisbecomes (_, t) -> Declarative.thesisbecomes t
204 | GrafiteAst.ExistsElim (_, just, id1, t1, id2, t2) ->
205 Declarative.existselim ~dbd:(LibraryDb.instance())
206 ~automation_cache:status#automation_cache just id1 t1 id2 t2
207 | GrafiteAst.Case (_,id,params) -> Declarative.case id params
208 | GrafiteAst.AndElim(_,just,id1,t1,id2,t2) ->
209 Declarative.andelim ~dbd:(LibraryDb.instance ())
210 ~automation_cache:status#automation_cache just id1 t1 id2 t2
211 | GrafiteAst.RewritingStep (_,termine,t1,t2,cont) ->
212 Declarative.rewritingstep ~dbd:(LibraryDb.instance ())
213 ~automation_cache:status#automation_cache termine t1 t2 cont
215 let classify_tactic tactic =
217 (* tactics that can't close the goal (return a goal we want to "select") *)
218 | GrafiteAst.Rewrite _
220 | GrafiteAst.Replace _
221 | GrafiteAst.Reduce _
223 | GrafiteAst.Generalize _
226 | GrafiteAst.Decompose _ -> true
227 (* tactics like apply *)
230 let reorder_metasenv start refine tactic goals current_goal always_opens_a_goal=
231 (* let print_m name metasenv =
232 prerr_endline (">>>>> " ^ name);
233 prerr_endline (CicMetaSubst.ppmetasenv [] metasenv)
235 (* phase one calculates:
236 * new_goals_from_refine: goals added by refine
237 * head_goal: the first goal opened by ythe tactic
238 * other_goals: other goals opened by the tactic
240 let new_goals_from_refine = PEH.compare_metasenvs start refine in
241 let new_goals_from_tactic = PEH.compare_metasenvs refine tactic in
242 let head_goal, other_goals, goals =
244 | [] -> None,[],goals
246 (* assert (List.mem hd new_goals_from_tactic);
247 * invalidato dalla goal_tac
249 Some hd, List.filter ((<>) hd) new_goals_from_tactic, List.filter ((<>)
254 | None -> new_goals_from_refine @ other_goals
255 | Some x -> x :: new_goals_from_refine @ other_goals
257 (* extract the metas generated by refine and tactic *)
258 let metas_for_tactic_head =
261 | Some head_goal -> List.filter (fun (n,_,_) -> n = head_goal) tactic in
262 let metas_for_tactic_goals =
264 (fun x -> List.find (fun (metano,_,_) -> metano = x) tactic)
267 let metas_for_refine_goals =
268 List.filter (fun (n,_,_) -> List.mem n new_goals_from_refine) tactic in
269 let produced_metas, goals =
271 if always_opens_a_goal then
272 metas_for_tactic_head @ metas_for_refine_goals @
273 metas_for_tactic_goals
275 (* print_m "metas_for_refine_goals" metas_for_refine_goals;
276 print_m "metas_for_tactic_head" metas_for_tactic_head;
277 print_m "metas_for_tactic_goals" metas_for_tactic_goals; *)
278 metas_for_refine_goals @ metas_for_tactic_head @
279 metas_for_tactic_goals
282 let goals = List.map (fun (metano, _, _) -> metano) produced_metas in
283 produced_metas, goals
285 (* residual metas, preserving the original order *)
290 | (metano, _, _) :: tl when metano = e ->
291 [], List.map (fun (x,_,_) -> x) tl
292 | (metano, _, _) :: tl -> let b, a = split e tl in metano :: b, a
294 let find n metasenv =
296 Some (List.find (fun (metano, _, _) -> metano = n) metasenv)
297 with Not_found -> None
302 match find n tactic with
306 let before_l, after_l = split current_goal start in
308 List.filter (fun x -> not (List.mem x produced_goals)) before_l in
310 List.filter (fun x -> not (List.mem x produced_goals)) after_l in
311 let before = extract before_l in
312 let after = extract after_l in
316 print_m "BEGIN" start;
317 prerr_endline ("goal was: " ^ string_of_int current_goal);
318 prerr_endline ("and metas from refine are:");
320 (fun t -> prerr_string (" " ^ string_of_int t))
321 new_goals_from_refine;
323 print_m "before" before;
324 print_m "metas_for_tactic_head" metas_for_tactic_head;
325 print_m "metas_for_refine_goals" metas_for_refine_goals;
326 print_m "metas_for_tactic_goals" metas_for_tactic_goals;
327 print_m "produced_metas" produced_metas;
328 print_m "after" after;
329 |+ FINE DEBUG CODE +| *)
330 before @ produced_metas @ after, goals
332 let apply_tactic ~disambiguate_tactic (text,prefix_len,tactic) (status, goal) =
333 let starting_metasenv = GrafiteTypes.get_proof_metasenv status in
334 let before = List.map (fun g, _, _ -> g) starting_metasenv in
335 let status, tactic = disambiguate_tactic status goal (text,prefix_len,tactic) in
336 let metasenv_after_refinement = GrafiteTypes.get_proof_metasenv status in
337 let proof = GrafiteTypes.get_current_proof status in
338 let proof_status = proof, goal in
339 let always_opens_a_goal = classify_tactic tactic in
340 let tactic = tactic_of_ast status tactic in
341 let (proof, opened) = ProofEngineTypes.apply_tactic tactic proof_status in
342 let after = ProofEngineTypes.goals_of_proof proof in
343 let opened_goals, closed_goals = Tacticals.goals_diff ~before ~after ~opened in
344 let proof, opened_goals =
345 let uri, metasenv_after_tactic, subst, t, ty, attrs = proof in
346 let reordered_metasenv, opened_goals =
349 metasenv_after_refinement metasenv_after_tactic
350 opened goal always_opens_a_goal
352 let proof' = uri, reordered_metasenv, [], t, ty, attrs in
355 let incomplete_proof =
356 match status#proof_status with
357 | GrafiteTypes.Incomplete_proof p -> p
360 status#set_proof_status
361 (GrafiteTypes.Incomplete_proof
362 { incomplete_proof with GrafiteTypes.proof = proof }),
363 opened_goals, closed_goals
365 let apply_atomic_tactical ~disambiguate_tactic ~patch (text,prefix_len,tactic) (status, goal) =
366 let starting_metasenv = GrafiteTypes.get_proof_metasenv status in
367 let before = List.map (fun g, _, _ -> g) starting_metasenv in
368 let status, tactic = disambiguate_tactic status goal (text,prefix_len,tactic) in
369 let metasenv_after_refinement = GrafiteTypes.get_proof_metasenv status in
370 let proof = GrafiteTypes.get_current_proof status in
371 let proof_status = proof, goal in
372 let always_opens_a_goal = classify_tactic tactic in
373 let tactic = tactic_of_ast status tactic in
374 let tactic = patch tactic in
375 let (proof, opened) = ProofEngineTypes.apply_tactic tactic proof_status in
376 let after = ProofEngineTypes.goals_of_proof proof in
377 let opened_goals, closed_goals = Tacticals.goals_diff ~before ~after ~opened in
378 let proof, opened_goals =
379 let uri, metasenv_after_tactic, _subst, t, ty, attrs = proof in
380 let reordered_metasenv, opened_goals =
383 metasenv_after_refinement metasenv_after_tactic
384 opened goal always_opens_a_goal
386 let proof' = uri, reordered_metasenv, _subst, t, ty, attrs in
389 let incomplete_proof =
390 match status#proof_status with
391 | GrafiteTypes.Incomplete_proof p -> p
394 status#set_proof_status
395 (GrafiteTypes.Incomplete_proof
396 { incomplete_proof with GrafiteTypes.proof = proof }),
397 opened_goals, closed_goals
400 'term 'lazy_term 'reduction 'obj 'ident.
402 (GrafiteTypes.status ->
403 ProofEngineTypes.goal ->
404 (('term, 'lazy_term, 'reduction, 'ident) GrafiteAst.tactic)
405 disambiguator_input ->
406 GrafiteTypes.status *
407 (Cic.term, Cic.lazy_term, Cic.lazy_term GrafiteAst.reduction, string) GrafiteAst.tactic) ->
409 disambiguate_command:
410 (GrafiteTypes.status ->
411 (('term,'obj) GrafiteAst.command) disambiguator_input ->
412 GrafiteTypes.status * (Cic.term,Cic.obj) GrafiteAst.command) ->
415 (GrafiteTypes.status ->
416 (('term,'lazy_term) GrafiteAst.macro) disambiguator_input ->
417 Cic.context -> GrafiteTypes.status * (Cic.term,Cic.lazy_term) GrafiteAst.macro) ->
419 ?do_heavy_checks:bool ->
420 GrafiteTypes.status ->
421 (('term, 'lazy_term, 'reduction, 'obj, 'ident) GrafiteAst.statement)
422 disambiguator_input ->
423 GrafiteTypes.status * [`Old of UriManager.uri list | `New of NUri.uri list]
426 type 'a eval_command =
428 disambiguate_command:
429 (GrafiteTypes.status -> (('term,'obj) GrafiteAst.command) disambiguator_input ->
430 GrafiteTypes.status * (Cic.term,Cic.obj) GrafiteAst.command) ->
431 options -> GrafiteTypes.status ->
432 (('term,'obj) GrafiteAst.command) disambiguator_input ->
433 GrafiteTypes.status * [`Old of UriManager.uri list | `New of NUri.uri list]
436 type 'a eval_comment =
437 {ecm_go: 'term 'lazy_term 'reduction_kind 'obj 'ident.
438 disambiguate_command:
439 (GrafiteTypes.status -> (('term,'obj) GrafiteAst.command) disambiguator_input ->
440 GrafiteTypes.status * (Cic.term,Cic.obj) GrafiteAst.command) ->
441 options -> GrafiteTypes.status ->
442 (('term,'lazy_term,'reduction_kind,'obj,'ident) GrafiteAst.comment) disambiguator_input ->
443 GrafiteTypes.status * [`Old of UriManager.uri list | `New of NUri.uri list]
446 type 'a eval_executable =
447 {ee_go: 'term 'lazy_term 'reduction 'obj 'ident.
449 (GrafiteTypes.status ->
450 ProofEngineTypes.goal ->
451 (('term, 'lazy_term, 'reduction, 'ident) GrafiteAst.tactic)
452 disambiguator_input ->
453 GrafiteTypes.status *
454 (Cic.term, Cic.lazy_term, Cic.lazy_term GrafiteAst.reduction, string) GrafiteAst.tactic) ->
456 disambiguate_command:
457 (GrafiteTypes.status ->
458 (('term,'obj) GrafiteAst.command) disambiguator_input ->
459 GrafiteTypes.status * (Cic.term,Cic.obj) GrafiteAst.command) ->
462 (GrafiteTypes.status ->
463 (('term,'lazy_term) GrafiteAst.macro) disambiguator_input ->
464 Cic.context -> GrafiteTypes.status * (Cic.term,Cic.lazy_term) GrafiteAst.macro) ->
467 GrafiteTypes.status ->
468 (('term, 'lazy_term, 'reduction, 'obj, 'ident) GrafiteAst.code) disambiguator_input ->
469 GrafiteTypes.status * [`Old of UriManager.uri list | `New of NUri.uri list]
472 type 'a eval_from_moo =
473 { efm_go: GrafiteTypes.status -> string -> GrafiteTypes.status }
475 let coercion_moo_statement_of (uri,arity, saturations,_) =
477 (HExtlib.dummy_floc, CicUtil.term_of_uri uri, false, arity, saturations)
479 let basic_eval_unification_hint (t,n) status =
480 NCicUnifHint.add_user_provided_hint status t n
483 let inject_unification_hint =
484 let basic_eval_unification_hint (t,n)
485 ~refresh_uri_in_universe
488 let t = refresh_uri_in_term t in basic_eval_unification_hint (t,n)
490 NCicLibrary.Serializer.register#run "unification_hints"
491 object(_ : 'a NCicLibrary.register_type)
492 method run = basic_eval_unification_hint
496 let eval_unification_hint status t n =
497 let metasenv,subst,status,t =
498 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] ("",0,t) in
499 assert (metasenv=[]);
500 let t = NCicUntrusted.apply_subst subst [] t in
501 let status = basic_eval_unification_hint (t,n) status in
502 let dump = inject_unification_hint (t,n)::status#dump in
503 let status = status#set_dump dump in
507 let basic_index_obj l status =
508 status#set_auto_cache
511 List.fold_left (fun t k ->
512 NDiscriminationTree.DiscriminationTree.index t k v)
517 let record_index_obj =
519 ~refresh_uri_in_universe
524 (fun ks,v -> List.map refresh_uri_in_term ks, refresh_uri_in_term v)
527 NCicLibrary.Serializer.register#run "index_obj"
528 object(_ : 'a NCicLibrary.register_type)
533 let compute_keys uri height kind =
534 let mk_item orig_ty spec =
535 let ty,_,_ = NCicMetaSubst.saturate ~delta:max_int [] [] [] orig_ty 0 in
538 | NCic.Const (NReference.Ref (_,NReference.Def h))
539 | NCic.Appl (NCic.Const (NReference.Ref (_,NReference.Def h))::_)
542 NCicMetaSubst.saturate ~delta:(h-1) [] [] [] orig_ty 0 in
546 keys,NCic.Const(NReference.reference_of_spec uri spec)
550 | NCic.Fixpoint (ind,ifl,_) ->
552 (fun (_,_,rno,ty,_) i ->
553 if ind then mk_item ty (NReference.Fix (i,rno,height))
554 else mk_item ty (NReference.CoFix height)) ifl
555 | NCic.Inductive (b,lno,itl,_) ->
557 (fun (_,_,ty,_) i -> mk_item ty (NReference.Ind (b,i,lno))) itl
560 (fun ((_,_,ty),i,j) ->
561 mk_item ty (NReference.Con (i,j+1,lno)))
564 (fun (_,_,_,cl) i -> HExtlib.list_mapi (fun x j-> x,i,j) cl)
566 | NCic.Constant (_,_,Some _, ty, _) ->
567 [ mk_item ty (NReference.Def height) ]
568 | NCic.Constant (_,_,None, ty, _) ->
569 [ mk_item ty NReference.Decl ]
571 let data = HExtlib.filter_map
573 let keys = List.filter
576 | (NCic.Appl (NCic.Meta _::_)) -> false
582 HLog.debug ("Indexing:" ^
583 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
584 HLog.debug ("With keys:" ^ String.concat "\n" (List.map (fun t ->
585 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t) keys));
590 HLog.debug ("Not indexing:" ^
591 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
598 let index_obj_for_auto status (uri, height, _, _, kind) =
599 (*prerr_endline (string_of_int height);*)
600 let data = compute_keys uri height kind in
601 let status = basic_index_obj data status in
602 let dump = record_index_obj data :: status#dump in
606 let index_eq uri status =
607 let eq_status = status#eq_cache in
608 let eq_status1 = NCicParamod.index_obj eq_status uri in
609 status#set_eq_cache eq_status1
612 let record_index_eq =
613 let basic_index_eq uri
614 ~refresh_uri_in_universe
616 = index_eq (NCicLibrary.refresh_uri uri)
618 NCicLibrary.Serializer.register#run "index_eq"
619 object(_ : 'a NCicLibrary.register_type)
620 method run = basic_index_eq
624 let index_eq_for_auto status uri =
625 if NnAuto.is_a_fact_obj status uri then
626 let newstatus = index_eq uri status in
627 if newstatus#eq_cache == status#eq_cache then status
629 ((*prerr_endline ("recording " ^ (NUri.string_of_uri uri));*)
630 let dump = record_index_eq uri :: newstatus#dump
631 in newstatus#set_dump dump)
633 ((*prerr_endline "Not a fact";*)
637 let basic_eval_add_constraint (u1,u2) status =
638 NCicLibrary.add_constraint status u1 u2
641 let inject_constraint =
642 let basic_eval_add_constraint (u1,u2)
643 ~refresh_uri_in_universe
646 let u1 = refresh_uri_in_universe u1 in
647 let u2 = refresh_uri_in_universe u2 in
648 basic_eval_add_constraint (u1,u2)
650 NCicLibrary.Serializer.register#run "constraints"
651 object(_:'a NCicLibrary.register_type)
652 method run = basic_eval_add_constraint
656 let eval_add_constraint status u1 u2 =
657 let status = basic_eval_add_constraint (u1,u2) status in
658 let dump = inject_constraint (u1,u2)::status#dump in
659 let status = status#set_dump dump in
663 let add_coercions_of_lemmas lemmas status =
667 match CoercDb.is_a_coercion (Cic.Const (uri,[])) with
669 | Some (_,tgt,_,sat,_) ->
670 let arity = match tgt with CoercDb.Fun n -> n | _ -> 0 in
671 Some (coercion_moo_statement_of (uri,arity,sat,0)))
674 let status = GrafiteTypes.add_moo_content moo_content status in
675 status#set_coercions (CoercDb.dump ()),
678 let eval_coercion status ~add_composites uri arity saturations =
680 try CicUtil.uri_of_term uri
681 with Invalid_argument _ ->
682 raise (Invalid_argument "coercion can only be constants/constructors")
685 GrafiteSync.add_coercion ~add_composites
686 ~pack_coercion_obj:CicRefine.pack_coercion_obj
687 status uri arity saturations status#baseuri in
688 let moo_content = coercion_moo_statement_of (uri,arity,saturations,0) in
689 let status = GrafiteTypes.add_moo_content [moo_content] status in
690 add_coercions_of_lemmas lemmas status
692 let eval_prefer_coercion status c =
694 try CicUtil.uri_of_term c
695 with Invalid_argument _ ->
696 raise (Invalid_argument "coercion can only be constants/constructors")
698 let status = GrafiteSync.prefer_coercion status uri in
699 let moo_content = GrafiteAst.PreferCoercion (HExtlib.dummy_floc,c) in
700 let status = GrafiteTypes.add_moo_content [moo_content] status in
703 module MatitaStatus =
705 type input_status = GrafiteTypes.status * ProofEngineTypes.goal
708 GrafiteTypes.status * ProofEngineTypes.goal list * ProofEngineTypes.goal list
710 type tactic = input_status -> output_status
712 let mk_tactic tac = tac
713 let apply_tactic tac = tac
714 let goals (_, opened, closed) = opened, closed
715 let get_stack (status, _) = GrafiteTypes.get_stack status
717 let set_stack stack (status, opened, closed) =
718 GrafiteTypes.set_stack stack status, opened, closed
720 let inject (status, _) = (status, [], [])
721 let focus goal (status, _, _) = (status, goal)
724 module MatitaTacticals = Continuationals.Make(MatitaStatus)
726 let tactic_of_ast' tac =
727 MatitaTacticals.Tactical (MatitaTacticals.Tactic (MatitaStatus.mk_tactic tac))
729 let punctuation_tactical_of_ast (text,prefix_len,punct) =
731 | GrafiteAst.Dot _loc -> MatitaTacticals.Dot
732 | GrafiteAst.Semicolon _loc -> MatitaTacticals.Semicolon
733 | GrafiteAst.Branch _loc -> MatitaTacticals.Branch
734 | GrafiteAst.Shift _loc -> MatitaTacticals.Shift
735 | GrafiteAst.Pos (_loc, i) -> MatitaTacticals.Pos i
736 | GrafiteAst.Merge _loc -> MatitaTacticals.Merge
737 | GrafiteAst.Wildcard _loc -> MatitaTacticals.Wildcard
739 let non_punctuation_tactical_of_ast (text,prefix_len,punct) =
741 | GrafiteAst.Focus (_loc,goals) -> MatitaTacticals.Focus goals
742 | GrafiteAst.Unfocus _loc -> MatitaTacticals.Unfocus
743 | GrafiteAst.Skip _loc -> MatitaTacticals.Tactical MatitaTacticals.Skip
745 let eval_tactical status tac =
746 let status, _, _ = MatitaTacticals.eval tac (status, ~-1) in
747 let status = (* is proof completed? *)
748 match status#proof_status with
749 | GrafiteTypes.Incomplete_proof
750 { GrafiteTypes.stack = stack; proof = proof }
751 when Continuationals.Stack.is_empty stack ->
752 status#set_proof_status (GrafiteTypes.Proof proof)
757 let add_obj = GrafiteSync.add_obj ~pack_coercion_obj:CicRefine.pack_coercion_obj
759 let eval_ng_punct (_text, _prefix_len, punct) =
761 | GrafiteAst.Dot _ -> NTactics.dot_tac
762 | GrafiteAst.Semicolon _ -> fun x -> x
763 | GrafiteAst.Branch _ -> NTactics.branch_tac ~force:false
764 | GrafiteAst.Shift _ -> NTactics.shift_tac
765 | GrafiteAst.Pos (_,l) -> NTactics.pos_tac l
766 | GrafiteAst.Wildcard _ -> NTactics.wildcard_tac
767 | GrafiteAst.Merge _ -> NTactics.merge_tac
770 let eval_ng_tac tac =
771 let rec aux f (text, prefix_len, tac) =
773 | GrafiteAst.NApply (_loc, t) -> NTactics.apply_tac (text,prefix_len,t)
774 | GrafiteAst.NSmartApply (_loc, t) ->
775 NnAuto.smart_apply_tac (text,prefix_len,t)
776 | GrafiteAst.NAssert (_loc, seqs) ->
779 (function (hyps,concl) ->
782 (id,`Decl t) -> id,`Decl (text,prefix_len,t)
783 |(id,`Def (b,t))->id,`Def((text,prefix_len,b),(text,prefix_len,t))
785 (text,prefix_len,concl))
787 | GrafiteAst.NAuto (_loc, (None,a)) -> NAuto.auto_tac ~params:(None,a)
788 | GrafiteAst.NAuto (_loc, (Some l,a)) ->
790 ~params:(Some List.map (fun x -> "",0,x) l,a)
791 | GrafiteAst.NBranch _ -> NTactics.branch_tac ~force:false
792 | GrafiteAst.NCases (_loc, what, where) ->
794 ~what:(text,prefix_len,what)
795 ~where:(text,prefix_len,where)
796 | GrafiteAst.NCase1 (_loc,n) -> NTactics.case1_tac n
797 | GrafiteAst.NChange (_loc, pat, ww) ->
799 ~where:(text,prefix_len,pat) ~with_what:(text,prefix_len,ww)
800 | GrafiteAst.NConstructor (_loc,num,args) ->
801 NTactics.constructor_tac
802 ?num ~args:(List.map (fun x -> text,prefix_len,x) args)
803 | GrafiteAst.NCut (_loc, t) -> NTactics.cut_tac (text,prefix_len,t)
804 (*| GrafiteAst.NDiscriminate (_,what) -> NDestructTac.discriminate_tac ~what:(text,prefix_len,what)
805 | GrafiteAst.NSubst (_,what) -> NDestructTac.subst_tac ~what:(text,prefix_len,what)*)
806 | GrafiteAst.NDestruct _ -> NDestructTac.destruct_tac
807 | GrafiteAst.NDot _ -> NTactics.dot_tac
808 | GrafiteAst.NElim (_loc, what, where) ->
810 ~what:(text,prefix_len,what)
811 ~where:(text,prefix_len,where)
812 | GrafiteAst.NFocus (_,l) -> NTactics.focus_tac l
813 | GrafiteAst.NGeneralize (_loc, where) ->
814 NTactics.generalize_tac ~where:(text,prefix_len,where)
815 | GrafiteAst.NId _ -> (fun x -> x)
816 | GrafiteAst.NIntro (_loc,n) -> NTactics.intro_tac n
817 | GrafiteAst.NInversion (_loc, what, where) ->
818 NTactics.inversion_tac
819 ~what:(text,prefix_len,what)
820 ~where:(text,prefix_len,where)
821 | GrafiteAst.NLApply (_loc, t) -> NTactics.lapply_tac (text,prefix_len,t)
822 | GrafiteAst.NLetIn (_loc,where,what,name) ->
823 NTactics.letin_tac ~where:(text,prefix_len,where)
824 ~what:(text,prefix_len,what) name
825 | GrafiteAst.NMerge _ -> NTactics.merge_tac
826 | GrafiteAst.NPos (_,l) -> NTactics.pos_tac l
827 | GrafiteAst.NPosbyname (_,s) -> NTactics.case_tac s
828 | GrafiteAst.NReduce (_loc, reduction, where) ->
829 NTactics.reduce_tac ~reduction ~where:(text,prefix_len,where)
830 | GrafiteAst.NRewrite (_loc,dir,what,where) ->
831 NTactics.rewrite_tac ~dir ~what:(text,prefix_len,what)
832 ~where:(text,prefix_len,where)
833 | GrafiteAst.NSemicolon _ -> fun x -> x
834 | GrafiteAst.NShift _ -> NTactics.shift_tac
835 | GrafiteAst.NSkip _ -> NTactics.skip_tac
836 | GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac
837 | GrafiteAst.NWildcard _ -> NTactics.wildcard_tac
838 | GrafiteAst.NTry (_,tac) -> NTactics.try_tac
839 (aux f (text, prefix_len, tac))
840 | GrafiteAst.NAssumption _ -> NTactics.assumption_tac
841 | GrafiteAst.NBlock (_,l) ->
842 NTactics.block_tac (List.map (fun x -> aux f (text,prefix_len,x)) l)
843 |GrafiteAst.NRepeat (_,tac) ->
844 NTactics.repeat_tac (f f (text, prefix_len, tac))
846 aux aux tac (* trick for non uniform recursion call *)
849 let subst_metasenv_and_fix_names status =
850 let u,h,metasenv, subst,o = status#obj in
852 NCicUntrusted.map_obj_kind ~skip_body:true
853 (NCicUntrusted.apply_subst subst []) o
855 status#set_obj(u,h,NCicUntrusted.apply_subst_metasenv subst metasenv,subst,o)
859 let rec eval_ncommand opts status (text,prefix_len,cmd) =
861 | GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
862 | GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
863 NCicCoercDeclaration.eval_ncoercion status name t ty source target
864 | GrafiteAst.NQed loc ->
865 if status#ng_mode <> `ProofMode then
866 raise (GrafiteTypes.Command_error "Not in proof mode")
868 let uri,height,menv,subst,obj_kind = status#obj in
871 (GrafiteTypes.Command_error"You can't Qed an incomplete theorem")
874 NCicUntrusted.map_obj_kind
875 (NCicUntrusted.apply_subst subst []) obj_kind in
876 let height = NCicTypeChecker.height_of_obj_kind uri [] obj_kind in
877 (* fix the height inside the object *)
878 let rec fix () = function
879 | NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri ->
880 NCic.Const (NReference.reference_of_spec u
882 | NReference.Def _ -> NReference.Def height
883 | NReference.Fix (i,j,_) -> NReference.Fix(i,j,height)
884 | NReference.CoFix _ -> NReference.CoFix height
885 | NReference.Ind _ | NReference.Con _
886 | NReference.Decl as s -> s))
887 | t -> NCicUtils.map (fun _ () -> ()) () fix t
892 NCicUntrusted.map_obj_kind (fix ()) obj_kind
895 let obj = uri,height,[],[],obj_kind in
896 let old_status = status in
897 let status = NCicLibrary.add_obj status obj in
900 NCic.Constant (_,_,_,_,(_,`Example,_))
901 | NCic.Fixpoint (_,_,(_,`Example,_)) -> false
906 let status = index_obj_for_auto status obj in
907 index_eq_for_auto status uri
913 with _ -> prerr_endline "got an exception"; status
915 (* prerr_endline (NCicPp.ppobj obj); *)
916 HLog.message ("New object: " ^ NUri.string_of_uri uri);
918 (*prerr_endline (NCicPp.ppobj obj);*)
919 let boxml = NCicElim.mk_elims obj in
920 let boxml = boxml @ NCicElim.mk_projections obj in
923 let timestamp,uris_rev =
925 (fun (status,uris_rev) (uri,_,_,_,_) as obj ->
926 let status = NCicLibrary.add_obj status obj in
928 ) (status,[]) objs in
929 let uris = uri::List.rev uris_rev in
931 let status = status#set_ng_mode `CommandMode in
932 let status = LexiconSync.add_aliases_for_objs status (`New [uri]) in
935 (fun (status,uris) boxml ->
938 eval_ncommand opts status
939 ("",0,GrafiteAst.NObj (HExtlib.dummy_floc,boxml))
941 if nstatus#ng_mode <> `CommandMode then
943 HLog.error "error in generating projection/eliminator";
944 prerr_endline (NCicPp.ppobj nstatus#obj);
948 nstatus, concat_nuris uris nuris
950 | MultiPassDisambiguator.DisambiguationError _
951 | NCicTypeChecker.TypeCheckerFailure _ ->
952 HLog.warn "error in generating projection/eliminator";
954 ) (status,`New [] (* uris *)) boxml in
955 let _,_,_,_,nobj = obj in
956 let status = match nobj with
957 NCic.Inductive (true,leftno,[it],_) ->
958 let _,ind_name,ty,cl = it in
960 (fun status outsort ->
961 let status = status#set_ng_mode `ProofMode in
963 (let status,invobj = NInversion.mk_inverter
964 (ind_name ^ "_inv_" ^ (snd (NCicElim.ast_of_sort outsort)))
965 it leftno outsort status status#baseuri in
966 let _,_,menv,_,_ = invobj in
968 [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
969 | _ -> status,`New []))
971 with _ -> HLog.warn "error in generating inversion principle";
972 let status = status#set_ng_mode `CommandMode in status)
975 List.map (fun s -> NCic.Type s) (NCicEnvironment.get_universes ()))
980 _,_,_,_,NCic.Inductive
981 (true,leftno,[_,_,_,[_,_,_]],(_,`Record fields))
984 (fun (name,is_coercion,arity) ->
985 if is_coercion then Some(name,leftno,arity) else None) fields
989 (fun (status,uris) (name,cpos,arity) ->
991 let metasenv,subst,status,t =
992 GrafiteDisambiguate.disambiguate_nterm None status [] [] []
993 ("",0,CicNotationPt.Ident (name,None)) in
994 assert (metasenv = [] && subst = []);
996 NCicCoercDeclaration.
997 basic_eval_and_record_ncoercion_from_t_cpos_arity
998 status (name,t,cpos,arity)
1000 let uris = concat_nuris nuris uris in
1002 with MultiPassDisambiguator.DisambiguationError _->
1003 HLog.warn ("error in generating coercion: "^name);
1005 (status,uris) coercions
1010 NCicLibrary.time_travel old_status;
1012 | GrafiteAst.NCopy (log,tgt,src_uri, map) ->
1013 if status#ng_mode <> `CommandMode then
1014 raise (GrafiteTypes.Command_error "Not in command mode")
1016 let tgt_uri_ext, old_ok =
1017 match NCicEnvironment.get_checked_obj src_uri with
1018 | _,_,[],[], (NCic.Inductive _ as ok) -> ".ind", ok
1019 | _,_,[],[], (NCic.Fixpoint _ as ok) -> ".con", ok
1020 | _,_,[],[], (NCic.Constant _ as ok) -> ".con", ok
1023 let tgt_uri = NUri.uri_of_string (status#baseuri^"/"^tgt^tgt_uri_ext) in
1024 let map = (src_uri, tgt_uri) :: map in
1026 let rec subst () = function
1027 | NCic.Meta _ -> assert false
1028 | NCic.Const (NReference.Ref (u,spec)) as t ->
1030 (NReference.reference_of_spec (List.assoc u map)spec)
1031 with Not_found -> t)
1032 | t -> NCicUtils.map (fun _ _ -> ()) () subst t
1034 NCicUntrusted.map_obj_kind ~skip_body:false (subst ()) old_ok
1036 let ninitial_stack = Continuationals.Stack.of_nmetasenv [] in
1037 let status = status#set_obj (tgt_uri,0,[],[],ok) in
1038 (*prerr_endline (NCicPp.ppobj (tgt_uri,0,[],[],ok));*)
1039 let status = status#set_stack ninitial_stack in
1040 let status = subst_metasenv_and_fix_names status in
1041 let status = status#set_ng_mode `ProofMode in
1042 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
1043 | GrafiteAst.NObj (loc,obj) ->
1044 if status#ng_mode <> `CommandMode then
1045 raise (GrafiteTypes.Command_error "Not in command mode")
1048 GrafiteDisambiguate.disambiguate_nobj status
1049 ~baseuri:status#baseuri (text,prefix_len,obj) in
1050 let uri,height,nmenv,nsubst,nobj = obj in
1051 let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in
1052 let status = status#set_obj obj in
1053 let status = status#set_stack ninitial_stack in
1054 let status = subst_metasenv_and_fix_names status in
1055 let status = status#set_ng_mode `ProofMode in
1058 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
1059 | _ -> status,`New [])
1060 | GrafiteAst.NDiscriminator (_,_) -> assert false (*(loc, indty) ->
1061 if status#ng_mode <> `CommandMode then
1062 raise (GrafiteTypes.Command_error "Not in command mode")
1064 let status = status#set_ng_mode `ProofMode in
1065 let metasenv,subst,status,indty =
1066 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] (text,prefix_len,indty) in
1067 let indtyno, (_,_,tys,_,_) = match indty with
1068 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
1069 indtyno, NCicEnvironment.get_checked_indtys r
1070 | _ -> prerr_endline ("engine: indty expected... (fix this error message)"); assert false in
1071 let it = List.nth tys indtyno in
1072 let status,obj = NDestructTac.mk_discriminator it status in
1073 let _,_,menv,_,_ = obj in
1075 [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
1076 | _ -> prerr_endline ("Discriminator: non empty metasenv");
1078 | GrafiteAst.NInverter (loc, name, indty, selection, sort) ->
1079 if status#ng_mode <> `CommandMode then
1080 raise (GrafiteTypes.Command_error "Not in command mode")
1082 let metasenv,subst,status,sort = match sort with
1083 | None -> [],[],status,NCic.Sort NCic.Prop
1084 | Some s -> GrafiteDisambiguate.disambiguate_nterm None status [] [] []
1087 assert (metasenv = []);
1088 let sort = NCicReduction.whd ~subst [] sort in
1089 let sort = match sort with
1091 | _ -> raise (Invalid_argument (Printf.sprintf "ninverter: found target %s, which is not a sort"
1092 (NCicPp.ppterm ~metasenv ~subst ~context:[] sort)))
1094 let status = status#set_ng_mode `ProofMode in
1095 let metasenv,subst,status,indty =
1096 GrafiteDisambiguate.disambiguate_nterm None status [] [] subst (text,prefix_len,indty) in
1097 let indtyno,(_,leftno,tys,_,_) = match indty with
1098 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
1099 indtyno, NCicEnvironment.get_checked_indtys r
1100 | _ -> prerr_endline ("engine: indty =" ^ NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] indty) ; assert false in
1101 let it = List.nth tys indtyno in
1102 let status,obj = NInversion.mk_inverter name it leftno ?selection sort
1103 status status#baseuri in
1104 let _,_,menv,_,_ = obj in
1107 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
1108 | _ -> assert false)
1109 | GrafiteAst.NUnivConstraint (loc,u1,u2) ->
1110 eval_add_constraint status [`Type,u1] [`Type,u2]
1113 let rec eval_command = {ec_go = fun ~disambiguate_command opts status
1114 (text,prefix_len,cmd) ->
1115 let status,cmd = disambiguate_command status (text,prefix_len,cmd) in
1118 | GrafiteAst.Index (loc,None,uri) ->
1119 assert false (* TODO: for user input *)
1120 | GrafiteAst.Index (loc,Some key,uri) ->
1122 status#automation_cache.AutomationCache.univ
1124 let universe = Universe.index universe key (CicUtil.term_of_uri uri) in
1126 status#automation_cache with AutomationCache.univ = universe }
1128 let status = status#set_automation_cache cache in
1131 let candidates = Universe.get_candidates status.GrafiteTypes.universe key in
1132 ("candidates for " ^ (CicPp.ppterm key) ^ " = " ^
1133 (String.concat "\n" (List.map CicPp.ppterm candidates)))
1137 let status = GrafiteTypes.add_moo_content [cmd] status in
1139 | GrafiteAst.Select (_,uri) as cmd ->
1140 if List.mem cmd status#moo_content_rev then status, `Old []
1143 AutomationCache.add_term_to_active status#automation_cache
1144 [] [] [] (CicUtil.term_of_uri uri) None
1146 let status = status#set_automation_cache cache in
1147 let status = GrafiteTypes.add_moo_content [cmd] status in
1149 | GrafiteAst.Pump (_,steps) ->
1151 AutomationCache.pump status#automation_cache steps
1153 let status = status#set_automation_cache cache in
1155 | GrafiteAst.PreferCoercion (loc, coercion) ->
1156 eval_prefer_coercion status coercion
1157 | GrafiteAst.Coercion (loc, uri, add_composites, arity, saturations) ->
1159 eval_coercion status ~add_composites uri arity saturations
1162 | GrafiteAst.Inverter (loc, name, indty, params) ->
1163 let buri = status#baseuri in
1164 let uri = UriManager.uri_of_string (buri ^ "/" ^ name ^ ".con") in
1166 try CicUtil.uri_of_term indty
1167 with Invalid_argument _ ->
1168 raise (Invalid_argument "not an inductive type to invert") in
1170 Inversion_principle.build_inverter ~add_obj status uri indty_uri params
1173 | GrafiteAst.Default (loc, what, uris) as cmd ->
1174 LibraryObjects.set_default what uris;
1175 GrafiteTypes.add_moo_content [cmd] status,`Old []
1176 | GrafiteAst.Drop loc -> raise Drop
1177 | GrafiteAst.Include (loc, mode, new_or_old, baseuri) ->
1178 (* Old Include command is not recursive; new one is *)
1180 if new_or_old = `OldAndNew then
1181 let moopath_rw, moopath_r =
1182 LibraryMisc.obj_file_of_baseuri
1183 ~must_exist:false ~baseuri ~writable:true,
1184 LibraryMisc.obj_file_of_baseuri
1185 ~must_exist:false ~baseuri ~writable:false in
1187 if Sys.file_exists moopath_r then moopath_r else
1188 if Sys.file_exists moopath_rw then moopath_rw else
1189 raise (IncludedFileNotCompiled (moopath_rw,baseuri))
1191 eval_from_moo.efm_go status moopath
1196 NCicLibrary.Serializer.require ~baseuri:(NUri.uri_of_string baseuri)
1199 GrafiteTypes.add_moo_content
1200 [GrafiteAst.Include (loc,mode,`New,baseuri)] status
1203 | GrafiteAst.Print (_,"proofterm") ->
1204 let _,_,_,p,_, _ = GrafiteTypes.get_current_proof status in
1205 prerr_endline (Auto.pp_proofterm (Lazy.force p));
1207 | GrafiteAst.Print (_,_) -> status,`Old []
1208 | GrafiteAst.Qed loc ->
1209 let uri, metasenv, _subst, bo, ty, attrs =
1210 match status#proof_status with
1211 | GrafiteTypes.Proof (Some uri, metasenv, subst, body, ty, attrs) ->
1212 uri, metasenv, subst, body, ty, attrs
1213 | GrafiteTypes.Proof (None, metasenv, subst, body, ty, attrs) ->
1214 raise (GrafiteTypes.Command_error
1215 ("Someone allows to start a theorem without giving the "^
1216 "name/uri. This should be fixed!"))
1219 (GrafiteTypes.Command_error "You can't Qed an incomplete theorem")
1221 if metasenv <> [] then
1223 (GrafiteTypes.Command_error
1224 "Proof not completed! metasenv is not empty!");
1225 let name = UriManager.name_of_uri uri in
1226 let obj = Cic.Constant (name,Some (Lazy.force bo),ty,[],attrs) in
1227 let status, lemmas = add_obj uri obj status in
1228 status#set_proof_status GrafiteTypes.No_proof,
1229 (*CSC: I throw away the arities *)
1231 | GrafiteAst.Relation (loc, id, a, aeq, refl, sym, trans) ->
1232 Setoids.add_relation id a aeq refl sym trans;
1233 status, `Old [] (*CSC: TO BE FIXED *)
1234 | GrafiteAst.Set (loc, name, value) -> status, `Old []
1235 (* GrafiteTypes.set_option status name value,[] *)
1236 | GrafiteAst.Obj (loc,obj) ->
1239 Cic.Constant (name,_,_,_,_)
1240 | Cic.CurrentProof (name,_,_,_,_,_) -> ".con",name
1241 | Cic.InductiveDefinition (types,_,_,_) ->
1243 (match types with (name,_,_,_)::_ -> name | _ -> assert false)
1244 | _ -> assert false in
1245 let buri = status#baseuri in
1246 let uri = UriManager.uri_of_string (buri ^ "/" ^ name ^ ext) in
1247 let obj = CicRefine.pack_coercion_obj obj in
1248 let metasenv = GrafiteTypes.get_proof_metasenv status in
1250 | Cic.CurrentProof (_,metasenv',bo,ty,_, attrs) ->
1251 let name = UriManager.name_of_uri uri in
1252 if not(CicPp.check name ty) then
1253 HLog.warn ("Bad name: " ^ name);
1254 if opts.do_heavy_checks then
1256 let dbd = LibraryDb.instance () in
1257 let similar = Whelp.match_term ~dbd ty in
1258 let similar_len = List.length similar in
1259 if similar_len> 30 then
1261 ("Duplicate check will compare your theorem with " ^
1262 string_of_int similar_len ^
1263 " theorems, this may take a while."));
1267 let t = CicUtil.term_of_uri u in
1269 CicTypeChecker.type_of_aux'
1270 metasenv' [] t CicUniv.oblivion_ugraph
1272 fst(CicReduction.are_convertible [] ty' ty g))
1275 (match convertible with
1279 ("Theorem already proved: " ^ UriManager.string_of_uri x ^
1280 "\nPlease use a variant."));
1283 let initial_proof = (Some uri, metasenv', _subst, lazy bo, ty, attrs) in
1284 let initial_stack = Continuationals.Stack.of_metasenv metasenv' in
1285 status#set_proof_status
1286 (GrafiteTypes.Incomplete_proof
1287 { GrafiteTypes.proof = initial_proof; stack = initial_stack }),
1290 if metasenv <> [] then
1291 raise (GrafiteTypes.Command_error (
1292 "metasenv not empty while giving a definition with body: " ^
1293 CicMetaSubst.ppmetasenv [] metasenv));
1294 let status, lemmas = add_obj uri obj status in
1295 let status,new_lemmas = add_coercions_of_lemmas lemmas status in
1296 status#set_proof_status GrafiteTypes.No_proof,
1297 `Old (uri::new_lemmas@lemmas)
1299 match status#proof_status with
1300 GrafiteTypes.Intermediate _ ->
1301 status#set_proof_status GrafiteTypes.No_proof,uris
1304 } and eval_executable = {ee_go = fun ~disambiguate_tactic ~disambiguate_command
1305 ~disambiguate_macro opts status (text,prefix_len,ex) ->
1307 | GrafiteAst.Tactic (_(*loc*), Some tac, punct) ->
1308 let tac = apply_tactic ~disambiguate_tactic (text,prefix_len,tac) in
1309 let status = eval_tactical status (tactic_of_ast' tac) in
1310 (* CALL auto on every goal, easy way of testing it
1312 GrafiteAst.AutoBatch
1313 (loc, ([],["depth","2";"timeout","1";"type","1"])) in
1315 let auto = apply_tactic ~disambiguate_tactic ("",0,auto) in
1316 let _ = eval_tactical status (tactic_of_ast' auto) in
1317 print_endline "GOOD"; ()
1318 with ProofEngineTypes.Fail _ -> print_endline "BAD" | _ -> ());*)
1319 eval_tactical status
1320 (punctuation_tactical_of_ast (text,prefix_len,punct)),`Old []
1321 | GrafiteAst.Tactic (_, None, punct) ->
1322 eval_tactical status
1323 (punctuation_tactical_of_ast (text,prefix_len,punct)),`Old []
1324 | GrafiteAst.NTactic (_(*loc*), tacl) ->
1325 if status#ng_mode <> `ProofMode then
1326 raise (GrafiteTypes.Command_error "Not in proof mode")
1331 let status = eval_ng_tac (text,prefix_len,tac) status in
1332 subst_metasenv_and_fix_names status)
1336 | GrafiteAst.NonPunctuationTactical (_, tac, punct) ->
1338 eval_tactical status
1339 (non_punctuation_tactical_of_ast (text,prefix_len,tac))
1341 eval_tactical status
1342 (punctuation_tactical_of_ast (text,prefix_len,punct)),`Old []
1343 | GrafiteAst.Command (_, cmd) ->
1344 eval_command.ec_go ~disambiguate_command opts status (text,prefix_len,cmd)
1345 | GrafiteAst.NCommand (_, cmd) ->
1346 eval_ncommand opts status (text,prefix_len,cmd)
1347 | GrafiteAst.Macro (loc, macro) ->
1348 raise (Macro (loc,disambiguate_macro status (text,prefix_len,macro)))
1349 | GrafiteAst.NMacro (loc, macro) ->
1350 raise (NMacro (loc,macro))
1352 } and eval_from_moo = {efm_go = fun status fname ->
1353 let ast_of_cmd cmd =
1354 ("",0,GrafiteAst.Executable (HExtlib.dummy_floc,
1355 GrafiteAst.Command (HExtlib.dummy_floc,
1358 let moo = GrafiteMarshal.load_moo fname in
1361 let ast = ast_of_cmd ast in
1364 ~disambiguate_tactic:(fun status _ (_,_,tactic) -> status,tactic)
1365 ~disambiguate_command:(fun status (_,_,cmd) -> status,cmd)
1366 ~disambiguate_macro:(fun _ _ -> assert false)
1369 assert (lemmas=`Old []);
1372 } and eval_ast = {ea_go = fun ~disambiguate_tactic ~disambiguate_command
1373 ~disambiguate_macro ?(do_heavy_checks=false) status
1374 (text,prefix_len,st)
1376 let opts = { do_heavy_checks = do_heavy_checks ; } in
1378 | GrafiteAst.Executable (_,ex) ->
1379 eval_executable.ee_go ~disambiguate_tactic ~disambiguate_command
1380 ~disambiguate_macro opts status (text,prefix_len,ex)
1381 | GrafiteAst.Comment (_,c) ->
1382 eval_comment.ecm_go ~disambiguate_command opts status (text,prefix_len,c)
1383 } and eval_comment = { ecm_go = fun ~disambiguate_command opts status (text,prefix_len,c) ->
1389 let eval_ast = eval_ast.ea_go