src/HOL/Library/List_Lenlexorder.thy
author paulson <lp15@cam.ac.uk>
Tue, 18 Aug 2020 14:44:59 +0100
changeset 72166 bb37571139bf
parent 72164 b7c54ff7f2dd
child 72184 881bd98bddee
permissions -rw-r--r--
fixed for new lex-order. And the effing indentation!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
71766
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     1
(*  Title:      HOL/Library/List_Lenlexorder.thy
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     2
*)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     3
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     4
section \<open>Lexicographic order on lists\<close>
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     5
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     6
theory List_Lenlexorder
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     7
imports Main
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     8
begin
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     9
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    10
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    11
instantiation list :: (ord) ord
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    12
begin
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    13
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    14
definition
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    15
  list_less_def: "xs < ys \<longleftrightarrow> (xs, ys) \<in> lenlex {(u, v). u < v}"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    16
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    17
definition
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    18
  list_le_def: "(xs :: _ list) \<le> ys \<longleftrightarrow> xs < ys \<or> xs = ys"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    19
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    20
instance ..
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    21
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    22
end
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    23
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    24
instance list :: (order) order
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    25
proof
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    26
  have tr: "trans {(u, v::'a). u < v}"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    27
    using trans_def by fastforce
72164
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    28
  have ant: "antisym {(u, v::'a). u < v}"
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    29
    using antisym_def order.asym by auto
71766
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    30
  have \<section>: False
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    31
    if "(xs,ys) \<in> lenlex {(u, v). u < v}" "(ys,xs) \<in> lenlex {(u, v). u < v}" for xs ys :: "'a list"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    32
  proof -
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    33
    have "(xs,xs) \<in> lenlex {(u, v). u < v}"
72164
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    34
      using that ant transD [OF lenlex_transI [OF tr]] by blast
71766
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    35
    then show False
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    36
      by (meson case_prodD lenlex_irreflexive less_irrefl mem_Collect_eq)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    37
  qed
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    38
  show "xs \<le> xs" for xs :: "'a list" by (simp add: list_le_def)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    39
  show "xs \<le> zs" if "xs \<le> ys" and "ys \<le> zs" for xs ys zs :: "'a list"
72164
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    40
    using that ant transD [OF lenlex_transI [OF tr]]
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    41
    by (auto simp add: list_le_def list_less_def)
71766
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    42
  show "xs = ys" if "xs \<le> ys" "ys \<le> xs" for xs ys :: "'a list"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    43
    using \<section> that list_le_def list_less_def by blast
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    44
  show "xs < ys \<longleftrightarrow> xs \<le> ys \<and> \<not> ys \<le> xs" for xs ys :: "'a list"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    45
    by (auto simp add: list_less_def list_le_def dest: \<section>)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    46
qed
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    47
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    48
instance list :: (linorder) linorder
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    49
proof
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    50
  fix xs ys :: "'a list"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    51
  have "total (lenlex {(u, v::'a). u < v})"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    52
    by (rule total_lenlex) (auto simp: total_on_def)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    53
  then show "xs \<le> ys \<or> ys \<le> xs"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    54
    by (auto simp add: total_on_def list_le_def list_less_def)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    55
qed
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    56
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    57
instantiation list :: (linorder) distrib_lattice
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    58
begin
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    59
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    60
definition "(inf :: 'a list \<Rightarrow> _) = min"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    61
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    62
definition "(sup :: 'a list \<Rightarrow> _) = max"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    63
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    64
instance
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    65
  by standard (auto simp add: inf_list_def sup_list_def max_min_distrib2)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    66
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    67
end
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    68
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    69
lemma not_less_Nil [simp]: "\<not> x < []"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    70
  by (simp add: list_less_def)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    71
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    72
lemma Nil_less_Cons [simp]: "[] < a # x"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    73
  by (simp add: list_less_def)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    74
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    75
lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    76
  unfolding list_le_def by (cases x) auto
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    77
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    78
lemma Nil_le_Cons [simp]: "[] \<le> x"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    79
  unfolding list_le_def by (cases x) auto
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    80
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    81
instantiation list :: (order) order_bot
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    82
begin
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    83
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    84
definition "bot = []"
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    85
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    86
instance
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    87
  by standard (simp add: bot_list_def)
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    88
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    89
end
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    90
72164
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    91
lemma Cons_less_Cons: 
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    92
  fixes a :: "'a::order"
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    93
  shows "a # xs < b # ys \<longleftrightarrow> length xs < length ys \<or> length xs = length ys \<and> (a < b \<or> a = b \<and> xs < ys)"
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    94
  using lenlex_length
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    95
  by (fastforce simp: list_less_def Cons_lenlex_iff)
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    96
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    97
lemma Cons_le_Cons:
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    98
  fixes a :: "'a::order"
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
    99
  shows "a # xs \<le> b # ys \<longleftrightarrow> length xs < length ys \<or> length xs = length ys \<and> (a < b \<or> a = b \<and> xs \<le> ys)"
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
   100
  by (auto simp: list_le_def Cons_less_Cons)
b7c54ff7f2dd S Holub's proposed generalisation of the lexicographic product of two orderings
paulson <lp15@cam.ac.uk>
parents: 71766
diff changeset
   101
71766
1249b998e377 New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   102
end