src/HOL/Prolog/HOHH.ML
changeset 21425 c11ab38b78a7
parent 21424 5295ffa18285
child 21426 87ac12bed1ab
     1.1 --- a/src/HOL/Prolog/HOHH.ML	Mon Nov 20 11:51:10 2006 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,123 +0,0 @@
     1.4 -(*  Title:    HOL/Prolog/HOHH.ML
     1.5 -    ID:       $Id$
     1.6 -    Author:   David von Oheimb (based on a lecture on Lambda Prolog by Nadathur)
     1.7 -*)
     1.8 -
     1.9 -exception not_HOHH;
    1.10 -
    1.11 -fun isD t = case t of
    1.12 -    Const("Trueprop",_)$t     => isD t
    1.13 -  | Const("op &"  ,_)$l$r     => isD l andalso isD r
    1.14 -  | Const("op -->",_)$l$r     => isG l andalso isD r
    1.15 -  | Const(   "==>",_)$l$r     => isG l andalso isD r
    1.16 -  | Const("All",_)$Abs(s,_,t) => isD t
    1.17 -  | Const("all",_)$Abs(s,_,t) => isD t
    1.18 -  | Const("op |",_)$_$_       => false
    1.19 -  | Const("Ex" ,_)$_          => false
    1.20 -  | Const("not",_)$_          => false
    1.21 -  | Const("True",_)           => false
    1.22 -  | Const("False",_)          => false
    1.23 -  | l $ r                     => isD l
    1.24 -  | Const _ (* rigid atom *)  => true
    1.25 -  | Bound _ (* rigid atom *)  => true
    1.26 -  | Free  _ (* rigid atom *)  => true
    1.27 -  | _    (* flexible atom,
    1.28 -            anything else *)  => false
    1.29 -and
    1.30 -    isG t = case t of
    1.31 -    Const("Trueprop",_)$t     => isG t
    1.32 -  | Const("op &"  ,_)$l$r     => isG l andalso isG r
    1.33 -  | Const("op |"  ,_)$l$r     => isG l andalso isG r
    1.34 -  | Const("op -->",_)$l$r     => isD l andalso isG r
    1.35 -  | Const(   "==>",_)$l$r     => isD l andalso isG r
    1.36 -  | Const("All",_)$Abs(_,_,t) => isG t
    1.37 -  | Const("all",_)$Abs(_,_,t) => isG t
    1.38 -  | Const("Ex" ,_)$Abs(_,_,t) => isG t
    1.39 -  | Const("True",_)           => true
    1.40 -  | Const("not",_)$_          => false
    1.41 -  | Const("False",_)          => false
    1.42 -  | _ (* atom *)              => true;
    1.43 -
    1.44 -val check_HOHH_tac1 = PRIMITIVE (fn thm =>
    1.45 -        if isG (concl_of thm) then thm else raise not_HOHH);
    1.46 -val check_HOHH_tac2 = PRIMITIVE (fn thm =>
    1.47 -        if forall isG (prems_of thm) then thm else raise not_HOHH);
    1.48 -fun check_HOHH thm  = (if isD (concl_of thm) andalso forall isG (prems_of thm)
    1.49 -                        then thm else raise not_HOHH);
    1.50 -
    1.51 -fun atomizeD thm = let
    1.52 -    fun at  thm = case concl_of thm of
    1.53 -      _$(Const("All" ,_)$Abs(s,_,_))=> at(thm RS (read_instantiate [("x",
    1.54 -                                        "?"^(if s="P" then "PP" else s))] spec))
    1.55 -    | _$(Const("op &",_)$_$_)       => at(thm RS conjunct1)@at(thm RS conjunct2)
    1.56 -    | _$(Const("op -->",_)$_$_)     => at(thm RS mp)
    1.57 -    | _                             => [thm]
    1.58 -in map zero_var_indexes (at thm) end;
    1.59 -
    1.60 -val atomize_ss =
    1.61 -  Simplifier.theory_context (the_context ()) empty_ss
    1.62 -  setmksimps (mksimps mksimps_pairs)
    1.63 -  addsimps [
    1.64 -        all_conj_distrib, (* "(! x. P x & Q x) = ((! x. P x) & (! x. Q x))" *)
    1.65 -        imp_conjL RS sym, (* "(D :- G1 :- G2) = (D :- G1 & G2)" *)
    1.66 -        imp_conjR,        (* "(D1 & D2 :- G) = ((D1 :- G) & (D2 :- G))" *)
    1.67 -        imp_all];         (* "((!x. D) :- G) = (!x. D :- G)" *)
    1.68 -
    1.69 -(*val hyp_resolve_tac = METAHYPS (fn prems =>
    1.70 -                                  resolve_tac (List.concat (map atomizeD prems)) 1);
    1.71 -  -- is nice, but cannot instantiate unknowns in the assumptions *)
    1.72 -fun hyp_resolve_tac i st = let
    1.73 -        fun ap (Const("All",_)$Abs(_,_,t))=(case ap t of (k,a,t) => (k+1,a  ,t))
    1.74 -        |   ap (Const("op -->",_)$_$t)    =(case ap t of (k,_,t) => (k,true ,t))
    1.75 -        |   ap t                          =                         (0,false,t);
    1.76 -(*
    1.77 -        fun rep_goal (Const ("all",_)$Abs (_,_,t)) = rep_goal t
    1.78 -        |   rep_goal (Const ("==>",_)$s$t)         =
    1.79 -                        (case rep_goal t of (l,t) => (s::l,t))
    1.80 -        |   rep_goal t                             = ([]  ,t);
    1.81 -        val (prems, Const("Trueprop", _)$concl) = rep_goal
    1.82 -                                                (#3(dest_state (st,i)));
    1.83 -*)
    1.84 -        val subgoal = #3(dest_state (st,i));
    1.85 -        val prems = Logic.strip_assums_hyp subgoal;
    1.86 -        val concl = HOLogic.dest_Trueprop (Logic.strip_assums_concl subgoal);
    1.87 -        fun drot_tac k i = DETERM (rotate_tac k i);
    1.88 -        fun spec_tac 0 i = all_tac
    1.89 -        |   spec_tac k i = EVERY' [dtac spec, drot_tac ~1, spec_tac (k-1)] i;
    1.90 -        fun dup_spec_tac k i = if k = 0 then all_tac else EVERY'
    1.91 -                      [DETERM o (etac all_dupE), drot_tac ~2, spec_tac (k-1)] i;
    1.92 -        fun same_head _ (Const (x,_)) (Const (y,_)) = x = y
    1.93 -        |   same_head k (s$_)         (t$_)         = same_head k s t
    1.94 -        |   same_head k (Bound i)     (Bound j)     = i = j + k
    1.95 -        |   same_head _ _             _             = true;
    1.96 -        fun mapn f n []      = []
    1.97 -        |   mapn f n (x::xs) = f n x::mapn f (n+1) xs;
    1.98 -        fun pres_tac (k,arrow,t) n i = drot_tac n i THEN (
    1.99 -                if same_head k t concl
   1.100 -                then dup_spec_tac k i THEN
   1.101 -                     (if arrow then etac mp i THEN drot_tac (~n) i else atac i)
   1.102 -                else no_tac);
   1.103 -        val ptacs = mapn (fn n => fn t =>
   1.104 -                          pres_tac (ap (HOLogic.dest_Trueprop t)) n i) 0 prems;
   1.105 -        in Library.foldl (op APPEND) (no_tac, ptacs) st end;
   1.106 -
   1.107 -fun ptac prog = let
   1.108 -  val proga = List.concat (map atomizeD prog)                   (* atomize the prog *)
   1.109 -  in    (REPEAT_DETERM1 o FIRST' [
   1.110 -                rtac TrueI,                     (* "True" *)
   1.111 -                rtac conjI,                     (* "[| P; Q |] ==> P & Q" *)
   1.112 -                rtac allI,                      (* "(!!x. P x) ==> ! x. P x" *)
   1.113 -                rtac exI,                       (* "P x ==> ? x. P x" *)
   1.114 -                rtac impI THEN'                 (* "(P ==> Q) ==> P --> Q" *)
   1.115 -                  asm_full_simp_tac atomize_ss THEN'    (* atomize the asms *)
   1.116 -                  (REPEAT_DETERM o (etac conjE))        (* split the asms *)
   1.117 -                ])
   1.118 -        ORELSE' resolve_tac [disjI1,disjI2]     (* "P ==> P | Q","Q ==> P | Q"*)
   1.119 -        ORELSE' ((resolve_tac proga APPEND' hyp_resolve_tac)
   1.120 -                 THEN' (fn _ => check_HOHH_tac2))
   1.121 -end;
   1.122 -
   1.123 -fun prolog_tac prog = check_HOHH_tac1 THEN
   1.124 -                      DEPTH_SOLVE (ptac (map check_HOHH prog) 1);
   1.125 -
   1.126 -val prog_HOHH = [];