New
authornipkow
Fri Apr 15 14:14:24 2005 +0200 (2005-04-15)
changeset 15737c7e522520910
parent 15736 1bb0399a9517
child 15738 1c1d40ff875a
New
src/HOL/Library/Char_ord.thy
src/HOL/Library/List_lexord.thy
src/HOL/Library/Product_ord.thy
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Char_ord.thy	Fri Apr 15 14:14:24 2005 +0200
     1.3 @@ -0,0 +1,99 @@
     1.4 +(*  Title:      HOL/Library/Char_ord.thy
     1.5 +    ID:         $Id$
     1.6 +    Author:     Norbert Voelker
     1.7 +*)
     1.8 +
     1.9 +header {* Instantiation of order classes type char *}
    1.10 +
    1.11 +theory Char_ord
    1.12 +imports Product_ord
    1.13 +begin
    1.14 +
    1.15 +text {* Conversions between nibbles and integers in [0..15]. *} 
    1.16 +
    1.17 +consts 
    1.18 +  nibble_to_int:: "nibble \<Rightarrow> int"
    1.19 +  int_to_nibble:: "int \<Rightarrow> nibble"
    1.20 +
    1.21 +primrec 
    1.22 +  "nibble_to_int Nibble0 = 0"  
    1.23 +  "nibble_to_int Nibble1 = 1" 
    1.24 +  "nibble_to_int Nibble2 = 2" 
    1.25 +  "nibble_to_int Nibble3 = 3" 
    1.26 +  "nibble_to_int Nibble4 = 4" 
    1.27 +  "nibble_to_int Nibble5 = 5" 
    1.28 +  "nibble_to_int Nibble6 = 6" 
    1.29 +  "nibble_to_int Nibble7 = 7" 
    1.30 +  "nibble_to_int Nibble8 = 8" 
    1.31 +  "nibble_to_int Nibble9 = 9" 
    1.32 +  "nibble_to_int NibbleA = 10" 
    1.33 +  "nibble_to_int NibbleB = 11" 
    1.34 +  "nibble_to_int NibbleC = 12" 
    1.35 +  "nibble_to_int NibbleD = 13" 
    1.36 +  "nibble_to_int NibbleE = 14" 
    1.37 +  "nibble_to_int NibbleF = 15"
    1.38 +
    1.39 +defs 
    1.40 +  int_to_nibble_def:  
    1.41 +    "int_to_nibble x \<equiv> (let y = x mod 16 in 
    1.42 +       if y = 0 then Nibble0 else
    1.43 +       if y = 1 then Nibble1 else
    1.44 +       if y = 2 then Nibble2 else
    1.45 +       if y = 3 then Nibble3 else
    1.46 +       if y = 4 then Nibble4 else
    1.47 +       if y = 5 then Nibble5 else
    1.48 +       if y = 6 then Nibble6 else
    1.49 +       if y = 7 then Nibble7 else
    1.50 +       if y = 8 then Nibble8 else
    1.51 +       if y = 9 then Nibble9 else
    1.52 +       if y = 10 then NibbleA else
    1.53 +       if y = 11 then NibbleB else
    1.54 +       if y = 12 then NibbleC else
    1.55 +       if y = 13 then NibbleD else
    1.56 +       if y = 14 then NibbleE else
    1.57 +       NibbleF)"
    1.58 +
    1.59 +lemma int_to_nibble_nibble_to_int: "int_to_nibble(nibble_to_int x) = x"
    1.60 +  by (case_tac x, auto simp: int_to_nibble_def Let_def)
    1.61 +
    1.62 +lemma inj_nibble_to_int: "inj nibble_to_int"
    1.63 +  by (rule inj_on_inverseI, rule int_to_nibble_nibble_to_int)
    1.64 +
    1.65 +lemmas nibble_to_int_eq = inj_nibble_to_int [THEN inj_eq]
    1.66 +
    1.67 +lemma nibble_to_int_ge_0: "0 \<le> nibble_to_int x"
    1.68 +  by (case_tac x, auto)
    1.69 +
    1.70 +lemma nibble_to_int_less_16: "nibble_to_int x < 16"
    1.71 +  by (case_tac x, auto)
    1.72 +
    1.73 +text {* Conversion between chars and int pairs. *}
    1.74 +
    1.75 +consts 
    1.76 +  char_to_int_pair :: "char \<Rightarrow> int \<times> int"
    1.77 +primrec
    1.78 +  "char_to_int_pair(Char a b) = (nibble_to_int a, nibble_to_int b)" 
    1.79 +
    1.80 +lemma inj_char_to_int_pair: "inj char_to_int_pair"
    1.81 +  by (rule inj_onI, case_tac x, case_tac y, auto simp: nibble_to_int_eq)
    1.82 +
    1.83 +lemmas char_to_int_pair_eq = inj_char_to_int_pair [THEN inj_eq]
    1.84 +
    1.85 +text {* Instantiation of order classes *} 
    1.86 +
    1.87 +instance char :: ord ..
    1.88 +
    1.89 +defs (overloaded)
    1.90 +  char_le_def:  "c \<le> d \<equiv> (char_to_int_pair c \<le> char_to_int_pair d)" 
    1.91 +  char_less_def: "c < d \<equiv> (char_to_int_pair c < char_to_int_pair d)" 
    1.92 +
    1.93 +lemmas char_ord_defs = char_less_def char_le_def
    1.94 +
    1.95 +instance char::order
    1.96 +  apply (intro_classes, unfold char_ord_defs)
    1.97 +  by (auto simp: char_to_int_pair_eq order_less_le)
    1.98 +
    1.99 +instance char::linorder
   1.100 +  by (intro_classes, unfold char_le_def, auto)
   1.101 +
   1.102 +end
   1.103 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/HOL/Library/List_lexord.thy	Fri Apr 15 14:14:24 2005 +0200
     2.3 @@ -0,0 +1,53 @@
     2.4 +(*  Title:      HOL/Library/List_lexord.thy
     2.5 +    ID:         $Id$
     2.6 +    Author:     Norbert Voelker
     2.7 +*)
     2.8 +
     2.9 +header {* Instantiation of order classes for lexord on lists *}
    2.10 +
    2.11 +theory List_lexord
    2.12 +imports Main
    2.13 +begin
    2.14 +
    2.15 +instance list :: (ord) ord ..
    2.16 +defs(overloaded)
    2.17 +  list_le_def:  "(xs::('a::ord) list) \<le> ys \<equiv> (xs < ys \<or> xs = ys)" 
    2.18 +  list_less_def: "(xs::('a::ord) list) < ys \<equiv> (xs,ys) \<in> lexord {(u,v). u < v}"
    2.19 +
    2.20 +lemmas list_ord_defs = list_less_def list_le_def
    2.21 +
    2.22 +instance list::(order)order
    2.23 +  apply (intro_classes, unfold list_ord_defs)
    2.24 +  apply (rule disjI2, safe)
    2.25 +  apply (blast intro: lexord_trans transI order_less_trans)
    2.26 +  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
    2.27 +  apply simp
    2.28 +  apply (blast intro: lexord_trans transI order_less_trans)
    2.29 +  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
    2.30 +  apply simp
    2.31 +  by assumption
    2.32 +
    2.33 +instance list::(linorder)linorder
    2.34 +  apply (intro_classes, unfold list_le_def list_less_def, safe)
    2.35 +  apply (cut_tac x="x" and y="y" and  r = "{(a,b). a < b}"  in lexord_linear)
    2.36 +  by (force, simp)
    2.37 +
    2.38 +lemma not_less_Nil[simp]: "~(x < [])";
    2.39 +  by (unfold list_less_def, simp);
    2.40 +
    2.41 +lemma Nil_less_Cons[simp]: "[] < a # x";
    2.42 +  by (unfold list_less_def, simp);
    2.43 +
    2.44 +lemma Cons_less_Cons[simp]: "(a # x < b # y) = (a < b | a = b & x < y)";
    2.45 +  by (unfold list_less_def, simp);
    2.46 +
    2.47 +lemma le_Nil[simp]: "(x <= [])   = (x = [])";
    2.48 +  by (unfold list_ord_defs, case_tac x, auto);
    2.49 +
    2.50 +lemma Nil_le_Cons[simp]: "([] <= x)";
    2.51 +  by (unfold list_ord_defs, case_tac x, auto);
    2.52 +
    2.53 +lemma Cons_le_Cons[simp]: "(a # x <= b # y) = (a < b | a = b & x <= y)";
    2.54 +  by (unfold list_ord_defs, auto);
    2.55 +
    2.56 +end
    2.57 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/HOL/Library/Product_ord.thy	Fri Apr 15 14:14:24 2005 +0200
     3.3 @@ -0,0 +1,28 @@
     3.4 +(*  Title:      HOL/Library/Product_ord.thy
     3.5 +    ID:         $Id$
     3.6 +    Author:     Norbert Voelker
     3.7 +*)
     3.8 +
     3.9 +header {* Instantiation of order classes for product types *}
    3.10 +
    3.11 +theory Product_ord
    3.12 +imports Main
    3.13 +begin
    3.14 +
    3.15 +instance "*" :: (ord,ord) ord ..
    3.16 +
    3.17 +defs (overloaded)
    3.18 +  prod_le_def: "(x \<le> y) \<equiv> (fst x < fst y) | (fst x = fst y & snd x \<le> snd y)" 
    3.19 +  prod_less_def: "(x < y) \<equiv> (fst x < fst y) | (fst x = fst y & snd x < snd y)"
    3.20 +
    3.21 +
    3.22 +lemmas prod_ord_defs = prod_less_def prod_le_def
    3.23 +
    3.24 +instance "*" :: (order,order) order 
    3.25 +  apply (intro_classes, unfold prod_ord_defs)
    3.26 +  by (auto intro: order_less_trans)
    3.27 +
    3.28 +instance "*":: (linorder,linorder)linorder
    3.29 +  by (intro_classes, unfold prod_le_def, auto)
    3.30 +
    3.31 +end
    3.32 \ No newline at end of file