CookBook/Package/simple_inductive_package.ML
author Christian Urban <urbanc@in.tum.de>
Sat, 14 Feb 2009 00:11:50 +0000
changeset 116 c9ff326e3ce5
parent 111 3798baeee55f
child 118 5f003fdf2653
permissions -rw-r--r--
more changes to the package chapter
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}*)
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
     7
    ((Binding.binding * Attrib.src list) * term) list ->  (*{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
     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
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    23
(* @chunk definitions *) 
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    24
fun define_aux s ((binding, syn), (attr, trm)) lthy =
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    25
let 
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    26
  val ((_, (_ , thm)), lthy) = LocalTheory.define s ((binding, syn), (attr, trm)) lthy
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    27
in 
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    28
  (thm, lthy) 
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    29
end
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    30
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    31
fun DEFINITION params' rules preds preds' Tss lthy =
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    32
let
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    33
  val rules' = map (ObjectLogic.atomize_term (ProofContext.theory_of lthy)) rules
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    34
in
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    35
  fold_map (fn ((((R, _), syn), pred), Ts) =>
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    36
    let 
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    37
      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
    38
        
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    39
      val t0 = list_comb (pred, zs);
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    40
      val t1 = fold_rev (curry HOLogic.mk_imp) rules' t0;
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    41
      val t2 = fold_rev mk_all preds' t1;      
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    42
      val t3 = fold_rev lambda (params' @ zs) t2;
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    43
    in
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    44
      define_aux Thm.internalK ((R, syn), (Attrib.empty_binding, t3))
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    45
    end) (preds ~~ preds' ~~ Tss) lthy
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    46
end
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    47
(* @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
    48
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
    49
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
    50
  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
    51
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
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
    53
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
    54
111
3798baeee55f rearranged some functions
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    55
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
    56
(* @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
    57
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
    58
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
    59
    val (Pnames, lthy3) = Variable.variant_fixes (replicate (length preds') "P") 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
    60
    val Ps = map (fn (s, Ts) => Free (s, Ts ---> HOLogic.boolT)) (Pnames ~~ Tss);
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
    val cPs = map (cterm_of (ProofContext.theory_of lthy3)) Ps;
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
    val rules'' = map (subst_free (preds' ~~ Ps)) rules;
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    63
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
    64
    fun prove_indrule ((R, P), Ts)  =
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    65
      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
    66
        val (znames, lthy4) = Variable.variant_fixes (replicate (length Ts) "z") lthy3;
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    67
        val zs = map Free (znames ~~ Ts)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    68
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
    69
        val prem = HOLogic.mk_Trueprop (list_comb (R, zs))
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    70
        val goal = Logic.list_implies (rules'', HOLogic.mk_Trueprop (list_comb (P, zs)))
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    71
      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
    72
        Goal.prove lthy4 [] [prem] goal
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    73
          (fn {prems, ...} => EVERY1
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    74
             ([ObjectLogic.full_atomize_tac,
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    75
               cut_facts_tac 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
    76
               K (rewrite_goals_tac defs)] @
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    77
              map (fn ct => dtac (inst_spec ct)) cPs @
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    78
              [assume_tac])) |>
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    79
           singleton (ProofContext.export lthy4 lthy1)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    80
      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
    81
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
    82
  map prove_indrule (preds' ~~ Ps ~~ Tss)
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
    83
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
    84
(* @end *)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    85
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
    86
(* @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
    87
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
    88
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
    89
  fun prove_intro (i, r) =
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    90
      Goal.prove lthy2 [] [] r
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    91
        (fn {prems, context = ctxt} => EVERY
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    92
           [ObjectLogic.rulify_tac 1,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    93
            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
    94
            REPEAT (resolve_tac [@{thm allI},@{thm impI}] 1),
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    95
            SUBPROOF (fn {params, prems, context = ctxt', ...} =>
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    96
              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
    97
                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
    98
                val (params1, params2) = chop (length params - length preds') params;
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    99
              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
   100
                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
   101
                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
   102
                EVERY1 (map (fn prem =>
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   103
                  SUBPROOF (fn {prems = prems', concl, ...} =>
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   104
                    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
   105
          
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   106
                      val prem' = prems' MRS prem;
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   107
                      val prem'' = case prop_of prem' of
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   108
                          _ $ (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
   109
                            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
   110
                                  |> 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
   111
                        | _ => 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
   112
                    in rtac prem'' 1 end) ctxt') prems1)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   113
              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
   114
      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
   115
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
   116
  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
   117
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
   118
(* @end *)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   119
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
   120
(* @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
   121
fun 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
   122
  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
   123
    val params' = map (fn (p, T) => Free (Binding.base_name p, T)) 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
   124
    val preds' = map (fn ((R, T), _) => list_comb (Free (Binding.base_name R, T), params')) preds;
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
    val Tss = map (binder_types o fastype_of) preds';   
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   126
    val (ass,rules) = split_list specs;    
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   127
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
   128
    val (defs, lthy1) = DEFINITION params' rules preds preds' Tss 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
   129
    val (_, lthy2) = Variable.add_fixes (map (Binding.base_name o fst) params) 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
   130
      
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   131
    val inducts = 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
   132
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   133
    val intros = 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
   134
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   135
    val mut_name = space_implode "_" (map (Binding.base_name o fst o fst) preds);
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
    val case_names = map (Binding.base_name o fst o fst) specs
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   137
  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
   138
    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
   139
    |> 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
   140
        ((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
   141
    |-> (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
   142
         ((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
   143
    |>> 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
   144
    ||>> (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
   145
         ((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
   146
          [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
   147
           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
   148
           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
   149
          (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
   150
    |> 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
   151
  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
   152
(* @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
   153
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
(* @chunk add_inductive *)
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   155
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
   156
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
   157
  val specs' = map (fn (a, s) => [(a, [s])]) specs
12533bb49615 recovered old version of simple_induct; split the main function into small functions
Christian Urban <urbanc@in.tum.de>
parents: 102
diff changeset
   158
  val ((varst, specst), _) = Specification.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
   159
  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
   160
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
   161
  (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
   162
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
   163
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
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
   165
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
   166
  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
   167
  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
   168
  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
   169
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
   170
  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
   171
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
   172
(* @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
   173
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   174
(* @chunk 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
   175
val parser = 
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
   176
   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
   177
   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
   178
   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
   179
   Scan.optional 
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
   180
       (OuterParse.$$$ "where" |--
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
   181
          OuterParse.!!! 
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
   182
            (OuterParse.enum1 "|" 
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
   183
               (SpecParse.opt_thm_name ":" -- OuterParse.prop))) []
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   184
(* @end *)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   185
116
c9ff326e3ce5 more changes to the package chapter
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   186
(* @chunk syntax *)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   187
val ind_decl =
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
   188
  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
   189
    (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
   190
      Toplevel.local_theory loc (add_inductive preds params specs))
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   191
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   192
val _ = OuterSyntax.command "simple_inductive" "define inductive predicates"
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
   193
  OuterKeyword.thy_decl ind_decl;
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   194
(* @end *)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   195
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   196
end;