src/HOL/Library/Product_ord.thy
author huffman
Fri Mar 30 12:32:35 2012 +0200 (2012-03-30)
changeset 47220 52426c62b5d0
parent 44063 4588597ba37e
child 47961 e0a85be4fca0
permissions -rw-r--r--
replace lemmas eval_nat_numeral with a simpler reformulation
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]:
haftmann@38857
    25
  "(x1\<Colon>'a\<Colon>{ord, equal}, y1) \<le> (x2, y2) \<longleftrightarrow> x1 < x2 \<or> x1 \<le> x2 \<and> y1 \<le> y2"
haftmann@38857
    26
  "(x1\<Colon>'a\<Colon>{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
haftmann@37678
    29
instance prod :: (preorder, preorder) preorder proof
haftmann@31040
    30
qed (auto simp: prod_le_def prod_less_def less_le_not_le intro: order_trans)
nipkow@15737
    31
haftmann@37678
    32
instance prod :: (order, order) order proof
haftmann@31040
    33
qed (auto simp add: prod_le_def)
haftmann@31040
    34
haftmann@37678
    35
instance prod :: (linorder, linorder) linorder proof
haftmann@31040
    36
qed (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
haftmann@25502
    42
  inf_prod_def: "(inf \<Colon> 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = min"
haftmann@25571
    43
haftmann@25571
    44
definition
haftmann@25502
    45
  sup_prod_def: "(sup \<Colon> 'a \<times> 'b \<Rightarrow> _ \<Rightarrow> _) = max"
haftmann@25571
    46
haftmann@31040
    47
instance proof
haftmann@31040
    48
qed (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
haftmann@31040
    58
instance proof
haftmann@31040
    59
qed (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
haftmann@31040
    69
instance proof
haftmann@31040
    70
qed (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)"
huffman@44063
    89
      apply (induct a arbitrary: b rule: less_induct)
huffman@44063
    90
      apply (rule less_induct [where 'a='b])
huffman@44063
    91
      apply (rule P)
huffman@44063
    92
      apply (auto simp add: prod_less_eq)
huffman@44063
    93
      done
huffman@44063
    94
  qed
huffman@44063
    95
qed
huffman@44063
    96
haftmann@25571
    97
end