| author | haftmann | 
| Fri, 03 Nov 2006 14:22:38 +0100 | |
| changeset 21152 | e97992896170 | 
| parent 21105 | 9e812f9f3a97 | 
| child 21237 | b803f9870e97 | 
| permissions | -rw-r--r-- | 
| 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 | |
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 6 | This is a wrapper around the inductive package which corrects some of its | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 7 | slightly annoying behaviours and makes the whole business more controllable. | 
| 
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 | Specifically: | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 10 | |
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 11 | - Following newer Isar conventions, declaration and definition are done in one step | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 12 | |
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 13 | - The specification is expected in fully quantified form. This allows the client to | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 14 | control the variable order. The variables will appear in the result in the same order. | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 15 | This is especially relevant for the elimination rule, where the order usually *does* matter. | 
| 
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 | |
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 18 | All this will probably become obsolete in the near future, when the new "predicate" package | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 19 | is in place. | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 20 | |
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 21 | *) | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 22 | |
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 23 | signature FUNDEF_INDUCTIVE_WRAP = | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 24 | sig | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 25 | val inductive_def : term list | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 26 | -> ((bstring * typ) * mixfix) * local_theory | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 27 | -> thm list * (term * thm * local_theory) | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 28 | end | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 29 | |
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 30 | structure FundefInductiveWrap = | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 31 | struct | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 32 | |
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 33 | open FundefLib | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 34 | |
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 35 | fun requantify ctxt lfix (qs, t) thm = | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 36 | let | 
| 21105 | 37 | val thy = theory_of_thm thm | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 38 | val frees = frees_in_term ctxt t | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 39 | |> remove (op =) lfix | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 40 | val vars = Term.add_vars (prop_of thm) [] |> rev | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 41 | |
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 42 | val varmap = frees ~~ vars | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 43 | in | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 44 | fold_rev (fn Free (n, T) => | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 45 |                    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: 
21025diff
changeset | 46 | qs | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 47 | thm | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 48 | end | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 49 | |
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 50 | |
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 51 | |
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 52 | 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 | 53 | let | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 54 | val qdefs = map dest_all_all defs | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 55 | |
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 56 |       val (lthy, {intrs = intrs_gen, elims = [elim_gen], preds = [ Rdef ], ...}) =
 | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 57 | InductivePackage.add_inductive_i true (*verbose*) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 58 | "" (* no altname *) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 59 | false (* no coind *) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 60 | false (* elims, please *) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 61 | false (* induction thm please *) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 62 | [(R, SOME T, NoSyn)] (* the relation *) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 63 | [] (* no parameters *) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 64 |                                            (map (fn t => (("", []), t)) defs) (* the intros *)
 | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 65 | [] (* no special monos *) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 66 | lthy | 
| 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: 
21025diff
changeset | 68 | val thy = ProofContext.theory_of lthy | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 69 | |
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 70 | fun inst qdef intr_gen = | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 71 | intr_gen | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 72 | |> Thm.freezeT | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 73 | |> requantify lthy (R, T) qdef | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 74 | |
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 75 | val intrs = map2 inst qdefs intrs_gen | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 76 | |
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 77 | val elim = elim_gen | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 78 | |> Thm.freezeT | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 79 | |> forall_intr_vars (* FIXME... *) | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 80 | |
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 81 | val Rdef_real = prop_of (Thm.freezeT elim_gen) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 82 | |> Logic.dest_implies |> fst | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 83 | |> Term.strip_comb |> snd |> hd (* Trueprop *) | 
| 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 84 | |> Term.strip_comb |> fst | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 85 | in | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 86 | (intrs, (Rdef_real, elim, lthy)) | 
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 87 | end | 
| 21051 
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
 krauss parents: 
21025diff
changeset | 88 | |
| 20523 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 89 | end | 
| 
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
 krauss parents: diff
changeset | 90 |