src/HOL/Recdef.thy
author krauss
Tue Jul 28 08:48:56 2009 +0200 (2009-07-28)
changeset 32244 a99723d77ae0
parent 31723 f5cafe803b55
child 32462 c33faa289520
permissions -rw-r--r--
moved obsolete same_fst to Recdef.thy
     1 (*  Title:      HOL/Recdef.thy
     2     Author:     Konrad Slind and Markus Wenzel, TU Muenchen
     3 *)
     4 
     5 header {* TFL: recursive function definitions *}
     6 
     7 theory Recdef
     8 imports FunDef Plain
     9 uses
    10   ("Tools/TFL/casesplit.ML")
    11   ("Tools/TFL/utils.ML")
    12   ("Tools/TFL/usyntax.ML")
    13   ("Tools/TFL/dcterm.ML")
    14   ("Tools/TFL/thms.ML")
    15   ("Tools/TFL/rules.ML")
    16   ("Tools/TFL/thry.ML")
    17   ("Tools/TFL/tfl.ML")
    18   ("Tools/TFL/post.ML")
    19   ("Tools/recdef.ML")
    20 begin
    21 
    22 text{** This form avoids giant explosions in proofs.  NOTE USE OF ==*}
    23 lemma def_wfrec: "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a"
    24 apply auto
    25 apply (blast intro: wfrec)
    26 done
    27 
    28 
    29 lemma tfl_wf_induct: "ALL R. wf R -->  
    30        (ALL P. (ALL x. (ALL y. (y,x):R --> P y) --> P x) --> (ALL x. P x))"
    31 apply clarify
    32 apply (rule_tac r = R and P = P and a = x in wf_induct, assumption, blast)
    33 done
    34 
    35 lemma tfl_cut_apply: "ALL f R. (x,a):R --> (cut f R a)(x) = f(x)"
    36 apply clarify
    37 apply (rule cut_apply, assumption)
    38 done
    39 
    40 lemma tfl_wfrec:
    41      "ALL M R f. (f=wfrec R M) --> wf R --> (ALL x. f x = M (cut f R x) x)"
    42 apply clarify
    43 apply (erule wfrec)
    44 done
    45 
    46 lemma tfl_eq_True: "(x = True) --> x"
    47   by blast
    48 
    49 lemma tfl_rev_eq_mp: "(x = y) --> y --> x";
    50   by blast
    51 
    52 lemma tfl_simp_thm: "(x --> y) --> (x = x') --> (x' --> y)"
    53   by blast
    54 
    55 lemma tfl_P_imp_P_iff_True: "P ==> P = True"
    56   by blast
    57 
    58 lemma tfl_imp_trans: "(A --> B) ==> (B --> C) ==> (A --> C)"
    59   by blast
    60 
    61 lemma tfl_disj_assoc: "(a \<or> b) \<or> c == a \<or> (b \<or> c)"
    62   by simp
    63 
    64 lemma tfl_disjE: "P \<or> Q ==> P --> R ==> Q --> R ==> R"
    65   by blast
    66 
    67 lemma tfl_exE: "\<exists>x. P x ==> \<forall>x. P x --> Q ==> Q"
    68   by blast
    69 
    70 use "Tools/TFL/casesplit.ML"
    71 use "Tools/TFL/utils.ML"
    72 use "Tools/TFL/usyntax.ML"
    73 use "Tools/TFL/dcterm.ML"
    74 use "Tools/TFL/thms.ML"
    75 use "Tools/TFL/rules.ML"
    76 use "Tools/TFL/thry.ML"
    77 use "Tools/TFL/tfl.ML"
    78 use "Tools/TFL/post.ML"
    79 use "Tools/recdef.ML"
    80 setup Recdef.setup
    81 
    82 text {*Wellfoundedness of @{text same_fst}*}
    83 
    84 definition
    85  same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set"
    86 where
    87     "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}"
    88    --{*For @{text rec_def} declarations where the first n parameters
    89        stay unchanged in the recursive call. *}
    90 
    91 lemma same_fstI [intro!]:
    92      "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R"
    93 by (simp add: same_fst_def)
    94 
    95 lemma wf_same_fst:
    96   assumes prem: "(!!x. P x ==> wf(R x))"
    97   shows "wf(same_fst P R)"
    98 apply (simp cong del: imp_cong add: wf_def same_fst_def)
    99 apply (intro strip)
   100 apply (rename_tac a b)
   101 apply (case_tac "wf (R a)")
   102  apply (erule_tac a = b in wf_induct, blast)
   103 apply (blast intro: prem)
   104 done
   105 
   106 text {*Rule setup*}
   107 
   108 lemmas [recdef_simp] =
   109   inv_image_def
   110   measure_def
   111   lex_prod_def
   112   same_fst_def
   113   less_Suc_eq [THEN iffD2]
   114 
   115 lemmas [recdef_cong] =
   116   if_cong let_cong image_cong INT_cong UN_cong bex_cong ball_cong imp_cong
   117 
   118 lemmas [recdef_wf] =
   119   wf_trancl
   120   wf_less_than
   121   wf_lex_prod
   122   wf_inv_image
   123   wf_measure
   124   wf_pred_nat
   125   wf_same_fst
   126   wf_empty
   127 
   128 end