1
(* Une tactique qui tente de d�montrer toute seule le but courant,
2
interruptible par pcoq (si dans le fichier C:\WINDOWS\free il y a un A)
41
let parse_com = Pcoq.parse_string Pcoq.Constr.constr;;
43
try (Pcoq.parse_string Pcoq.Tactic.tactic t)
44
with _ -> (msgnl (hov 0 (str"pas pars�: " ++ str t));
49
let st =open_in_bin ((Sys.getenv "HOME")^"/.free") in
50
let c=input_char st in
58
msgnl (hov 0 [< 'str"Isfree========= "; 'fNL >]);
59
let s = Stream.of_channel stdin in
60
msgnl (hov 0 [< 'str"Isfree s "; 'fNL >]);
62
msgnl (hov 0 [< 'str"Isfree empty "; 'fNL >]);
64
with _ -> (msgnl (hov 0 [< 'str"Isfree not empty "; 'fNL >]);
71
else (failwith "not free")
75
Name(xid) -> Environ.push_rel (x,None,t) e
76
| Anonymous -> Environ.push_rel (x,None,t) e
77
(* les constantes ayant une d�finition apparaissant dans x *)
78
let rec def_const_in_term_rec vl x =
79
match (kind_of_term x) with
81
let vl = (adrel (n,t) vl) in def_const_in_term_rec vl c
83
let vl = (adrel (n,t) vl) in def_const_in_term_rec vl c
84
| App(f,args) -> def_const_in_term_rec vl f
85
| Sort(Prop(Null)) -> Prop(Null)
88
let (mib, mip) = Global.lookup_inductive ind in
89
new_sort_in_family (inductive_sort_family mip)
91
def_const_in_term_rec vl (mkInd (inductive_of_constructor c))
93
-> def_const_in_term_rec vl x
94
| Cast(x,_,t)-> def_const_in_term_rec vl t
95
| Const(c) -> def_const_in_term_rec vl (Typeops.type_of_constant vl c)
96
| _ -> def_const_in_term_rec vl (type_of vl Evd.empty x)
98
let def_const_in_term_ x =
99
def_const_in_term_rec (Global.env()) (strip_outer_cast x)
101
(*************************************************************************
102
recopi�s de refiner.ml, car print_subscript pas export�e dans refiner.mli
103
modif de print_info_script avec pr_bar
106
let pr_bar () = str "|"
108
let rec print_info_script sigma osign pf =
109
let {evar_hyps=sign; evar_concl=cl} = pf.goal in
113
Tactic_printer.pr_rule r ++
118
if pf1.ref = None then
121
(str";" ++ brk(1,3) ++
122
print_info_script sigma sign pf1)
123
| _ -> ( str";[" ++ fnl() ++
124
prlist_with_sep pr_bar
125
(print_info_script sigma sign) spfl ++
128
let format_print_info_script sigma osign pf =
129
hov 0 (print_info_script sigma osign pf)
131
let print_subscript sigma sign pf =
132
(* if is_tactic_proof pf then
133
format_print_info_script sigma sign (subproof_of_proof pf)
135
format_print_info_script sigma sign pf
139
msgnl_with Format.str_formatter x;
140
Format.flush_str_formatter ()
143
(***********************************************************************
144
copi� de tactics/eauto.ml
147
(***************************************************************************)
148
(* A tactic similar to Auto, but using EApply, Assumption and e_give_exact *)
149
(***************************************************************************)
151
let priority l = List.map snd (List.filter (fun (pr,_) -> pr = 0) l)
153
let unify_e_resolve (c,clenv) gls =
154
let clenv' = connect_clenv gls clenv in
155
let _ = clenv_unique_resolver false clenv' gls in
156
Hiddentac.h_simplest_eapply c gls
158
let rec e_trivial_fail_db db_list local_db goal =
160
registered_e_assumption ::
161
(tclTHEN Tactics.intro
163
let d = pf_last_hyp g' in
164
let hintl = make_resolve_hyp (pf_env g') (project g') d in
165
(e_trivial_fail_db db_list
166
(Hint_db.add_list hintl local_db) g'))) ::
167
(List.map fst (e_trivial_resolve db_list local_db (pf_concl goal)) )
169
tclFIRST (List.map tclCOMPLETE tacl) goal
171
and e_my_find_search db_list local_db hdc concl =
172
let hdc = head_of_constr_reference hdc in
174
if occur_existential concl then
175
list_map_append (fun db ->
176
let flags = {Auto.auto_unif_flags with Unification.modulo_delta = Hint_db.transparent_state db} in
177
List.map (fun x -> flags, x) (Hint_db.map_all hdc db)) (local_db::db_list)
179
list_map_append (fun db ->
180
let flags = {Auto.auto_unif_flags with Unification.modulo_delta = Hint_db.transparent_state db} in
181
List.map (fun x -> flags, x) (Hint_db.map_auto (hdc,concl) db)) (local_db::db_list)
184
fun (st, ({pri=b; pat = p; code=t} as _patac)) ->
188
| Res_pf (term,cl) -> unify_resolve st (term,cl)
189
| ERes_pf (term,cl) -> unify_e_resolve (term,cl)
190
| Give_exact (c) -> e_give_exact_constr c
191
| Res_pf_THEN_trivial_fail (term,cl) ->
192
tclTHEN (unify_e_resolve (term,cl))
193
(e_trivial_fail_db db_list local_db)
194
| Unfold_nth c -> unfold_in_concl [all_occurrences,c]
195
| Extern tacast -> Auto.conclPattern concl p tacast
197
(free_try tac,pr_autotactic t))
199
fun gls -> pPNL (pr_autotactic t); Format.print_flush ();
201
with e when Logic.catchable_exception(e) ->
202
(Format.print_string "Fail\n";
203
Format.print_flush ();
207
List.map tac_of_hint hintl
209
and e_trivial_resolve db_list local_db gl =
212
(e_my_find_search db_list local_db
213
(fst (head_constr_bound gl)) gl)
214
with Bound | Not_found -> []
216
let e_possible_resolve db_list local_db gl =
217
try List.map snd (e_my_find_search db_list local_db
218
(fst (head_constr_bound gl)) gl)
219
with Bound | Not_found -> []
221
let assumption_tac_list id = apply_tac_list (e_give_exact_constr (mkVar id))
223
let find_first_goal gls =
224
try first_goal gls with UserError _ -> assert false
226
(*s The following module [SearchProblem] is used to instantiate the generic
227
exploration functor [Explore.Make]. *)
229
module MySearchProblem = struct
232
depth : int; (*r depth of search before failing *)
233
tacres : goal list sigma * validation;
234
last_tactic : std_ppcmds;
235
dblist : Auto.hint_db list;
236
localdb : Auto.hint_db list }
238
let success s = (sig_it (fst s.tacres)) = []
240
let rec filter_tactics (glls,v) = function
242
| (tac,pptac) :: tacl ->
244
let (lgls,ptl) = apply_tac_list tac glls in
245
let v' p = v (ptl p) in
246
((lgls,v'),pptac) :: filter_tactics (glls,v) tacl
247
with e when Logic.catchable_exception e ->
248
filter_tactics (glls,v) tacl
250
(* Ordering of states is lexicographic on depth (greatest first) then
251
number of remaining goals. *)
253
let d = s'.depth - s.depth in
254
let nbgoals s = List.length (sig_it (fst s.tacres)) in
255
if d <> 0 then d else nbgoals s - nbgoals s'
261
let lg = fst s.tacres in
262
let nbgl = List.length (sig_it lg) in
264
let g = find_first_goal lg in
265
let assumption_tacs =
267
filter_tactics s.tacres
269
(fun id -> (e_give_exact_constr (mkVar id),
270
(str "Exact" ++ spc()++ pr_id id)))
273
List.map (fun (res,pp) -> { depth = s.depth; tacres = res;
274
last_tactic = pp; dblist = s.dblist;
275
localdb = List.tl s.localdb }) l
279
(fun ((lgls,_) as res,pp) ->
280
let g' = first_goal lgls in
282
make_resolve_hyp (pf_env g') (project g') (pf_last_hyp g')
284
let ldb = Hint_db.add_list hintl (List.hd s.localdb) in
285
{ depth = s.depth; tacres = res;
286
last_tactic = pp; dblist = s.dblist;
287
localdb = ldb :: List.tl s.localdb })
288
(filter_tactics s.tacres [Tactics.intro,(str "Intro" )])
292
filter_tactics s.tacres
293
(e_possible_resolve s.dblist (List.hd s.localdb) (pf_concl g))
296
(fun ((lgls,_) as res, pp) ->
297
let nbgl' = List.length (sig_it lgls) in
299
{ depth = s.depth; tacres = res; last_tactic = pp;
300
dblist = s.dblist; localdb = List.tl s.localdb }
302
{ depth = pred s.depth; tacres = res;
303
dblist = s.dblist; last_tactic = pp;
305
list_addn (nbgl'-nbgl) (List.hd s.localdb) s.localdb })
308
List.sort compare (assumption_tacs @ intro_tac @ rec_tacs)
311
msg (hov 0 (str " depth="++ int s.depth ++ spc() ++
312
s.last_tactic ++ str "\n"))
316
module MySearch = Explore.Make(MySearchProblem)
318
let make_initial_state n gl dblist localdb =
319
{ MySearchProblem.depth = n;
320
MySearchProblem.tacres = tclIDTAC gl;
321
MySearchProblem.last_tactic = (mt ());
322
MySearchProblem.dblist = dblist;
323
MySearchProblem.localdb = [localdb] }
325
let e_depth_search debug p db_list local_db gl =
327
let tac = if debug then MySearch.debug_depth_first else MySearch.depth_first in
328
let s = tac (make_initial_state p gl db_list local_db) in
329
s.MySearchProblem.tacres
330
with Not_found -> error "EAuto: depth first search failed"
332
let e_breadth_search debug n db_list local_db gl =
335
if debug then MySearch.debug_breadth_first else MySearch.breadth_first
337
let s = tac (make_initial_state n gl db_list local_db) in
338
s.MySearchProblem.tacres
339
with Not_found -> error "EAuto: breadth first search failed"
341
let e_search_auto debug (n,p) db_list gl =
342
let local_db = make_local_hint_db true [] gl in
344
e_depth_search debug p db_list local_db gl
346
e_breadth_search debug n db_list local_db gl
348
let eauto debug np dbnames =
352
try searchtable_map x
353
with Not_found -> error ("EAuto: "^x^": No such Hint database"))
356
tclTRY (e_search_auto debug np db_list)
358
let full_eauto debug n gl =
359
let dbnames = current_db_names () in
360
let dbnames = list_subtract dbnames ["v62"] in
361
let db_list = List.map searchtable_map dbnames in
362
let _local_db = make_local_hint_db true [] gl in
363
tclTRY (e_search_auto debug n db_list) gl
365
let my_full_eauto n gl = full_eauto false (n,0) gl
367
(**********************************************************************
368
copi� de tactics/auto.ml on a juste modifi� search_gen
371
(* local_db is a Hint database containing the hypotheses of current goal *)
372
(* Papageno : cette fonction a �t� pas mal simplifi�e depuis que la base
373
de Hint imp�rative a �t� remplac�e par plusieurs bases fonctionnelles *)
375
let rec trivial_fail_db db_list local_db gl =
379
let hintl = make_resolve_hyp (pf_env g') (project g') (pf_last_hyp g')
380
in trivial_fail_db db_list (Hint_db.add_list hintl local_db) g')
383
(assumption::intro_tac::
384
(List.map tclCOMPLETE
385
(trivial_resolve db_list local_db (pf_concl gl)))) gl
387
and my_find_search db_list local_db hdc concl =
389
if occur_existential concl then
390
list_map_append (fun db ->
391
let flags = {Auto.auto_unif_flags with Unification.modulo_delta = Hint_db.transparent_state db} in
392
List.map (fun x -> flags, x) (Hint_db.map_all hdc db)) (local_db::db_list)
394
list_map_append (fun db ->
395
let flags = {Auto.auto_unif_flags with Unification.modulo_delta = Hint_db.transparent_state db} in
396
List.map (fun x -> flags, x) (Hint_db.map_auto (hdc,concl) db)) (local_db::db_list)
399
(fun (st, {pri=b; pat=p; code=t} as _patac) ->
402
| Res_pf (term,cl) -> unify_resolve st (term,cl)
403
| ERes_pf (_,c) -> (fun gl -> error "eres_pf")
404
| Give_exact c -> exact_check c
405
| Res_pf_THEN_trivial_fail (term,cl) ->
407
(unify_resolve st (term,cl))
408
(trivial_fail_db db_list local_db)
409
| Unfold_nth c -> unfold_in_concl [all_occurrences,c]
410
| Extern tacast -> conclPattern concl p tacast))
413
and trivial_resolve db_list local_db cl =
415
let hdconstr = fst (head_constr_bound cl) in
417
(my_find_search db_list local_db (head_of_constr_reference hdconstr) cl)
418
with Bound | Not_found ->
421
(**************************************************************************)
422
(* The classical Auto tactic *)
423
(**************************************************************************)
425
let possible_resolve db_list local_db cl =
427
let hdconstr = fst (head_constr_bound cl) in
429
(my_find_search db_list local_db (head_of_constr_reference hdconstr) cl)
430
with Bound | Not_found ->
433
let decomp_unary_term c gls =
434
let typc = pf_type_of gls c in
435
let t = head_constr typc in
436
if Hipattern.is_conjunction (applist t) then
439
errorlabstrm "Auto.decomp_unary_term" (str "not a unary type")
441
let decomp_empty_term c gls =
442
let typc = pf_type_of gls c in
443
let (hd,_) = decompose_app typc in
444
if Hipattern.is_empty_type hd then
447
errorlabstrm "Auto.decomp_empty_term" (str "not an empty type")
450
(* decomp is an natural number giving an indication on decomposition
451
of conjunction in hypotheses, 0 corresponds to no decomposition *)
452
(* n is the max depth of search *)
453
(* local_db contains the local Hypotheses *)
455
let rec search_gen decomp n db_list local_db extra_sign goal =
456
if n=0 then error "BOUND 2";
457
let decomp_tacs = match decomp with
460
(tclTRY_sign decomp_empty_term extra_sign)
463
(fun id -> tclTHEN (decomp_unary_term (mkVar id))
466
(free_try (search_gen decomp p db_list local_db []))))
467
(pf_ids_of_hyps goal))
472
let (hid,_,htyp as d) = pf_last_hyp g' in
475
[make_apply_entry (pf_env g') (project g')
482
(search_gen decomp n db_list (Hint_db.add_list hintl local_db) [d])
490
(search_gen decomp (n-1) db_list local_db empty_named_context)))
491
(possible_resolve db_list local_db (pf_concl goal))
493
tclFIRST (assumption::(decomp_tacs@(intro_tac::rec_tacs))) goal
496
let search = search_gen 0
498
let default_search_depth = ref 5
501
let dbnames = current_db_names () in
502
let dbnames = list_subtract dbnames ["v62"] in
503
let db_list = List.map searchtable_map dbnames in
504
let hyps = pf_hyps gl in
505
tclTRY (search n db_list (make_local_hint_db false [] gl) hyps) gl
507
let default_full_auto gl = full_auto !default_search_depth gl
508
(************************************************************************)
510
let blast_tactic = ref (free_try default_full_auto)
513
let blast_auto = (free_try default_full_auto)
514
(* (tclTHEN (free_try default_full_auto)
515
(free_try (my_full_eauto 2)))
518
let blast_simpl = (free_try (reduce (Simpl None) onConcl))
520
let blast_induction1 =
521
(free_try (tclTHEN (tclTRY intro)
522
(tclTRY (tclLAST_HYP simplest_elim))))
524
let blast_induction2 =
525
(free_try (tclTHEN (tclTRY (tclTHEN intro intro))
526
(tclTRY (tclLAST_HYP simplest_elim))))
528
let blast_induction3 =
529
(free_try (tclTHEN (tclTRY (tclTHEN intro (tclTHEN intro intro)))
530
(tclTRY (tclLAST_HYP simplest_elim))))
534
(tclORELSE (tclCOMPLETE blast_auto)
535
(tclORELSE (tclCOMPLETE (tclTHEN blast_simpl blast_auto))
536
(tclORELSE (tclCOMPLETE (tclTHEN blast_induction1
537
(tclTHEN blast_simpl blast_auto)))
538
(tclORELSE (tclCOMPLETE (tclTHEN blast_induction2
539
(tclTHEN blast_simpl blast_auto)))
540
(tclCOMPLETE (tclTHEN blast_induction3
541
(tclTHEN blast_simpl blast_auto)))))))
544
blast_tactic := (tclTHEN (free_try default_full_auto)
545
(free_try (my_full_eauto 4)))
550
let interro = ref false in
551
let interro_pos = ref 0 in
552
for i=0 to (length s)-1 do
554
then (interro := true;
558
['0';'1';'2';'3';'4';'5';'6';'7';'8';'9']))
570
try (let (sgl,v) as _res = !blast_tactic gls in
573
then (let pf = v (List.map leaf (sig_it sgl)) in
574
let sign = (sig_it gls).evar_hyps in
575
let x = print_subscript
576
(sig_sig gls) sign pf in
577
msgnl (hov 0 (str"Blast ==> " ++ x));
578
let x = print_subscript
579
(sig_sig gls) sign pf in
581
pp_string (hov 0 x ) in
582
(* on remplace les ?1 ?2 ... de refine par ? *)
583
parse_tac ((vire_extvar tac_string)
586
else (msgnl (hov 0 (str"Blast failed to prove the goal..."));
587
failwith "echec de blast"))
588
with _ -> failwith "echec de blast"
591
let blast_tac display_function = function
594
let exp_ast = (blast g) in
595
(display_function exp_ast;
597
| _ -> failwith "expecting other arguments";;
601
(function x -> msgnl(Pptactic.pr_glob_tactic (Global.env()) (Tacinterp.glob_tactic x)));;
604
overwriting_add_tactic "Blast1" blast_tac_txt;;
608
Grammar tactic ne_numarg_list : list :=
609
ne_numarg_single [numarg($n)] ->[$n]
610
| ne_numarg_cons [numarg($n) ne_numarg_list($ns)] -> [ $n ($LIST $ns) ].
611
Grammar tactic simple_tactic : ast :=
612
blast1 [ "Blast1" ne_numarg_list($ns) ] ->
613
[ (Blast1 ($LIST $ns)) ].
617
PATH=/usr/local/bin:/usr/bin:$PATH
618
COQTOP=d:/Tools/coq-7.0-3mai
619
CAMLLIB=/usr/local/lib/ocaml
620
CAMLP4LIB=/usr/local/lib/camlp4
624
d:/Tools/coq-7.0-3mai/bin/coqtop.byte.exe
626
#use "/cygdrive/D/Tools/coq-7.0-3mai/dev/base_include";;