src/HOL/Library/Old_Recdef.thy
author krauss
Tue, 02 Aug 2011 10:36:50 +0200
changeset 44013 5cfc1c36ae97
parent 39302 src/HOL/Recdef.thy@d7728f65b353
child 44014 88bd7d74a2c1
permissions -rw-r--r--
moved recdef package to HOL/Library/Old_Recdef.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44013
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
     1
(*  Title:      HOL/Library/Old_Recdef.thy
10773
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
     2
    Author:     Konrad Slind and Markus Wenzel, TU Muenchen
12023
wenzelm
parents: 11533
diff changeset
     3
*)
5123
97c1d5c7b701 stepping stones;
wenzelm
parents:
diff changeset
     4
12023
wenzelm
parents: 11533
diff changeset
     5
header {* TFL: recursive function definitions *}
7701
2c8c3b7003e5 load / setup recdef package (TFL);
wenzelm
parents: 7357
diff changeset
     6
44013
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
     7
theory Old_Recdef
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
     8
imports Main
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 15481
diff changeset
     9
uses
44013
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    10
  ("~~/src/HOL/Tools/TFL/casesplit.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    11
  ("~~/src/HOL/Tools/TFL/utils.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    12
  ("~~/src/HOL/Tools/TFL/usyntax.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    13
  ("~~/src/HOL/Tools/TFL/dcterm.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    14
  ("~~/src/HOL/Tools/TFL/thms.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    15
  ("~~/src/HOL/Tools/TFL/rules.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    16
  ("~~/src/HOL/Tools/TFL/thry.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    17
  ("~~/src/HOL/Tools/TFL/tfl.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    18
  ("~~/src/HOL/Tools/TFL/post.ML")
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    19
  ("~~/src/HOL/Tools/recdef.ML")
15131
c69542757a4d New theory header syntax.
nipkow
parents: 12437
diff changeset
    20
begin
10773
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
    21
32462
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    22
inductive
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    23
  wfrec_rel :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => 'a => 'b => bool"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    24
  for R :: "('a * 'a) set"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    25
  and F :: "('a => 'b) => 'a => 'b"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    26
where
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    27
  wfrecI: "ALL z. (z, x) : R --> wfrec_rel R F z (g z) ==>
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    28
            wfrec_rel R F x (F g x)"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    29
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 32462
diff changeset
    30
definition
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 32462
diff changeset
    31
  cut        :: "('a => 'b) => ('a * 'a)set => 'a => 'a => 'b" where
32462
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    32
  "cut f r x == (%y. if (y,x):r then f y else undefined)"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    33
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 32462
diff changeset
    34
definition
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 32462
diff changeset
    35
  adm_wf :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => bool" where
32462
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    36
  "adm_wf R F == ALL f g x.
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    37
     (ALL z. (z, x) : R --> f z = g z) --> F f x = F g x"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    38
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 32462
diff changeset
    39
definition
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 32462
diff changeset
    40
  wfrec :: "('a * 'a) set => (('a => 'b) => 'a => 'b) => 'a => 'b" where
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 35416
diff changeset
    41
  "wfrec R F == %x. THE y. wfrec_rel R (%f x. F (cut f R x) x) x y"
32462
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    42
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    43
subsection{*Well-Founded Recursion*}
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    44
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    45
text{*cut*}
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    46
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    47
lemma cuts_eq: "(cut f r x = cut g r x) = (ALL y. (y,x):r --> f(y)=g(y))"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
    48
by (simp add: fun_eq_iff cut_def)
32462
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    49
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    50
lemma cut_apply: "(x,a):r ==> (cut f r a)(x) = f(x)"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    51
by (simp add: cut_def)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    52
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    53
text{*Inductive characterization of wfrec combinator; for details see:
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    54
John Harrison, "Inductive definitions: automation and application"*}
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    55
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    56
lemma wfrec_unique: "[| adm_wf R F; wf R |] ==> EX! y. wfrec_rel R F x y"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    57
apply (simp add: adm_wf_def)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    58
apply (erule_tac a=x in wf_induct)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    59
apply (rule ex1I)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    60
apply (rule_tac g = "%x. THE y. wfrec_rel R F x y" in wfrec_rel.wfrecI)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    61
apply (fast dest!: theI')
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    62
apply (erule wfrec_rel.cases, simp)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    63
apply (erule allE, erule allE, erule allE, erule mp)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    64
apply (fast intro: the_equality [symmetric])
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    65
done
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    66
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    67
lemma adm_lemma: "adm_wf R (%f x. F (cut f R x) x)"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    68
apply (simp add: adm_wf_def)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    69
apply (intro strip)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    70
apply (rule cuts_eq [THEN iffD2, THEN subst], assumption)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    71
apply (rule refl)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    72
done
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    73
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    74
lemma wfrec: "wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a"
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    75
apply (simp add: wfrec_def)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    76
apply (rule adm_lemma [THEN wfrec_unique, THEN the1_equality], assumption)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    77
apply (rule wfrec_rel.wfrecI)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    78
apply (intro strip)
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    79
apply (erule adm_lemma [THEN wfrec_unique, THEN theI'])
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    80
done
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    81
c33faa289520 moved wfrec to Recdef.thy
krauss
parents: 32244
diff changeset
    82
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
    83
text{** This form avoids giant explosions in proofs.  NOTE USE OF ==*}
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
    84
lemma def_wfrec: "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
    85
apply auto
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
    86
apply (blast intro: wfrec)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
    87
done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
    88
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
    89
44013
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    90
subsection {* Nitpick setup *}
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    91
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    92
axiomatization wf_wfrec :: "('a \<times> 'a \<Rightarrow> bool) \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    93
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    94
definition wf_wfrec' :: "('a \<times> 'a \<Rightarrow> bool) \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" where
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    95
[nitpick_simp]: "wf_wfrec' R F x = F (cut (wf_wfrec R F) R x) x"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    96
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    97
definition wfrec' ::  "('a \<times> 'a \<Rightarrow> bool) \<Rightarrow> (('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" where
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    98
"wfrec' R F x \<equiv> if wf R then wf_wfrec' R F x
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
    99
                else THE y. wfrec_rel R (%f x. F (cut f R x) x) x y"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   100
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   101
setup {*
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   102
  Nitpick_HOL.register_ersatz_global
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   103
    [(@{const_name wf_wfrec}, @{const_name wf_wfrec'}),
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   104
     (@{const_name wfrec}, @{const_name wfrec'})]
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   105
*}
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   106
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   107
hide_const (open) wf_wfrec wf_wfrec' wfrec'
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   108
hide_fact (open) wf_wfrec'_def wfrec'_def
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   109
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   110
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   111
subsection {* Lemmas for TFL *}
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   112
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   113
lemma tfl_wf_induct: "ALL R. wf R -->  
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   114
       (ALL P. (ALL x. (ALL y. (y,x):R --> P y) --> P x) --> (ALL x. P x))"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   115
apply clarify
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   116
apply (rule_tac r = R and P = P and a = x in wf_induct, assumption, blast)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   117
done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   118
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   119
lemma tfl_cut_apply: "ALL f R. (x,a):R --> (cut f R a)(x) = f(x)"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   120
apply clarify
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   121
apply (rule cut_apply, assumption)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   122
done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   123
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   124
lemma tfl_wfrec:
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   125
     "ALL M R f. (f=wfrec R M) --> wf R --> (ALL x. f x = M (cut f R x) x)"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   126
apply clarify
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   127
apply (erule wfrec)
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   128
done
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 23742
diff changeset
   129
10773
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   130
lemma tfl_eq_True: "(x = True) --> x"
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   131
  by blast
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   132
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   133
lemma tfl_rev_eq_mp: "(x = y) --> y --> x";
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   134
  by blast
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   135
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   136
lemma tfl_simp_thm: "(x --> y) --> (x = x') --> (x' --> y)"
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   137
  by blast
6438
e55a1869ed38 'HOL/recdef' theory data;
wenzelm
parents: 5123
diff changeset
   138
10773
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   139
lemma tfl_P_imp_P_iff_True: "P ==> P = True"
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   140
  by blast
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   141
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   142
lemma tfl_imp_trans: "(A --> B) ==> (B --> C) ==> (A --> C)"
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   143
  by blast
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   144
12023
wenzelm
parents: 11533
diff changeset
   145
lemma tfl_disj_assoc: "(a \<or> b) \<or> c == a \<or> (b \<or> c)"
10773
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   146
  by simp
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   147
12023
wenzelm
parents: 11533
diff changeset
   148
lemma tfl_disjE: "P \<or> Q ==> P --> R ==> Q --> R ==> R"
10773
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   149
  by blast
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   150
12023
wenzelm
parents: 11533
diff changeset
   151
lemma tfl_exE: "\<exists>x. P x ==> \<forall>x. P x --> Q ==> Q"
10773
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   152
  by blast
0deff0197496 renamed .sml files to .ML;
wenzelm
parents: 10653
diff changeset
   153
44013
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   154
use "~~/src/HOL/Tools/TFL/casesplit.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   155
use "~~/src/HOL/Tools/TFL/utils.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   156
use "~~/src/HOL/Tools/TFL/usyntax.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   157
use "~~/src/HOL/Tools/TFL/dcterm.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   158
use "~~/src/HOL/Tools/TFL/thms.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   159
use "~~/src/HOL/Tools/TFL/rules.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   160
use "~~/src/HOL/Tools/TFL/thry.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   161
use "~~/src/HOL/Tools/TFL/tfl.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   162
use "~~/src/HOL/Tools/TFL/post.ML"
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   163
use "~~/src/HOL/Tools/recdef.ML"
31723
f5cafe803b55 discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 29654
diff changeset
   164
setup Recdef.setup
6438
e55a1869ed38 'HOL/recdef' theory data;
wenzelm
parents: 5123
diff changeset
   165
32244
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   166
text {*Wellfoundedness of @{text same_fst}*}
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   167
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   168
definition
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   169
 same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set"
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   170
where
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   171
    "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}"
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   172
   --{*For @{text rec_def} declarations where the first n parameters
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   173
       stay unchanged in the recursive call. *}
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   174
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   175
lemma same_fstI [intro!]:
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   176
     "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R"
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   177
by (simp add: same_fst_def)
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   178
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   179
lemma wf_same_fst:
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   180
  assumes prem: "(!!x. P x ==> wf(R x))"
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   181
  shows "wf(same_fst P R)"
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   182
apply (simp cong del: imp_cong add: wf_def same_fst_def)
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   183
apply (intro strip)
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   184
apply (rename_tac a b)
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   185
apply (case_tac "wf (R a)")
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   186
 apply (erule_tac a = b in wf_induct, blast)
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   187
apply (blast intro: prem)
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   188
done
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   189
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   190
text {*Rule setup*}
a99723d77ae0 moved obsolete same_fst to Recdef.thy
krauss
parents: 31723
diff changeset
   191
9855
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   192
lemmas [recdef_simp] =
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   193
  inv_image_def
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   194
  measure_def
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   195
  lex_prod_def
11284
981ea92a86dd made same_fst recdef_simp
nipkow
parents: 11165
diff changeset
   196
  same_fst_def
9855
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   197
  less_Suc_eq [THEN iffD2]
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   198
23150
073a65f0bc40 moved TFL files to canonical place;
wenzelm
parents: 22622
diff changeset
   199
lemmas [recdef_cong] =
22622
25693088396b Moving "FunDef" up in the HOL development graph, since it is independent from "Recdef" and "Datatype" now.
krauss
parents: 22399
diff changeset
   200
  if_cong let_cong image_cong INT_cong UN_cong bex_cong ball_cong imp_cong
44013
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   201
  map_cong filter_cong takeWhile_cong dropWhile_cong foldl_cong foldr_cong 
9855
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   202
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   203
lemmas [recdef_wf] =
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   204
  wf_trancl
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   205
  wf_less_than
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   206
  wf_lex_prod
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   207
  wf_inv_image
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   208
  wf_measure
44013
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 39302
diff changeset
   209
  wf_measures
9855
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   210
  wf_pred_nat
10653
55f33da63366 small mods.
nipkow
parents: 10212
diff changeset
   211
  wf_same_fst
9855
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   212
  wf_empty
709a295731e2 improved recdef setup;
wenzelm
parents: 8303
diff changeset
   213
6438
e55a1869ed38 'HOL/recdef' theory data;
wenzelm
parents: 5123
diff changeset
   214
end