src/HOL/Library/List_lexord.thy
author haftmann
Thu, 19 Jul 2007 21:47:39 +0200
changeset 23854 688a8a7bcd4e
parent 22845 5f9138bcb3d7
child 25502 9200b36280c0
permissions -rw-r--r--
uniform naming conventions for CG theories
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15737
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Library/List_lexord.thy
nipkow
parents:
diff changeset
     2
    ID:         $Id$
nipkow
parents:
diff changeset
     3
    Author:     Norbert Voelker
nipkow
parents:
diff changeset
     4
*)
nipkow
parents:
diff changeset
     5
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
     6
header {* Lexicographic order on lists *}
15737
nipkow
parents:
diff changeset
     7
nipkow
parents:
diff changeset
     8
theory List_lexord
nipkow
parents:
diff changeset
     9
imports Main
nipkow
parents:
diff changeset
    10
begin
nipkow
parents:
diff changeset
    11
21458
475b321982f7 added code lemmas
haftmann
parents: 17200
diff changeset
    12
instance list :: (ord) ord
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    13
  list_le_def:  "(xs::('a::ord) list) \<le> ys \<equiv> (xs < ys \<or> xs = ys)"
21458
475b321982f7 added code lemmas
haftmann
parents: 17200
diff changeset
    14
  list_less_def: "(xs::('a::ord) list) < ys \<equiv> (xs, ys) \<in> lexord {(u,v). u < v}" ..
15737
nipkow
parents:
diff changeset
    15
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
    16
lemmas list_ord_defs [code func del] = list_less_def list_le_def
15737
nipkow
parents:
diff changeset
    17
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    18
instance list :: (order) order
15737
nipkow
parents:
diff changeset
    19
  apply (intro_classes, unfold list_ord_defs)
22316
f662831459de added class "preorder"
haftmann
parents: 22177
diff changeset
    20
  apply safe
15737
nipkow
parents:
diff changeset
    21
  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
nipkow
parents:
diff changeset
    22
  apply simp
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    23
  apply assumption
22316
f662831459de added class "preorder"
haftmann
parents: 22177
diff changeset
    24
  apply (blast intro: lexord_trans transI order_less_trans)
f662831459de added class "preorder"
haftmann
parents: 22177
diff changeset
    25
  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
f662831459de added class "preorder"
haftmann
parents: 22177
diff changeset
    26
  apply simp
f662831459de added class "preorder"
haftmann
parents: 22177
diff changeset
    27
  apply (blast intro: lexord_trans transI order_less_trans)
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    28
  done
15737
nipkow
parents:
diff changeset
    29
21458
475b321982f7 added code lemmas
haftmann
parents: 17200
diff changeset
    30
instance list :: (linorder) linorder
15737
nipkow
parents:
diff changeset
    31
  apply (intro_classes, unfold list_le_def list_less_def, safe)
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    32
  apply (cut_tac x = x and y = y and  r = "{(a,b). a < b}"  in lexord_linear)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    33
   apply force
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    34
  apply simp
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    35
  done
15737
nipkow
parents:
diff changeset
    36
22483
86064f2f2188 added instance for lattice
haftmann
parents: 22316
diff changeset
    37
instance list :: (linorder) distrib_lattice
86064f2f2188 added instance for lattice
haftmann
parents: 22316
diff changeset
    38
  "inf \<equiv> min"
86064f2f2188 added instance for lattice
haftmann
parents: 22316
diff changeset
    39
  "sup \<equiv> max"
86064f2f2188 added instance for lattice
haftmann
parents: 22316
diff changeset
    40
  by intro_classes
86064f2f2188 added instance for lattice
haftmann
parents: 22316
diff changeset
    41
    (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)
86064f2f2188 added instance for lattice
haftmann
parents: 22316
diff changeset
    42
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
    43
lemmas [code func del] = inf_list_def sup_list_def
22744
5cbe966d67a2 Isar definitions are now added explicitly to code theorem table
haftmann
parents: 22483
diff changeset
    44
22177
515021e98684 improved
haftmann
parents: 21458
diff changeset
    45
lemma not_less_Nil [simp]: "\<not> (x < [])"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    46
  by (unfold list_less_def) simp
15737
nipkow
parents:
diff changeset
    47
22177
515021e98684 improved
haftmann
parents: 21458
diff changeset
    48
lemma Nil_less_Cons [simp]: "[] < a # x"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    49
  by (unfold list_less_def) simp
15737
nipkow
parents:
diff changeset
    50
22177
515021e98684 improved
haftmann
parents: 21458
diff changeset
    51
lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    52
  by (unfold list_less_def) simp
15737
nipkow
parents:
diff changeset
    53
22177
515021e98684 improved
haftmann
parents: 21458
diff changeset
    54
lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
515021e98684 improved
haftmann
parents: 21458
diff changeset
    55
  by (unfold list_ord_defs, cases x) auto
515021e98684 improved
haftmann
parents: 21458
diff changeset
    56
515021e98684 improved
haftmann
parents: 21458
diff changeset
    57
lemma Nil_le_Cons [simp]: "[] \<le> x"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    58
  by (unfold list_ord_defs, cases x) auto
15737
nipkow
parents:
diff changeset
    59
22177
515021e98684 improved
haftmann
parents: 21458
diff changeset
    60
lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    61
  by (unfold list_ord_defs) auto
15737
nipkow
parents:
diff changeset
    62
22177
515021e98684 improved
haftmann
parents: 21458
diff changeset
    63
lemma less_code [code func]:
515021e98684 improved
haftmann
parents: 21458
diff changeset
    64
  "xs < ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
515021e98684 improved
haftmann
parents: 21458
diff changeset
    65
  "[] < (x\<Colon>'a\<Colon>{eq, order}) # xs \<longleftrightarrow> True"
515021e98684 improved
haftmann
parents: 21458
diff changeset
    66
  "(x\<Colon>'a\<Colon>{eq, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
515021e98684 improved
haftmann
parents: 21458
diff changeset
    67
  by simp_all
515021e98684 improved
haftmann
parents: 21458
diff changeset
    68
515021e98684 improved
haftmann
parents: 21458
diff changeset
    69
lemma less_eq_code [code func]:
515021e98684 improved
haftmann
parents: 21458
diff changeset
    70
  "x # xs \<le> ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
515021e98684 improved
haftmann
parents: 21458
diff changeset
    71
  "[] \<le> (xs\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> True"
515021e98684 improved
haftmann
parents: 21458
diff changeset
    72
  "(x\<Colon>'a\<Colon>{eq, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
515021e98684 improved
haftmann
parents: 21458
diff changeset
    73
  by simp_all
515021e98684 improved
haftmann
parents: 21458
diff changeset
    74
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15737
diff changeset
    75
end