src/HOL/Library/Char_ord.thy
author haftmann
Sun May 06 21:50:17 2007 +0200 (2007-05-06)
changeset 22845 5f9138bcb3d7
parent 22805 1166a966e7b4
child 23394 474ff28210c0
permissions -rw-r--r--
changed code generator invocation syntax
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
haftmann@22805
    16
  fix n :: nibble show "n \<le> n" unfolding nibble_less_eq_def nibble_less_def by auto
haftmann@22805
    17
next
haftmann@22805
    18
  fix n m q :: nibble
haftmann@22805
    19
  assume "n \<le> m"
haftmann@22805
    20
  and "m \<le> q"
haftmann@22805
    21
  then show "n \<le> q" unfolding nibble_less_eq_def nibble_less_def by auto
haftmann@22805
    22
next
haftmann@22805
    23
  fix n m :: nibble
haftmann@22805
    24
  assume "n \<le> m"
haftmann@22805
    25
  and "m \<le> n"
haftmann@22805
    26
  then show "n = m" unfolding nibble_less_eq_def nibble_less_def by (auto simp add: nat_of_nibble_eq)
haftmann@22805
    27
next
haftmann@22805
    28
  fix n m :: nibble
haftmann@22805
    29
  show "n < m \<longleftrightarrow> n \<le> m \<and> n \<noteq> m"
haftmann@22805
    30
  unfolding nibble_less_eq_def nibble_less_def less_le by (auto simp add: nat_of_nibble_eq)
haftmann@22805
    31
next
haftmann@22805
    32
  fix n m :: nibble
haftmann@22805
    33
  show "n \<le> m \<or> m \<le> n"
haftmann@22805
    34
  unfolding nibble_less_eq_def by auto
haftmann@22805
    35
qed
nipkow@15737
    36
haftmann@22805
    37
instance nibble :: distrib_lattice
haftmann@22805
    38
  "inf \<equiv> min"
haftmann@22805
    39
  "sup \<equiv> max"
haftmann@22805
    40
  by default
haftmann@22805
    41
    (auto simp add: inf_nibble_def sup_nibble_def min_max.sup_inf_distrib1)
nipkow@15737
    42
wenzelm@19736
    43
instance char :: linorder
haftmann@22805
    44
  char_less_eq_def: "c1 \<le> c2 \<equiv> case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
haftmann@22805
    45
    n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
haftmann@22805
    46
  char_less_def:    "c1 < c2 \<equiv> case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
haftmann@22805
    47
    n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
haftmann@22805
    48
  by default (auto simp: char_less_eq_def char_less_def split: char.splits)
haftmann@22805
    49
haftmann@22845
    50
lemmas [code func del] = char_less_eq_def char_less_def
nipkow@15737
    51
haftmann@22483
    52
instance char :: distrib_lattice
haftmann@22483
    53
  "inf \<equiv> min"
haftmann@22483
    54
  "sup \<equiv> max"
haftmann@22805
    55
  by default
haftmann@22483
    56
    (auto simp add: inf_char_def sup_char_def min_max.sup_inf_distrib1)
haftmann@22483
    57
haftmann@22805
    58
lemma [simp, code func]:
haftmann@22805
    59
  shows char_less_eq_simp: "Char n1 m1 \<le> Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
haftmann@22805
    60
  and char_less_simp:      "Char n1 m1 < Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
haftmann@22805
    61
  unfolding char_less_eq_def char_less_def by simp_all
haftmann@21871
    62
wenzelm@17200
    63
end