src/HOL/Library/Product_Lexorder.thy
author Andreas Lochbihler
Wed Feb 27 10:33:30 2013 +0100 (2013-02-27)
changeset 51288 be7e9a675ec9
parent 51115 7dbd6832a689
child 52729 412c9e0381a1
permissions -rw-r--r--
add wellorder instance for Numeral_Type (suggested by Jesus Aransay)
     1 (*  Title:      HOL/Library/Product_Lexorder.thy
     2     Author:     Norbert Voelker
     3 *)
     4 
     5 header {* Lexicographic order on product types *}
     6 
     7 theory Product_Lexorder
     8 imports Main
     9 begin
    10 
    11 instantiation prod :: (ord, ord) ord
    12 begin
    13 
    14 definition
    15   "x \<le> y \<longleftrightarrow> fst x < fst y \<or> fst x \<le> fst y \<and> snd x \<le> snd y"
    16 
    17 definition
    18   "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 less_eq_prod_simp [simp, code]:
    25   "(x1, y1) \<le> (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 \<le> y2"
    26   by (simp add: less_eq_prod_def)
    27 
    28 lemma less_prod_simp [simp, code]:
    29   "(x1, y1) < (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 < y2"
    30   by (simp add: less_prod_def)
    31 
    32 text {* A stronger version for partial orders. *}
    33 
    34 lemma less_prod_def':
    35   fixes x y :: "'a::order \<times> 'b::ord"
    36   shows "x < y \<longleftrightarrow> fst x < fst y \<or> fst x = fst y \<and> snd x < snd y"
    37   by (auto simp add: less_prod_def le_less)
    38 
    39 instance prod :: (preorder, preorder) preorder
    40   by default (auto simp: less_eq_prod_def less_prod_def less_le_not_le intro: order_trans)
    41 
    42 instance prod :: (order, order) order
    43   by default (auto simp add: less_eq_prod_def)
    44 
    45 instance prod :: (linorder, linorder) linorder
    46   by default (auto simp: less_eq_prod_def)
    47 
    48 instantiation prod :: (linorder, linorder) distrib_lattice
    49 begin
    50 
    51 definition
    52   "(inf :: 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = min"
    53 
    54 definition
    55   "(sup :: 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = max"
    56 
    57 instance
    58   by default (auto simp add: inf_prod_def sup_prod_def min_max.sup_inf_distrib1)
    59 
    60 end
    61 
    62 instantiation prod :: (bot, bot) bot
    63 begin
    64 
    65 definition
    66   "bot = (bot, bot)"
    67 
    68 instance
    69   by default (auto simp add: bot_prod_def)
    70 
    71 end
    72 
    73 instantiation prod :: (top, top) top
    74 begin
    75 
    76 definition
    77   "top = (top, top)"
    78 
    79 instance
    80   by default (auto simp add: top_prod_def)
    81 
    82 end
    83 
    84 instance prod :: (wellorder, wellorder) wellorder
    85 proof
    86   fix P :: "'a \<times> 'b \<Rightarrow> bool" and z :: "'a \<times> 'b"
    87   assume P: "\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x"
    88   show "P z"
    89   proof (induct z)
    90     case (Pair a b)
    91     show "P (a, b)"
    92     proof (induct a arbitrary: b rule: less_induct)
    93       case (less a\<^isub>1) note a\<^isub>1 = this
    94       show "P (a\<^isub>1, b)"
    95       proof (induct b rule: less_induct)
    96         case (less b\<^isub>1) note b\<^isub>1 = this
    97         show "P (a\<^isub>1, b\<^isub>1)"
    98         proof (rule P)
    99           fix p assume p: "p < (a\<^isub>1, b\<^isub>1)"
   100           show "P p"
   101           proof (cases "fst p < a\<^isub>1")
   102             case True
   103             then have "P (fst p, snd p)" by (rule a\<^isub>1)
   104             then show ?thesis by simp
   105           next
   106             case False
   107             with p have 1: "a\<^isub>1 = fst p" and 2: "snd p < b\<^isub>1"
   108               by (simp_all add: less_prod_def')
   109             from 2 have "P (a\<^isub>1, snd p)" by (rule b\<^isub>1)
   110             with 1 show ?thesis by simp
   111           qed
   112         qed
   113       qed
   114     qed
   115   qed
   116 qed
   117 
   118 text {* Legacy lemma bindings *}
   119 
   120 lemmas prod_le_def = less_eq_prod_def
   121 lemmas prod_less_def = less_prod_def
   122 lemmas prod_less_eq = less_prod_def'
   123 
   124 end
   125