src/HOL/Library/Product_ord.thy
author wenzelm
Wed May 23 14:17:32 2012 +0200 (2012-05-23)
changeset 47961 e0a85be4fca0
parent 44063 4588597ba37e
permissions -rw-r--r--
more explicit proof;
misc tuning;
nipkow@15737
     1
(*  Title:      HOL/Library/Product_ord.thy
nipkow@15737
     2
    Author:     Norbert Voelker
nipkow@15737
     3
*)
nipkow@15737
     4
wenzelm@17200
     5
header {* Order on product types *}
nipkow@15737
     6
nipkow@15737
     7
theory Product_ord
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@37765
    15
  prod_le_def: "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@37765
    18
  prod_less_def: "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@28562
    24
lemma [code]:
wenzelm@47961
    25
  "(x1::'a::{ord, equal}, y1) \<le> (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 \<le> y2"
wenzelm@47961
    26
  "(x1::'a::{ord, equal}, y1) < (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 < y2"
haftmann@25502
    27
  unfolding prod_le_def prod_less_def by simp_all
haftmann@22177
    28
wenzelm@47961
    29
instance prod :: (preorder, preorder) preorder
wenzelm@47961
    30
  by default (auto simp: prod_le_def prod_less_def less_le_not_le intro: order_trans)
nipkow@15737
    31
wenzelm@47961
    32
instance prod :: (order, order) order
wenzelm@47961
    33
  by default (auto simp add: prod_le_def)
haftmann@31040
    34
wenzelm@47961
    35
instance prod :: (linorder, linorder) linorder
wenzelm@47961
    36
  by default (auto simp: prod_le_def)
nipkow@15737
    37
haftmann@37678
    38
instantiation prod :: (linorder, linorder) distrib_lattice
haftmann@25571
    39
begin
haftmann@25571
    40
haftmann@25571
    41
definition
wenzelm@47961
    42
  inf_prod_def: "(inf :: 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = min"
haftmann@25571
    43
haftmann@25571
    44
definition
wenzelm@47961
    45
  sup_prod_def: "(sup :: 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = max"
haftmann@25571
    46
wenzelm@47961
    47
instance
wenzelm@47961
    48
  by default (auto simp add: inf_prod_def sup_prod_def min_max.sup_inf_distrib1)
haftmann@31040
    49
haftmann@31040
    50
end
haftmann@31040
    51
haftmann@37678
    52
instantiation prod :: (bot, bot) bot
haftmann@31040
    53
begin
haftmann@31040
    54
haftmann@31040
    55
definition
haftmann@31040
    56
  bot_prod_def: "bot = (bot, bot)"
haftmann@31040
    57
wenzelm@47961
    58
instance
wenzelm@47961
    59
  by default (auto simp add: bot_prod_def prod_le_def)
haftmann@31040
    60
haftmann@31040
    61
end
haftmann@31040
    62
haftmann@37678
    63
instantiation prod :: (top, top) top
haftmann@31040
    64
begin
haftmann@31040
    65
haftmann@31040
    66
definition
haftmann@31040
    67
  top_prod_def: "top = (top, top)"
haftmann@31040
    68
wenzelm@47961
    69
instance
wenzelm@47961
    70
  by default (auto simp add: top_prod_def prod_le_def)
haftmann@22483
    71
wenzelm@19736
    72
end
haftmann@25571
    73
huffman@44063
    74
text {* A stronger version of the definition holds for partial orders. *}
huffman@44063
    75
huffman@44063
    76
lemma prod_less_eq:
huffman@44063
    77
  fixes x y :: "'a::order \<times> 'b::ord"
huffman@44063
    78
  shows "x < y \<longleftrightarrow> fst x < fst y \<or> (fst x = fst y \<and> snd x < snd y)"
huffman@44063
    79
  unfolding prod_less_def fst_conv snd_conv le_less by auto
huffman@44063
    80
huffman@44063
    81
instance prod :: (wellorder, wellorder) wellorder
huffman@44063
    82
proof
huffman@44063
    83
  fix P :: "'a \<times> 'b \<Rightarrow> bool" and z :: "'a \<times> 'b"
huffman@44063
    84
  assume P: "\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x"
huffman@44063
    85
  show "P z"
huffman@44063
    86
  proof (induct z)
huffman@44063
    87
    case (Pair a b)
huffman@44063
    88
    show "P (a, b)"
wenzelm@47961
    89
    proof (induct a arbitrary: b rule: less_induct)
wenzelm@47961
    90
      case (less a\<^isub>1) note a\<^isub>1 = this
wenzelm@47961
    91
      show "P (a\<^isub>1, b)"
wenzelm@47961
    92
      proof (induct b rule: less_induct)
wenzelm@47961
    93
        case (less b\<^isub>1) note b\<^isub>1 = this
wenzelm@47961
    94
        show "P (a\<^isub>1, b\<^isub>1)"
wenzelm@47961
    95
        proof (rule P)
wenzelm@47961
    96
          fix p assume p: "p < (a\<^isub>1, b\<^isub>1)"
wenzelm@47961
    97
          show "P p"
wenzelm@47961
    98
          proof (cases "fst p < a\<^isub>1")
wenzelm@47961
    99
            case True
wenzelm@47961
   100
            then have "P (fst p, snd p)" by (rule a\<^isub>1)
wenzelm@47961
   101
            then show ?thesis by simp
wenzelm@47961
   102
          next
wenzelm@47961
   103
            case False
wenzelm@47961
   104
            with p have 1: "a\<^isub>1 = fst p" and 2: "snd p < b\<^isub>1"
wenzelm@47961
   105
              by (simp_all add: prod_less_eq)
wenzelm@47961
   106
            from 2 have "P (a\<^isub>1, snd p)" by (rule b\<^isub>1)
wenzelm@47961
   107
            with 1 show ?thesis by simp
wenzelm@47961
   108
          qed
wenzelm@47961
   109
        qed
wenzelm@47961
   110
      qed
wenzelm@47961
   111
    qed
huffman@44063
   112
  qed
huffman@44063
   113
qed
huffman@44063
   114
haftmann@25571
   115
end