ProgTutorial/Package/Ind_Code.thy
author Norbert Schirmer <norbert.schirmer@web.de>
Wed, 22 May 2019 13:24:30 +0200
changeset 575 c3dbc04471a9
parent 574 034150db9d91
permissions -rw-r--r--
fixing some Line references
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
441
Christian Urban <urbanc@in.tum.de>
parents: 440
diff changeset
     2
imports Ind_General_Scheme "../First_Steps" 
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
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
     5
section \<open>The Gory Details\label{sec:code}\<close> 
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
     6
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
     7
text \<open>
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
     8
  As mentioned before the code falls roughly into three parts: the code that deals
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
     9
  with the definitions, with the induction principles and with the introduction
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    10
  rules. In addition there are some administrative functions that string everything 
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    11
  together.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    12
\<close>
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
    13
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    14
subsection \<open>Definitions\<close>
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
    15
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    16
text \<open>
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    17
  We first have to produce for each predicate the user specifies an appropriate
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    18
  definition, whose general form is
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
    19
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
  @{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
    21
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
    22
  and then ``register'' the definition inside a local theory. 
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    23
  To do the latter, we use the following wrapper for the function
394
0019ebf76e10 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 375
diff changeset
    24
  @{ML_ind define in Local_Theory}. 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
    25
  annotation and a term representing the right-hand side of the definition.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    26
\<close>
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
    27
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    28
ML %linenosgray\<open>fun make_defn ((predname, mx), trm) lthy =
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    29
let 
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
    30
  val arg = ((predname, mx), (Binding.empty_atts, trm))
401
36d61044f9bf updated to new Isabelle and clarified Skip_Proof
Christian Urban <urbanc@in.tum.de>
parents: 394
diff changeset
    31
  val ((_, (_ , thm)), lthy') = Local_Theory.define arg lthy
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    32
in 
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
    33
  (thm, lthy') 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    34
end\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    35
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    36
text \<open>
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    37
  It returns the definition (as a theorem) and the local theory in which the
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
    38
  definition has been made. We use @{ML_ind empty_atts in Binding} in Line 3, 
401
36d61044f9bf updated to new Isabelle and clarified Skip_Proof
Christian Urban <urbanc@in.tum.de>
parents: 394
diff changeset
    39
  since the definitions for our inductive predicates are not meant to be seen 
36d61044f9bf updated to new Isabelle and clarified Skip_Proof
Christian Urban <urbanc@in.tum.de>
parents: 394
diff changeset
    40
  by the user and therefore do not need to have any theorem attributes. 
36d61044f9bf updated to new Isabelle and clarified Skip_Proof
Christian Urban <urbanc@in.tum.de>
parents: 394
diff changeset
    41
 
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
    42
  The next two functions construct the right-hand sides of the definitions, 
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    43
  which are terms whose general form is:
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    44
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    45
  @{text [display] "\<lambda>zs. \<forall>preds. orules \<longrightarrow> pred zs"}
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    46
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    47
  When constructing these terms, the variables \<open>zs\<close> need to be chosen so 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    48
  that they do not occur in the \<open>orules\<close> and also be distinct from the 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    49
  \<open>preds\<close>.
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
    50
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    51
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    52
  The first function, named \<open>defn_aux\<close>, constructs the term for one
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    53
  particular predicate (the argument \<open>pred\<close> in the code below). The
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
    54
  number of arguments of this predicate is determined by the number of
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    55
  argument types given in \<open>arg_tys\<close>. The other arguments of the
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    56
  function are the \<open>orules\<close> and all the \<open>preds\<close>.
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    57
\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    58
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    59
ML %linenosgray\<open>fun defn_aux lthy orules preds (pred, arg_tys) =
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    60
let 
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    61
  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
    62
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    63
  val fresh_args = 
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
    64
        arg_tys 
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    65
        |> map (pair "z")
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
    66
        |> Variable.variant_frees lthy (preds @ orules) 
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    67
        |> map Free
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    68
in
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    69
  list_comb (pred, fresh_args)
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    70
  |> fold_rev (curry HOLogic.mk_imp) orules
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    71
  |> fold_rev mk_all preds
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    72
  |> fold_rev lambda fresh_args 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    73
end\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    74
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    75
text \<open>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    76
  The function \<open>mk_all\<close> in Line 3 is just a helper function for constructing 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    77
  universal quantifications. The code in Lines 5 to 9 produces the fresh \<open>zs\<close>. For this it pairs every argument type with the string
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    78
  @{text [quotes] "z"} (Line 7); then generates variants for all these strings
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    79
  so that they are unique w.r.t.~to the predicates and \<open>orules\<close> (Line 8);
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
    80
  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
    81
  strings.
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    82
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
    83
  The unique variables are applied to the predicate in Line 11 using the
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    84
  function @{ML list_comb}; then the \<open>orules\<close> are prefixed (Line 12); in
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
    85
  Line 13 we quantify over all predicates; and in line 14 we just abstract
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    86
  over all the \<open>zs\<close>, i.e., the fresh arguments of the
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
    87
  predicate. A testcase for this function is
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    88
\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    89
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    90
local_setup %gray \<open>fn lthy =>
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
    91
let
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
    92
  val def = defn_aux lthy eo_orules eo_preds (e_pred, e_arg_tys)
173
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
    93
in
441
Christian Urban <urbanc@in.tum.de>
parents: 440
diff changeset
    94
  pwriteln (pretty_term lthy def); lthy
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    95
end\<close>
173
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
    96
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    97
text \<open>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
    98
  where we use the shorthands defined in Figure~\ref{fig:shorthands}.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
    99
  The testcase calls @{ML defn_aux} for the predicate \<open>even\<close> and prints
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   100
  out the generated definition. So we obtain as printout 
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   101
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   102
  @{text [display] 
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   103
"\<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
   104
                         \<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
   105
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   106
  If we try out the function with the rules for freshness
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   107
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   108
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   109
local_setup %gray \<open>fn lthy =>
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   110
let
358
9cf3bc448210 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 346
diff changeset
   111
  val arg = (fresh_pred, fresh_arg_tys)
9cf3bc448210 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 346
diff changeset
   112
  val def = defn_aux lthy fresh_orules [fresh_pred] arg
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   113
in
441
Christian Urban <urbanc@in.tum.de>
parents: 440
diff changeset
   114
  pwriteln (pretty_term lthy def); lthy
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   115
end\<close>
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   116
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   117
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   118
text \<open>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   119
  we obtain
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   120
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   121
  @{term [display] 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   122
"\<lambda>z za. \<forall>fresh. (\<forall>a b. \<not> a = b \<longrightarrow> fresh a (Var b)) \<longrightarrow>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   123
               (\<forall>a s t. fresh a t \<longrightarrow> fresh a s \<longrightarrow> fresh a (App t s)) \<longrightarrow>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   124
                (\<forall>a t. fresh a (Lam a t)) \<longrightarrow>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   125
                (\<forall>a b t. \<not> a = b \<longrightarrow> fresh a t \<longrightarrow> fresh a (Lam b t)) \<longrightarrow> fresh z za"}
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   126
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   127
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   128
  The second function, named \<open>defns\<close>, has to iterate the function
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   129
  @{ML defn_aux} over all predicates. The argument \<open>preds\<close> is again
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   130
  the list of predicates as @{ML_type term}s; the argument \<open>prednames\<close> is the list of binding names of the predicates; \<open>mxs\<close> 
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   131
  are the list of syntax, or mixfix, annotations for the predicates; 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   132
  \<open>arg_tyss\<close> is the list of argument-type-lists.
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   133
\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   134
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   135
ML %linenosgray\<open>fun defns rules preds prednames mxs arg_typss lthy =
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   136
let
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   137
  val orules = map (Object_Logic.atomize_term lthy) rules
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   138
  val defs = map (defn_aux lthy orules preds) (preds ~~ arg_typss) 
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   139
in
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   140
  fold_map make_defn (prednames ~~ mxs ~~ defs) lthy
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   141
end\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   142
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   143
text \<open>
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   144
  The user will state the introduction rules using meta-implications and
575
c3dbc04471a9 fixing some Line references
Norbert Schirmer <norbert.schirmer@web.de>
parents: 574
diff changeset
   145
  meta-quanti\-fications. In Line 3, we transform these introduction rules
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   146
  into the object logic (since definitions cannot be stated with
575
c3dbc04471a9 fixing some Line references
Norbert Schirmer <norbert.schirmer@web.de>
parents: 574
diff changeset
   147
  meta-connectives). We use the function
c3dbc04471a9 fixing some Line references
Norbert Schirmer <norbert.schirmer@web.de>
parents: 574
diff changeset
   148
  @{ML_ind atomize_term in Object_Logic} to make the transformation (Line 3). The call
c3dbc04471a9 fixing some Line references
Norbert Schirmer <norbert.schirmer@web.de>
parents: 574
diff changeset
   149
  to @{ML defn_aux} in Line 4 produces all right-hand sides of the
c3dbc04471a9 fixing some Line references
Norbert Schirmer <norbert.schirmer@web.de>
parents: 574
diff changeset
   150
  definitions. The actual definitions are then made in Line 6.  The result of
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   151
  the function is a list of theorems and a local theory (the theorems are
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   152
  registered with the local theory). A testcase for this function is
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   153
\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   154
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   155
local_setup %gray \<open>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
   156
let
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   157
  val (defs, lthy') = 
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   158
    defns eo_rules eo_preds eo_prednames eo_mxs eo_arg_tyss 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
   159
in
440
a0b280dd4bc7 partially moved from string_of_term to pretty_term
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
   160
  pwriteln (pretty_thms_no_vars lthy' defs); lthy
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   161
end\<close>
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
   162
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   163
text \<open>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   164
  where we feed into the function all parameters corresponding to
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   165
  the \<open>even\<close>/\<open>odd\<close> example. The definitions we obtain
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   166
  are:
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   167
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   168
  @{text [display, break]
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   169
"even \<equiv> \<lambda>z. \<forall>even odd. (even 0) \<longrightarrow> (\<forall>n. odd n \<longrightarrow> even (Suc n))  
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   170
                                \<longrightarrow> (\<forall>n. even n \<longrightarrow> odd (Suc n)) \<longrightarrow> even z,
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   171
odd \<equiv> \<lambda>z. \<forall>even odd. (even 0) \<longrightarrow> (\<forall>n. odd n \<longrightarrow> even (Suc n)) 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   172
                               \<longrightarrow> (\<forall>n. even n \<longrightarrow> odd (Suc n)) \<longrightarrow> odd z"}
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
   173
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   174
  Note that in the testcase we return the local theory \<open>lthy\<close> 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   175
  (not the modified \<open>lthy'\<close>). As a result the test case has no effect
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   176
  on the ambient theory. The reason is that if we introduce the
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   177
  definition again, we pollute the name space with two versions of 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   178
  \<open>even\<close> and \<open>odd\<close>. We want to avoid this here.
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   179
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   180
  This completes the code for introducing the definitions. Next we deal with
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   181
  the induction principles. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   182
\<close>
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   183
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   184
subsection \<open>Induction Principles\<close>
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   185
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   186
text \<open>
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   187
  Recall that the manual proof for the induction principle 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   188
  of \<open>even\<close> was:
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   189
\<close>
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   190
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   191
lemma manual_ind_prin_even: 
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   192
assumes prem: "even z"
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   193
shows "P 0 \<Longrightarrow> (\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P z"
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   194
apply(atomize (full))
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   195
apply(cut_tac prem)
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   196
apply(unfold even_def)
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   197
apply(drule spec[where x=P])
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   198
apply(drule spec[where x=Q])
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   199
apply(assumption)
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   200
done
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   201
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   202
text \<open>
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   203
  The code for automating such induction principles has to accomplish two tasks: 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   204
  constructing the induction principles from the given introduction
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   205
  rules and then automatically generating proofs for them using a tactic. 
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   206
  
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   207
  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
   208
  quantifiers. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   209
\<close>
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   210
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   211
ML %grayML\<open>fun inst_spec ctrm =
358
9cf3bc448210 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 346
diff changeset
   212
let
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   213
  val cty = Thm.ctyp_of_cterm ctrm
358
9cf3bc448210 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 346
diff changeset
   214
in 
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   215
  Thm.instantiate' [SOME cty] [NONE, SOME ctrm] @{thm spec} 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   216
end\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   217
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   218
text \<open>
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   219
  This helper function uses the function @{ML_ind instantiate' in Thm}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   220
  and instantiates the \<open>?x\<close> in the theorem @{thm spec} with a given
323
92f6a772e013 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
   221
  @{ML_type cterm}. We call this helper function in the following
92f6a772e013 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
   222
  tactic.\label{fun:instspectac}.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   223
\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   224
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   225
ML %grayML\<open>fun inst_spec_tac ctxt ctrms = 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   226
  EVERY' (map (dresolve_tac ctxt o single o inst_spec) ctrms)\<close>
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   227
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   228
text \<open>
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   229
  This tactic expects a list of @{ML_type cterm}s. It allows us in the 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   230
  proof below to instantiate the three quantifiers in the assumption. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   231
\<close>
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   232
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   233
lemma 
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   234
fixes P::"nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool"
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   235
shows "\<forall>x y z. P x y z \<Longrightarrow> True"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   236
apply (tactic \<open>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   237
  inst_spec_tac @{context} [@{cterm "a::nat"},@{cterm "b::nat"},@{cterm "c::nat"}] 1\<close>)
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   238
txt \<open>
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   239
  We obtain the goal state
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   240
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   241
  \begin{minipage}{\textwidth}
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   242
  @{subgoals} 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   243
  \end{minipage}\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   244
(*<*)oops(*>*)
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   245
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   246
text \<open>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   247
  The complete tactic for proving the induction principles can now
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   248
  be implemented as follows:
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   249
\<close>
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
   250
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   251
ML %linenosgray\<open>fun ind_tac ctxt defs prem insts =
552
82c482467d75 updated to latest isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   252
  EVERY1 [Object_Logic.full_atomize_tac ctxt,
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   253
          cut_facts_tac prem,
552
82c482467d75 updated to latest isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   254
          rewrite_goal_tac ctxt defs,
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   255
          inst_spec_tac ctxt insts,
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   256
          assume_tac ctxt]\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   257
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   258
text \<open>
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   259
  We have to give it as arguments the definitions, the premise (a list of
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   260
  formulae) and the instantiations. The premise is \<open>even n\<close> in lemma
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   261
  @{thm [source] manual_ind_prin_even} shown above; in our code it will always be a list
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   262
  consisting of a single formula. Compare this tactic with the manual proof
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   263
  for the lemma @{thm [source] manual_ind_prin_even}: as you can see there is
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   264
  almost a one-to-one correspondence between the \isacommand{apply}-script and
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   265
  the @{ML ind_tac}. We first rewrite the goal to use only object connectives (Line 2),
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   266
  "cut in" the premise (Line 3), unfold the definitions (Line 4), instantiate
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   267
  the assumptions of the goal (Line 5) and then conclude with @{ML assume_tac}.
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   268
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   269
  Two testcases for this tactic are:
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   270
\<close>
183
8bb4eaa2ec92 a simplification suggested by Stefan and some polishing
Christian Urban <urbanc@in.tum.de>
parents: 180
diff changeset
   271
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   272
lemma automatic_ind_prin_even:
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   273
assumes prem: "even z"
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   274
shows "P 0 \<Longrightarrow> (\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P z"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   275
by (tactic \<open>ind_tac @{context} eo_defs @{thms prem} 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   276
                    [@{cterm "P::nat\<Rightarrow>bool"}, @{cterm "Q::nat\<Rightarrow>bool"}]\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   277
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   278
lemma automatic_ind_prin_fresh:
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   279
assumes prem: "fresh z za" 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   280
shows "(\<And>a b. a \<noteq> b \<Longrightarrow> P a (Var b)) \<Longrightarrow> 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   281
        (\<And>a t s. \<lbrakk>P a t; P a s\<rbrakk> \<Longrightarrow> P a (App t s)) \<Longrightarrow>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   282
        (\<And>a t. P a (Lam a t)) \<Longrightarrow> 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   283
        (\<And>a b t. \<lbrakk>a \<noteq> b; P a t\<rbrakk> \<Longrightarrow> P a (Lam b t)) \<Longrightarrow> P z za"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   284
by (tactic \<open>ind_tac @{context} @{thms fresh_def} @{thms prem} 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   285
                          [@{cterm "P::string\<Rightarrow>trm\<Rightarrow>bool"}]\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   286
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   287
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   288
text \<open>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   289
  While the tactic for proving the induction principles is relatively simple,
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   290
  it will be a bit more work to construct the goals from the introduction rules
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   291
  the user provides.  Therefore let us have a closer look at the first 
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   292
  proved theorem:
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   293
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   294
  \begin{isabelle}
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   295
  \isacommand{thm}~@{thm [source] automatic_ind_prin_even}\\
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   296
  \<open>> \<close>~@{thm automatic_ind_prin_even}
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   297
  \end{isabelle}
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   298
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   299
  The variables \<open>z\<close>, \<open>P\<close> and \<open>Q\<close> are schematic
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   300
  variables (since they are not quantified in the lemma). These 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   301
  variables must be schematic, otherwise they cannot be instantiated 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   302
  by the user. To generate these schematic variables we use a common trick
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   303
  in Isabelle programming: we first declare them as \emph{free}, 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   304
  \emph{but fixed}, and then use the infrastructure to turn them into 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   305
  schematic variables.
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   306
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   307
  In general we have to construct for each predicate \<open>pred\<close> a goal 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   308
  of the form
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   309
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   310
  @{text [display] 
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   311
  "pred ?zs \<Longrightarrow> rules[preds := ?Ps] \<Longrightarrow> ?P ?zs"}
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   312
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   313
  where the predicates \<open>preds\<close> are replaced in \<open>rules\<close> by new 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   314
  distinct variables \<open>?Ps\<close>. We also need to generate fresh arguments 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   315
  \<open>?zs\<close> for the predicate  \<open>pred\<close> and the \<open>?P\<close> in 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   316
  the conclusion. 
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   317
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   318
  We generate these goals in two steps. The first function, named \<open>prove_ind\<close>, 
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   319
  expects that the introduction rules are already appropriately substituted. The argument
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   320
  \<open>srules\<close> stands for these substituted rules; \<open>cnewpreds\<close> are
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   321
  the certified terms coresponding to the variables \<open>?Ps\<close>; \<open>pred\<close> is the predicate for which we prove the induction principle;
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   322
  \<open>newpred\<close> is its replacement and \<open>arg_tys\<close> are the argument
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   323
  types of this predicate.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   324
\<close>
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   325
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   326
ML %linenosgray\<open>fun prove_ind lthy defs srules cnewpreds ((pred, newpred), arg_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
   327
let
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   328
  val zs = replicate (length arg_tys) "z"
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   329
  val (newargnames, lthy') = Variable.variant_fixes zs lthy;
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   330
  val newargs = map Free (newargnames ~~ arg_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
   331
  
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
  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
   333
  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
   334
         (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
   335
in
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   336
  Goal.prove lthy' [] [prem] goal
552
82c482467d75 updated to latest isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   337
      (fn {prems, context, ...} => ind_tac context defs prems cnewpreds)
475
25371f74c768 updated to post-2011-1 Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 448
diff changeset
   338
  |> singleton (Proof_Context.export lthy' lthy)
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   339
end\<close>
179
75381fa516cd more work on the simple-induct. chapter
Christian Urban <urbanc@in.tum.de>
parents: 178
diff changeset
   340
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   341
text \<open>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   342
  In Line 3 we produce names \<open>zs\<close> 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
   343
  argument type list. Line 4 makes these names unique and declares them as 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   344
  free, but fixed, variables in the local theory \<open>lthy'\<close>. 
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   345
  That means they are not schematic variables (yet).
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   346
  In Line 5 we construct the terms corresponding to these variables. 
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   347
  The variables are applied to the predicate in Line 7 (this corresponds
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   348
  to the first premise \<open>pred zs\<close> of the induction principle). 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   349
  In Line 8 and 9, we first construct the term  \<open>P zs\<close> 
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   350
  and then add the (substituted) introduction rules as preconditions. In 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   351
  case that no introduction rules are given, the conclusion of this 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   352
  implication needs to be wrapped inside a @{term Trueprop}, otherwise 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   353
  the Isabelle's goal mechanism will fail.\footnote{FIXME: check with 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   354
  Stefan...is this so?} 
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   355
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
   356
  In Line 11 we set up the goal to be proved using the function @{ML_ind 
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   357
  prove in Goal}; in the next line we call the tactic for proving the
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   358
  induction principle. As mentioned before, this tactic expects the
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   359
  definitions, the premise and the (certified) predicates with which the
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   360
  introduction rules have been substituted. The code in these two lines will
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   361
  return a theorem. However, it is a theorem proved inside the local theory
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   362
  \<open>lthy'\<close>, where the variables \<open>zs\<close> are free, but fixed (see
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   363
  Line 4). By exporting this theorem from \<open>lthy'\<close> (which contains the
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   364
  \<open>zs\<close> as free variables) to \<open>lthy\<close> (which does not), we
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   365
  obtain the desired schematic variables \<open>?zs\<close>.  A testcase for this
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   366
  function is
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   367
\<close>
180
9c25418db6f0 added a recipy about SAT solvers
Christian Urban <urbanc@in.tum.de>
parents: 179
diff changeset
   368
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   369
local_setup %gray \<open>fn lthy =>
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   370
let
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   371
  val newpreds = [@{term "P::nat \<Rightarrow> bool"}, @{term "Q::nat \<Rightarrow> bool"}]
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   372
  val cnewpreds = [@{cterm "P::nat \<Rightarrow> bool"}, @{cterm "Q::nat \<Rightarrow> bool"}]
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   373
  val newpred = @{term "P::nat \<Rightarrow> bool"}
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   374
  val srules =  map (subst_free (eo_preds ~~ newpreds)) eo_rules
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   375
  val intro = 
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   376
      prove_ind lthy eo_defs srules cnewpreds ((e_pred, newpred), e_arg_tys)
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   377
in
440
a0b280dd4bc7 partially moved from string_of_term to pretty_term
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
   378
  pwriteln (pretty_thm lthy intro); lthy
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   379
end\<close>
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   380
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   381
text \<open>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   382
  This prints out the theorem:
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   383
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   384
  @{text [display]
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   385
  " \<lbrakk>even ?z; P 0; \<And>n. Q n \<Longrightarrow> P (Suc n); \<And>n. P n \<Longrightarrow> Q (Suc n)\<rbrakk> \<Longrightarrow> P ?z"}
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   386
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   387
  The export from \<open>lthy'\<close> to \<open>lthy\<close> in Line 13 above 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   388
  has correctly turned the free, but fixed, \<open>z\<close> into a schematic 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   389
  variable \<open>?z\<close>; the variables \<open>P\<close> and \<open>Q\<close> are not yet
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   390
  schematic. 
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   391
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   392
  We still have to produce the new predicates with which the introduction
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   393
  rules are substituted and iterate @{ML prove_ind} over all
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   394
  predicates. This is what the second function, named \<open>inds\<close> does. 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   395
\<close>
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   396
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   397
ML %linenosgray\<open>fun inds rules defs preds arg_tyss lthy  =
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   398
let
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   399
  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
   400
  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
   401
  
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   402
  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
   403
  val newpreds = map Free (newprednames ~~ tyss')
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   404
  val cnewpreds = map (Thm.cterm_of lthy') newpreds
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   405
  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
   406
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   407
in
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   408
  map (prove_ind lthy' defs srules cnewpreds) 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   409
        (preds ~~ newpreds ~~ arg_tyss)
475
25371f74c768 updated to post-2011-1 Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 448
diff changeset
   410
          |> Proof_Context.export lthy' lthy
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   411
end\<close>
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   412
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   413
text \<open>
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   414
  In Line 3, we generate a string @{text [quotes] "P"} for each predicate. 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   415
  In Line 4, we use the same trick as in the previous function, that is making the 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   416
  \<open>Ps\<close> fresh and declaring them as free, but fixed, in
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   417
  the new local theory \<open>lthy'\<close>. In Line 6, we construct the types of these new predicates
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   418
  using the given argument types. Next we turn them into terms and subsequently
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   419
  certify them (Line 7 and 8). We can now produce the substituted introduction rules 
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   420
  (Line 9) using the function @{ML_ind subst_free in Term}. Line 12 and 13 just iterate 
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   421
  the proofs for all predicates.
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   422
  From this we obtain a list of theorems. Finally we need to export the 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   423
  fixed variables \<open>Ps\<close> to obtain the schematic variables \<open>?Ps\<close> 
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   424
  (Line 14).
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   425
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   426
  A testcase for this function is
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   427
\<close>
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   428
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   429
local_setup %gray \<open>fn lthy =>
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   430
let 
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   431
  val ind_thms = inds eo_rules eo_defs eo_preds eo_arg_tyss lthy
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   432
in
440
a0b280dd4bc7 partially moved from string_of_term to pretty_term
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
   433
  pwriteln (pretty_thms lthy ind_thms); lthy
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   434
end\<close>
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   435
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   436
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   437
text \<open>
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   438
  which prints out
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
@{text [display]
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   441
"even ?z \<Longrightarrow> ?P1 0 \<Longrightarrow> 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   442
 (\<And>m. ?Pa1 m \<Longrightarrow> ?P1 (Suc m)) \<Longrightarrow> (\<And>m. ?P1 m \<Longrightarrow> ?Pa1 (Suc m)) \<Longrightarrow> ?P1 ?z,
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   443
odd ?z \<Longrightarrow> ?P1 0 \<Longrightarrow>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   444
 (\<And>m. ?Pa1 m \<Longrightarrow> ?P1 (Suc m)) \<Longrightarrow> (\<And>m. ?P1 m \<Longrightarrow> ?Pa1 (Suc m)) \<Longrightarrow> ?Pa1 ?z"}
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   445
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   446
  Note that now both, the \<open>?Ps\<close> and the \<open>?zs\<close>, are schematic
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   447
  variables. The numbers attached to these variables have been introduced by 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   448
  the pretty-printer and are \emph{not} important for the user. 
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   449
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   450
  This completes the code for the induction principles. The final peice
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   451
  of reasoning infrastructure we need are the introduction rules. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   452
\<close>
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   453
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   454
subsection \<open>Introduction Rules\<close>
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   455
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   456
text \<open>
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   457
  Constructing the goals for the introduction rules is easy: they
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   458
  are just the rules given by the user. However, their proofs are 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   459
  quite a bit more involved than the ones for the induction principles. 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   460
  To explain the general method, our running example will be
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   461
  the introduction rule
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   462
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   463
  \begin{isabelle}
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   464
  @{prop "\<And>a b t. \<lbrakk>a \<noteq> b; fresh a t\<rbrakk> \<Longrightarrow> fresh a (Lam b t)"}
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   465
  \end{isabelle}
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   466
  
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   467
  about freshness for lambdas. In order to ease somewhat 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   468
  our work here, we use the following two helper functions.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   469
\<close>
184
c7f04a008c9c some polishing
Christian Urban <urbanc@in.tum.de>
parents: 183
diff changeset
   470
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   471
ML %grayML\<open>val all_elims = fold (fn ct => fn th => th RS inst_spec ct)
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   472
val imp_elims = fold (fn th => fn th' => [th', th] MRS @{thm mp})\<close>
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   473
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   474
text \<open>
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   475
  To see what these functions do, let us suppose we have the following three
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   476
  theorems. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   477
\<close>
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   478
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   479
lemma all_elims_test:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   480
fixes P::"nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool"
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   481
shows "\<forall>x y z. P x y z" sorry
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   482
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   483
lemma imp_elims_test:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   484
shows "A \<longrightarrow> B \<longrightarrow> C" sorry
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   485
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   486
lemma imp_elims_test':
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   487
shows "A" "B" sorry
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   488
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   489
text \<open>
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   490
  The function @{ML all_elims} takes a list of (certified) terms and instantiates
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   491
  theorems of the form @{thm [source] all_elims_test}. For example we can instantiate
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   492
  the quantifiers in this theorem with @{term a}, @{term b} and @{term c} as follows:
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   493
572
438703674711 prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 569
diff changeset
   494
  @{ML_response [display, gray]
569
f875a25aa72d prefer cartouches over " in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 567
diff changeset
   495
\<open>let
f875a25aa72d prefer cartouches over " in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 567
diff changeset
   496
  val ctrms = [@{cterm "a::nat"}, @{cterm "b::nat"}, @{cterm "c::nat"}]
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   497
  val new_thm = all_elims ctrms @{thm all_elims_test}
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   498
in
440
a0b280dd4bc7 partially moved from string_of_term to pretty_term
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
   499
  pwriteln (pretty_thm_no_vars @{context} new_thm)
569
f875a25aa72d prefer cartouches over " in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 567
diff changeset
   500
end\<close>
f875a25aa72d prefer cartouches over " in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 567
diff changeset
   501
  \<open>P a b c\<close>}
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   502
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   503
  Note the difference with @{ML inst_spec_tac} from Page~\pageref{fun:instspectac}:
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   504
  @{ML inst_spec_tac} is a tactic which operates on a goal state; in contrast
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   505
  @{ML all_elims} operates on theorems. 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   506
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   507
  Similarly, the function @{ML imp_elims} eliminates preconditions from implications. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   508
  For example we can eliminate the preconditions \<open>A\<close> and \<open>B\<close> from
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   509
  @{thm [source] imp_elims_test}:
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   510
572
438703674711 prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 569
diff changeset
   511
  @{ML_response [display, gray]
569
f875a25aa72d prefer cartouches over " in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 567
diff changeset
   512
\<open>let
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   513
  val res = imp_elims @{thms imp_elims_test'} @{thm imp_elims_test}
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   514
in
440
a0b280dd4bc7 partially moved from string_of_term to pretty_term
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
   515
  pwriteln (pretty_thm_no_vars @{context} res)
569
f875a25aa72d prefer cartouches over " in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 567
diff changeset
   516
end\<close>
572
438703674711 prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 569
diff changeset
   517
  \<open>Q\<close>}
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   518
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   519
  Now we set up the proof for the introduction rule as follows:
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   520
\<close>
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   521
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   522
lemma fresh_Lam:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   523
shows "\<And>a b t. \<lbrakk>a \<noteq> b; fresh a t\<rbrakk> \<Longrightarrow> fresh a (Lam b t)"
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   524
(*<*)oops(*>*)
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   525
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   526
text \<open>
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   527
  The first step in the proof will be to expand the definitions of freshness
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   528
  and then introduce quantifiers and implications. For this we
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   529
  will use the tactic
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   530
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   531
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   532
ML %linenosgray\<open>fun expand_tac ctxt defs =
552
82c482467d75 updated to latest isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   533
  Object_Logic.rulify_tac ctxt 1
82c482467d75 updated to latest isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   534
  THEN rewrite_goal_tac ctxt defs 1
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   535
  THEN (REPEAT (resolve_tac ctxt [@{thm allI}, @{thm impI}] 1))\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   536
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   537
text \<open>
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   538
  The function in Line 2 ``rulifies'' the lemma.\footnote{FIXME: explain this better} 
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   539
  This will turn out to 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   540
  be important later on. Applying this tactic in our proof of \<open>fresh_Lem\<close>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   541
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   542
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   543
(*<*)
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   544
lemma fresh_Lam:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   545
shows "\<And>a b t. \<lbrakk>a \<noteq> b; fresh a t\<rbrakk> \<Longrightarrow> fresh a (Lam b t)"
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   546
(*>*)
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   547
apply(tactic \<open>expand_tac @{context} @{thms fresh_def}\<close>)
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   548
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   549
txt \<open>
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   550
  gives us the goal state
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   551
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   552
  \begin{isabelle}
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   553
  @{subgoals [display]}
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   554
  \end{isabelle}
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   555
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   556
  As you can see, there are parameters (namely \<open>a\<close>, \<open>b\<close> and
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   557
  \<open>t\<close>) which come from the introduction rule and parameters (in the
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   558
  case above only \<open>fresh\<close>) which come from the universal
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   559
  quantification in the definition @{term "fresh a (App t s)"}.  Similarly,
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   560
  there are assumptions that come from the premises of the rule (namely the
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   561
  first two) and assumptions from the definition of the predicate (assumption
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   562
  three to six). We need to treat these parameters and assumptions
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   563
  differently. In the code below we will therefore separate them into \<open>params1\<close> and \<open>params2\<close>, respectively \<open>prems1\<close> and \<open>prems2\<close>. To do this separation, it is best to open a subproof with the
369
74ba778b09c9 tuned index
Christian Urban <urbanc@in.tum.de>
parents: 358
diff changeset
   564
  tactic @{ML_ind SUBPROOF in Subgoal}, since this tactic provides us with the parameters (as
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   565
  list of @{ML_type cterm}s) and the assumptions (as list of @{ML_type thm}s). 
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   566
  The problem with @{ML SUBPROOF}, however, is that it always expects us to 
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   567
  completely discharge the goal (see Section~\ref{sec:simpletacs}). This is 
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   568
  a bit inconvenient for our gradual explanation of the proof here. Therefore
316
74f0a06f751f further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents: 315
diff changeset
   569
  we use first the function @{ML_ind  FOCUS in Subgoal}, which does s
299
d0b81d6e1b28 updated to Isabelle changes and merged sections in the FirstSteps chapter
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   570
  ame as @{ML SUBPROOF} 
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   571
  but does not require us to completely discharge the goal. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   572
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   573
(*<*)oops(*>*)
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   574
text_raw \<open>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   575
\begin{figure}[t]
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   576
\begin{minipage}{\textwidth}
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   577
\begin{isabelle}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   578
\<close>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   579
ML %grayML\<open>fun chop_print params1 params2 prems1 prems2 ctxt =
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   580
let 
574
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   581
 val pps = [Pretty.big_list "Params1 from the rule:" 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   582
              (map (pretty_cterm ctxt) params1), 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   583
            Pretty.big_list "Params2 from the predicate:" 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   584
              (map (pretty_cterm ctxt) params2), 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   585
            Pretty.big_list "Prems1 from the rule:" 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   586
              (map (pretty_thm ctxt) prems1),
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   587
            Pretty.big_list "Prems2 from the predicate:" 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   588
              (map (pretty_thm ctxt) prems2)] 
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   589
in 
440
a0b280dd4bc7 partially moved from string_of_term to pretty_term
Christian Urban <urbanc@in.tum.de>
parents: 418
diff changeset
   590
  pps |> Pretty.chunks
448
957f69b9b7df added something about Goal.prove_multi
Christian Urban <urbanc@in.tum.de>
parents: 441
diff changeset
   591
      |> Pretty.string_of
957f69b9b7df added something about Goal.prove_multi
Christian Urban <urbanc@in.tum.de>
parents: 441
diff changeset
   592
      |> tracing
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   593
end\<close>
448
957f69b9b7df added something about Goal.prove_multi
Christian Urban <urbanc@in.tum.de>
parents: 441
diff changeset
   594
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   595
text_raw\<open>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   596
\end{isabelle}
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   597
\end{minipage}
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   598
\caption{A helper function that prints out the parameters and premises that
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   599
  need to be treated differently.\label{fig:chopprint}}
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   600
\end{figure}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   601
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   602
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   603
text \<open>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   604
  First we calculate the values for \<open>params1/2\<close> and \<open>prems1/2\<close>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   605
  from \<open>params\<close> and \<open>prems\<close>, respectively. To better see what is
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   606
  going in our example, we will print out these values using the printing
299
d0b81d6e1b28 updated to Isabelle changes and merged sections in the FirstSteps chapter
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   607
  function in Figure~\ref{fig:chopprint}. Since @{ML FOCUS in Subgoal} will
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   608
  supply us the \<open>params\<close> and \<open>prems\<close> as lists, we can 
369
74ba778b09c9 tuned index
Christian Urban <urbanc@in.tum.de>
parents: 358
diff changeset
   609
  separate them using the function @{ML_ind chop in Library}. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   610
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   611
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   612
ML %linenosgray\<open>fun chop_test_tac preds rules =
299
d0b81d6e1b28 updated to Isabelle changes and merged sections in the FirstSteps chapter
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   613
  Subgoal.FOCUS (fn {params, prems, context, ...} =>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   614
  let
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   615
    val cparams = map snd params
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   616
    val (params1, params2) = chop (length cparams - length preds) cparams
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   617
    val (prems1, prems2) = chop (length prems - length rules) prems
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   618
  in
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   619
    chop_print params1 params2 prems1 prems2 context; all_tac
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   620
  end)\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   621
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   622
text \<open>
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   623
  For the separation we can rely on the fact that Isabelle deterministically 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   624
  produces parameters and premises in a goal state. The last parameters
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   625
  that were introduced come from the quantifications in the definitions
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   626
  (see the tactic @{ML expand_tac}).
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   627
  Therefore we only have to subtract in Line 5 the number of predicates (in this
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   628
  case only \<open>1\<close>) from the lenghts of all parameters. Similarly
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   629
  with the \<open>prems\<close> in line 6: the last premises in the goal state come from 
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   630
  unfolding the definition of the predicate in the conclusion. So we can 
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   631
  just subtract the number of rules from the number of all premises. 
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   632
  To check our calculations we print them out in Line 8 using the
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   633
  function @{ML chop_print} from Figure~\ref{fig:chopprint} and then 
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   634
  just do nothing, that is @{ML all_tac}. Applying this tactic in our example 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   635
\<close>
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   636
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   637
(*<*)
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   638
lemma fresh_Lam:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   639
shows "\<And>a b t. \<lbrakk>a \<noteq> b; fresh a t\<rbrakk> \<Longrightarrow> fresh a (Lam b t)"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   640
apply(tactic \<open>expand_tac @{context} @{thms fresh_def}\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   641
(*>*)
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   642
apply(tactic \<open>chop_test_tac [fresh_pred] fresh_rules @{context} 1\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   643
(*<*)oops(*>*)
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   644
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   645
text \<open>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   646
  gives
209
17b1512f51af soem slight polishing
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   647
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   648
  \begin{isabelle}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   649
  \<open>Params1 from the rule:\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   650
  \<open>a, b, t\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   651
  \<open>Params2 from the predicate:\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   652
  \<open>fresh\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   653
  \<open>Prems1 from the rule:\<close>\\
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   654
  @{term "a \<noteq> b"}\\
574
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   655
  @{text "\<forall>fresh."}\\
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   656
  @{text "(\<forall>a b. a \<noteq> b \<longrightarrow> fresh a (Var b)) \<longrightarrow>"}\\
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   657
  @{text "(\<forall>a t s. fresh a t \<longrightarrow> fresh a s \<longrightarrow> fresh a (App t s)) \<longrightarrow>"}\\
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   658
  @{text "(\<forall>a t. fresh a (Lam a t)) \<longrightarrow> "}\\
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   659
  @{text "(\<forall>a b t. a \<noteq> b \<longrightarrow> fresh a t \<longrightarrow> fresh a (Lam b t)) \<longrightarrow> fresh a t"}\\
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   660
   \<open>Prems2 from the predicate:\<close>\\
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   661
   @{term "\<forall>a b. a \<noteq> b \<longrightarrow> fresh a (Var b)"}\\
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   662
   @{term "\<forall>a t s. fresh a t \<longrightarrow> fresh a s \<longrightarrow> fresh a (App t s)"}\\
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   663
   @{term "\<forall>a t. fresh a (Lam a t)"}\\
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   664
   @{term "\<forall>a b t. a \<noteq> b \<longrightarrow> fresh a t \<longrightarrow> fresh a (Lam b t)"}
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   665
  \end{isabelle}
208
0634d42bb69f a bit more work on the simple-inductive package
Christian Urban <urbanc@in.tum.de>
parents: 194
diff changeset
   666
192
2fff636e1fa0 some polishing
Christian Urban <urbanc@in.tum.de>
parents: 190
diff changeset
   667
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   668
  We now have to select from \<open>prems2\<close> the premise 
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   669
  that corresponds to the introduction rule we prove, namely:
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   670
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   671
  @{term [display] "\<forall>a b t. a \<noteq> b \<longrightarrow> fresh a t \<longrightarrow> fresh a (Lam a t)"}
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   672
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   673
  To use this premise with @{ML resolve_tac}, we need to instantiate its 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   674
  quantifiers (with \<open>params1\<close>) and transform it into rule 
418
1d1e4cda8c54 updated to new isabelle
Christian Urban <urbanc@in.tum.de>
parents: 401
diff changeset
   675
  format (using @{ML_ind  rulify in Object_Logic}). So we can modify the 
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   676
  code as follows:
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   677
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   678
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   679
ML %linenosgray\<open>fun apply_prem_tac i preds rules =
299
d0b81d6e1b28 updated to Isabelle changes and merged sections in the FirstSteps chapter
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   680
  Subgoal.FOCUS (fn {params, prems, context, ...} =>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   681
  let
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   682
    val cparams = map snd params
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   683
    val (params1, params2) = chop (length cparams - length preds) cparams
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   684
    val (prems1, prems2) = chop (length prems - length rules) prems
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   685
  in
574
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   686
    resolve_tac context 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   687
      [Object_Logic.rulify context (all_elims params1 (nth prems2 i))] 1
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   688
  end)\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   689
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   690
text \<open>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   691
  The argument \<open>i\<close> corresponds to the number of the 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   692
  introduction we want to prove. We will later on let it range
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   693
  from \<open>0\<close> to the number of \<open>rules - 1\<close>.
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   694
  Below we apply this function with \<open>3\<close>, since 
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   695
  we are proving the fourth introduction rule. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   696
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   697
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   698
(*<*)
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   699
lemma fresh_Lam:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   700
shows "\<And>a b t. \<lbrakk>a \<noteq> b; fresh a t\<rbrakk> \<Longrightarrow> fresh a (Lam b t)"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   701
apply(tactic \<open>expand_tac @{context} @{thms fresh_def}\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   702
(*>*)
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   703
apply(tactic \<open>apply_prem_tac 3 [fresh_pred] fresh_rules @{context} 1\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   704
(*<*)oops(*>*)
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   705
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   706
text \<open>
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   707
  The goal state we obtain is: 
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   708
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   709
  \begin{isabelle}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   710
  \<open>1.\<close>~\<open>\<dots> \<Longrightarrow> \<close>~@{prop "a \<noteq> b"}\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   711
  \<open>2.\<close>~\<open>\<dots> \<Longrightarrow> \<close>~@{prop "fresh a t"}
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   712
  \end{isabelle}
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   713
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   714
  As expected there are two subgoals, where the first comes from the
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   715
  non-recursive premise of the introduction rule and the second comes 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   716
  from the recursive one. The first goal can be solved immediately 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   717
  by \<open>prems1\<close>. The second needs more work. It can be solved 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   718
  with the other premise in \<open>prems1\<close>, namely
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   719
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   720
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   721
  @{term [break,display]
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   722
  "\<forall>fresh.
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   723
      (\<forall>a b. a \<noteq> b \<longrightarrow> fresh a (Var b)) \<longrightarrow>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   724
      (\<forall>a t s. fresh a t \<longrightarrow> fresh a s \<longrightarrow> fresh a (App t s)) \<longrightarrow>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   725
      (\<forall>a t. fresh a (Lam a t)) \<longrightarrow> 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   726
      (\<forall>a b t. a \<noteq> b \<longrightarrow> fresh a t \<longrightarrow> fresh a (Lam b t)) \<longrightarrow> fresh a t"}
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   727
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   728
  but we have to instantiate it appropriately. These instantiations
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   729
  come from \<open>params1\<close> and \<open>prems2\<close>. We can determine
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   730
  whether we are in the simple or complicated case by checking whether
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   731
  the topmost connective is an \<open>\<forall>\<close>. The premises in the simple
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   732
  case cannot have such a quantification, since the first step 
569
f875a25aa72d prefer cartouches over " in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 567
diff changeset
   733
  of @{ML \<open>expand_tac\<close>} was to ``rulify'' the lemma. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   734
  The premise of the complicated case must have at least one  \<open>\<forall>\<close>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   735
  coming from the quantification over the \<open>preds\<close>. So 
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   736
  we can implement the following function
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   737
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   738
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   739
ML %grayML\<open>fun prepare_prem ctxt params2 prems2 prem =  
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   740
  resolve_tac ctxt [case Thm.prop_of prem of
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   741
           _ $ (Const (@{const_name All}, _) $ _) =>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   742
                 prem |> all_elims params2 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   743
                      |> imp_elims prems2
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   744
         | _ => prem]\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   745
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   746
text \<open>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   747
  which either applies the premise outright (the default case) or if 
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   748
  it has an outermost universial quantification, instantiates it first 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   749
  with  \<open>params1\<close> and then \<open>prems1\<close>. The following 
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   750
  tactic will therefore prove the lemma completely.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   751
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   752
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   753
ML %grayML\<open>fun prove_intro_tac i preds rules =
552
82c482467d75 updated to latest isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   754
  SUBPROOF (fn {params, prems, context, ...} =>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   755
  let
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   756
    val cparams = map snd params
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   757
    val (params1, params2) = chop (length cparams - length preds) cparams
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   758
    val (prems1, prems2) = chop (length prems - length rules) prems
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   759
  in
574
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   760
    resolve_tac context 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   761
      [Object_Logic.rulify context (all_elims params1 (nth prems2 i))] 1
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   762
    THEN EVERY1 (map (prepare_prem context params2 prems2) prems1)
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   763
  end)\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   764
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   765
text \<open>
299
d0b81d6e1b28 updated to Isabelle changes and merged sections in the FirstSteps chapter
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   766
  Note that the tactic is now @{ML SUBPROOF}, not @{ML FOCUS in Subgoal} anymore. 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   767
  The full proof of the introduction rule is as follows:
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   768
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   769
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   770
lemma fresh_Lam:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   771
shows "\<And>a b t. \<lbrakk>a \<noteq> b; fresh a t\<rbrakk> \<Longrightarrow> fresh a (Lam b t)"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   772
apply(tactic \<open>expand_tac @{context} @{thms fresh_def}\<close>)
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   773
apply(tactic \<open>prove_intro_tac 3 [fresh_pred] fresh_rules @{context} 1\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   774
done
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   775
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   776
text \<open>
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   777
  Phew!\ldots  
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   778
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   779
  Unfortunately, not everything is done yet. If you look closely
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   780
  at the general principle outlined for the introduction rules in 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   781
  Section~\ref{sec:nutshell}, we have  not yet dealt with the case where 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   782
  recursive premises have preconditions. The introduction rule
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   783
  of the accessible part is such a rule. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   784
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   785
448
957f69b9b7df added something about Goal.prove_multi
Christian Urban <urbanc@in.tum.de>
parents: 441
diff changeset
   786
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   787
lemma accpartI:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   788
shows "\<And>R x. (\<And>y. R y x \<Longrightarrow> accpart R y) \<Longrightarrow> accpart R x"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   789
apply(tactic \<open>expand_tac @{context} @{thms accpart_def}\<close>)
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   790
apply(tactic \<open>chop_test_tac [acc_pred] acc_rules @{context} 1\<close>)
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   791
apply(tactic \<open>apply_prem_tac 0 [acc_pred] acc_rules @{context} 1\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   792
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   793
txt \<open>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   794
  Here @{ML chop_test_tac} prints out the following
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   795
  values for \<open>params1/2\<close> and \<open>prems1/2\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   796
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   797
  \begin{isabelle}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   798
  \<open>Params1 from the rule:\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   799
  \<open>x\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   800
  \<open>Params2 from the predicate:\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   801
  \<open>P\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   802
  \<open>Prems1 from the rule:\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   803
  \<open>R ?y x \<Longrightarrow> \<forall>P. (\<forall>x. (\<forall>y. R y x \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> P ?y\<close>\\
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   804
  \<open>Prems2 from the predicate:\<close>\\
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   805
  @{term "\<forall>x. (\<forall>y. R y x \<longrightarrow> P y) \<longrightarrow> P x"}\\
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   806
  \end{isabelle}
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   807
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   808
  and after application of the introduction rule 
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   809
  using @{ML apply_prem_tac}, we are in the goal state
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   810
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   811
  \begin{isabelle}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   812
  \<open>1.\<close>~@{term "\<And>y. R y x \<Longrightarrow> P y"}
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   813
  \end{isabelle}
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   814
  
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   815
  
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   816
\<close>(*<*)oops(*>*)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   817
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   818
text \<open>
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   819
  In order to make progress, we have to use the precondition
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   820
  \<open>R y x\<close> (in general there can be many of them). The best way
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   821
  to get a handle on these preconditions is to open up another subproof,
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   822
  since the preconditions will then be bound to \<open>prems\<close>. Therfore we
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   823
  modify the function @{ML prepare_prem} as follows
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   824
\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   825
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   826
ML %linenosgray\<open>fun prepare_prem params2 prems2 ctxt prem =  
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   827
  SUBPROOF (fn {prems, ...} =>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   828
  let
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   829
    val prem' = prems MRS prem
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   830
  in 
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   831
    resolve_tac ctxt [case Thm.prop_of prem' of
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   832
           _ $ (Const (@{const_name All}, _) $ _) =>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   833
                 prem' |> all_elims params2 
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   834
                       |> imp_elims prems2
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   835
         | _ => prem'] 1
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   836
  end) ctxt\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   837
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   838
text \<open>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   839
  In Line 4 we use the \<open>prems\<close> from the @{ML SUBPROOF} and resolve 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   840
  them with \<open>prem\<close>. In the simple cases, that is where the \<open>prem\<close> 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   841
  comes from a non-recursive premise of the rule, \<open>prems\<close> will be 
369
74ba778b09c9 tuned index
Christian Urban <urbanc@in.tum.de>
parents: 358
diff changeset
   842
  just the empty list and the function @{ML_ind MRS in Drule} does nothing. Similarly, in the 
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   843
  cases where the recursive premises of the rule do not have preconditions. 
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   844
  In case there are preconditions, then Line 4 discharges them. After
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   845
  that we can proceed as before, i.e., check whether the outermost
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   846
  connective is \<open>\<forall>\<close>.
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   847
  
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   848
  The function @{ML prove_intro_tac} only needs to be changed so that it
575
c3dbc04471a9 fixing some Line references
Norbert Schirmer <norbert.schirmer@web.de>
parents: 574
diff changeset
   849
  gives the context to @{ML prepare_prem} (Line 10). The modified version
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   850
  is below.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   851
\<close>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   852
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   853
ML %linenosgray\<open>fun prove_intro_tac i preds rules =
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   854
  SUBPROOF (fn {params, prems, context, ...} =>
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   855
  let
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   856
    val cparams = map snd params
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   857
    val (params1, params2) = chop (length cparams - length preds) cparams
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   858
    val (prems1, prems2) = chop (length prems - length rules) prems
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   859
  in
574
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   860
    resolve_tac context 
034150db9d91 polish document
Norbert Schirmer <norbert.schirmer@web.de>
parents: 572
diff changeset
   861
      [Object_Logic.rulify context (all_elims params1 (nth prems2 i))] 1
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   862
    THEN EVERY1 (map (prepare_prem params2 prems2 context) prems1)
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   863
  end)\<close>
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   864
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   865
text \<open>
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   866
  With these two functions we can now also prove the introduction
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   867
  rule for the accessible part. 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   868
\<close>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   869
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   870
lemma accpartI:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   871
shows "\<And>R x. (\<And>y. R y x \<Longrightarrow> accpart R y) \<Longrightarrow> accpart R x"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   872
apply(tactic \<open>expand_tac @{context} @{thms accpart_def}\<close>)
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   873
apply(tactic \<open>prove_intro_tac 0 [acc_pred] acc_rules @{context} 1\<close>)
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   874
done
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   875
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   876
text \<open>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   877
  Finally we need two functions that string everything together. The first
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   878
  function is the tactic that performs the proofs.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   879
\<close>
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   880
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   881
ML %linenosgray\<open>fun intro_tac defs rules preds i ctxt =
552
82c482467d75 updated to latest isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   882
  EVERY1 [Object_Logic.rulify_tac ctxt,
82c482467d75 updated to latest isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 517
diff changeset
   883
          rewrite_goal_tac ctxt defs,
562
daf404920ab9 Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents: 552
diff changeset
   884
          REPEAT o (resolve_tac ctxt [@{thm allI}, @{thm impI}]),
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   885
          prove_intro_tac i preds rules ctxt]\<close>
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   886
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   887
text \<open>
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   888
  Lines 2 to 4 in this tactic correspond to the function @{ML expand_tac}. 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   889
  Some testcases for this tactic are:
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   890
\<close>
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   891
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   892
lemma even0_intro:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   893
shows "even 0"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   894
by (tactic \<open>intro_tac eo_defs eo_rules eo_preds 0 @{context}\<close>)
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   895
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   896
lemma evenS_intro:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   897
shows "\<And>m. odd m \<Longrightarrow> even (Suc m)"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   898
by (tactic \<open>intro_tac eo_defs eo_rules eo_preds 1 @{context}\<close>)
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   899
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   900
lemma fresh_App:
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
   901
shows "\<And>a t s. \<lbrakk>fresh a t; fresh a s\<rbrakk> \<Longrightarrow> fresh a (App t s)"
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   902
by (tactic \<open>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   903
  intro_tac @{thms fresh_def} fresh_rules [fresh_pred] 1 @{context}\<close>)
190
ca0ac2e75f6d more one the simple-inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 189
diff changeset
   904
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   905
text \<open>
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   906
  The second function sets up in Line 4 the goals to be proved (this is easy
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   907
  for the introduction rules since they are exactly the rules 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   908
  given by the user) and iterates @{ML intro_tac} over all 
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   909
  introduction rules.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   910
\<close>
173
d820cb5873ea used latex package boxedminipage
Christian Urban <urbanc@in.tum.de>
parents: 165
diff changeset
   911
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   912
ML %linenosgray\<open>fun intros rules preds defs lthy = 
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   913
let
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   914
  fun intros_aux (i, goal) =
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   915
    Goal.prove lthy [] [] goal
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   916
      (fn {context, ...} => intro_tac defs rules preds i context)
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   917
in
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   918
  map_index intros_aux rules
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   919
end\<close>
164
3f617d7a2691 more work on simple_inductive
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
   920
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   921
text \<open>
369
74ba778b09c9 tuned index
Christian Urban <urbanc@in.tum.de>
parents: 358
diff changeset
   922
  The iteration is done with the function @{ML_ind map_index in Library} since we
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   923
  need the introduction rule together with its number (counted from
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   924
  \<open>0\<close>). This completes the code for the functions deriving the
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   925
  reasoning infrastructure. It remains to implement some administrative
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   926
  code that strings everything together.
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   927
\<close>
212
ac01ddb285f6 polishing
Christian Urban <urbanc@in.tum.de>
parents: 211
diff changeset
   928
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   929
subsection \<open>Administrative Functions\<close>
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   930
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   931
text \<open>
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   932
  We have produced various theorems (definitions, induction principles and
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   933
  introduction rules), but apart from the definitions, we have not yet 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   934
  registered them with the theorem database. This is what the functions 
394
0019ebf76e10 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 375
diff changeset
   935
  @{ML_ind  note in Local_Theory} does. 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   936
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   937
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   938
  For convenience, we use the following 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   939
  three wrappers this function:
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   940
\<close>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   941
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   942
ML %grayML\<open>fun note_many qname ((name, attrs), thms) = 
394
0019ebf76e10 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 375
diff changeset
   943
  Local_Theory.note ((Binding.qualify false qname name, attrs), thms) 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   944
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   945
fun note_single1 qname ((name, attrs), thm) = 
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   946
  note_many qname ((name, attrs), [thm]) 
176
3da5f3f07d8b updated to new read_specification
Christian Urban <urbanc@in.tum.de>
parents: 173
diff changeset
   947
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   948
fun note_single2 name attrs (qname, thm) = 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   949
  note_many (Binding.name_of qname) ((name, attrs), [thm])\<close>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   950
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   951
text \<open>
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   952
  The function that ``holds everything together'' is \<open>add_inductive\<close>. 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   953
  Its arguments are the specification of the predicates \<open>pred_specs\<close> 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   954
  and the introduction rules \<open>rule_spec\<close>.   
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   955
\<close>
211
d5accbc67e1b more work on simple inductive and marked all sections that are still seriously incomplete with TBD
Christian Urban <urbanc@in.tum.de>
parents: 210
diff changeset
   956
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   957
ML %linenosgray\<open>fun add_inductive pred_specs rule_specs lthy =
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   958
let
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   959
  val mxs = map snd pred_specs
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   960
  val pred_specs' = map fst pred_specs
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   961
  val prednames = map fst pred_specs'
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   962
  val preds = map (fn (p, ty) => Free (Binding.name_of p, ty)) pred_specs'
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   963
  val tyss = map (binder_types o fastype_of) preds   
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
   964
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   965
  val (namesattrs, rules) = split_list rule_specs    
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   966
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   967
  val (defs, lthy') = defns rules preds prednames mxs tyss lthy      
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   968
  val ind_prins = inds rules defs preds tyss lthy' 	
210
db8e302f44c8 more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents: 209
diff changeset
   969
  val intro_rules = intros rules preds defs lthy'
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   970
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   971
  val mut_name = space_implode "_" (map Binding.name_of prednames)
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   972
  val case_names = map (Binding.name_of o fst) namesattrs
165
890fbfef6d6b partially adapted to new antiquotation infrastructure
Christian Urban <urbanc@in.tum.de>
parents: 164
diff changeset
   973
in
295
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   974
  lthy' |> note_many mut_name ((@{binding "intros"}, []), intro_rules) 
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   975
        ||>> note_many mut_name ((@{binding "inducts"}, []), ind_prins)
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   976
        ||>> fold_map (note_single1 mut_name) (namesattrs ~~ intro_rules)  
24c68350d059 polished the package chapter used FOCUS to explain the subproofs
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   977
        ||>> fold_map (note_single2 @{binding "induct"} 
375
92f7328dc5cc added type work and updated to Isabelle and poly 5.3
Christian Urban <urbanc@in.tum.de>
parents: 369
diff changeset
   978
              [Attrib.internal (K (Rule_Cases.case_names case_names)),
92f7328dc5cc added type work and updated to Isabelle and poly 5.3
Christian Urban <urbanc@in.tum.de>
parents: 369
diff changeset
   979
               Attrib.internal (K (Rule_Cases.consumes 1)),
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   980
               Attrib.internal (K (Induct.induct_pred ""))]) 
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
   981
             (prednames ~~ ind_prins) 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   982
        |> snd
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   983
end\<close>
91
667a0943c40b added a section that will eventually describe the code
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   984
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   985
text \<open>
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   986
  In Line 3 the function extracts the syntax annotations from the predicates. 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   987
  Lines 4 to 6 extract the names of the predicates and generate
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   988
  the variables terms (with types) corresponding to the predicates. 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   989
  Line 7 produces the argument types for each predicate. 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   990
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   991
  Line 9 extracts the introduction rules from the specifications
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   992
  and stores also in \<open>namesattrs\<close> the names and attributes the
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   993
  user may have attached to these rules.
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   994
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   995
  Line 11 produces the definitions and also registers the definitions
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   996
  in the local theory \<open>lthy'\<close>. The next two lines produce
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   997
  the induction principles and the introduction rules (all of them
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
   998
  as theorems). Both need the local theory \<open>lthy'\<close> in which
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
   999
  the definitions have been registered.
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1000
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1001
  Lines 15 produces the name that is used to register the introduction
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1002
  rules. It is costum to collect all introduction rules under 
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
  1003
  \<open>string.intros\<close>, whereby \<open>string\<close> stands for the 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1004
  @{text [quotes] "_"}-separated list of predicate names (for example
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
  1005
  \<open>even_odd\<close>. Also by custom, the case names in intuction 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1006
  proofs correspond to the names of the introduction rules. These
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1007
  are generated in Line 16.
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1008
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
  1009
  Lines 18 and 19 now add to \<open>lthy'\<close> all the introduction rules 
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
  1010
  und induction principles under the name \<open>mut_name.intros\<close> and
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
  1011
  \<open>mut_name.inducts\<close>, respectively (see previous paragraph).
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
  1012
  
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
  1013
  Line 20 add further every introduction rule under its own name
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1014
  (given by the user).\footnote{FIXME: what happens if the user did not give
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
  1015
  any name.} Line 21 registers the induction principles. For this we have
375
92f7328dc5cc added type work and updated to Isabelle and poly 5.3
Christian Urban <urbanc@in.tum.de>
parents: 369
diff changeset
  1016
  to use some specific attributes. The first @{ML_ind  case_names in Rule_Cases} 
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1017
  corresponds to the case names that are used by Isar to reference the proof
569
f875a25aa72d prefer cartouches over " in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents: 567
diff changeset
  1018
  obligations in the induction. The second @{ML \<open>consumes 1\<close> in Rule_Cases}
215
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1019
  indicates that the first premise of the induction principle (namely
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1020
  the predicate over which the induction proceeds) is eliminated. 
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1021
8d1a344a621e more work on the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 212
diff changeset
  1022
  This completes all the code and fits in with the ``front end'' described
237
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
  1023
  in Section~\ref{sec:interface}.\footnote{FIXME: Describe @{ML Induct.induct_pred}. 
0a8981f52045 very slight polishing to the simple inductive chapter
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
  1024
  Why the mut-name? 
224
647cab4a72c2 finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents: 219
diff changeset
  1025
  What does @{ML Binding.qualify} do?}
565
cecd7a941885 isabelle update_cartouches -t
Norbert Schirmer <norbert.schirmer@web.de>
parents: 562
diff changeset
  1026
\<close>
517
d8c376662bb4 removed special ML-setup and replaced it by explicit markups (i.e., %grayML)
Christian Urban <urbanc@in.tum.de>
parents: 475
diff changeset
  1027
(*<*)end(*>*)