Theory List_lexord

Up to index of Isabelle/HOL/Library

theory List_lexord
imports List
begin

(*  Title:      HOL/Library/List_lexord.thy
    ID:         $Id: List_lexord.thy,v 1.11 2008/01/02 14:14:18 haftmann Exp $
    Author:     Norbert Voelker
*)

header {* Lexicographic order on lists *}

theory List_lexord
imports List
begin

instantiation list :: (ord) ord
begin

definition
  list_less_def [code func del]: "(xs::('a::ord) list) < ys <-> (xs, ys) ∈ lexord {(u,v). u < v}"

definition
  list_le_def [code func del]: "(xs::('a::ord) list) ≤ ys <-> (xs < ys ∨ xs = ys)"

instance ..

end

instance list :: (order) order
  apply (intro_classes, unfold list_less_def list_le_def)
  apply safe
  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
  apply simp
  apply assumption
  apply (blast intro: lexord_trans transI order_less_trans)
  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
  apply simp
  apply (blast intro: lexord_trans transI order_less_trans)
  done

instance list :: (linorder) linorder
  apply (intro_classes, unfold list_le_def list_less_def, safe)
  apply (cut_tac x = x and y = y and  r = "{(a,b). a < b}"  in lexord_linear)
   apply force
  apply simp
  done

instantiation list :: (linorder) distrib_lattice
begin

definition
  [code func del]: "(inf :: 'a list => _) = min"

definition
  [code func del]: "(sup :: 'a list => _) = max"

instance
  by intro_classes
    (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)

end

lemma not_less_Nil [simp]: "¬ (x < [])"
  by (unfold list_less_def) simp

lemma Nil_less_Cons [simp]: "[] < a # x"
  by (unfold list_less_def) simp

lemma Cons_less_Cons [simp]: "a # x < b # y <-> a < b ∨ a = b ∧ x < y"
  by (unfold list_less_def) simp

lemma le_Nil [simp]: "x ≤ [] <-> x = []"
  by (unfold list_le_def, cases x) auto

lemma Nil_le_Cons [simp]: "[] ≤ x"
  by (unfold list_le_def, cases x) auto

lemma Cons_le_Cons [simp]: "a # x ≤ b # y <-> a < b ∨ a = b ∧ x ≤ y"
  by (unfold list_le_def) auto

lemma less_code [code func]:
  "xs < ([]::'a::{eq, order} list) <-> False"
  "[] < (x::'a::{eq, order}) # xs <-> True"
  "(x::'a::{eq, order}) # xs < y # ys <-> x < y ∨ x = y ∧ xs < ys"
  by simp_all

lemma less_eq_code [code func]:
  "x # xs ≤ ([]::'a::{eq, order} list) <-> False"
  "[] ≤ (xs::'a::{eq, order} list) <-> True"
  "(x::'a::{eq, order}) # xs ≤ y # ys <-> x < y ∨ x = y ∧ xs ≤ ys"
  by simp_all

end

lemma not_less_Nil:

  ¬ x < []

lemma Nil_less_Cons:

  [] < a # x

lemma Cons_less_Cons:

  (a # x < b # y) = (a < ba = bx < y)

lemma le_Nil:

  (x  []) = (x = [])

lemma Nil_le_Cons:

  []  x

lemma Cons_le_Cons:

  (a # x  b # y) = (a < ba = bx  y)

lemma less_code:

  (xs < []) = False
  ([] < x # xs) = True
  (x # xs < y # ys) = (x < yx = yxs < ys)

lemma less_eq_code:

  (x # xs  []) = False
  ([]  xs) = True
  (x # xs  y # ys) = (x < yx = yxs  ys)