src/ZF/UNITY/GenPrefix.thy
author wenzelm
Tue, 10 Jul 2007 23:29:43 +0200
changeset 23719 ccd9cb15c062
parent 15634 bca33c49b083
child 24892 c663e675e177
permissions -rw-r--r--
more markup for inner and outer syntax; added enclose;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
     1
(*  ID:         $Id$
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
     2
    Author:     Sidi O Ehmety, Cambridge University Computer Laboratory
d9320fb0a570 New files
ehmety
parents:
diff changeset
     3
    Copyright   2001  University of Cambridge
d9320fb0a570 New files
ehmety
parents:
diff changeset
     4
d9320fb0a570 New files
ehmety
parents:
diff changeset
     5
   <xs,ys>:gen_prefix(r)
d9320fb0a570 New files
ehmety
parents:
diff changeset
     6
     if ys = xs' @ zs where length(xs) = length(xs')
d9320fb0a570 New files
ehmety
parents:
diff changeset
     7
     and corresponding elements of xs, xs' are pairwise related by r
d9320fb0a570 New files
ehmety
parents:
diff changeset
     8
d9320fb0a570 New files
ehmety
parents:
diff changeset
     9
Based on Lex/Prefix
d9320fb0a570 New files
ehmety
parents:
diff changeset
    10
*)
d9320fb0a570 New files
ehmety
parents:
diff changeset
    11
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    12
header{*Charpentier's Generalized Prefix Relation*}
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    13
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    14
theory GenPrefix
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    15
imports Main 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    16
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    17
begin
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
    18
14055
a3f592e3f4bd Further tweaks of ZF/UNITY
paulson
parents: 14046
diff changeset
    19
constdefs (*really belongs in ZF/Trancl*)
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    20
  part_order :: "[i, i] => o"
14055
a3f592e3f4bd Further tweaks of ZF/UNITY
paulson
parents: 14046
diff changeset
    21
  "part_order(A, r) == refl(A,r) & trans[A](r) & antisym(r)"
a3f592e3f4bd Further tweaks of ZF/UNITY
paulson
parents: 14046
diff changeset
    22
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
    23
consts
d9320fb0a570 New files
ehmety
parents:
diff changeset
    24
  gen_prefix :: "[i, i] => i"
d9320fb0a570 New files
ehmety
parents:
diff changeset
    25
  
d9320fb0a570 New files
ehmety
parents:
diff changeset
    26
inductive
d9320fb0a570 New files
ehmety
parents:
diff changeset
    27
  (* Parameter A is the domain of zs's elements *)
d9320fb0a570 New files
ehmety
parents:
diff changeset
    28
  
d9320fb0a570 New files
ehmety
parents:
diff changeset
    29
  domains "gen_prefix(A, r)" <= "list(A)*list(A)"
d9320fb0a570 New files
ehmety
parents:
diff changeset
    30
  
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    31
  intros
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    32
    Nil:     "<[],[]>:gen_prefix(A, r)"
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
    33
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    34
    prepend: "[| <xs,ys>:gen_prefix(A, r);  <x,y>:r; x:A; y:A |]
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
    35
	      ==> <Cons(x,xs), Cons(y,ys)>: gen_prefix(A, r)"
d9320fb0a570 New files
ehmety
parents:
diff changeset
    36
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    37
    append:  "[| <xs,ys>:gen_prefix(A, r); zs:list(A) |]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    38
	      ==> <xs, ys@zs>:gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    39
    type_intros app_type list.Nil list.Cons
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
    40
d9320fb0a570 New files
ehmety
parents:
diff changeset
    41
constdefs
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    42
   prefix :: "i=>i"
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
    43
  "prefix(A) == gen_prefix(A, id(A))"
d9320fb0a570 New files
ehmety
parents:
diff changeset
    44
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    45
   strict_prefix :: "i=>i"
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
    46
  "strict_prefix(A) == prefix(A) - id(list(A))"
d9320fb0a570 New files
ehmety
parents:
diff changeset
    47
d9320fb0a570 New files
ehmety
parents:
diff changeset
    48
syntax
d9320fb0a570 New files
ehmety
parents:
diff changeset
    49
  (* less or equal and greater or equal over prefixes *)
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    50
  pfixLe :: "[i, i] => o"               (infixl "pfixLe" 50)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    51
  pfixGe :: "[i, i] => o"               (infixl "pfixGe" 50)
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
    52
d9320fb0a570 New files
ehmety
parents:
diff changeset
    53
translations
d9320fb0a570 New files
ehmety
parents:
diff changeset
    54
   "xs pfixLe ys" == "<xs, ys>:gen_prefix(nat, Le)"
d9320fb0a570 New files
ehmety
parents:
diff changeset
    55
   "xs pfixGe ys" == "<xs, ys>:gen_prefix(nat, Ge)"
d9320fb0a570 New files
ehmety
parents:
diff changeset
    56
  
d9320fb0a570 New files
ehmety
parents:
diff changeset
    57
15634
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    58
lemma reflD: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    59
 "[| refl(A, r); x \<in> A |] ==> <x,x>:r"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    60
apply (unfold refl_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    61
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    62
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    63
(*** preliminary lemmas ***)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    64
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    65
lemma Nil_gen_prefix: "xs \<in> list(A) ==> <[], xs> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    66
by (drule gen_prefix.append [OF gen_prefix.Nil], simp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    67
declare Nil_gen_prefix [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    68
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    69
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    70
lemma gen_prefix_length_le: "<xs,ys> \<in> gen_prefix(A, r) ==> length(xs) \<le> length(ys)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    71
apply (erule gen_prefix.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    72
apply (subgoal_tac [3] "ys \<in> list (A) ")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    73
apply (auto dest: gen_prefix.dom_subset [THEN subsetD]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    74
            intro: le_trans simp add: length_app)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    75
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    76
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    77
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    78
lemma Cons_gen_prefix_aux:
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    79
  "[| <xs', ys'> \<in> gen_prefix(A, r) |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    80
   ==> (\<forall>x xs. x \<in> A --> xs'= Cons(x,xs) -->  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    81
       (\<exists>y ys. y \<in> A & ys' = Cons(y,ys) & 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    82
       <x,y>:r & <xs, ys> \<in> gen_prefix(A, r)))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    83
apply (erule gen_prefix.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    84
prefer 3 apply (force intro: gen_prefix.append, auto) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    85
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    86
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    87
lemma Cons_gen_prefixE:
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    88
  "[| <Cons(x,xs), zs> \<in> gen_prefix(A, r);  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    89
    !!y ys. [|zs = Cons(y, ys); y \<in> A; x \<in> A; <x,y>:r;  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    90
      <xs,ys> \<in> gen_prefix(A, r) |] ==> P |] ==> P"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    91
apply (frule gen_prefix.dom_subset [THEN subsetD], auto) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    92
apply (blast dest: Cons_gen_prefix_aux) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    93
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    94
declare Cons_gen_prefixE [elim!]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    95
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    96
lemma Cons_gen_prefix_Cons: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    97
"(<Cons(x,xs),Cons(y,ys)> \<in> gen_prefix(A, r))  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    98
  <-> (x \<in> A & y \<in> A & <x,y>:r & <xs,ys> \<in> gen_prefix(A, r))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
    99
apply (auto intro: gen_prefix.prepend)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   100
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   101
declare Cons_gen_prefix_Cons [iff]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   102
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   103
(** Monotonicity of gen_prefix **)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   104
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   105
lemma gen_prefix_mono2: "r<=s ==> gen_prefix(A, r) <= gen_prefix(A, s)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   106
apply clarify
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   107
apply (frule gen_prefix.dom_subset [THEN subsetD], clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   108
apply (erule rev_mp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   109
apply (erule gen_prefix.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   110
apply (auto intro: gen_prefix.append)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   111
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   112
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   113
lemma gen_prefix_mono1: "A<=B ==>gen_prefix(A, r) <= gen_prefix(B, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   114
apply clarify
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   115
apply (frule gen_prefix.dom_subset [THEN subsetD], clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   116
apply (erule rev_mp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   117
apply (erule_tac P = "y \<in> list (A) " in rev_mp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   118
apply (erule_tac P = "xa \<in> list (A) " in rev_mp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   119
apply (erule gen_prefix.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   120
apply (simp (no_asm_simp))
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   121
apply clarify
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   122
apply (erule ConsE)+
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   123
apply (auto dest: gen_prefix.dom_subset [THEN subsetD]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   124
            intro: gen_prefix.append list_mono [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   125
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   126
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   127
lemma gen_prefix_mono: "[| A <= B; r <= s |] ==> gen_prefix(A, r) <= gen_prefix(B, s)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   128
apply (rule subset_trans)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   129
apply (rule gen_prefix_mono1)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   130
apply (rule_tac [2] gen_prefix_mono2, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   131
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   132
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   133
(*** gen_prefix order ***)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   134
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   135
(* reflexivity *)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   136
lemma refl_gen_prefix: "refl(A, r) ==> refl(list(A), gen_prefix(A, r))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   137
apply (unfold refl_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   138
apply (induct_tac "x", auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   139
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   140
declare refl_gen_prefix [THEN reflD, simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   141
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   142
(* Transitivity *)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   143
(* A lemma for proving gen_prefix_trans_comp *)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   144
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   145
lemma append_gen_prefix [rule_format (no_asm)]: "xs \<in> list(A) ==>  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   146
   \<forall>zs. <xs @ ys, zs> \<in> gen_prefix(A, r) --> <xs, zs>: gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   147
apply (erule list.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   148
apply (auto dest: gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   149
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   150
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   151
(* Lemma proving transitivity and more*)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   152
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   153
lemma gen_prefix_trans_comp [rule_format (no_asm)]:
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   154
     "<x, y>: gen_prefix(A, r) ==>  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   155
   (\<forall>z \<in> list(A). <y,z> \<in> gen_prefix(A, s)--><x, z> \<in> gen_prefix(A, s O r))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   156
apply (erule gen_prefix.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   157
apply (auto elim: ConsE simp add: Nil_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   158
apply (subgoal_tac "ys \<in> list (A) ")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   159
prefer 2 apply (blast dest: gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   160
apply (drule_tac xs = ys and r = s in append_gen_prefix, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   161
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   162
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   163
lemma trans_comp_subset: "trans(r) ==> r O r <= r"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   164
by (auto dest: transD)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   165
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   166
lemma trans_gen_prefix: "trans(r) ==> trans(gen_prefix(A,r))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   167
apply (simp (no_asm) add: trans_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   168
apply clarify
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   169
apply (rule trans_comp_subset [THEN gen_prefix_mono2, THEN subsetD], assumption)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   170
apply (rule gen_prefix_trans_comp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   171
apply (auto dest: gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   172
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   173
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   174
lemma trans_on_gen_prefix: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   175
 "trans(r) ==> trans[list(A)](gen_prefix(A, r))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   176
apply (drule_tac A = A in trans_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   177
apply (unfold trans_def trans_on_def, blast)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   178
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   179
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   180
lemma prefix_gen_prefix_trans:
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   181
    "[| <x,y> \<in> prefix(A); <y, z> \<in> gen_prefix(A, r); r<=A*A |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   182
      ==>  <x, z> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   183
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   184
apply (rule_tac P = "%r. <x,z> \<in> gen_prefix (A, r) " in right_comp_id [THEN subst])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   185
apply (blast dest: gen_prefix_trans_comp gen_prefix.dom_subset [THEN subsetD])+
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   186
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   187
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   188
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   189
lemma gen_prefix_prefix_trans: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   190
"[| <x,y> \<in> gen_prefix(A,r); <y, z> \<in> prefix(A); r<=A*A |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   191
  ==>  <x, z> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   192
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   193
apply (rule_tac P = "%r. <x,z> \<in> gen_prefix (A, r) " in left_comp_id [THEN subst])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   194
apply (blast dest: gen_prefix_trans_comp gen_prefix.dom_subset [THEN subsetD])+
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   195
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   196
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   197
(** Antisymmetry **)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   198
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   199
lemma nat_le_lemma [rule_format]: "n \<in> nat ==> \<forall>b \<in> nat. n #+ b \<le> n --> b = 0"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   200
by (induct_tac "n", auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   201
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   202
lemma antisym_gen_prefix: "antisym(r) ==> antisym(gen_prefix(A, r))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   203
apply (simp (no_asm) add: antisym_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   204
apply (rule impI [THEN allI, THEN allI])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   205
apply (erule gen_prefix.induct, blast) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   206
apply (simp add: antisym_def, blast)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   207
txt{*append case is hardest*}
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   208
apply clarify
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   209
apply (subgoal_tac "length (zs) = 0")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   210
apply (subgoal_tac "ys \<in> list (A) ")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   211
prefer 2 apply (blast dest: gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   212
apply (drule_tac psi = "<ys @ zs, xs> \<in> gen_prefix (A,r) " in asm_rl)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   213
apply simp
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   214
apply (subgoal_tac "length (ys @ zs) = length (ys) #+ length (zs) &ys \<in> list (A) &xs \<in> list (A) ")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   215
prefer 2 apply (blast intro: length_app dest: gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   216
apply (drule gen_prefix_length_le)+
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   217
apply clarify
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   218
apply simp
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   219
apply (drule_tac j = "length (xs) " in le_trans)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   220
apply blast
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   221
apply (auto intro: nat_le_lemma)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   222
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   223
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   224
(*** recursion equations ***)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   225
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   226
lemma gen_prefix_Nil: "xs \<in> list(A) ==> <xs, []> \<in> gen_prefix(A,r) <-> (xs = [])"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   227
by (induct_tac "xs", auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   228
declare gen_prefix_Nil [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   229
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   230
lemma same_gen_prefix_gen_prefix: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   231
 "[| refl(A, r);  xs \<in> list(A) |] ==>  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   232
    <xs@ys, xs@zs>: gen_prefix(A, r) <-> <ys,zs> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   233
apply (unfold refl_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   234
apply (induct_tac "xs")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   235
apply (simp_all (no_asm_simp))
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   236
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   237
declare same_gen_prefix_gen_prefix [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   238
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   239
lemma gen_prefix_Cons: "[| xs \<in> list(A); ys \<in> list(A); y \<in> A |] ==>  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   240
    <xs, Cons(y,ys)> \<in> gen_prefix(A,r)  <->  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   241
      (xs=[] | (\<exists>z zs. xs=Cons(z,zs) & z \<in> A & <z,y>:r & <zs,ys> \<in> gen_prefix(A,r)))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   242
apply (induct_tac "xs", auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   243
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   244
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   245
lemma gen_prefix_take_append: "[| refl(A,r);  <xs,ys> \<in> gen_prefix(A, r); zs \<in> list(A) |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   246
      ==>  <xs@zs, take(length(xs), ys) @ zs> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   247
apply (erule gen_prefix.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   248
apply (simp (no_asm_simp))
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   249
apply (frule_tac [!] gen_prefix.dom_subset [THEN subsetD], auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   250
apply (frule gen_prefix_length_le)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   251
apply (subgoal_tac "take (length (xs), ys) \<in> list (A) ")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   252
apply (simp_all (no_asm_simp) add: diff_is_0_iff [THEN iffD2] take_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   253
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   254
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   255
lemma gen_prefix_append_both: "[| refl(A, r);  <xs,ys> \<in> gen_prefix(A,r);    
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   256
         length(xs) = length(ys); zs \<in> list(A) |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   257
      ==>  <xs@zs, ys @ zs> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   258
apply (drule_tac zs = zs in gen_prefix_take_append, assumption+)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   259
apply (subgoal_tac "take (length (xs), ys) =ys")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   260
apply (auto intro!: take_all dest: gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   261
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   262
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   263
(*NOT suitable for rewriting since [y] has the form y#ys*)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   264
lemma append_cons_conv: "xs \<in> list(A) ==> xs @ Cons(y, ys) = (xs @ [y]) @ ys"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   265
by (auto simp add: app_assoc)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   266
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   267
lemma append_one_gen_prefix_lemma [rule_format]:
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   268
     "[| <xs,ys> \<in> gen_prefix(A, r);  refl(A, r) |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   269
      ==> length(xs) < length(ys) -->  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   270
          <xs @ [nth(length(xs), ys)], ys> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   271
apply (erule gen_prefix.induct, blast)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   272
apply (frule gen_prefix.dom_subset [THEN subsetD], clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   273
apply (simp_all add: length_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   274
(* Append case is hardest *)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   275
apply (frule gen_prefix_length_le [THEN le_iff [THEN iffD1]])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   276
apply (frule gen_prefix.dom_subset [THEN subsetD], clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   277
apply (subgoal_tac "length (xs) :nat&length (ys) :nat &length (zs) :nat")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   278
prefer 2 apply (blast intro: length_type, clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   279
apply (simp_all add: nth_append length_type length_app)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   280
apply (rule conjI)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   281
apply (blast intro: gen_prefix.append)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   282
apply (erule_tac V = "length (xs) < length (ys) -->?u" in thin_rl)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   283
apply (erule_tac a = zs in list.cases, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   284
apply (rule_tac P1 = "%x. <?u (x), ?v>:?w" in nat_diff_split [THEN iffD2])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   285
apply auto
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   286
apply (simplesubst append_cons_conv)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   287
apply (rule_tac [2] gen_prefix.append)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   288
apply (auto elim: ConsE simp add: gen_prefix_append_both)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   289
done 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   290
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   291
lemma append_one_gen_prefix: "[| <xs,ys>: gen_prefix(A, r);  length(xs) < length(ys);  refl(A, r) |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   292
      ==> <xs @ [nth(length(xs), ys)], ys> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   293
apply (blast intro: append_one_gen_prefix_lemma)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   294
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   295
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   296
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   297
(** Proving the equivalence with Charpentier's definition **)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   298
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   299
lemma gen_prefix_imp_nth_lemma [rule_format]: "xs \<in> list(A) ==>   
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   300
  \<forall>ys \<in> list(A). \<forall>i \<in> nat. i < length(xs)  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   301
          --> <xs, ys>: gen_prefix(A, r) --> <nth(i, xs), nth(i, ys)>:r"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   302
apply (induct_tac "xs", simp, clarify) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   303
apply simp 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   304
apply (erule natE, auto) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   305
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   306
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   307
lemma gen_prefix_imp_nth: "[| <xs,ys> \<in> gen_prefix(A,r); i < length(xs)|]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   308
      ==> <nth(i, xs), nth(i, ys)>:r"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   309
apply (cut_tac A = A in gen_prefix.dom_subset)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   310
apply (rule gen_prefix_imp_nth_lemma)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   311
apply (auto simp add: lt_nat_in_nat)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   312
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   313
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   314
lemma nth_imp_gen_prefix [rule_format]: "xs \<in> list(A) ==>  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   315
  \<forall>ys \<in> list(A). length(xs) \<le> length(ys)   
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   316
      --> (\<forall>i. i < length(xs) --> <nth(i, xs), nth(i,ys)>:r)   
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   317
      --> <xs, ys> \<in> gen_prefix(A, r)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   318
apply (induct_tac "xs")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   319
apply (simp_all (no_asm_simp))
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   320
apply clarify
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   321
apply (erule_tac a = ys in list.cases, simp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   322
apply (force intro!: nat_0_le simp add: lt_nat_in_nat)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   323
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   324
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   325
lemma gen_prefix_iff_nth: "(<xs,ys> \<in> gen_prefix(A,r)) <->  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   326
      (xs \<in> list(A) & ys \<in> list(A) & length(xs) \<le> length(ys) &  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   327
      (\<forall>i. i < length(xs) --> <nth(i,xs), nth(i, ys)>: r))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   328
apply (rule iffI)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   329
apply (frule gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   330
apply (frule gen_prefix_length_le, auto) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   331
apply (rule_tac [2] nth_imp_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   332
apply (drule gen_prefix_imp_nth)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   333
apply (auto simp add: lt_nat_in_nat)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   334
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   335
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   336
(** prefix is a partial order: **)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   337
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   338
lemma refl_prefix: "refl(list(A), prefix(A))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   339
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   340
apply (rule refl_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   341
apply (auto simp add: refl_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   342
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   343
declare refl_prefix [THEN reflD, simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   344
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   345
lemma trans_prefix: "trans(prefix(A))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   346
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   347
apply (rule trans_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   348
apply (auto simp add: trans_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   349
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   350
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   351
lemmas prefix_trans = trans_prefix [THEN transD, standard]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   352
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   353
lemma trans_on_prefix: "trans[list(A)](prefix(A))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   354
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   355
apply (rule trans_on_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   356
apply (auto simp add: trans_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   357
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   358
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   359
lemmas prefix_trans_on = trans_on_prefix [THEN trans_onD, standard]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   360
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   361
(* Monotonicity of "set" operator WRT prefix *)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   362
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   363
lemma set_of_list_prefix_mono: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   364
"<xs,ys> \<in> prefix(A) ==> set_of_list(xs) <= set_of_list(ys)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   365
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   366
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   367
apply (erule gen_prefix.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   368
apply (subgoal_tac [3] "xs \<in> list (A) &ys \<in> list (A) ")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   369
prefer 4 apply (blast dest: gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   370
apply (auto simp add: set_of_list_append)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   371
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   372
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   373
(** recursion equations **)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   374
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   375
lemma Nil_prefix: "xs \<in> list(A) ==> <[],xs> \<in> prefix(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   376
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   377
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   378
apply (simp (no_asm_simp) add: Nil_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   379
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   380
declare Nil_prefix [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   381
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   382
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   383
lemma prefix_Nil: "<xs, []> \<in> prefix(A) <-> (xs = [])"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   384
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   385
apply (unfold prefix_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   386
apply (frule gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   387
apply (drule_tac psi = "<xs, []> \<in> gen_prefix (A, id (A))" in asm_rl)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   388
apply (simp add: gen_prefix_Nil)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   389
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   390
declare prefix_Nil [iff]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   391
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   392
lemma Cons_prefix_Cons: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   393
"<Cons(x,xs), Cons(y,ys)> \<in> prefix(A) <-> (x=y & <xs,ys> \<in> prefix(A) & y \<in> A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   394
apply (unfold prefix_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   395
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   396
declare Cons_prefix_Cons [iff]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   397
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   398
lemma same_prefix_prefix: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   399
"xs \<in> list(A)==> <xs@ys,xs@zs> \<in> prefix(A) <-> (<ys,zs> \<in> prefix(A))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   400
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   401
apply (subgoal_tac "refl (A,id (A))")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   402
apply (simp (no_asm_simp))
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   403
apply (auto simp add: refl_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   404
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   405
declare same_prefix_prefix [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   406
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   407
lemma same_prefix_prefix_Nil: "xs \<in> list(A) ==> <xs@ys,xs> \<in> prefix(A) <-> (<ys,[]> \<in> prefix(A))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   408
apply (rule_tac P = "%x. <?u, x>:?v <-> ?w (x) " in app_right_Nil [THEN subst])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   409
apply (rule_tac [2] same_prefix_prefix, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   410
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   411
declare same_prefix_prefix_Nil [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   412
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   413
lemma prefix_appendI: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   414
"[| <xs,ys> \<in> prefix(A); zs \<in> list(A) |] ==> <xs,ys@zs> \<in> prefix(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   415
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   416
apply (erule gen_prefix.append, assumption)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   417
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   418
declare prefix_appendI [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   419
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   420
lemma prefix_Cons: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   421
"[| xs \<in> list(A); ys \<in> list(A); y \<in> A |] ==>  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   422
  <xs,Cons(y,ys)> \<in> prefix(A) <->  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   423
  (xs=[] | (\<exists>zs. xs=Cons(y,zs) & <zs,ys> \<in> prefix(A)))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   424
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   425
apply (auto simp add: gen_prefix_Cons)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   426
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   427
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   428
lemma append_one_prefix: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   429
  "[| <xs,ys> \<in> prefix(A); length(xs) < length(ys) |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   430
  ==> <xs @ [nth(length(xs),ys)], ys> \<in> prefix(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   431
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   432
apply (subgoal_tac "refl (A, id (A))")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   433
apply (simp (no_asm_simp) add: append_one_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   434
apply (auto simp add: refl_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   435
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   436
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   437
lemma prefix_length_le: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   438
"<xs,ys> \<in> prefix(A) ==> length(xs) \<le> length(ys)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   439
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   440
apply (blast dest: gen_prefix_length_le)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   441
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   442
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   443
lemma prefix_type: "prefix(A)<=list(A)*list(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   444
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   445
apply (blast intro!: gen_prefix.dom_subset)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   446
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   447
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   448
lemma strict_prefix_type: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   449
"strict_prefix(A) <= list(A)*list(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   450
apply (unfold strict_prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   451
apply (blast intro!: prefix_type [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   452
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   453
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   454
lemma strict_prefix_length_lt_aux: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   455
     "<xs,ys> \<in> prefix(A) ==> xs\<noteq>ys --> length(xs) < length(ys)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   456
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   457
apply (erule gen_prefix.induct, clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   458
apply (subgoal_tac [!] "ys \<in> list(A) & xs \<in> list(A)")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   459
apply (auto dest: gen_prefix.dom_subset [THEN subsetD]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   460
            simp add: length_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   461
apply (subgoal_tac "length (zs) =0")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   462
apply (drule_tac [2] not_lt_imp_le)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   463
apply (rule_tac [5] j = "length (ys) " in lt_trans2)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   464
apply auto
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   465
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   466
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   467
lemma strict_prefix_length_lt: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   468
     "<xs,ys>:strict_prefix(A) ==> length(xs) < length(ys)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   469
apply (unfold strict_prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   470
apply (rule strict_prefix_length_lt_aux [THEN mp])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   471
apply (auto dest: prefix_type [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   472
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   473
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   474
(*Equivalence to the definition used in Lex/Prefix.thy*)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   475
lemma prefix_iff: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   476
    "<xs,zs> \<in> prefix(A) <-> (\<exists>ys \<in> list(A). zs = xs@ys) & xs \<in> list(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   477
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   478
apply (auto simp add: gen_prefix_iff_nth lt_nat_in_nat nth_append nth_type app_type length_app)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   479
apply (subgoal_tac "drop (length (xs), zs) \<in> list (A) ")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   480
apply (rule_tac x = "drop (length (xs), zs) " in bexI)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   481
apply safe
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   482
 prefer 2 apply (simp add: length_type drop_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   483
apply (rule nth_equalityI)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   484
apply (simp_all (no_asm_simp) add: nth_append app_type drop_type length_app length_drop)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   485
apply (rule nat_diff_split [THEN iffD2], simp_all, clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   486
apply (drule_tac i = "length (zs) " in leI)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   487
apply (force simp add: le_subset_iff, safe)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   488
apply (subgoal_tac "length (xs) #+ (i #- length (xs)) = i")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   489
apply (subst nth_drop)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   490
apply (simp_all (no_asm_simp) add: leI split add: nat_diff_split)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   491
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   492
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   493
lemma prefix_snoc: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   494
"[|xs \<in> list(A); ys \<in> list(A); y \<in> A |] ==>  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   495
   <xs, ys@[y]> \<in> prefix(A) <-> (xs = ys@[y] | <xs,ys> \<in> prefix(A))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   496
apply (simp (no_asm) add: prefix_iff)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   497
apply (rule iffI, clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   498
apply (erule_tac xs = ysa in rev_list_elim, simp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   499
apply (simp add: app_type app_assoc [symmetric])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   500
apply (auto simp add: app_assoc app_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   501
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   502
declare prefix_snoc [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   503
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   504
lemma prefix_append_iff [rule_format]: "zs \<in> list(A) ==> \<forall>xs \<in> list(A). \<forall>ys \<in> list(A).  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   505
   (<xs, ys@zs> \<in> prefix(A)) <->  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   506
  (<xs,ys> \<in> prefix(A) | (\<exists>us. xs = ys@us & <us,zs> \<in> prefix(A)))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   507
apply (erule list_append_induct, force, clarify) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   508
apply (rule iffI) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   509
apply (simp add: add: app_assoc [symmetric])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   510
apply (erule disjE)  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   511
apply (rule disjI2) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   512
apply (rule_tac x = "y @ [x]" in exI) 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   513
apply (simp add: add: app_assoc [symmetric], force+)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   514
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   515
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   516
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   517
(*Although the prefix ordering is not linear, the prefixes of a list
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   518
  are linearly ordered.*)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   519
lemma common_prefix_linear_lemma [rule_format]: "[| zs \<in> list(A); xs \<in> list(A); ys \<in> list(A) |]  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   520
   ==> <xs, zs> \<in> prefix(A) --> <ys,zs> \<in> prefix(A)  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   521
  --><xs,ys> \<in> prefix(A) | <ys,xs> \<in> prefix(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   522
apply (erule list_append_induct, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   523
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   524
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   525
lemma common_prefix_linear: "[|<xs, zs> \<in> prefix(A); <ys,zs> \<in> prefix(A) |]    
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   526
      ==> <xs,ys> \<in> prefix(A) | <ys,xs> \<in> prefix(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   527
apply (cut_tac prefix_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   528
apply (blast del: disjCI intro: common_prefix_linear_lemma)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   529
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   530
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   531
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   532
(*** pfixLe, pfixGe \<in> properties inherited from the translations ***)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   533
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   534
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   535
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   536
(** pfixLe **)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   537
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   538
lemma refl_Le: "refl(nat,Le)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   539
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   540
apply (unfold refl_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   541
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   542
declare refl_Le [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   543
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   544
lemma antisym_Le: "antisym(Le)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   545
apply (unfold antisym_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   546
apply (auto intro: le_anti_sym)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   547
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   548
declare antisym_Le [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   549
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   550
lemma trans_on_Le: "trans[nat](Le)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   551
apply (unfold trans_on_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   552
apply (blast intro: le_trans)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   553
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   554
declare trans_on_Le [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   555
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   556
lemma trans_Le: "trans(Le)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   557
apply (unfold trans_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   558
apply (blast intro: le_trans)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   559
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   560
declare trans_Le [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   561
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   562
lemma part_order_Le: "part_order(nat,Le)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   563
by (unfold part_order_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   564
declare part_order_Le [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   565
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   566
lemma pfixLe_refl: "x \<in> list(nat) ==> x pfixLe x"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   567
by (blast intro: refl_gen_prefix [THEN reflD] refl_Le)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   568
declare pfixLe_refl [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   569
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   570
lemma pfixLe_trans: "[| x pfixLe y; y pfixLe z |] ==> x pfixLe z"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   571
by (blast intro: trans_gen_prefix [THEN transD] trans_Le)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   572
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   573
lemma pfixLe_antisym: "[| x pfixLe y; y pfixLe x |] ==> x = y"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   574
by (blast intro: antisym_gen_prefix [THEN antisymE] antisym_Le)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   575
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   576
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   577
lemma prefix_imp_pfixLe: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   578
"<xs,ys>:prefix(nat)==> xs pfixLe ys"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   579
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   580
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   581
apply (rule gen_prefix_mono [THEN subsetD], auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   582
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   583
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   584
lemma refl_Ge: "refl(nat, Ge)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   585
by (unfold refl_def Ge_def, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   586
declare refl_Ge [iff]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   587
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   588
lemma antisym_Ge: "antisym(Ge)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   589
apply (unfold antisym_def Ge_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   590
apply (auto intro: le_anti_sym)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   591
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   592
declare antisym_Ge [iff]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   593
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   594
lemma trans_Ge: "trans(Ge)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   595
apply (unfold trans_def Ge_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   596
apply (auto intro: le_trans)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   597
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   598
declare trans_Ge [iff]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   599
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   600
lemma pfixGe_refl: "x \<in> list(nat) ==> x pfixGe x"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   601
by (blast intro: refl_gen_prefix [THEN reflD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   602
declare pfixGe_refl [simp]
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   603
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   604
lemma pfixGe_trans: "[| x pfixGe y; y pfixGe z |] ==> x pfixGe z"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   605
by (blast intro: trans_gen_prefix [THEN transD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   606
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   607
lemma pfixGe_antisym: "[| x pfixGe y; y pfixGe x |] ==> x = y"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   608
by (blast intro: antisym_gen_prefix [THEN antisymE])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   609
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   610
lemma prefix_imp_pfixGe: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   611
  "<xs,ys>:prefix(nat) ==> xs pfixGe ys"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   612
apply (unfold prefix_def Ge_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   613
apply (rule gen_prefix_mono [THEN subsetD], auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   614
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   615
(* Added by Sidi \<in> prefix and take *)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   616
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   617
lemma prefix_imp_take: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   618
"<xs, ys> \<in> prefix(A) ==> xs = take(length(xs), ys)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   619
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   620
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   621
apply (erule gen_prefix.induct)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   622
apply (subgoal_tac [3] "length (xs) :nat")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   623
apply (auto dest: gen_prefix.dom_subset [THEN subsetD] simp add: length_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   624
apply (frule gen_prefix.dom_subset [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   625
apply (frule gen_prefix_length_le)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   626
apply (auto simp add: take_append)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   627
apply (subgoal_tac "length (xs) #- length (ys) =0")
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   628
apply (simp_all (no_asm_simp) add: diff_is_0_iff)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   629
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   630
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   631
lemma prefix_length_equal: "[|<xs,ys> \<in> prefix(A); length(xs)=length(ys)|] ==> xs = ys"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   632
apply (cut_tac A = A in prefix_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   633
apply (drule subsetD, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   634
apply (drule prefix_imp_take)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   635
apply (erule trans, simp)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   636
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   637
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   638
lemma prefix_length_le_equal: "[|<xs,ys> \<in> prefix(A); length(ys) \<le> length(xs)|] ==> xs = ys"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   639
by (blast intro: prefix_length_equal le_anti_sym prefix_length_le)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   640
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   641
lemma take_prefix [rule_format]: "xs \<in> list(A) ==> \<forall>n \<in> nat. <take(n, xs), xs> \<in> prefix(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   642
apply (unfold prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   643
apply (erule list.induct, simp, clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   644
apply (erule natE, auto)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   645
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   646
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   647
lemma prefix_take_iff: "<xs,ys> \<in> prefix(A) <-> (xs=take(length(xs), ys) & xs \<in> list(A) & ys \<in> list(A))"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   648
apply (rule iffI)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   649
apply (frule prefix_type [THEN subsetD])
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   650
apply (blast intro: prefix_imp_take, clarify)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   651
apply (erule ssubst)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   652
apply (blast intro: take_prefix length_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   653
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   654
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   655
lemma prefix_imp_nth: "[| <xs,ys> \<in> prefix(A); i < length(xs)|] ==> nth(i,xs) = nth(i,ys)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   656
by (auto dest!: gen_prefix_imp_nth simp add: prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   657
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   658
lemma nth_imp_prefix: 
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   659
     "[|xs \<in> list(A); ys \<in> list(A); length(xs) \<le> length(ys);   
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   660
        !!i. i < length(xs) ==> nth(i, xs) = nth(i,ys)|]   
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   661
      ==> <xs,ys> \<in> prefix(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   662
apply (auto simp add: prefix_def nth_imp_gen_prefix)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   663
apply (auto intro!: nth_imp_gen_prefix simp add: prefix_def)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   664
apply (blast intro: nth_type lt_trans2)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   665
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   666
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   667
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   668
lemma length_le_prefix_imp_prefix: "[|length(xs) \<le> length(ys);  
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   669
        <xs,zs> \<in> prefix(A); <ys,zs> \<in> prefix(A)|] ==> <xs,ys> \<in> prefix(A)"
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   670
apply (cut_tac A = A in prefix_type)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   671
apply (rule nth_imp_prefix, blast, blast)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   672
 apply assumption
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   673
apply (rule_tac b = "nth (i,zs)" in trans)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   674
 apply (blast intro: prefix_imp_nth)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   675
apply (blast intro: sym prefix_imp_nth prefix_length_le lt_trans2)
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   676
done
bca33c49b083 conversion of UNITY to Isar scripts
paulson
parents: 14055
diff changeset
   677
12197
d9320fb0a570 New files
ehmety
parents:
diff changeset
   678
end