Theories/Prefix_subtract.thy
author urbanc
Wed, 23 Mar 2011 12:17:30 +0000
changeset 149 e122cb146ecc
permissions -rw-r--r--
added the most current versions of the theories.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
149
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     1
theory Prefix_subtract
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     2
  imports Main "~~/src/HOL/Library/List_Prefix"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     3
begin
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     4
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     5
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     6
section {* A small theory of prefix subtraction *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     7
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     8
text {*
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     9
  The notion of @{text "prefix_subtract"} makes 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    10
  the second direction of the Myhill-Nerode theorem 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    11
  more readable.
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    12
*}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    13
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    14
instantiation list :: (type) minus
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    15
begin
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    16
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    17
fun minus_list :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    18
where
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    19
  "minus_list []     xs     = []" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    20
| "minus_list (x#xs) []     = x#xs" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    21
| "minus_list (x#xs) (y#ys) = (if x = y then minus_list xs ys else (x#xs))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    22
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    23
instance by default
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    24
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    25
end
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    26
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    27
lemma [simp]: "x - [] = x"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    28
by (induct x) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    29
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    30
lemma [simp]: "(x @ y) - x = y"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    31
by (induct x) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    32
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    33
lemma [simp]: "x - x = []"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    34
by (induct x) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    35
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    36
lemma [simp]: "x = z @ y \<Longrightarrow> x - z = y "
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    37
by (induct x) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    38
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    39
lemma diff_prefix:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    40
  "\<lbrakk>c \<le> a - b; b \<le> a\<rbrakk> \<Longrightarrow> b @ c \<le> a"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    41
by (auto elim: prefixE)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    42
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    43
lemma diff_diff_append: 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    44
  "\<lbrakk>c < a - b; b < a\<rbrakk> \<Longrightarrow> (a - b) - c = a - (b @ c)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    45
apply (clarsimp simp:strict_prefix_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    46
by (drule diff_prefix, auto elim:prefixE)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    47
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    48
lemma append_eq_cases:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    49
  assumes a: "x @ y = m @ n"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    50
  shows "x \<le> m \<or> m \<le> x"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    51
unfolding prefix_def using a
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    52
by (auto simp add: append_eq_append_conv2)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    53
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    54
lemma append_eq_dest:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    55
  assumes a: "x @ y = m @ n" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    56
  shows "(x \<le> m \<and> (m - x) @ n = y) \<or> (m \<le> x \<and> (x - m) @ y = n)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    57
using append_eq_cases[OF a] a
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    58
by (auto elim: prefixE)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    59
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    60
end