CookBook/Package/simple_inductive_package.ML
author boehmes
Wed, 25 Feb 2009 10:10:23 +0100
changeset 139 ed1eb9cb2533
parent 129 e0d368a45537
child 159 64fa844064fa
permissions -rw-r--r--
Improved conversion subsection.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     1
(* @chunk SIMPLE_INDUCTIVE_PACKAGE *)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     2
signature SIMPLE_INDUCTIVE_PACKAGE =
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     3
sig
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     4
  val add_inductive_i:
76
b99fa5fa63fc adapted to changes in binding.ML
Christian Urban <urbanc@in.tum.de>
parents: 55
diff changeset
     5
    ((Binding.binding * typ) * mixfix) list ->  (*{predicates}*)
b99fa5fa63fc adapted to changes in binding.ML
Christian Urban <urbanc@in.tum.de>
parents: 55
diff changeset
     6
    (Binding.binding * typ) list ->  (*{parameters}*)
121
26e5b41faa74 polishing
Christian Urban <urbanc@in.tum.de>
parents: 120
diff changeset
     7
    (Attrib.binding * term) list ->  (*{rules}*)
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
     8
    local_theory -> local_theory
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     9
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    10
  val add_inductive:
76
b99fa5fa63fc adapted to changes in binding.ML
Christian Urban <urbanc@in.tum.de>
parents: 55
diff changeset
    11
    (Binding.binding * string option * mixfix) list ->  (*{predicates}*)
b99fa5fa63fc adapted to changes in binding.ML
Christian Urban <urbanc@in.tum.de>
parents: 55
diff changeset
    12
    (Binding.binding * string option * mixfix) list ->  (*{parameters}*)
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    13
    (Attrib.binding * string) list ->  (*{rules}*)
102
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
    14
    local_theory -> local_theory
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    15
end;
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    16
(* @end *)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    17
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    18
structure SimpleInductivePackage: SIMPLE_INDUCTIVE_PACKAGE =
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    19
struct
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    20
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    21
fun mk_all x P = HOLogic.all_const (fastype_of x) $ lambda x P 
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    22
118
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    23
(* @chunk definitions_aux *) 
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    24
fun definitions_aux s ((binding, syn), (attr, trm)) lthy =
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    25
let 
118
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    26
  val ((_, (_, thm)), lthy) = 
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    27
                LocalTheory.define s ((binding, syn), (attr, trm)) lthy
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    28
in 
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    29
  (thm, lthy) 
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    30
end
118
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    31
(* @end *)
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    32
118
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    33
(* @chunk definitions *) 
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    34
fun definitions params rules preds preds' Tss lthy =
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    35
let
118
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    36
  val thy = ProofContext.theory_of lthy
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    37
  val rules' = map (ObjectLogic.atomize_term thy) rules
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    38
in
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    39
  fold_map (fn ((((R, _), syn), pred), Ts) =>
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    40
    let 
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    41
      val zs = map Free (Variable.variant_frees lthy rules' (map (pair "z") Ts))
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    42
        
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    43
      val t0 = list_comb (pred, zs);
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    44
      val t1 = fold_rev (curry HOLogic.mk_imp) rules' t0;
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    45
      val t2 = fold_rev mk_all preds' t1;      
118
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    46
      val t3 = fold_rev lambda (params @ zs) t2;
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    47
    in
118
5f003fdf2653 polished and added more material to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 116
diff changeset
    48
      definitions_aux Thm.internalK ((R, syn), (Attrib.empty_binding, t3))
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    49
    end) (preds ~~ preds' ~~ Tss) lthy
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    50
end
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    51
(* @end *)
102
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
    52
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    53
fun inst_spec ct = 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    54
  Drule.instantiate' [SOME (ctyp_of_term ct)] [NONE, SOME ct] @{thm spec};
102
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
    55
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
    56
val all_elims = fold (fn ct => fn th => th RS inst_spec ct);
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
    57
val imp_elims = fold (fn th => fn th' => [th', th] MRS @{thm mp});
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
    58
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    59
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    60
(* @chunk induction_rules *)
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    61
fun INDUCTION rules preds' Tss defs lthy1 lthy2 =
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    62
let
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    63
  val (Pnames, lthy3) = Variable.variant_fixes (replicate (length preds') "P") lthy2;
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    64
  val Ps = map (fn (s, Ts) => Free (s, Ts ---> HOLogic.boolT)) (Pnames ~~ Tss);
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    65
  val cPs = map (cterm_of (ProofContext.theory_of lthy3)) Ps;
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    66
  val rules'' = map (subst_free (preds' ~~ Ps)) rules;
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    67
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    68
  fun prove_indrule ((R, P), Ts)  =
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    69
  let
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    70
    val (znames, lthy4) = Variable.variant_fixes (replicate (length Ts) "z") lthy3;
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    71
    val zs = map Free (znames ~~ Ts)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    72
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    73
    val prem = HOLogic.mk_Trueprop (list_comb (R, zs))
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    74
    val goal = Logic.list_implies (rules'', HOLogic.mk_Trueprop (list_comb (P, zs)))
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    75
  in
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    76
    Goal.prove lthy4 [] [prem] goal
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    77
      (fn {prems, ...} => EVERY1
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    78
         ([ObjectLogic.full_atomize_tac,
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    79
           cut_facts_tac prems,
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    80
           K (rewrite_goals_tac defs)] @
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    81
          map (fn ct => dtac (inst_spec ct)) cPs @
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    82
          [assume_tac])) |>
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    83
       singleton (ProofContext.export lthy4 lthy1)
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    84
  end;
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    85
in
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    86
      map prove_indrule (preds' ~~ Ps ~~ Tss)
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
    87
  end
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    88
(* @end *)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    89
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    90
(* @chunk intro_rules *) 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    91
fun INTROS rules preds' defs lthy1 lthy2 = 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    92
let
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    93
  fun prove_intro (i, r) =
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    94
      Goal.prove lthy2 [] [] r
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    95
        (fn {prems, context = ctxt} => EVERY
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    96
           [ObjectLogic.rulify_tac 1,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    97
            rewrite_goals_tac defs,
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    98
            REPEAT (resolve_tac [@{thm allI},@{thm impI}] 1),
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    99
            SUBPROOF (fn {params, prems, context = ctxt', ...} =>
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   100
              let
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   101
                val (prems1, prems2) = chop (length prems - length rules) prems;
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   102
                val (params1, params2) = chop (length params - length preds') params;
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   103
              in
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   104
                rtac (ObjectLogic.rulify (all_elims params1 (nth prems2 i))) 1 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   105
                THEN
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   106
                EVERY1 (map (fn prem =>
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   107
                  SUBPROOF (fn {prems = prems', concl, ...} =>
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   108
                    let
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   109
          
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   110
                      val prem' = prems' MRS prem;
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   111
                      val prem'' = case prop_of prem' of
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   112
                          _ $ (Const (@{const_name All}, _) $ _) =>
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   113
                            prem' |> all_elims params2 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   114
                                  |> imp_elims prems2
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   115
                        | _ => prem';
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   116
                    in rtac prem'' 1 end) ctxt') prems1)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   117
              end) ctxt 1]) |>
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   118
      singleton (ProofContext.export lthy2 lthy1)
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   119
in
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   120
  map_index prove_intro rules
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   121
end
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   122
(* @end *)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   123
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   124
(* @chunk add_inductive_i *)
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   125
fun add_inductive_i preds params specs lthy =
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   126
let
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   127
  val params' = map (fn (p, T) => Free (Binding.base_name p, T)) params;
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   128
  val preds' = map (fn ((R, T), _) => list_comb (Free (Binding.base_name R, T), params')) preds;
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   129
  val Tss = map (binder_types o fastype_of) preds';   
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   130
  val (ass,rules) = split_list specs;    
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   131
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   132
  val (defs, lthy1) = definitions params' rules preds preds' Tss lthy
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   133
  val (_, lthy2) = Variable.add_fixes (map (Binding.base_name o fst) params) lthy1;
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   134
      
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   135
  val inducts = INDUCTION rules preds' Tss defs lthy1 lthy2
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   136
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   137
  val intros = INTROS rules preds' defs lthy1 lthy2
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   138
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   139
  val mut_name = space_implode "_" (map (Binding.base_name o fst o fst) preds);
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   140
  val case_names = map (Binding.base_name o fst o fst) specs
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   141
in
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   142
    lthy1 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   143
    |> LocalTheory.notes Thm.theoremK (map (fn (((a, atts), _), th) =>
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   144
        ((Binding.qualify mut_name a, atts), [([th], [])])) (specs ~~ intros)) 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   145
    |-> (fn intross => LocalTheory.note Thm.theoremK
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   146
         ((Binding.qualify mut_name (Binding.name "intros"), []), maps snd intross)) 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   147
    |>> snd 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   148
    ||>> (LocalTheory.notes Thm.theoremK (map (fn (((R, _), _), th) =>
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   149
         ((Binding.qualify (Binding.base_name R) (Binding.name "induct"),
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   150
          [Attrib.internal (K (RuleCases.case_names case_names)),
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   151
           Attrib.internal (K (RuleCases.consumes 1)),
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   152
           Attrib.internal (K (Induct.induct_pred ""))]), [([th], [])]))
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   153
          (preds ~~ inducts)) #>> maps snd) 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   154
    |> snd
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   155
end
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   156
(* @end *)
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   157
120
c39f83d8daeb some polishing; split up the file External Solver into two
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   158
(* @chunk read_specification *)
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   159
fun read_specification' vars specs lthy =
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   160
let 
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   161
  val specs' = map (fn (a, s) => [(a, [s])]) specs
120
c39f83d8daeb some polishing; split up the file External Solver into two
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   162
  val ((varst, specst), _) = 
c39f83d8daeb some polishing; split up the file External Solver into two
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   163
                   Specification.read_specification vars specs' lthy
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   164
  val specst' = map (apsnd the_single) specst
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   165
in   
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   166
  (varst, specst')
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   167
end 
120
c39f83d8daeb some polishing; split up the file External Solver into two
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   168
(* @end *)
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   169
120
c39f83d8daeb some polishing; split up the file External Solver into two
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   170
(* @chunk add_inductive *)
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   171
fun add_inductive preds params specs lthy =
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   172
let
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   173
  val (vars, specs') = read_specification' (preds @ params) specs lthy;
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   174
  val (preds', params') = chop (length preds) vars;
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   175
  val params'' = map fst params'
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   176
in
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   177
  add_inductive_i preds' params'' specs' lthy
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   178
end;
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   179
(* @end *)
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   180
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   181
(* @chunk parser *)
120
c39f83d8daeb some polishing; split up the file External Solver into two
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   182
val spec_parser = 
102
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
   183
   OuterParse.opt_target --
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
   184
   OuterParse.fixes -- 
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
   185
   OuterParse.for_fixes --
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
   186
   Scan.optional 
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   187
     (OuterParse.$$$ "where" |--
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   188
        OuterParse.!!! 
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   189
          (OuterParse.enum1 "|" 
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 121
diff changeset
   190
             (SpecParse.opt_thm_name ":" -- OuterParse.prop))) []
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   191
(* @end *)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   192
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   193
(* @chunk syntax *)
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   194
val specification =
120
c39f83d8daeb some polishing; split up the file External Solver into two
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   195
  spec_parser >>
102
5e309df58557 general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents: 91
diff changeset
   196
    (fn (((loc, preds), params), specs) =>
110
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   197
      Toplevel.local_theory loc (add_inductive preds params specs))
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   198
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   199
val _ = OuterSyntax.command "simple_inductive" "define inductive predicates"
129
e0d368a45537 started a section about simprocs
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   200
          OuterKeyword.thy_decl specification
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   201
(* @end *)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   202
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   203
end;