src/HOL/Fun.thy
changeset 23878 bd651ecd4b8a
parent 23738 3a801ffdc58c
child 24017 363287741ebe
equal deleted inserted replaced
23877:307f75aaefca 23878:bd651ecd4b8a
   456   thus "surj (swap a b f)" by (rule surj_imp_surj_swap) 
   456   thus "surj (swap a b f)" by (rule surj_imp_surj_swap) 
   457 qed
   457 qed
   458 
   458 
   459 lemma bij_swap_iff: "bij (swap a b f) = bij f"
   459 lemma bij_swap_iff: "bij (swap a b f) = bij f"
   460 by (simp add: bij_def)
   460 by (simp add: bij_def)
   461 
       
   462 
       
   463 subsection {* Order and lattice on functions *}
       
   464 
       
   465 instance "fun" :: (type, ord) ord
       
   466   le_fun_def: "f \<le> g \<equiv> \<forall>x. f x \<le> g x"
       
   467   less_fun_def: "f < g \<equiv> f \<le> g \<and> f \<noteq> g" ..
       
   468 
       
   469 lemmas [code func del] = le_fun_def less_fun_def
       
   470 
       
   471 instance "fun" :: (type, order) order
       
   472   by default
       
   473     (auto simp add: le_fun_def less_fun_def expand_fun_eq
       
   474        intro: order_trans order_antisym)
       
   475 
       
   476 lemma le_funI: "(\<And>x. f x \<le> g x) \<Longrightarrow> f \<le> g"
       
   477   unfolding le_fun_def by simp
       
   478 
       
   479 lemma le_funE: "f \<le> g \<Longrightarrow> (f x \<le> g x \<Longrightarrow> P) \<Longrightarrow> P"
       
   480   unfolding le_fun_def by simp
       
   481 
       
   482 lemma le_funD: "f \<le> g \<Longrightarrow> f x \<le> g x"
       
   483   unfolding le_fun_def by simp
       
   484 
       
   485 text {*
       
   486   Handy introduction and elimination rules for @{text "\<le>"}
       
   487   on unary and binary predicates
       
   488 *}
       
   489 
       
   490 lemma predicate1I [Pure.intro!, intro!]:
       
   491   assumes PQ: "\<And>x. P x \<Longrightarrow> Q x"
       
   492   shows "P \<le> Q"
       
   493   apply (rule le_funI)
       
   494   apply (rule le_boolI)
       
   495   apply (rule PQ)
       
   496   apply assumption
       
   497   done
       
   498 
       
   499 lemma predicate1D [Pure.dest, dest]: "P \<le> Q \<Longrightarrow> P x \<Longrightarrow> Q x"
       
   500   apply (erule le_funE)
       
   501   apply (erule le_boolE)
       
   502   apply assumption+
       
   503   done
       
   504 
       
   505 lemma predicate2I [Pure.intro!, intro!]:
       
   506   assumes PQ: "\<And>x y. P x y \<Longrightarrow> Q x y"
       
   507   shows "P \<le> Q"
       
   508   apply (rule le_funI)+
       
   509   apply (rule le_boolI)
       
   510   apply (rule PQ)
       
   511   apply assumption
       
   512   done
       
   513 
       
   514 lemma predicate2D [Pure.dest, dest]: "P \<le> Q \<Longrightarrow> P x y \<Longrightarrow> Q x y"
       
   515   apply (erule le_funE)+
       
   516   apply (erule le_boolE)
       
   517   apply assumption+
       
   518   done
       
   519 
       
   520 lemma rev_predicate1D: "P x ==> P <= Q ==> Q x"
       
   521   by (rule predicate1D)
       
   522 
       
   523 lemma rev_predicate2D: "P x y ==> P <= Q ==> Q x y"
       
   524   by (rule predicate2D)
       
   525 
       
   526 instance "fun" :: (type, lattice) lattice
       
   527   inf_fun_eq: "inf f g \<equiv> (\<lambda>x. inf (f x) (g x))"
       
   528   sup_fun_eq: "sup f g \<equiv> (\<lambda>x. sup (f x) (g x))"
       
   529 apply intro_classes
       
   530 unfolding inf_fun_eq sup_fun_eq
       
   531 apply (auto intro: le_funI)
       
   532 apply (rule le_funI)
       
   533 apply (auto dest: le_funD)
       
   534 apply (rule le_funI)
       
   535 apply (auto dest: le_funD)
       
   536 done
       
   537 
       
   538 lemmas [code func del] = inf_fun_eq sup_fun_eq
       
   539 
       
   540 instance "fun" :: (type, distrib_lattice) distrib_lattice
       
   541   by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
       
   542 
   461 
   543 
   462 
   544 subsection {* Proof tool setup *} 
   463 subsection {* Proof tool setup *} 
   545 
   464 
   546 text {* simplifies terms of the form
   465 text {* simplifies terms of the form
   598 val o_def = @{thm o_def}
   517 val o_def = @{thm o_def}
   599 val injD = @{thm injD}
   518 val injD = @{thm injD}
   600 val datatype_injI = @{thm datatype_injI}
   519 val datatype_injI = @{thm datatype_injI}
   601 val range_ex1_eq = @{thm range_ex1_eq}
   520 val range_ex1_eq = @{thm range_ex1_eq}
   602 val expand_fun_eq = @{thm expand_fun_eq}
   521 val expand_fun_eq = @{thm expand_fun_eq}
   603 val sup_fun_eq = @{thm sup_fun_eq}
       
   604 val sup_bool_eq = @{thm sup_bool_eq}
       
   605 *}
   522 *}
   606 
   523 
   607 end
   524 end