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