src/HOL/Library/Char_ord.thy
author wenzelm
Thu, 14 Jun 2007 23:04:39 +0200
changeset 23394 474ff28210c0
parent 22845 5f9138bcb3d7
child 25502 9200b36280c0
permissions -rw-r--r--
tuned proofs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15737
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Library/Char_ord.thy
nipkow
parents:
diff changeset
     2
    ID:         $Id$
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
     3
    Author:     Norbert Voelker, Florian Haftmann
15737
nipkow
parents:
diff changeset
     4
*)
nipkow
parents:
diff changeset
     5
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
     6
header {* Order on characters *}
15737
nipkow
parents:
diff changeset
     7
nipkow
parents:
diff changeset
     8
theory Char_ord
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
     9
imports Product_ord Char_nat
15737
nipkow
parents:
diff changeset
    10
begin
nipkow
parents:
diff changeset
    11
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    12
instance nibble :: linorder
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    13
  nibble_less_eq_def: "n \<le> m \<equiv> nat_of_nibble n \<le> nat_of_nibble m"
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    14
  nibble_less_def: "n < m \<equiv> nat_of_nibble n < nat_of_nibble m"
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    15
proof
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    16
  fix n :: nibble
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    17
  show "n \<le> n" unfolding nibble_less_eq_def nibble_less_def by auto
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    18
next
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    19
  fix n m q :: nibble
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    20
  assume "n \<le> m"
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    21
    and "m \<le> q"
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    22
  then show "n \<le> q" unfolding nibble_less_eq_def nibble_less_def by auto
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    23
next
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    24
  fix n m :: nibble
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    25
  assume "n \<le> m"
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    26
    and "m \<le> n"
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    27
  then show "n = m"
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    28
    unfolding nibble_less_eq_def nibble_less_def
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    29
    by (auto simp add: nat_of_nibble_eq)
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    30
next
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    31
  fix n m :: nibble
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    32
  show "n < m \<longleftrightarrow> n \<le> m \<and> n \<noteq> m"
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    33
    unfolding nibble_less_eq_def nibble_less_def less_le
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    34
    by (auto simp add: nat_of_nibble_eq)
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    35
next
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    36
  fix n m :: nibble
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    37
  show "n \<le> m \<or> m \<le> n"
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    38
    unfolding nibble_less_eq_def by auto
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    39
qed
15737
nipkow
parents:
diff changeset
    40
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    41
instance nibble :: distrib_lattice
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    42
    "inf \<equiv> min"
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    43
    "sup \<equiv> max"
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    44
  by default (auto simp add:
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    45
    inf_nibble_def sup_nibble_def min_max.sup_inf_distrib1)
15737
nipkow
parents:
diff changeset
    46
19736
wenzelm
parents: 17200
diff changeset
    47
instance char :: linorder
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    48
  char_less_eq_def: "c1 \<le> c2 \<equiv> case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    49
    n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    50
  char_less_def:    "c1 < c2 \<equiv> case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    51
    n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    52
  by default (auto simp: char_less_eq_def char_less_def split: char.splits)
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    53
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22805
diff changeset
    54
lemmas [code func del] = char_less_eq_def char_less_def
15737
nipkow
parents:
diff changeset
    55
22483
86064f2f2188 added instance for lattice
haftmann
parents: 21911
diff changeset
    56
instance char :: distrib_lattice
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    57
    "inf \<equiv> min"
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    58
    "sup \<equiv> max"
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    59
  by default (auto simp add:
474ff28210c0 tuned proofs;
wenzelm
parents: 22845
diff changeset
    60
    inf_char_def sup_char_def min_max.sup_inf_distrib1)
22483
86064f2f2188 added instance for lattice
haftmann
parents: 21911
diff changeset
    61
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    62
lemma [simp, code func]:
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    63
  shows char_less_eq_simp: "Char n1 m1 \<le> Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    64
  and char_less_simp:      "Char n1 m1 < Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    65
  unfolding char_less_eq_def char_less_def by simp_all
21871
9ce66839d9f1 added code generation syntax for some char combinators
haftmann
parents: 21404
diff changeset
    66
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    67
end