src/HOL/Library/Product_ord.thy
author huffman
Fri Mar 30 12:32:35 2012 +0200 (2012-03-30)
changeset 47220 52426c62b5d0
parent 44063 4588597ba37e
child 47961 e0a85be4fca0
permissions -rw-r--r--
replace lemmas eval_nat_numeral with a simpler reformulation
     1 (*  Title:      HOL/Library/Product_ord.thy
     2     Author:     Norbert Voelker
     3 *)
     4 
     5 header {* Order on product types *}
     6 
     7 theory Product_ord
     8 imports Main
     9 begin
    10 
    11 instantiation prod :: (ord, ord) ord
    12 begin
    13 
    14 definition
    15   prod_le_def: "x \<le> y \<longleftrightarrow> fst x < fst y \<or> fst x \<le> fst y \<and> snd x \<le> snd y"
    16 
    17 definition
    18   prod_less_def: "x < y \<longleftrightarrow> fst x < fst y \<or> fst x \<le> fst y \<and> snd x < snd y"
    19 
    20 instance ..
    21 
    22 end
    23 
    24 lemma [code]:
    25   "(x1\<Colon>'a\<Colon>{ord, equal}, y1) \<le> (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 \<le> y2"
    26   "(x1\<Colon>'a\<Colon>{ord, equal}, y1) < (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 < y2"
    27   unfolding prod_le_def prod_less_def by simp_all
    28 
    29 instance prod :: (preorder, preorder) preorder proof
    30 qed (auto simp: prod_le_def prod_less_def less_le_not_le intro: order_trans)
    31 
    32 instance prod :: (order, order) order proof
    33 qed (auto simp add: prod_le_def)
    34 
    35 instance prod :: (linorder, linorder) linorder proof
    36 qed (auto simp: prod_le_def)
    37 
    38 instantiation prod :: (linorder, linorder) distrib_lattice
    39 begin
    40 
    41 definition
    42   inf_prod_def: "(inf \<Colon> 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = min"
    43 
    44 definition
    45   sup_prod_def: "(sup \<Colon> 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = max"
    46 
    47 instance proof
    48 qed (auto simp add: inf_prod_def sup_prod_def min_max.sup_inf_distrib1)
    49 
    50 end
    51 
    52 instantiation prod :: (bot, bot) bot
    53 begin
    54 
    55 definition
    56   bot_prod_def: "bot = (bot, bot)"
    57 
    58 instance proof
    59 qed (auto simp add: bot_prod_def prod_le_def)
    60 
    61 end
    62 
    63 instantiation prod :: (top, top) top
    64 begin
    65 
    66 definition
    67   top_prod_def: "top = (top, top)"
    68 
    69 instance proof
    70 qed (auto simp add: top_prod_def prod_le_def)
    71 
    72 end
    73 
    74 text {* A stronger version of the definition holds for partial orders. *}
    75 
    76 lemma prod_less_eq:
    77   fixes x y :: "'a::order \<times> 'b::ord"
    78   shows "x < y \<longleftrightarrow> fst x < fst y \<or> (fst x = fst y \<and> snd x < snd y)"
    79   unfolding prod_less_def fst_conv snd_conv le_less by auto
    80 
    81 instance prod :: (wellorder, wellorder) wellorder
    82 proof
    83   fix P :: "'a \<times> 'b \<Rightarrow> bool" and z :: "'a \<times> 'b"
    84   assume P: "\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x"
    85   show "P z"
    86   proof (induct z)
    87     case (Pair a b)
    88     show "P (a, b)"
    89       apply (induct a arbitrary: b rule: less_induct)
    90       apply (rule less_induct [where 'a='b])
    91       apply (rule P)
    92       apply (auto simp add: prod_less_eq)
    93       done
    94   qed
    95 qed
    96 
    97 end