
wenzelm@7701: (*  Title:      HOL/Recdef.thy
wenzelm@10773:     Author:     Konrad Slind and Markus Wenzel, TU Muenchen
wenzelm@12023: *)
wenzelm@5123: 
wenzelm@12023: header {* TFL: recursive function definitions *}
wenzelm@7701: 
nipkow@15131: theory Recdef
haftmann@29654: imports FunDef Plain
haftmann@16417: uses
wenzelm@23150:   ("Tools/TFL/casesplit.ML")
wenzelm@23150:   ("Tools/TFL/utils.ML")
wenzelm@23150:   ("Tools/TFL/usyntax.ML")
wenzelm@23150:   ("Tools/TFL/dcterm.ML")
wenzelm@23150:   ("Tools/TFL/thms.ML")
wenzelm@23150:   ("Tools/TFL/rules.ML")
wenzelm@23150:   ("Tools/TFL/thry.ML")
wenzelm@23150:   ("Tools/TFL/tfl.ML")
wenzelm@23150:   ("Tools/TFL/post.ML")
haftmann@31723:   ("Tools/recdef.ML")
nipkow@15131: begin
wenzelm@10773: 
krauss@26748: text{** This form avoids giant explosions in proofs.  NOTE USE OF ==*}
krauss@26748: lemma def_wfrec: "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a"
krauss@26748: apply auto
krauss@26748: apply (blast intro: wfrec)
krauss@26748: done
krauss@26748: 
krauss@26748: 
krauss@26748: lemma tfl_wf_induct: "ALL R. wf R -->  
krauss@26748:        (ALL P. (ALL x. (ALL y. (y,x):R --> P y) --> P x) --> (ALL x. P x))"
krauss@26748: apply clarify
krauss@26748: apply (rule_tac r = R and P = P and a = x in wf_induct, assumption, blast)
krauss@26748: done
krauss@26748: 
krauss@26748: lemma tfl_cut_apply: "ALL f R. (x,a):R --> (cut f R a)(x) = f(x)"
krauss@26748: apply clarify
krauss@26748: apply (rule cut_apply, assumption)
krauss@26748: done
krauss@26748: 
krauss@26748: lemma tfl_wfrec:
krauss@26748:      "ALL M R f. (f=wfrec R M) --> wf R --> (ALL x. f x = M (cut f R x) x)"
krauss@26748: apply clarify
krauss@26748: apply (erule wfrec)
krauss@26748: done
krauss@26748: 
wenzelm@10773: lemma tfl_eq_True: "(x = True) --> x"
wenzelm@10773:   by blast
wenzelm@10773: 
wenzelm@10773: lemma tfl_rev_eq_mp: "(x = y) --> y --> x";
wenzelm@10773:   by blast
wenzelm@10773: 
wenzelm@10773: lemma tfl_simp_thm: "(x --> y) --> (x = x') --> (x' --> y)"
wenzelm@10773:   by blast
wenzelm@6438: 
wenzelm@10773: lemma tfl_P_imp_P_iff_True: "P ==> P = True"
wenzelm@10773:   by blast
wenzelm@10773: 
wenzelm@10773: lemma tfl_imp_trans: "(A --> B) ==> (B --> C) ==> (A --> C)"
wenzelm@10773:   by blast
wenzelm@10773: 
wenzelm@12023: lemma tfl_disj_assoc: "(a \<or> b) \<or> c == a \<or> (b \<or> c)"
wenzelm@10773:   by simp
wenzelm@10773: 
wenzelm@12023: lemma tfl_disjE: "P \<or> Q ==> P --> R ==> Q --> R ==> R"
wenzelm@10773:   by blast
wenzelm@10773: 
wenzelm@12023: lemma tfl_exE: "\<exists>x. P x ==> \<forall>x. P x --> Q ==> Q"
wenzelm@10773:   by blast
wenzelm@10773: 
wenzelm@23150: use "Tools/TFL/casesplit.ML"
wenzelm@23150: use "Tools/TFL/utils.ML"
wenzelm@23150: use "Tools/TFL/usyntax.ML"
wenzelm@23150: use "Tools/TFL/dcterm.ML"
wenzelm@23150: use "Tools/TFL/thms.ML"
wenzelm@23150: use "Tools/TFL/rules.ML"
wenzelm@23150: use "Tools/TFL/thry.ML"
wenzelm@23150: use "Tools/TFL/tfl.ML"
wenzelm@23150: use "Tools/TFL/post.ML"
haftmann@31723: use "Tools/recdef.ML"
haftmann@31723: setup Recdef.setup
wenzelm@6438: 
krauss@32244: text {*Wellfoundedness of @{text same_fst}*}
krauss@32244: 
krauss@32244: definition
krauss@32244:  same_fst :: "('a => bool) => ('a => ('b * 'b)set) => (('a*'b)*('a*'b))set"
krauss@32244: where
krauss@32244:     "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}"
krauss@32244:    --{*For @{text rec_def} declarations where the first n parameters
krauss@32244:        stay unchanged in the recursive call. *}
krauss@32244: 
krauss@32244: lemma same_fstI [intro!]:
krauss@32244:      "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R"
krauss@32244: by (simp add: same_fst_def)
krauss@32244: 
krauss@32244: lemma wf_same_fst:
krauss@32244:   assumes prem: "(!!x. P x ==> wf(R x))"
krauss@32244:   shows "wf(same_fst P R)"
krauss@32244: apply (simp cong del: imp_cong add: wf_def same_fst_def)
krauss@32244: apply (intro strip)
krauss@32244: apply (rename_tac a b)
krauss@32244: apply (case_tac "wf (R a)")
krauss@32244:  apply (erule_tac a = b in wf_induct, blast)
krauss@32244: apply (blast intro: prem)
krauss@32244: done
krauss@32244: 
krauss@32244: text {*Rule setup*}
krauss@32244: 
wenzelm@9855: lemmas [recdef_simp] =
wenzelm@9855:   inv_image_def
wenzelm@9855:   measure_def
wenzelm@9855:   lex_prod_def
nipkow@11284:   same_fst_def
wenzelm@9855:   less_Suc_eq [THEN iffD2]
wenzelm@9855: 
wenzelm@23150: lemmas [recdef_cong] =
krauss@22622:   if_cong let_cong image_cong INT_cong UN_cong bex_cong ball_cong imp_cong
wenzelm@9855: 
wenzelm@9855: lemmas [recdef_wf] =
wenzelm@9855:   wf_trancl
wenzelm@9855:   wf_less_than
wenzelm@9855:   wf_lex_prod
wenzelm@9855:   wf_inv_image
wenzelm@9855:   wf_measure
wenzelm@9855:   wf_pred_nat
nipkow@10653:   wf_same_fst
wenzelm@9855:   wf_empty
wenzelm@9855: 
wenzelm@6438: end




