src/HOL/Library/Char_ord.thy
changeset 25764 878c37886eed
parent 25502 9200b36280c0
child 27368 9f90ac19e32b
equal deleted inserted replaced
25763:474f8ba9dfa9 25764:878c37886eed
     7 
     7 
     8 theory Char_ord
     8 theory Char_ord
     9 imports Product_ord Char_nat
     9 imports Product_ord Char_nat
    10 begin
    10 begin
    11 
    11 
    12 instance nibble :: linorder
    12 instantiation nibble :: linorder
    13   nibble_less_eq_def: "n \<le> m \<equiv> nat_of_nibble n \<le> nat_of_nibble m"
    13 begin
    14   nibble_less_def: "n < m \<equiv> nat_of_nibble n < nat_of_nibble m"
    14 
    15 proof
    15 definition
       
    16   nibble_less_eq_def: "n \<le> m \<longleftrightarrow> nat_of_nibble n \<le> nat_of_nibble m"
       
    17 
       
    18 definition
       
    19   nibble_less_def: "n < m \<longleftrightarrow> nat_of_nibble n < nat_of_nibble m"
       
    20 
       
    21 instance proof
    16   fix n :: nibble
    22   fix n :: nibble
    17   show "n \<le> n" unfolding nibble_less_eq_def nibble_less_def by auto
    23   show "n \<le> n" unfolding nibble_less_eq_def nibble_less_def by auto
    18 next
    24 next
    19   fix n m q :: nibble
    25   fix n m q :: nibble
    20   assume "n \<le> m"
    26   assume "n \<le> m"
    36   fix n m :: nibble
    42   fix n m :: nibble
    37   show "n \<le> m \<or> m \<le> n"
    43   show "n \<le> m \<or> m \<le> n"
    38     unfolding nibble_less_eq_def by auto
    44     unfolding nibble_less_eq_def by auto
    39 qed
    45 qed
    40 
    46 
    41 instance nibble :: distrib_lattice
    47 end
       
    48 
       
    49 instantiation nibble :: distrib_lattice
       
    50 begin
       
    51 
       
    52 definition
    42   "(inf \<Colon> nibble \<Rightarrow> _) = min"
    53   "(inf \<Colon> nibble \<Rightarrow> _) = min"
       
    54 
       
    55 definition
    43   "(sup \<Colon> nibble \<Rightarrow> _) = max"
    56   "(sup \<Colon> nibble \<Rightarrow> _) = max"
    44   by default (auto simp add:
    57 
       
    58 instance by default (auto simp add:
    45     inf_nibble_def sup_nibble_def min_max.sup_inf_distrib1)
    59     inf_nibble_def sup_nibble_def min_max.sup_inf_distrib1)
    46 
    60 
    47 instance char :: linorder
    61 end
    48   char_less_eq_def: "c1 \<le> c2 \<equiv> case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
    62 
    49     n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
    63 instantiation char :: linorder
    50   char_less_def:    "c1 < c2 \<equiv> case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
    64 begin
    51     n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
    65 
       
    66 definition
       
    67   char_less_eq_def [code func del]: "c1 \<le> c2 \<longleftrightarrow> (case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
       
    68     n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2)"
       
    69 
       
    70 definition
       
    71   char_less_def [code func del]: "c1 < c2 \<longleftrightarrow> (case c1 of Char n1 m1 \<Rightarrow> case c2 of Char n2 m2 \<Rightarrow>
       
    72     n1 < n2 \<or> n1 = n2 \<and> m1 < m2)"
       
    73 
       
    74 instance
    52   by default (auto simp: char_less_eq_def char_less_def split: char.splits)
    75   by default (auto simp: char_less_eq_def char_less_def split: char.splits)
    53 
    76 
    54 lemmas [code func del] = char_less_eq_def char_less_def
    77 end
    55 
    78 
    56 instance char :: distrib_lattice
    79 instantiation char :: distrib_lattice
       
    80 begin
       
    81 
       
    82 definition
    57   "(inf \<Colon> char \<Rightarrow> _) = min"
    83   "(inf \<Colon> char \<Rightarrow> _) = min"
       
    84 
       
    85 definition
    58   "(sup \<Colon> char \<Rightarrow> _) = max"
    86   "(sup \<Colon> char \<Rightarrow> _) = max"
    59   by default (auto simp add:
    87 
       
    88 instance   by default (auto simp add:
    60     inf_char_def sup_char_def min_max.sup_inf_distrib1)
    89     inf_char_def sup_char_def min_max.sup_inf_distrib1)
       
    90 
       
    91 end
    61 
    92 
    62 lemma [simp, code func]:
    93 lemma [simp, code func]:
    63   shows char_less_eq_simp: "Char n1 m1 \<le> Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
    94   shows char_less_eq_simp: "Char n1 m1 \<le> Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 \<le> m2"
    64   and char_less_simp:      "Char n1 m1 < Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
    95   and char_less_simp:      "Char n1 m1 < Char n2 m2 \<longleftrightarrow> n1 < n2 \<or> n1 = n2 \<and> m1 < m2"
    65   unfolding char_less_eq_def char_less_def by simp_all
    96   unfolding char_less_eq_def char_less_def by simp_all