src/HOL/Library/Product_Lexorder.thy
author haftmann
Thu, 25 Jul 2013 08:57:16 +0200
changeset 53866 412c9e0381a1
parent 52252 7dbd6832a689
child 54152 a1119cf551e8
permissions -rw-r--r--
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann@52252
     1
(*  Title:      HOL/Library/Product_Lexorder.thy
nipkow@15737
     2
    Author:     Norbert Voelker
nipkow@15737
     3
*)
nipkow@15737
     4
haftmann@52252
     5
header {* Lexicographic order on product types *}
nipkow@15737
     6
haftmann@52252
     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@52252
    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@52252
    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@52252
    24
lemma less_eq_prod_simp [simp, code]:
haftmann@52252
    25
  "(x1, y1) \<le> (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 \<le> y2"
haftmann@52252
    26
  by (simp add: less_eq_prod_def)
haftmann@52252
    27
haftmann@52252
    28
lemma less_prod_simp [simp, code]:
haftmann@52252
    29
  "(x1, y1) < (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 < y2"
haftmann@52252
    30
  by (simp add: less_prod_def)
haftmann@52252
    31
haftmann@52252
    32
text {* A stronger version for partial orders. *}
haftmann@52252
    33
haftmann@52252
    34
lemma less_prod_def':
haftmann@52252
    35
  fixes x y :: "'a::order \<times> 'b::ord"
haftmann@52252
    36
  shows "x < y \<longleftrightarrow> fst x < fst y \<or> fst x = fst y \<and> snd x < snd y"
haftmann@52252
    37
  by (auto simp add: less_prod_def le_less)
haftmann@22177
    38
wenzelm@48976
    39
instance prod :: (preorder, preorder) preorder
haftmann@52252
    40
  by default (auto simp: less_eq_prod_def less_prod_def less_le_not_le intro: order_trans)
nipkow@15737
    41
wenzelm@48976
    42
instance prod :: (order, order) order
haftmann@52252
    43
  by default (auto simp add: less_eq_prod_def)
haftmann@31040
    44
wenzelm@48976
    45
instance prod :: (linorder, linorder) linorder
haftmann@52252
    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@52252
    52
  "(inf :: 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = min"
haftmann@25571
    53
haftmann@25571
    54
definition
haftmann@52252
    55
  "(sup :: 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = max"
haftmann@25571
    56
wenzelm@48976
    57
instance
wenzelm@48976
    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@52252
    66
  "bot = (bot, bot)"
haftmann@31040
    67
haftmann@53866
    68
instance ..
haftmann@31040
    69
haftmann@31040
    70
end
haftmann@31040
    71
haftmann@53866
    72
instance prod :: (order_bot, order_bot) order_bot
haftmann@53866
    73
  by default (auto simp add: bot_prod_def)
haftmann@53866
    74
haftmann@37678
    75
instantiation prod :: (top, top) top
haftmann@31040
    76
begin
haftmann@31040
    77
haftmann@31040
    78
definition
haftmann@52252
    79
  "top = (top, top)"
haftmann@31040
    80
haftmann@53866
    81
instance ..
haftmann@22483
    82
wenzelm@19736
    83
end
haftmann@25571
    84
haftmann@53866
    85
instance prod :: (order_top, order_top) order_top
haftmann@53866
    86
  by default (auto simp add: top_prod_def)
haftmann@53866
    87
huffman@44927
    88
instance prod :: (wellorder, wellorder) wellorder
huffman@44927
    89
proof
huffman@44927
    90
  fix P :: "'a \<times> 'b \<Rightarrow> bool" and z :: "'a \<times> 'b"
huffman@44927
    91
  assume P: "\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x"
huffman@44927
    92
  show "P z"
huffman@44927
    93
  proof (induct z)
huffman@44927
    94
    case (Pair a b)
huffman@44927
    95
    show "P (a, b)"
wenzelm@48976
    96
    proof (induct a arbitrary: b rule: less_induct)
wenzelm@48976
    97
      case (less a\<^isub>1) note a\<^isub>1 = this
wenzelm@48976
    98
      show "P (a\<^isub>1, b)"
wenzelm@48976
    99
      proof (induct b rule: less_induct)
wenzelm@48976
   100
        case (less b\<^isub>1) note b\<^isub>1 = this
wenzelm@48976
   101
        show "P (a\<^isub>1, b\<^isub>1)"
wenzelm@48976
   102
        proof (rule P)
wenzelm@48976
   103
          fix p assume p: "p < (a\<^isub>1, b\<^isub>1)"
wenzelm@48976
   104
          show "P p"
wenzelm@48976
   105
          proof (cases "fst p < a\<^isub>1")
wenzelm@48976
   106
            case True
wenzelm@48976
   107
            then have "P (fst p, snd p)" by (rule a\<^isub>1)
wenzelm@48976
   108
            then show ?thesis by simp
wenzelm@48976
   109
          next
wenzelm@48976
   110
            case False
wenzelm@48976
   111
            with p have 1: "a\<^isub>1 = fst p" and 2: "snd p < b\<^isub>1"
haftmann@52252
   112
              by (simp_all add: less_prod_def')
wenzelm@48976
   113
            from 2 have "P (a\<^isub>1, snd p)" by (rule b\<^isub>1)
wenzelm@48976
   114
            with 1 show ?thesis by simp
wenzelm@48976
   115
          qed
wenzelm@48976
   116
        qed
wenzelm@48976
   117
      qed
wenzelm@48976
   118
    qed
huffman@44927
   119
  qed
huffman@44927
   120
qed
huffman@44927
   121
haftmann@52252
   122
text {* Legacy lemma bindings *}
haftmann@52252
   123
haftmann@52252
   124
lemmas prod_le_def = less_eq_prod_def
haftmann@52252
   125
lemmas prod_less_def = less_prod_def
haftmann@52252
   126
lemmas prod_less_eq = less_prod_def'
haftmann@52252
   127
haftmann@25571
   128
end
haftmann@52252
   129