src/HOL/Library/Product_Lexorder.thy
changeset 51115 7dbd6832a689
parent 47961 e0a85be4fca0
child 52729 412c9e0381a1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Product_Lexorder.thy	Thu Feb 14 14:14:55 2013 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +(*  Title:      HOL/Library/Product_Lexorder.thy
     1.5 +    Author:     Norbert Voelker
     1.6 +*)
     1.7 +
     1.8 +header {* Lexicographic order on product types *}
     1.9 +
    1.10 +theory Product_Lexorder
    1.11 +imports Main
    1.12 +begin
    1.13 +
    1.14 +instantiation prod :: (ord, ord) ord
    1.15 +begin
    1.16 +
    1.17 +definition
    1.18 +  "x \<le> y \<longleftrightarrow> fst x < fst y \<or> fst x \<le> fst y \<and> snd x \<le> snd y"
    1.19 +
    1.20 +definition
    1.21 +  "x < y \<longleftrightarrow> fst x < fst y \<or> fst x \<le> fst y \<and> snd x < snd y"
    1.22 +
    1.23 +instance ..
    1.24 +
    1.25 +end
    1.26 +
    1.27 +lemma less_eq_prod_simp [simp, code]:
    1.28 +  "(x1, y1) \<le> (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 \<le> y2"
    1.29 +  by (simp add: less_eq_prod_def)
    1.30 +
    1.31 +lemma less_prod_simp [simp, code]:
    1.32 +  "(x1, y1) < (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 < y2"
    1.33 +  by (simp add: less_prod_def)
    1.34 +
    1.35 +text {* A stronger version for partial orders. *}
    1.36 +
    1.37 +lemma less_prod_def':
    1.38 +  fixes x y :: "'a::order \<times> 'b::ord"
    1.39 +  shows "x < y \<longleftrightarrow> fst x < fst y \<or> fst x = fst y \<and> snd x < snd y"
    1.40 +  by (auto simp add: less_prod_def le_less)
    1.41 +
    1.42 +instance prod :: (preorder, preorder) preorder
    1.43 +  by default (auto simp: less_eq_prod_def less_prod_def less_le_not_le intro: order_trans)
    1.44 +
    1.45 +instance prod :: (order, order) order
    1.46 +  by default (auto simp add: less_eq_prod_def)
    1.47 +
    1.48 +instance prod :: (linorder, linorder) linorder
    1.49 +  by default (auto simp: less_eq_prod_def)
    1.50 +
    1.51 +instantiation prod :: (linorder, linorder) distrib_lattice
    1.52 +begin
    1.53 +
    1.54 +definition
    1.55 +  "(inf :: 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = min"
    1.56 +
    1.57 +definition
    1.58 +  "(sup :: 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = max"
    1.59 +
    1.60 +instance
    1.61 +  by default (auto simp add: inf_prod_def sup_prod_def min_max.sup_inf_distrib1)
    1.62 +
    1.63 +end
    1.64 +
    1.65 +instantiation prod :: (bot, bot) bot
    1.66 +begin
    1.67 +
    1.68 +definition
    1.69 +  "bot = (bot, bot)"
    1.70 +
    1.71 +instance
    1.72 +  by default (auto simp add: bot_prod_def)
    1.73 +
    1.74 +end
    1.75 +
    1.76 +instantiation prod :: (top, top) top
    1.77 +begin
    1.78 +
    1.79 +definition
    1.80 +  "top = (top, top)"
    1.81 +
    1.82 +instance
    1.83 +  by default (auto simp add: top_prod_def)
    1.84 +
    1.85 +end
    1.86 +
    1.87 +instance prod :: (wellorder, wellorder) wellorder
    1.88 +proof
    1.89 +  fix P :: "'a \<times> 'b \<Rightarrow> bool" and z :: "'a \<times> 'b"
    1.90 +  assume P: "\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x"
    1.91 +  show "P z"
    1.92 +  proof (induct z)
    1.93 +    case (Pair a b)
    1.94 +    show "P (a, b)"
    1.95 +    proof (induct a arbitrary: b rule: less_induct)
    1.96 +      case (less a\<^isub>1) note a\<^isub>1 = this
    1.97 +      show "P (a\<^isub>1, b)"
    1.98 +      proof (induct b rule: less_induct)
    1.99 +        case (less b\<^isub>1) note b\<^isub>1 = this
   1.100 +        show "P (a\<^isub>1, b\<^isub>1)"
   1.101 +        proof (rule P)
   1.102 +          fix p assume p: "p < (a\<^isub>1, b\<^isub>1)"
   1.103 +          show "P p"
   1.104 +          proof (cases "fst p < a\<^isub>1")
   1.105 +            case True
   1.106 +            then have "P (fst p, snd p)" by (rule a\<^isub>1)
   1.107 +            then show ?thesis by simp
   1.108 +          next
   1.109 +            case False
   1.110 +            with p have 1: "a\<^isub>1 = fst p" and 2: "snd p < b\<^isub>1"
   1.111 +              by (simp_all add: less_prod_def')
   1.112 +            from 2 have "P (a\<^isub>1, snd p)" by (rule b\<^isub>1)
   1.113 +            with 1 show ?thesis by simp
   1.114 +          qed
   1.115 +        qed
   1.116 +      qed
   1.117 +    qed
   1.118 +  qed
   1.119 +qed
   1.120 +
   1.121 +text {* Legacy lemma bindings *}
   1.122 +
   1.123 +lemmas prod_le_def = less_eq_prod_def
   1.124 +lemmas prod_less_def = less_prod_def
   1.125 +lemmas prod_less_eq = less_prod_def'
   1.126 +
   1.127 +end
   1.128 +