1 (* Title: HOL/Prolog/prolog.ML |
1 (* Title: HOL/Prolog/prolog.ML |
2 Author: David von Oheimb (based on a lecture on Lambda Prolog by Nadathur) |
2 Author: David von Oheimb (based on a lecture on Lambda Prolog by Nadathur) |
3 *) |
3 *) |
4 |
4 |
5 Options.default_put_bool @{system_option show_main_goal} true; |
5 Options.default_put_bool \<^system_option>\<open>show_main_goal\<close> true; |
6 |
6 |
7 structure Prolog = |
7 structure Prolog = |
8 struct |
8 struct |
9 |
9 |
10 exception not_HOHH; |
10 exception not_HOHH; |
11 |
11 |
12 fun isD t = case t of |
12 fun isD t = case t of |
13 Const(@{const_name Trueprop},_)$t => isD t |
13 Const(\<^const_name>\<open>Trueprop\<close>,_)$t => isD t |
14 | Const(@{const_name HOL.conj} ,_)$l$r => isD l andalso isD r |
14 | Const(\<^const_name>\<open>HOL.conj\<close> ,_)$l$r => isD l andalso isD r |
15 | Const(@{const_name HOL.implies},_)$l$r => isG l andalso isD r |
15 | Const(\<^const_name>\<open>HOL.implies\<close>,_)$l$r => isG l andalso isD r |
16 | Const(@{const_name Pure.imp},_)$l$r => isG l andalso isD r |
16 | Const(\<^const_name>\<open>Pure.imp\<close>,_)$l$r => isG l andalso isD r |
17 | Const(@{const_name All},_)$Abs(s,_,t) => isD t |
17 | Const(\<^const_name>\<open>All\<close>,_)$Abs(s,_,t) => isD t |
18 | Const(@{const_name Pure.all},_)$Abs(s,_,t) => isD t |
18 | Const(\<^const_name>\<open>Pure.all\<close>,_)$Abs(s,_,t) => isD t |
19 | Const(@{const_name HOL.disj},_)$_$_ => false |
19 | Const(\<^const_name>\<open>HOL.disj\<close>,_)$_$_ => false |
20 | Const(@{const_name Ex} ,_)$_ => false |
20 | Const(\<^const_name>\<open>Ex\<close> ,_)$_ => false |
21 | Const(@{const_name Not},_)$_ => false |
21 | Const(\<^const_name>\<open>Not\<close>,_)$_ => false |
22 | Const(@{const_name True},_) => false |
22 | Const(\<^const_name>\<open>True\<close>,_) => false |
23 | Const(@{const_name False},_) => false |
23 | Const(\<^const_name>\<open>False\<close>,_) => false |
24 | l $ r => isD l |
24 | l $ r => isD l |
25 | Const _ (* rigid atom *) => true |
25 | Const _ (* rigid atom *) => true |
26 | Bound _ (* rigid atom *) => true |
26 | Bound _ (* rigid atom *) => true |
27 | Free _ (* rigid atom *) => true |
27 | Free _ (* rigid atom *) => true |
28 | _ (* flexible atom, |
28 | _ (* flexible atom, |
29 anything else *) => false |
29 anything else *) => false |
30 and |
30 and |
31 isG t = case t of |
31 isG t = case t of |
32 Const(@{const_name Trueprop},_)$t => isG t |
32 Const(\<^const_name>\<open>Trueprop\<close>,_)$t => isG t |
33 | Const(@{const_name HOL.conj} ,_)$l$r => isG l andalso isG r |
33 | Const(\<^const_name>\<open>HOL.conj\<close> ,_)$l$r => isG l andalso isG r |
34 | Const(@{const_name HOL.disj} ,_)$l$r => isG l andalso isG r |
34 | Const(\<^const_name>\<open>HOL.disj\<close> ,_)$l$r => isG l andalso isG r |
35 | Const(@{const_name HOL.implies},_)$l$r => isD l andalso isG r |
35 | Const(\<^const_name>\<open>HOL.implies\<close>,_)$l$r => isD l andalso isG r |
36 | Const(@{const_name Pure.imp},_)$l$r => isD l andalso isG r |
36 | Const(\<^const_name>\<open>Pure.imp\<close>,_)$l$r => isD l andalso isG r |
37 | Const(@{const_name All},_)$Abs(_,_,t) => isG t |
37 | Const(\<^const_name>\<open>All\<close>,_)$Abs(_,_,t) => isG t |
38 | Const(@{const_name Pure.all},_)$Abs(_,_,t) => isG t |
38 | Const(\<^const_name>\<open>Pure.all\<close>,_)$Abs(_,_,t) => isG t |
39 | Const(@{const_name Ex} ,_)$Abs(_,_,t) => isG t |
39 | Const(\<^const_name>\<open>Ex\<close> ,_)$Abs(_,_,t) => isG t |
40 | Const(@{const_name True},_) => true |
40 | Const(\<^const_name>\<open>True\<close>,_) => true |
41 | Const(@{const_name Not},_)$_ => false |
41 | Const(\<^const_name>\<open>Not\<close>,_)$_ => false |
42 | Const(@{const_name False},_) => false |
42 | Const(\<^const_name>\<open>False\<close>,_) => false |
43 | _ (* atom *) => true; |
43 | _ (* atom *) => true; |
44 |
44 |
45 val check_HOHH_tac1 = PRIMITIVE (fn thm => |
45 val check_HOHH_tac1 = PRIMITIVE (fn thm => |
46 if isG (Thm.concl_of thm) then thm else raise not_HOHH); |
46 if isG (Thm.concl_of thm) then thm else raise not_HOHH); |
47 val check_HOHH_tac2 = PRIMITIVE (fn thm => |
47 val check_HOHH_tac2 = PRIMITIVE (fn thm => |
50 then thm else raise not_HOHH); |
50 then thm else raise not_HOHH); |
51 |
51 |
52 fun atomizeD ctxt thm = |
52 fun atomizeD ctxt thm = |
53 let |
53 let |
54 fun at thm = case Thm.concl_of thm of |
54 fun at thm = case Thm.concl_of thm of |
55 _$(Const(@{const_name All} ,_)$Abs(s,_,_))=> |
55 _$(Const(\<^const_name>\<open>All\<close> ,_)$Abs(s,_,_))=> |
56 let val s' = if s="P" then "PP" else s in |
56 let val s' = if s="P" then "PP" else s in |
57 at(thm RS (Rule_Insts.read_instantiate ctxt [((("x", 0), Position.none), s')] [s'] spec)) |
57 at(thm RS (Rule_Insts.read_instantiate ctxt [((("x", 0), Position.none), s')] [s'] spec)) |
58 end |
58 end |
59 | _$(Const(@{const_name HOL.conj},_)$_$_) => at(thm RS conjunct1)@at(thm RS conjunct2) |
59 | _$(Const(\<^const_name>\<open>HOL.conj\<close>,_)$_$_) => at(thm RS conjunct1)@at(thm RS conjunct2) |
60 | _$(Const(@{const_name HOL.implies},_)$_$_) => at(thm RS mp) |
60 | _$(Const(\<^const_name>\<open>HOL.implies\<close>,_)$_$_) => at(thm RS mp) |
61 | _ => [thm] |
61 | _ => [thm] |
62 in map zero_var_indexes (at thm) end; |
62 in map zero_var_indexes (at thm) end; |
63 |
63 |
64 val atomize_ss = |
64 val atomize_ss = |
65 (empty_simpset @{context} |> Simplifier.set_mksimps (mksimps mksimps_pairs)) |
65 (empty_simpset \<^context> |> Simplifier.set_mksimps (mksimps mksimps_pairs)) |
66 addsimps [ |
66 addsimps [ |
67 @{thm all_conj_distrib}, (* "(! x. P x & Q x) = ((! x. P x) & (! x. Q x))" *) |
67 @{thm all_conj_distrib}, (* "(! x. P x & Q x) = ((! x. P x) & (! x. Q x))" *) |
68 @{thm imp_conjL} RS sym, (* "(D :- G1 :- G2) = (D :- G1 & G2)" *) |
68 @{thm imp_conjL} RS sym, (* "(D :- G1 :- G2) = (D :- G1 & G2)" *) |
69 @{thm imp_conjR}, (* "(D1 & D2 :- G) = ((D1 :- G) & (D2 :- G))" *) |
69 @{thm imp_conjR}, (* "(D1 & D2 :- G) = ((D1 :- G) & (D2 :- G))" *) |
70 @{thm imp_all}] (* "((!x. D) :- G) = (!x. D :- G)" *) |
70 @{thm imp_all}] (* "((!x. D) :- G) = (!x. D :- G)" *) |
74 (*val hyp_resolve_tac = Subgoal.FOCUS_PREMS (fn {prems, ...} => |
74 (*val hyp_resolve_tac = Subgoal.FOCUS_PREMS (fn {prems, ...} => |
75 resolve_tac (maps atomizeD prems) 1); |
75 resolve_tac (maps atomizeD prems) 1); |
76 -- is nice, but cannot instantiate unknowns in the assumptions *) |
76 -- is nice, but cannot instantiate unknowns in the assumptions *) |
77 fun hyp_resolve_tac ctxt = SUBGOAL (fn (subgoal, i) => |
77 fun hyp_resolve_tac ctxt = SUBGOAL (fn (subgoal, i) => |
78 let |
78 let |
79 fun ap (Const(@{const_name All},_)$Abs(_,_,t))=(case ap t of (k,a,t) => (k+1,a ,t)) |
79 fun ap (Const(\<^const_name>\<open>All\<close>,_)$Abs(_,_,t))=(case ap t of (k,a,t) => (k+1,a ,t)) |
80 | ap (Const(@{const_name HOL.implies},_)$_$t) =(case ap t of (k,_,t) => (k,true ,t)) |
80 | ap (Const(\<^const_name>\<open>HOL.implies\<close>,_)$_$t) =(case ap t of (k,_,t) => (k,true ,t)) |
81 | ap t = (0,false,t); |
81 | ap t = (0,false,t); |
82 (* |
82 (* |
83 fun rep_goal (Const (@{const_name Pure.all},_)$Abs (_,_,t)) = rep_goal t |
83 fun rep_goal (Const (@{const_name Pure.all},_)$Abs (_,_,t)) = rep_goal t |
84 | rep_goal (Const (@{const_name Pure.imp},_)$s$t) = |
84 | rep_goal (Const (@{const_name Pure.imp},_)$s$t) = |
85 (case rep_goal t of (l,t) => (s::l,t)) |
85 (case rep_goal t of (l,t) => (s::l,t)) |