| author | wenzelm | 
| Fri, 08 Nov 2024 16:57:48 +0100 | |
| changeset 81405 | c519a14bd3f6 | 
| parent 64556 | 851ae0e7b09c | 
| child 82805 | 61aae966dd95 | 
| permissions | -rw-r--r-- | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 1 | (* Title: Tools/intuitionistic.ML | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 2 | Author: Stefan Berghofer, TU Muenchen | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 3 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 4 | Simple intuitionistic proof search. | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 5 | *) | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 6 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 7 | signature INTUITIONISTIC = | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 8 | sig | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 9 | val prover_tac: Proof.context -> int option -> int -> tactic | 
| 31299 | 10 | val method_setup: binding -> theory -> theory | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 11 | end; | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 12 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 13 | structure Intuitionistic: INTUITIONISTIC = | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 14 | struct | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 15 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 16 | (* main tactic *) | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 17 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 18 | local | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 19 | |
| 58957 | 20 | fun remdups_tac ctxt = SUBGOAL (fn (g, i) => | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 21 | let val prems = Logic.strip_assums_hyp g in | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 22 | REPEAT_DETERM_N (length prems - length (distinct op aconv prems)) | 
| 58957 | 23 | (ematch_tac ctxt [Drule.remdups_rl] i THEN Tactic.eq_assume_tac i) | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 24 | end); | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 25 | |
| 58957 | 26 | fun REMDUPS tac ctxt = tac ctxt THEN_ALL_NEW remdups_tac ctxt; | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 27 | |
| 59164 | 28 | fun bires_tac ctxt = Tactic.biresolution_from_nets_tac ctxt Context_Rules.orderlist; | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 29 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 30 | fun safe_step_tac ctxt = | 
| 33369 | 31 | Context_Rules.Swrap ctxt | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 32 | (eq_assume_tac ORELSE' | 
| 59164 | 33 | bires_tac ctxt true (Context_Rules.netpair_bang ctxt)); | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 34 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 35 | fun unsafe_step_tac ctxt = | 
| 33369 | 36 | Context_Rules.wrap ctxt | 
| 58963 
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
 wenzelm parents: 
58957diff
changeset | 37 | (assume_tac ctxt APPEND' | 
| 59164 | 38 | bires_tac ctxt false (Context_Rules.netpair_bang ctxt) APPEND' | 
| 39 | bires_tac ctxt false (Context_Rules.netpair ctxt)); | |
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 40 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 41 | fun step_tac ctxt i = | 
| 58957 | 42 | REPEAT_DETERM1 (REMDUPS safe_step_tac ctxt i) ORELSE | 
| 43 | REMDUPS unsafe_step_tac ctxt i; | |
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 44 | |
| 55627 | 45 | fun intprover_tac ctxt gs d lim = SUBGOAL (fn (g, i) => | 
| 46 | if d > lim then no_tac | |
| 47 | else | |
| 48 | let | |
| 49 | val ps = Logic.strip_assums_hyp g; | |
| 50 | val c = Logic.strip_assums_concl g; | |
| 51 | in | |
| 52 | if member (fn ((ps1, c1), (ps2, c2)) => | |
| 53 | c1 aconv c2 andalso | |
| 54 | length ps1 = length ps2 andalso | |
| 55 | eq_set (op aconv) (ps1, ps2)) gs (ps, c) | |
| 56 | then no_tac | |
| 57 | else (step_tac ctxt THEN_ALL_NEW intprover_tac ctxt ((ps, c) :: gs) (d + 1) lim) i | |
| 58 | end); | |
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 59 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 60 | in | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 61 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 62 | fun prover_tac ctxt opt_lim = | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 63 | SELECT_GOAL (DEEPEN (2, the_default 20 opt_lim) (intprover_tac ctxt [] 0) 4 1); | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 64 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 65 | end; | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 66 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 67 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 68 | (* method setup *) | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 69 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 70 | local | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 71 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 72 | val introN = "intro"; | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 73 | val elimN = "elim"; | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 74 | val destN = "dest"; | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 75 | |
| 58048 
aa6296d09e0e
more explicit Method.modifier with reported position;
 wenzelm parents: 
55627diff
changeset | 76 | fun modifier name kind kind' att pos = | 
| 36960 
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
 wenzelm parents: 
35625diff
changeset | 77 | Args.$$$ name |-- (kind >> K NONE || kind' |-- Parse.nat --| Args.colon >> SOME) | 
| 58048 
aa6296d09e0e
more explicit Method.modifier with reported position;
 wenzelm parents: 
55627diff
changeset | 78 | >> (fn arg => Method.modifier (att arg) pos); | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 79 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 80 | val modifiers = | 
| 64556 | 81 | [modifier destN Args.bang_colon Args.bang Context_Rules.dest_bang \<^here>, | 
| 82 | modifier destN Args.colon (Scan.succeed ()) Context_Rules.dest \<^here>, | |
| 83 | modifier elimN Args.bang_colon Args.bang Context_Rules.elim_bang \<^here>, | |
| 84 | modifier elimN Args.colon (Scan.succeed ()) Context_Rules.elim \<^here>, | |
| 85 | modifier introN Args.bang_colon Args.bang Context_Rules.intro_bang \<^here>, | |
| 86 | modifier introN Args.colon (Scan.succeed ()) Context_Rules.intro \<^here>, | |
| 87 | Args.del -- Args.colon >> K (Method.modifier Context_Rules.rule_del \<^here>)]; | |
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 88 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 89 | in | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 90 | |
| 31299 | 91 | fun method_setup name = | 
| 92 | Method.setup name | |
| 36960 
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
 wenzelm parents: 
35625diff
changeset | 93 | (Scan.lift (Scan.option Parse.nat) --| Method.sections modifiers >> | 
| 33554 | 94 | (fn opt_lim => fn ctxt => | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
52732diff
changeset | 95 | SIMPLE_METHOD' (Object_Logic.atomize_prems_tac ctxt THEN' prover_tac ctxt opt_lim))) | 
| 31299 | 96 | "intuitionistic proof search"; | 
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 97 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 98 | end; | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 99 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 100 | end; | 
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: diff
changeset | 101 |