src/HOL/Library/Char_ord.thy
author wenzelm
Wed, 08 Mar 2017 10:50:59 +0100
changeset 65151 a7394aa4d21c
parent 63462 c1fe30f2bc32
child 67399 eab6ce8368fa
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
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
     2
    Author:     Norbert Voelker, Florian Haftmann
15737
nipkow
parents:
diff changeset
     3
*)
nipkow
parents:
diff changeset
     4
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 58881
diff changeset
     5
section \<open>Order on characters\<close>
15737
nipkow
parents:
diff changeset
     6
nipkow
parents:
diff changeset
     7
theory Char_ord
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
     8
  imports Main
15737
nipkow
parents:
diff changeset
     9
begin
nipkow
parents:
diff changeset
    10
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    11
instantiation char :: linorder
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    12
begin
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    13
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
    14
definition "c1 \<le> c2 \<longleftrightarrow> nat_of_char c1 \<le> nat_of_char c2"
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
    15
definition "c1 < c2 \<longleftrightarrow> nat_of_char c1 < nat_of_char c2"
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    16
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
    17
instance
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    18
  by standard (auto simp add: less_eq_char_def less_char_def)
22805
1166a966e7b4 moved stuff to Char_nat.thy
haftmann
parents: 22483
diff changeset
    19
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    20
end
15737
nipkow
parents:
diff changeset
    21
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    22
lemma less_eq_char_simps:
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    23
  "0 \<le> c"
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    24
  "Char k \<le> 0 \<longleftrightarrow> numeral k mod 256 = (0 :: nat)"
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    25
  "Char k \<le> Char l \<longleftrightarrow> numeral k mod 256 \<le> (numeral l mod 256 :: nat)"
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    26
  for c :: char
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    27
  by (simp_all add: Char_def less_eq_char_def)
51160
599ff65b85e2 systematic conversions between nat and nibble/char;
haftmann
parents: 48926
diff changeset
    28
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    29
lemma less_char_simps:
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    30
  "\<not> c < 0"
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    31
  "0 < Char k \<longleftrightarrow> (0 :: nat) < numeral k mod 256"
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    32
  "Char k < Char l \<longleftrightarrow> numeral k mod 256 < (numeral l mod 256 :: nat)"
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    33
  for c :: char
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 61076
diff changeset
    34
  by (simp_all add: Char_def less_char_def)
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    35
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    36
instantiation char :: distrib_lattice
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    37
begin
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    38
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 60679
diff changeset
    39
definition "(inf :: char \<Rightarrow> _) = min"
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 60679
diff changeset
    40
definition "(sup :: char \<Rightarrow> _) = max"
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    41
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
    42
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
    43
  by standard (auto simp add: inf_char_def sup_char_def max_min_distrib2)
22483
86064f2f2188 added instance for lattice
haftmann
parents: 21911
diff changeset
    44
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    45
end
878c37886eed removed some legacy instantiations
haftmann
parents: 25502
diff changeset
    46
54595
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    47
instantiation String.literal :: linorder
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    48
begin
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    49
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    50
context includes literal.lifting
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    51
begin
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    52
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    53
lift_definition less_literal :: "String.literal \<Rightarrow> String.literal \<Rightarrow> bool"
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    54
  is "ord.lexordp op <" .
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    55
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    56
lift_definition less_eq_literal :: "String.literal \<Rightarrow> String.literal \<Rightarrow> bool"
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    57
  is "ord.lexordp_eq op <" .
54595
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    58
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    59
instance
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    60
proof -
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    61
  interpret linorder "ord.lexordp_eq op <" "ord.lexordp op < :: string \<Rightarrow> string \<Rightarrow> bool"
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    62
    by (rule linorder.lexordp_linorder[where less_eq="op \<le>"]) unfold_locales
54595
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    63
  show "PROP ?thesis"
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    64
    by intro_classes (transfer, simp add: less_le_not_le linear)+
54595
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    65
qed
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    66
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    67
end
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    68
55426
90f2ceed2828 make lifting setup for String.literal local to prevent transfer from replacing STR ''...'' literals
Andreas Lochbihler
parents: 54863
diff changeset
    69
end
54595
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    70
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    71
lemma less_literal_code [code]:
57437
0baf08c075b9 qualified String.explode and String.implode
haftmann
parents: 55426
diff changeset
    72
  "op < = (\<lambda>xs ys. ord.lexordp op < (String.explode xs) (String.explode ys))"
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    73
  by (simp add: less_literal.rep_eq fun_eq_iff)
54595
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    74
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    75
lemma less_eq_literal_code [code]:
57437
0baf08c075b9 qualified String.explode and String.implode
haftmann
parents: 55426
diff changeset
    76
  "op \<le> = (\<lambda>xs ys. ord.lexordp_eq op < (String.explode xs) (String.explode ys))"
63462
c1fe30f2bc32 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    77
  by (simp add: less_eq_literal.rep_eq fun_eq_iff)
54595
a2eeeb335a48 instantiate linorder for String.literal by lexicographic order
Andreas Lochbihler
parents: 51160
diff changeset
    78
55426
90f2ceed2828 make lifting setup for String.literal local to prevent transfer from replacing STR ''...'' literals
Andreas Lochbihler
parents: 54863
diff changeset
    79
lifting_update literal.lifting
90f2ceed2828 make lifting setup for String.literal local to prevent transfer from replacing STR ''...'' literals
Andreas Lochbihler
parents: 54863
diff changeset
    80
lifting_forget literal.lifting
90f2ceed2828 make lifting setup for String.literal local to prevent transfer from replacing STR ''...'' literals
Andreas Lochbihler
parents: 54863
diff changeset
    81
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    82
end