src/HOL/Tools/function_package/inductive_wrap.ML
author krauss
Mon, 22 Jan 2007 17:29:43 +0100
changeset 22166 0a50d4db234a
parent 21365 4ee8e2702241
child 22612 1f017e6a0395
permissions -rw-r--r--
* Preliminary implementation of tail recursion * Clarified internal interfaces
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
     1
(*  Title:      HOL/Tools/function_package/inductive_wrap.ML
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
     2
    ID:         $Id$
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
     3
    Author:     Alexander Krauss, TU Muenchen
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
     4
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
     5
21237
b803f9870e97 untabified
krauss
parents: 21105
diff changeset
     6
A wrapper around the inductive package, restoring the quantifiers in
b803f9870e97 untabified
krauss
parents: 21105
diff changeset
     7
the introduction and elimination rules.
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
     8
*)
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
     9
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    10
signature FUNDEF_INDUCTIVE_WRAP =
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    11
sig
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    12
  val inductive_def :  term list 
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    13
                       -> ((bstring * typ) * mixfix) * local_theory
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21365
diff changeset
    14
                       -> thm list * (term * thm * thm * local_theory)
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    15
end
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    16
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    17
structure FundefInductiveWrap =
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    18
struct
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    19
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    20
open FundefLib
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    21
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    22
fun requantify ctxt lfix (qs, t) thm =
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    23
    let
21105
9e812f9f3a97 Removed debugging output
krauss
parents: 21051
diff changeset
    24
      val thy = theory_of_thm thm
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    25
      val frees = frees_in_term ctxt t 
21237
b803f9870e97 untabified
krauss
parents: 21105
diff changeset
    26
                  |> remove (op =) lfix
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    27
      val vars = Term.add_vars (prop_of thm) [] |> rev
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    28
                 
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    29
      val varmap = frees ~~ vars
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    30
    in
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    31
      fold_rev (fn Free (n, T) => 
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    32
                   forall_intr_rename (n, cterm_of thy (Var (the_default (("",0), T) (AList.lookup (op =) varmap (n, T))))))
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    33
               qs
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    34
               thm
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    35
    end             
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    36
  
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    37
  
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    38
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    39
fun inductive_def defs (((R, T), mixfix), lthy) =
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    40
    let
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    41
      val qdefs = map dest_all_all defs
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    42
                  
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21365
diff changeset
    43
      val ({intrs = intrs_gen, elims = [elim_gen], preds = [ Rdef ], induct, ...}, lthy) =
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    44
          InductivePackage.add_inductive_i true (*verbose*)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    45
                                           "" (* no altname *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    46
                                           false (* no coind *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    47
                                           false (* elims, please *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    48
                                           false (* induction thm please *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    49
                                           [(R, SOME T, NoSyn)] (* the relation *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    50
                                           [] (* no parameters *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    51
                                           (map (fn t => (("", []), t)) defs) (* the intros *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    52
                                           [] (* no special monos *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    53
                                           lthy
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    54
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    55
      val thy = ProofContext.theory_of lthy
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    56
                
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    57
      fun inst qdef intr_gen =
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    58
          intr_gen
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    59
            |> Thm.freezeT
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    60
            |> requantify lthy (R, T) qdef 
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    61
          
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    62
      val intrs = map2 inst qdefs intrs_gen
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    63
                  
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    64
      val elim = elim_gen
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    65
                   |> Thm.freezeT
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    66
                   |> forall_intr_vars (* FIXME... *)
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    67
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    68
      val Rdef_real = prop_of (Thm.freezeT elim_gen)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    69
                       |> Logic.dest_implies |> fst
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    70
                       |> Term.strip_comb |> snd |> hd (* Trueprop *)
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    71
                       |> Term.strip_comb |> fst
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    72
    in
22166
0a50d4db234a * Preliminary implementation of tail recursion
krauss
parents: 21365
diff changeset
    73
      (intrs, (Rdef_real, elim, induct, lthy))
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    74
    end
21051
c49467a9c1e1 Switched function package to use the new package for inductive predicates.
krauss
parents: 21025
diff changeset
    75
    
20523
36a59e5d0039 Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
diff changeset
    76
end