src/Provers/ind.ML
author wenzelm
Thu, 22 Apr 2004 10:52:32 +0200
changeset 14643 130076a81b84
parent 4452 b2ee34200dab
child 14772 c52060b69a8c
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	Provers/ind
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Tobias Nipkow
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Generic induction package -- for use with simplifier
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
signature IND_DATA =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
  sig
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
  val spec: thm (* All(?P) ==> ?P(?a) *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
signature IND =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
  sig
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
  val all_frees_tac: string -> int -> tactic
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
  val ALL_IND_TAC: thm -> (int -> tactic) -> (int -> tactic)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
  val IND_TAC: thm -> (int -> tactic) -> string -> (int -> tactic)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
functor InductionFun(Ind_Data: IND_DATA):IND =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
local open Ind_Data in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
val _$(_$Var(a_ixname,aT)) = concl_of spec;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
val a_name = implode(tl(explode(Syntax.string_of_vname a_ixname)));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
fun add_term_frees tsig =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
let fun add(tm, vars) = case tm of
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
	Free(v,T) => if Type.typ_instance(tsig,T,aT) then v ins vars
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
		     else vars
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
      | Abs (_,_,body) => add(body,vars)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
      | rator$rand => add(rator, add(rand, vars))
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
      | _ => vars
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
in add end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
fun qnt_tac i = fn (tac,var) => tac THEN res_inst_tac [(a_name,var)] spec i;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
(*Generalizes over all free variables, with the named var outermost.*)
1512
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    43
fun all_frees_tac (var:string) i thm = 
14643
wenzelm
parents: 4452
diff changeset
    44
    let val tsig = Sign.tsig_of (Thm.sign_of_thm thm);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
        val frees = add_term_frees tsig (nth_elem(i-1,prems_of thm),[var]);
4452
b2ee34200dab adapted to new sort function;
wenzelm
parents: 1512
diff changeset
    46
        val frees' = sort (rev_order o string_ord) (frees \ var) @ [var]
1512
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    47
    in foldl (qnt_tac i) (all_tac,frees') thm end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
fun REPEAT_SIMP_TAC simp_tac n i =
1512
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    50
let fun repeat thm = 
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    51
        (COND (has_fewer_prems n) all_tac
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    52
	 let val k = nprems_of thm
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    53
	 in simp_tac i THEN COND (has_fewer_prems k) repeat all_tac end)
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    54
	thm
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    55
in repeat end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
1512
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    57
fun ALL_IND_TAC sch simp_tac i thm = 
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    58
	(resolve_tac [sch] i THEN
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 0
diff changeset
    59
	 REPEAT_SIMP_TAC simp_tac (nprems_of thm) i) thm;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
fun IND_TAC sch simp_tac var =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
	all_frees_tac var THEN' ALL_IND_TAC sch simp_tac;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
end
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
end;