CookBook/Package/Ind_Code.thy
author Christian Urban <urbanc@in.tum.de>
Wed, 18 Mar 2009 03:27:15 +0100
changeset 185 043ef82000b4
parent 184 c7f04a008c9c
child 186 371e4375c994
permissions -rw-r--r--
some polishing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory Ind_Code
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
     2
imports "../Base" "../FirstSteps" Simple_Inductive_Package Ind_Prelims
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     5
section {* Code *}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     6
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     7
text {*
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
     8
  @{text [display] "rule ::= \<And>xs. As \<Longrightarrow> (\<And>ys. Bs \<Longrightarrow> pred ss)\<^isup>* \<Longrightarrow> pred ts"}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
     9
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    10
  @{text [display] "orule ::= \<forall>xs. As \<longrightarrow> (\<forall>ys. Bs \<longrightarrow> pred ss)\<^isup>* \<longrightarrow> pred ts"}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    11
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    12
  @{text [display] "def ::= pred \<equiv> \<lambda>zs. \<forall>preds. orules \<longrightarrow> pred zs"}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    13
  
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    14
  @{text [display] "ind ::= \<And>zs. pred zs \<Longrightarrow> rules[preds::=Ps] \<Longrightarrow> P zs"}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    15
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    16
  @{text [display] "oind ::= \<forall>zs. pred zs \<longrightarrow> orules[preds::=Ps] \<longrightarrow> P zs"}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    17
  
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    18
  So we have @{text "pred zs"} and @{text "orules[preds::=Ps]"}; have to show
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    19
  @{text "P zs"}. Expanding @{text "pred zs"} gives @{text "\<forall>preds. orules \<longrightarrow> pred zs"}.
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    20
  Instantiating the @{text "preds"} with @{text "Ps"} gives
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    21
  @{text "orules[preds::=Ps] \<longrightarrow> P zs"}. So we can conclude with @{text "P zs"}.
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    22
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    23
  We have to show @{text "\<forall>xs. As \<longrightarrow> (\<forall>ys. Bs \<longrightarrow> pred ss)\<^isup>* \<longrightarrow> pred ts"};
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    24
  expanding the defs 
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    25
  
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    26
  @{text [display]
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    27
  "\<forall>xs. As \<longrightarrow> (\<forall>ys. Bs \<longrightarrow> (\<forall>preds. orules \<longrightarrow> pred ss))\<^isup>* \<longrightarrow>  (\<forall>preds. orules \<longrightarrow> pred ts"}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    28
  
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    29
  so we have @{text "As"}, @{text "(\<forall>ys. Bs \<longrightarrow> (\<forall>preds. orules \<longrightarrow> pred ss))\<^isup>*"},
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    30
  @{text "orules"}; and have to show @{text "pred ts"}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    31
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    32
  the @{text "orules"} are of the form @{text "\<forall>xs. As \<longrightarrow> (\<forall>ys. Bs \<longrightarrow> pred ss)\<^isup>* \<longrightarrow> pred ts"}.
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    33
  
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    34
  using the @{text "As"} we ????
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    35
*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    36
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    37
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    38
text {*
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    39
  First we have to produce for each predicate its definitions of the form
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    40
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    41
  @{text [display] "pred \<equiv> \<lambda>zs. \<forall>preds. orules \<longrightarrow> pred zs"}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    42
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    43
  In order to make definitions, we use the following wrapper for 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    44
  @{ML LocalTheory.define}. The wrapper takes a predicate name, a syntax
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    45
  annotation and a term representing the right-hand side of the definition.
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    46
*}
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    47
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    48
ML %linenosgray{*fun make_defs ((predname, syn), trm) lthy =
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    49
let 
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    50
  val arg = ((predname, syn), (Attrib.empty_binding, trm))
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
    51
  val ((_, (_ , thm)), lthy') = LocalTheory.define Thm.internalK arg lthy
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    52
in 
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
    53
  (thm, lthy') 
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    54
end*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    55
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    56
text {*
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    57
  It returns the definition (as a theorem) and the local theory in which this definition has 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    58
  been made. In Line 4, @{ML internalK in Thm} is a flag attached to the 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    59
  theorem (others possibilities are @{ML definitionK in Thm} and @{ML axiomK in Thm}). 
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
    60
  These flags just classify theorems and have no significant meaning, except 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    61
  for tools that, for example, find theorems in the theorem database. We also
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    62
  use @{ML empty_binding in Attrib} in Line 3, since the definition does 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    63
  not need to have any theorem attributes. A testcase for this function is
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    64
*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    65
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    66
local_setup %gray {* fn lthy =>
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    67
let
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    68
  val arg =  ((Binding.name "MyTrue", NoSyn), @{term True})
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    69
  val (def, lthy') = make_defs arg lthy 
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    70
in
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    71
  warning (str_of_thm lthy' def); lthy'
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
    72
end *}
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    73
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    74
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    75
  which makes the definition @{prop "MyTrue \<equiv> True"} and then prints it out. 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    76
  Since we are testing the function inside \isacommand{local\_setup}, i.e.~make
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    77
  changes to the ambient theory, we can query the definition using the usual
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    78
  command \isacommand{thm}:
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    79
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    80
  \begin{isabelle}
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    81
  \isacommand{thm}~@{text "MyTrue_def"}\\
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    82
  @{text "> MyTrue \<equiv> True"}
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    83
  \end{isabelle}
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    84
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    85
  The next two functions construct the terms we need for the definitions for
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    86
  our \isacommand{simple\_inductive} command. These 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    87
  terms are of the form 
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    88
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    89
  @{text [display] "\<lambda>\<^raw:$zs$>. \<forall>preds. orules \<longrightarrow> pred \<^raw:$zs$>"}
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    90
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    91
  The variables @{text "\<^raw:$zs$>"} need to be chosen so that they do not occur
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    92
  in the @{text orules} and also be distinct from the @{text "preds"}. 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    93
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    94
  The first function constructs the term for one particular predicate, say
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    95
  @{text "pred"}; the number of arguments of this predicate is
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    96
  determined by the number of argument types of @{text "arg_tys"}. 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    97
  So it takes these two parameters as arguments. The other arguments are
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    98
  all the @{text "preds"} and the @{text "orules"}.
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    99
*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   100
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   101
ML %linenosgray{*fun defs_aux lthy orules preds (pred, arg_tys) =
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   102
let 
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   103
  fun mk_all x P = HOLogic.all_const (fastype_of x) $ lambda x P
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   104
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   105
  val fresh_args = 
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   106
        arg_tys 
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   107
        |> map (pair "z")
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   108
        |> Variable.variant_frees lthy (preds @ orules) 
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   109
        |> map Free
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   110
in
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   111
  list_comb (pred, fresh_args)
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   112
  |> fold_rev (curry HOLogic.mk_imp) orules
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   113
  |> fold_rev mk_all preds
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   114
  |> fold_rev lambda fresh_args 
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   115
end*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   116
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   117
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   118
  The function in Line 3 is just a helper function for constructing universal
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   119
  quantifications. The code in Lines 5 to 9 produces the fresh @{text
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   120
  "\<^raw:$zs$>"}. For this it pairs every argument type with the string
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   121
  @{text [quotes] "z"} (Line 7); then generates variants for all these strings
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   122
  so that they are unique w.r.t.~to the @{text "orules"} and the predicates;
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   123
  in Line 9 it generates the corresponding variable terms for the unique
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   124
  strings.
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   125
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   126
  The unique free variables are applied to the predicate (Line 11) using the
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   127
  function @{ML list_comb}; then the @{text orules} are prefixed (Line 12); in
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   128
  Line 13 we quantify over all predicates; and in line 14 we just abstract
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   129
  over all the @{text "\<^raw:$zs$>"}, i.e.~the fresh arguments of the
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   130
  predicate.
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   131
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   132
  A testcase for this function is
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   133
*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   134
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   135
local_setup %gray{* fn lthy =>
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   136
let
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   137
  val orules = [@{prop "even 0"},
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   138
                @{prop "\<forall>n::nat. odd n \<longrightarrow> even (Suc n)"},
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   139
                @{prop "\<forall>n::nat. even n \<longrightarrow> odd (Suc n)"}] 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   140
  val preds = [@{term "even::nat\<Rightarrow>bool"}, @{term "odd::nat\<Rightarrow>bool"}, @{term "z::nat"}]
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   141
  val pred = @{term "even::nat\<Rightarrow>bool"}
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   142
  val arg_tys = [@{typ "nat"}]
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   143
  val def = defs_aux lthy orules preds (pred, arg_tys)
173
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   144
in
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   145
  warning (Syntax.string_of_term lthy def); lthy
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   146
end *}
173
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   147
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   149
  It constructs the left-hand side for the definition of @{text "even"}. So we obtain 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   150
  as printout the term
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   151
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   152
  @{text [display] 
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   153
"\<lambda>z. \<forall>even odd. (even 0) \<longrightarrow> (\<forall>n. odd n \<longrightarrow> even (Suc n)) 
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   154
                         \<longrightarrow> (\<forall>n. even n \<longrightarrow> odd (Suc n)) \<longrightarrow> even z"}
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   155
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   156
  The main function for the definitions now has to just iterate the function
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   157
  @{ML defs_aux} over all predicates. The argument @{text "preds"} is again
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   158
  the the list of predicates as @{ML_type term}s; the argument @{text
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   159
  "prednames"} is the list of names of the predicates; @{text "arg_tyss"} is
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   160
  the list of argument-type-lists for each predicate.
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   161
*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   162
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   163
ML %linenosgray{*fun definitions rules preds prednames syns arg_typss lthy =
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   164
let
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   165
  val thy = ProofContext.theory_of lthy
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   166
  val orules = map (ObjectLogic.atomize_term thy) rules
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   167
  val defs = map (defs_aux lthy orules preds) (preds ~~ arg_typss) 
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   168
in
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   169
  fold_map make_defs (prednames ~~ syns ~~ defs) lthy
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   170
end*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   171
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   172
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   173
  The user will state the introduction rules using meta-implications and
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   174
  meta-quanti\-fications. In Line 4, we transform these introduction rules into
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   175
  the object logic (since definitions cannot be stated with
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   176
  meta-connectives). To do this transformation we have to obtain the theory
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   177
  behind the local theory (Line 3); with this theory we can use the function
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   178
  @{ML ObjectLogic.atomize_term} to make the transformation (Line 4). The call
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   179
  to @{ML defs_aux} in Line 5 produces all left-hand sides of the
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   180
  definitions. The actual definitions are then made in Line 7.  The result
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   181
  of the function is a list of theorems and a local theory.
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   182
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   183
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   184
  A testcase for this function is 
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   185
*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   186
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   187
local_setup %gray {* fn lthy =>
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   188
let
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   189
  val rules = [@{prop "even 0"},
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   190
               @{prop "\<And>n::nat. odd n \<Longrightarrow> even (Suc n)"},
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   191
               @{prop "\<And>n::nat. even n \<Longrightarrow> odd (Suc n)"}] 
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   192
  val preds = [@{term "even::nat\<Rightarrow>bool"}, @{term "odd::nat\<Rightarrow>bool"}]
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   193
  val prednames = [Binding.name "even", Binding.name "odd"] 
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   194
  val syns = [NoSyn, NoSyn] 
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   195
  val arg_tyss = [[@{typ "nat"}], [@{typ "nat"}]]
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   196
  val (defs, lthy') = definitions rules preds prednames syns arg_tyss lthy
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   197
in
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   198
  warning (str_of_thms lthy' defs); lthy'
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   199
end *}
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   200
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   201
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   202
  where we feed into the functions all parameters corresponding to
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   203
  the @{text even}-@{text odd} example. The definitions we obtain
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   204
  are:
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   205
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   206
  \begin{isabelle}
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   207
  \isacommand{thm}~@{text "even_def odd_def"}\\
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   208
  @{text [break]
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   209
"> even \<equiv> \<lambda>z. \<forall>even odd. (even 0) \<longrightarrow> (\<forall>n. odd n \<longrightarrow> even (Suc n)) 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   210
>                                 \<longrightarrow> (\<forall>n. even n \<longrightarrow> odd (Suc n)) \<longrightarrow> even z,
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   211
> odd \<equiv> \<lambda>z. \<forall>even odd. (even 0) \<longrightarrow> (\<forall>n. odd n \<longrightarrow> even (Suc n)) 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   212
>                                \<longrightarrow> (\<forall>n. even n \<longrightarrow> odd (Suc n)) \<longrightarrow> odd z"}
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   213
  \end{isabelle}
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   214
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   215
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   216
  This completes the code for making the definitions. Next we deal with
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   217
  the induction principles. Recall that the proof of the induction principle 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   218
  for @{text "even"} was:
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   219
*}
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   220
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   221
lemma man_ind_principle: 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   222
assumes prems: "even n"
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   223
shows "P 0 \<Longrightarrow> (\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P n"
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   224
apply(atomize (full))
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   225
apply(cut_tac prems)
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   226
apply(unfold even_def)
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   227
apply(drule spec[where x=P])
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   228
apply(drule spec[where x=Q])
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   229
apply(assumption)
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   230
done
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   231
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   232
text {* 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   233
  The code for such induction principles has to accomplish two tasks: 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   234
  constructing the induction principles from the given introduction
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   235
  rules and then automatically generating a proof of them using a tactic. 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   236
  
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   237
  The tactic will use the following helper function for instantiating universal 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   238
  quantifiers. 
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   239
*}
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   240
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   241
ML{*fun inst_spec ctrm = 
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   242
 Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec}*}
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   243
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   244
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   245
  This helper function instantiates the @{text "?x"} in the theorem 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   246
  @{thm spec} with a given @{ML_type cterm}. Together with the tactic
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   247
*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   248
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   249
ML{*fun inst_spec_tac ctrms = 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   250
  EVERY' (map (dtac o inst_spec) ctrms)*}
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   251
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   252
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   253
  we can use @{ML inst_spec} in the following proof to instantiate the 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   254
  three quantifiers in the assumption. 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   255
*}
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   256
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   257
lemma 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   258
  fixes P::"nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool"
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   259
  shows "\<forall>x y z. P x y z \<Longrightarrow> True"
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   260
apply (tactic {* 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   261
  inst_spec_tac  [@{cterm "a::nat"},@{cterm "b::nat"},@{cterm "c::nat"}] 1 *})
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   262
txt {* 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   263
  We obtain the goal state
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   264
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   265
  \begin{minipage}{\textwidth}
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   266
  @{subgoals} 
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   267
  \end{minipage}*}
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   268
(*<*)oops(*>*)
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   269
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   270
text {*
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   271
  Now the complete tactic for proving the induction principles can 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   272
  be implemented as follows:
163
2319cff107f0 removed rep_ss, and used dest_ss instead; some very slight changes to simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   273
*}
2319cff107f0 removed rep_ss, and used dest_ss instead; some very slight changes to simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   274
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   275
ML %linenosgray{*fun induction_tac defs prems insts =
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   276
  EVERY1 [ObjectLogic.full_atomize_tac,
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   277
          cut_facts_tac prems,
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   278
          K (rewrite_goals_tac defs),
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   279
          inst_spec_tac insts,
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   280
          assume_tac]*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   281
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   282
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   283
  We only have to give it as arguments the definitions, the premise 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   284
  (like @{text "even n"}) 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   285
  and the instantiations. Compare this with the manual proof given for the
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   286
  lemma @{thm [source] man_ind_principle}.  
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   287
  A testcase for this tactic is the function
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   288
*}
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   289
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   290
ML{*fun test_tac prems = 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   291
let
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   292
  val defs = [@{thm even_def}, @{thm odd_def}]
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   293
  val insts = [@{cterm "P::nat\<Rightarrow>bool"}, @{cterm "Q::nat\<Rightarrow>bool"}]
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   294
in 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   295
  induction_tac defs prems insts 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   296
end*}
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   297
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   298
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   299
  which indeed proves the induction principle: 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   300
*}
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   301
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   302
lemma 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   303
assumes prems: "even n"
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   304
shows "P 0 \<Longrightarrow> (\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P n"
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   305
apply(tactic {* test_tac @{thms prems} *})
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   306
done
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   307
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   308
text {*
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   309
  While the tactic for the induction principle is relatively simple, 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   310
  it is a bit harder to construct the goals from the introduction 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   311
  rules the user provides. In general we have to construct for each predicate 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   312
  @{text "pred"} a goal of the form
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   313
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   314
  @{text [display] 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   315
  "\<And>\<^raw:$zs$>. pred \<^raw:$zs$> \<Longrightarrow> rules[preds := \<^raw:$Ps$>] \<Longrightarrow> \<^raw:$P$> \<^raw:$zs$>"}
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   316
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   317
  where the given predicates @{text preds} are replaced in the introduction 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   318
  rules by new distinct variables written @{text "\<^raw:$Ps$>"}. 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   319
  We also need to generate fresh arguments for the predicate @{text "pred"} in
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   320
  the premise and the @{text "\<^raw:$P$>"} in the conclusion. We achieve
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   321
  that in two steps. 
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   322
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   323
  The function below expects that the introduction rules are already appropriately
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   324
  substituted. The argument @{text "srules"} stands for these substituted
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   325
   rules; @{text cnewpreds} are the certified terms coresponding
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   326
  to the variables @{text "\<^raw:$Ps$>"}; @{text "pred"} is the predicate for
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   327
  which we prove the introduction principle; @{text "newpred"} is its
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   328
  replacement and @{text "tys"} are the argument types of this predicate.
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   329
*}
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   330
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   331
ML %linenosgray{*fun prove_induction lthy defs srules cnewpreds ((pred, newpred), tys)  =
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   332
let
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   333
  val zs = replicate (length tys) "z"
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   334
  val (newargnames, lthy') = Variable.variant_fixes zs lthy;
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   335
  val newargs = map Free (newargnames ~~ tys)
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   336
  
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   337
  val prem = HOLogic.mk_Trueprop (list_comb (pred, newargs))
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   338
  val goal = Logic.list_implies 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   339
         (srules, HOLogic.mk_Trueprop (list_comb (newpred, newargs)))
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   340
in
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   341
  Goal.prove lthy' [] [prem] goal
178
fb8f22dd8ad0 adapted to latest Attrib.setup changes and more work on the simple induct chapter
Christian Urban <urbanc@in.tum.de>
parents: 177
diff changeset
   342
  (fn {prems, ...} => induction_tac defs prems cnewpreds)
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   343
  |> singleton (ProofContext.export lthy' lthy)
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   344
end *}
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   345
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   346
text {* 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   347
  In Line 3 we produce names @{text "\<^raw:$zs$>"} for each type in the 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   348
  argument type list. Line 4 makes these names unique and declares them as 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   349
  \emph{free} (but fixed) variables in the local theory @{text "lthy'"}. In 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   350
  Line 5 we just construct the terms corresponding to these variables. 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   351
  The term variables are applied to the predicate in Line 7 (this corresponds
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   352
  to the first premise @{text "pred \<^raw:$zs$>"} of the induction principle). 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   353
  In Line 8 and 9, we first construct the term  @{text "\<^raw:$P$>\<^raw:$zs$>"} 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   354
  and then add the (substituded) introduction rules as premises. In case that
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   355
  no introduction rules are given, the conclusion of this implication needs
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   356
  to be wrapped inside a @{term Trueprop}, otherwise the Isabelle's goal
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   357
  mechanism will fail. 
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   358
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   359
  In Line 11 we set up the goal to be proved; in the next line call the tactic
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   360
  for proving the induction principle. This tactic expects definitions, the
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   361
  premise and the (certified) predicates with which the introduction rules
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   362
  have been substituted. This will return a theorem. However, it is a theorem
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   363
  proved inside the local theory @{text "lthy'"}, where the variables @{text
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   364
  "\<^raw:$zs$>"} are fixed, but free. By exporting this theorem from @{text
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   365
  "lthy'"} (which contains the @{text "\<^raw:$zs$>"} as free) to @{text
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   366
  "lthy"} (which does not), we obtain the desired quantifications @{text
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   367
  "\<And>\<^raw:$zs$>"}.
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   368
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   369
  (FIXME testcase)
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   370
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   371
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   372
  Now it is left to produce the new predicates with which the introduction
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   373
  rules are substituted. 
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   374
*}
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   375
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   376
ML %linenosgray{*fun inductions rules defs preds arg_tyss lthy  =
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   377
let
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   378
  val Ps = replicate (length preds) "P"
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   379
  val (newprednames, lthy') = Variable.variant_fixes Ps lthy
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   380
  
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   381
  val thy = ProofContext.theory_of lthy'
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   382
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   383
  val tyss' = map (fn tys => tys ---> HOLogic.boolT) arg_tyss
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   384
  val newpreds = map Free (newprednames ~~ tyss')
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   385
  val cnewpreds = map (cterm_of thy) newpreds
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   386
  val srules = map (subst_free (preds ~~ newpreds)) rules
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   387
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   388
in
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   389
  map (prove_induction lthy' defs srules cnewpreds) 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   390
        (preds ~~ newpreds ~~ arg_tyss)
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   391
          |> ProofContext.export lthy' lthy
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   392
end*}
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   393
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   394
text {*
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   395
  In Line 3 we generate a string @{text [quotes] "P"} for each predicate. 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   396
  In Line 4, we use the same trick as in the previous function, that is making the 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   397
  @{text "\<^raw:$Ps$>"} fresh and declaring them as fixed but free in
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   398
  the new local theory @{text "lthy'"}. From the local theory we extract
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   399
  the ambient theory in Line 6. We need this theory in order to certify 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   400
  the new predicates. In Line 8 we calculate the types of these new predicates
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   401
  using the argument types. Next we turn them into terms and subsequently
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   402
  certify them. We can now produce the substituted introduction rules 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   403
  (Line 11). Line 14 and 15 just iterate the proofs for all predicates.
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   404
  From this we obtain a list of theorems. Finally we need to export the 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   405
  fixed variables @{text "\<^raw:$Ps$>"} to obtain the correct quantification 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   406
  (Line 16).
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   407
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   408
  A testcase for this function is
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   409
*}
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   410
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   411
local_setup %gray {* fn lthy =>
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   412
let 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   413
  val rules = [@{prop "even (0::nat)"},
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   414
               @{prop "\<And>n::nat. odd n \<Longrightarrow> even (Suc n)"},
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   415
               @{prop "\<And>n::nat. even n \<Longrightarrow> odd (Suc n)"}] 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   416
  val defs = [@{thm even_def}, @{thm odd_def}]
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   417
  val preds = [@{term "even::nat\<Rightarrow>bool"}, @{term "odd::nat\<Rightarrow>bool"}]
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   418
  val tyss = [[@{typ "nat"}], [@{typ "nat"}]]
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   419
  val ind_thms = inductions rules defs preds tyss lthy
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   420
in
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   421
  warning (str_of_thms lthy ind_thms); lthy
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   422
end  
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   423
*}
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   424
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   425
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   426
text {*
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   427
  which prints out
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   428
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   429
@{text [display]
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   430
"> even z \<Longrightarrow> 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   431
>  P 0 \<Longrightarrow> (\<And>m. Pa m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Pa (Suc m)) \<Longrightarrow> P z,
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   432
> odd z \<Longrightarrow> 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   433
>  P 0 \<Longrightarrow> (\<And>m. Pa m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Pa (Suc m)) \<Longrightarrow> Pa z"}
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   434
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   435
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   436
  This completes the code for the induction principles. Finally we can 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   437
  prove the introduction rules. 
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   438
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   439
*}
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   440
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   441
ML {* ObjectLogic.rulify  *}
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   442
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   443
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   444
ML{*val all_elims = fold (fn ct => fn th => th RS inst_spec ct)
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   445
val imp_elims = fold (fn th => fn th' => [th', th] MRS @{thm mp})*}
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   446
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   447
ML{*fun subproof2 prem params2 prems2 =  
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   448
 SUBPROOF (fn {prems, ...} =>
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   449
   let
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   450
     val prem' = prems MRS prem;
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   451
     val prem'' = 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   452
       case prop_of prem' of
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   453
           _ $ (Const (@{const_name All}, _) $ _) =>
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   454
             prem' |> all_elims params2 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   455
                   |> imp_elims prems2
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   456
         | _ => prem';
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   457
   in 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   458
     rtac prem'' 1 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   459
   end)*}
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   460
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   461
ML{*fun subproof1 rules preds i = 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   462
 SUBPROOF (fn {params, prems, context = ctxt', ...} =>
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   463
   let
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   464
     val (prems1, prems2) = chop (length prems - length rules) prems;
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   465
     val (params1, params2) = chop (length params - length preds) params;
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   466
   in
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   467
     rtac (ObjectLogic.rulify (all_elims params1 (nth prems2 i))) 1 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   468
     THEN
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   469
     EVERY1 (map (fn prem => subproof2 prem params2 prems2 ctxt') prems1)
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   470
   end)*}
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   471
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   472
ML{*
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   473
fun introductions_tac defs rules preds i ctxt =
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   474
  EVERY1 [ObjectLogic.rulify_tac,
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   475
          K (rewrite_goals_tac defs),
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   476
          REPEAT o (resolve_tac [@{thm allI}, @{thm impI}]),
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   477
          subproof1 rules preds i ctxt]*}
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   478
173
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   479
lemma evenS: 
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   480
  shows "odd m \<Longrightarrow> even (Suc m)"
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   481
apply(tactic {* 
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   482
let
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   483
  val rules = [@{prop "even (0::nat)"},
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   484
                 @{prop "\<And>n::nat. odd n \<Longrightarrow> even (Suc n)"},
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   485
                 @{prop "\<And>n::nat. even n \<Longrightarrow> odd (Suc n)"}] 
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   486
  val defs = [@{thm even_def}, @{thm odd_def}]
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   487
  val preds = [@{term "even::nat\<Rightarrow>bool"}, @{term "odd::nat\<Rightarrow>bool"}]
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   488
in
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   489
  introductions_tac defs rules preds 1 @{context}
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   490
end *})
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   491
done
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   492
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   493
ML{*fun introductions rules preds defs lthy = 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   494
let
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   495
  fun prove_intro (i, goal) =
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   496
    Goal.prove lthy [] [] goal
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   497
      (fn {context, ...} => introductions_tac defs rules preds i context)
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   498
in
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   499
  map_index prove_intro rules
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   500
end*}
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   501
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   502
text {* main internal function *}
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   503
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   504
ML %linenosgray{*fun add_inductive_i pred_specs rule_specs lthy =
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   505
let
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   506
  val syns = map snd pred_specs
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   507
  val pred_specs' = map fst pred_specs
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   508
  val prednames = map fst pred_specs'
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   509
  val preds = map (fn (p, ty) => Free (Binding.name_of p, ty)) pred_specs'
163
2319cff107f0 removed rep_ss, and used dest_ss instead; some very slight changes to simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 124
diff changeset
   510
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   511
  val tyss = map (binder_types o fastype_of) preds   
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   512
  val (attrs, rules) = split_list rule_specs    
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   513
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   514
  val (defs, lthy') = definitions rules preds prednames syns tyss lthy      
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   515
  val ind_rules = inductions rules defs preds tyss lthy' 	
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   516
  val intro_rules = introductions rules preds defs lthy'
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   518
  val mut_name = space_implode "_" (map Binding.name_of prednames)
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   519
  val case_names = map (Binding.name_of o fst) attrs
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   520
in
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   521
    lthy' 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   522
    |> LocalTheory.notes Thm.theoremK (map (fn (((a, atts), _), th) =>
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   523
        ((Binding.qualify false mut_name a, atts), [([th], [])])) (rule_specs ~~ intro_rules)) 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   524
    |-> (fn intross => LocalTheory.note Thm.theoremK
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   525
         ((Binding.qualify false mut_name (Binding.name "intros"), []), maps snd intross)) 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   526
    |>> snd 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   527
    ||>> (LocalTheory.notes Thm.theoremK (map (fn (((R, _), _), th) =>
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   528
         ((Binding.qualify false (Binding.name_of R) (Binding.name "induct"),
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   529
          [Attrib.internal (K (RuleCases.case_names case_names)),
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   530
           Attrib.internal (K (RuleCases.consumes 1)),
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   531
           Attrib.internal (K (Induct.induct_pred ""))]), [([th], [])]))
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   532
          (pred_specs ~~ ind_rules)) #>> maps snd) 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   533
    |> snd
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   534
end*}
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   536
ML{*fun add_inductive pred_specs rule_specs lthy =
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   537
let
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   538
  val ((pred_specs', rule_specs'), _) = 
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   539
         Specification.read_spec pred_specs rule_specs lthy
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   540
in
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   541
  add_inductive_i pred_specs' rule_specs' lthy
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   542
end*} 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   543
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   544
ML{*val spec_parser = 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   545
   OuterParse.fixes -- 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   546
   Scan.optional 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   547
     (OuterParse.$$$ "where" |--
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   548
        OuterParse.!!! 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   549
          (OuterParse.enum1 "|" 
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   550
             (SpecParse.opt_thm_name ":" -- OuterParse.prop))) []*}
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   551
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   552
ML{*val specification =
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   553
  spec_parser >>
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   554
    (fn ((pred_specs), rule_specs) => add_inductive pred_specs rule_specs)*}
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   555
185
043ef82000b4 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 184
diff changeset
   556
ML{*val _ = OuterSyntax.local_theory "simple_inductive" 
043ef82000b4 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 184
diff changeset
   557
              "define inductive predicates"
043ef82000b4 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 184
diff changeset
   558
                 OuterKeyword.thy_decl specification*}
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   560
text {*
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   561
  Things to include at the end:
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   562
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   563
  \begin{itemize}
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   564
  \item say something about add-inductive-i to return
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   565
  the rules
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   566
  \item say that the induction principle is weaker (weaker than
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   567
  what the standard inductive package generates)
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   568
  \end{itemize}
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   569
  
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   570
*}
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   571
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   572
simple_inductive
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   573
  Even and Odd
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   574
where
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   575
  Even0: "Even 0"
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   576
| EvenS: "Odd n \<Longrightarrow> Even (Suc n)"
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   577
| OddS: "Even n \<Longrightarrow> Odd (Suc n)"
124
0b9fa606a746 added to the first-steps section
Christian Urban <urbanc@in.tum.de>
parents: 118
diff changeset
   578
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
end