src/HOL/Library/Char_ord.thy
author haftmann
Thu Nov 29 17:08:26 2007 +0100 (2007-11-29)
changeset 25502 9200b36280c0
parent 23394 474ff28210c0
child 25764 878c37886eed
permissions -rw-r--r--
instance command as rudimentary class target
nipkow@15737
     1
(*  Title:      HOL/Library/Char_ord.thy
nipkow@15737
     2
    ID:         $Id$
haftmann@22805
     3
    Author:     Norbert Voelker, Florian Haftmann
nipkow@15737
     4
*)
nipkow@15737
     5
wenzelm@17200
     6
header {* Order on characters *}
nipkow@15737
     7
nipkow@15737
     8
theory Char_ord
haftmann@22805
     9
imports Product_ord Char_nat
nipkow@15737
    10
begin
nipkow@15737
    11
haftmann@22805
    12
instance nibble :: linorder
haftmann@22805
    13
  nibble_less_eq_def: "n \<le> m \<equiv> nat_of_nibble n \<le> nat_of_nibble m"
haftmann@22805
    14
  nibble_less_def: "n < m \<equiv> nat_of_nibble n < nat_of_nibble m"
haftmann@22805
    15
proof
wenzelm@23394
    16
  fix n :: nibble
wenzelm@23394
    17
  show "n \<le> n" unfolding nibble_less_eq_def nibble_less_def by auto
haftmann@22805
    18
next
haftmann@22805
    19
  fix n m q :: nibble
haftmann@22805
    20
  assume "n \<le> m"
wenzelm@23394
    21
    and "m \<le> q"
haftmann@22805
    22
  then show "n \<le> q" unfolding nibble_less_eq_def nibble_less_def by auto
haftmann@22805
    23
next
haftmann@22805
    24
  fix n m :: nibble
haftmann@22805
    25
  assume "n \<le> m"
wenzelm@23394
    26
    and "m \<le> n"
wenzelm@23394
    27
  then show "n = m"
wenzelm@23394
    28
    unfolding nibble_less_eq_def nibble_less_def
wenzelm@23394
    29
    by (auto simp add: nat_of_nibble_eq)
haftmann@22805
    30
next
haftmann@22805
    31
  fix n m :: nibble
haftmann@22805
    32
  show "n < m \<longleftrightarrow> n \<le> m \<and> n \<noteq> m"
wenzelm@23394
    33
    unfolding nibble_less_eq_def nibble_less_def less_le
wenzelm@23394
    34
    by (auto simp add: nat_of_nibble_eq)
haftmann@22805
    35
next
haftmann@22805
    36
  fix n m :: nibble
haftmann@22805
    37
  show "n \<le> m \<or> m \<le> n"
wenzelm@23394
    38
    unfolding nibble_less_eq_def by auto
haftmann@22805
    39
qed
nipkow@15737
    40
haftmann@22805
    41
instance nibble :: distrib_lattice
haftmann@25502
    42
  "(inf \<Colon> nibble \<Rightarrow> _) = min"
haftmann@25502
    43
  "(sup \<Colon> nibble \<Rightarrow> _) = max"
wenzelm@23394
    44
  by default (auto simp add:
wenzelm@23394
    45
    inf_nibble_def sup_nibble_def min_max.sup_inf_distrib1)
nipkow@15737
    46
wenzelm@19736
    47
instance char :: linorder
haftmann@22805
    48
  char_less_eq_def: "c1 \<le> c2 \<equiv> case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
haftmann@22805
    49
    n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
haftmann@22805
    50
  char_less_def:    "c1 < c2 \<equiv> case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
haftmann@22805
    51
    n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
haftmann@22805
    52
  by default (auto simp: char_less_eq_def char_less_def split: char.splits)
haftmann@22805
    53
haftmann@22845
    54
lemmas [code func del] = char_less_eq_def char_less_def
nipkow@15737
    55
haftmann@22483
    56
instance char :: distrib_lattice
haftmann@25502
    57
  "(inf \<Colon> char \<Rightarrow> _) = min"
haftmann@25502
    58
  "(sup \<Colon> char \<Rightarrow> _) = max"
wenzelm@23394
    59
  by default (auto simp add:
wenzelm@23394
    60
    inf_char_def sup_char_def min_max.sup_inf_distrib1)
haftmann@22483
    61
haftmann@22805
    62
lemma [simp, code func]:
haftmann@22805
    63
  shows char_less_eq_simp: "Char n1 m1 \<le> Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
haftmann@22805
    64
  and char_less_simp:      "Char n1 m1 < Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
haftmann@22805
    65
  unfolding char_less_eq_def char_less_def by simp_all
haftmann@21871
    66
wenzelm@17200
    67
end