src/HOL/Lambda/ListOrder.thy
changeset 22270 4ccb7e6be929
parent 21404 eb85850d3eb7
child 23464 bc2563c37b1a
equal deleted inserted replaced
22269:7c1e65897693 22270:4ccb7e6be929
    12   Lifting an order to lists of elements, relating exactly one
    12   Lifting an order to lists of elements, relating exactly one
    13   element.
    13   element.
    14 *}
    14 *}
    15 
    15 
    16 definition
    16 definition
    17   step1 :: "('a \<times> 'a) set => ('a list \<times> 'a list) set" where
    17   step1 :: "('a => 'a => bool) => 'a list => 'a list => bool" where
    18   "step1 r =
    18   "step1 r =
    19     {(ys, xs). \<exists>us z z' vs. xs = us @ z # vs \<and> (z', z) \<in> r \<and> ys =
    19     (\<lambda>ys xs. \<exists>us z z' vs. xs = us @ z # vs \<and> r z' z \<and> ys =
    20       us @ z' # vs}"
    20       us @ z' # vs)"
    21 
    21 
    22 
    22 
    23 lemma step1_converse [simp]: "step1 (r^-1) = (step1 r)^-1"
    23 lemma step1_converse [simp]: "step1 (r^--1) = (step1 r)^--1"
       
    24   apply (unfold step1_def)
       
    25   apply (blast intro!: order_antisym)
       
    26   done
       
    27 
       
    28 lemma in_step1_converse [iff]: "(step1 (r^--1) x y) = ((step1 r)^--1 x y)"
       
    29   apply auto
       
    30   done
       
    31 
       
    32 lemma not_Nil_step1 [iff]: "\<not> step1 r [] xs"
    24   apply (unfold step1_def)
    33   apply (unfold step1_def)
    25   apply blast
    34   apply blast
    26   done
    35   done
    27 
    36 
    28 lemma in_step1_converse [iff]: "(p \<in> step1 (r^-1)) = (p \<in> (step1 r)^-1)"
    37 lemma not_step1_Nil [iff]: "\<not> step1 r xs []"
    29   apply auto
       
    30   done
       
    31 
       
    32 lemma not_Nil_step1 [iff]: "([], xs) \<notin> step1 r"
       
    33   apply (unfold step1_def)
       
    34   apply blast
       
    35   done
       
    36 
       
    37 lemma not_step1_Nil [iff]: "(xs, []) \<notin> step1 r"
       
    38   apply (unfold step1_def)
    38   apply (unfold step1_def)
    39   apply blast
    39   apply blast
    40   done
    40   done
    41 
    41 
    42 lemma Cons_step1_Cons [iff]:
    42 lemma Cons_step1_Cons [iff]:
    43     "((y # ys, x # xs) \<in> step1 r) =
    43     "(step1 r (y # ys) (x # xs)) =
    44       ((y, x) \<in> r \<and> xs = ys \<or> x = y \<and> (ys, xs) \<in> step1 r)"
    44       (r y x \<and> xs = ys \<or> x = y \<and> step1 r ys xs)"
    45   apply (unfold step1_def)
    45   apply (unfold step1_def)
    46   apply simp
       
    47   apply (rule iffI)
    46   apply (rule iffI)
    48    apply (erule exE)
    47    apply (erule exE)
    49    apply (rename_tac ts)
    48    apply (rename_tac ts)
    50    apply (case_tac ts)
    49    apply (case_tac ts)
    51     apply fastsimp
    50     apply fastsimp
    54    apply blast
    53    apply blast
    55   apply (blast intro: Cons_eq_appendI)
    54   apply (blast intro: Cons_eq_appendI)
    56   done
    55   done
    57 
    56 
    58 lemma append_step1I:
    57 lemma append_step1I:
    59   "(ys, xs) \<in> step1 r \<and> vs = us \<or> ys = xs \<and> (vs, us) \<in> step1 r
    58   "step1 r ys xs \<and> vs = us \<or> ys = xs \<and> step1 r vs us
    60     ==> (ys @ vs, xs @ us) : step1 r"
    59     ==> step1 r (ys @ vs) (xs @ us)"
    61   apply (unfold step1_def)
    60   apply (unfold step1_def)
    62   apply auto
    61   apply auto
    63    apply blast
    62    apply blast
    64   apply (blast intro: append_eq_appendI)
    63   apply (blast intro: append_eq_appendI)
    65   done
    64   done
    66 
    65 
    67 lemma Cons_step1E [elim!]:
    66 lemma Cons_step1E [elim!]:
    68   assumes "(ys, x # xs) \<in> step1 r"
    67   assumes "step1 r ys (x # xs)"
    69     and "!!y. ys = y # xs \<Longrightarrow> (y, x) \<in> r \<Longrightarrow> R"
    68     and "!!y. ys = y # xs \<Longrightarrow> r y x \<Longrightarrow> R"
    70     and "!!zs. ys = x # zs \<Longrightarrow> (zs, xs) \<in> step1 r \<Longrightarrow> R"
    69     and "!!zs. ys = x # zs \<Longrightarrow> step1 r zs xs \<Longrightarrow> R"
    71   shows R
    70   shows R
    72   using prems
    71   using prems
    73   apply (cases ys)
    72   apply (cases ys)
    74    apply (simp add: step1_def)
    73    apply (simp add: step1_def)
    75   apply blast
    74   apply blast
    76   done
    75   done
    77 
    76 
    78 lemma Snoc_step1_SnocD:
    77 lemma Snoc_step1_SnocD:
    79   "(ys @ [y], xs @ [x]) \<in> step1 r
    78   "step1 r (ys @ [y]) (xs @ [x])
    80     ==> ((ys, xs) \<in> step1 r \<and> y = x \<or> ys = xs \<and> (y, x) \<in> r)"
    79     ==> (step1 r ys xs \<and> y = x \<or> ys = xs \<and> r y x)"
    81   apply (unfold step1_def)
    80   apply (unfold step1_def)
    82   apply simp
       
    83   apply (clarify del: disjCI)
    81   apply (clarify del: disjCI)
    84   apply (rename_tac vs)
    82   apply (rename_tac vs)
    85   apply (rule_tac xs = vs in rev_exhaust)
    83   apply (rule_tac xs = vs in rev_exhaust)
    86    apply force
    84    apply force
    87   apply simp
    85   apply simp
    88   apply blast
    86   apply blast
    89   done
    87   done
    90 
    88 
    91 lemma Cons_acc_step1I [intro!]:
    89 lemma Cons_acc_step1I [intro!]:
    92     "x \<in> acc r ==> xs \<in> acc (step1 r) \<Longrightarrow> x # xs \<in> acc (step1 r)"
    90     "acc r x ==> acc (step1 r) xs \<Longrightarrow> acc (step1 r) (x # xs)"
    93   apply (induct arbitrary: xs set: acc)
    91   apply (induct arbitrary: xs set: acc)
    94   apply (erule thin_rl)
    92   apply (erule thin_rl)
    95   apply (erule acc_induct)
    93   apply (erule acc_induct)
    96   apply (rule accI)
    94   apply (rule accI)
    97   apply blast
    95   apply blast
    98   done
    96   done
    99 
    97 
   100 lemma lists_accD: "xs \<in> lists (acc r) ==> xs \<in> acc (step1 r)"
    98 lemma lists_accD: "listsp (acc r) xs ==> acc (step1 r) xs"
   101   apply (induct set: lists)
    99   apply (induct set: listsp)
   102    apply (rule accI)
   100    apply (rule accI)
   103    apply simp
   101    apply simp
   104   apply (rule accI)
   102   apply (rule accI)
   105   apply (fast dest: acc_downward)
   103   apply (fast dest: acc_downward)
   106   done
   104   done
   107 
   105 
   108 lemma ex_step1I:
   106 lemma ex_step1I:
   109   "[| x \<in> set xs; (y, x) \<in> r |]
   107   "[| x \<in> set xs; r y x |]
   110     ==> \<exists>ys. (ys, xs) \<in> step1 r \<and> y \<in> set ys"
   108     ==> \<exists>ys. step1 r ys xs \<and> y \<in> set ys"
   111   apply (unfold step1_def)
   109   apply (unfold step1_def)
   112   apply (drule in_set_conv_decomp [THEN iffD1])
   110   apply (drule in_set_conv_decomp [THEN iffD1])
   113   apply force
   111   apply force
   114   done
   112   done
   115 
   113 
   116 lemma lists_accI: "xs \<in> acc (step1 r) ==> xs \<in> lists (acc r)"
   114 lemma lists_accI: "acc (step1 r) xs ==> listsp (acc r) xs"
   117   apply (induct set: acc)
   115   apply (induct set: acc)
   118   apply clarify
   116   apply clarify
   119   apply (rule accI)
   117   apply (rule accI)
   120   apply (drule ex_step1I, assumption)
   118   apply (drule_tac r=r in ex_step1I, assumption)
   121   apply blast
   119   apply blast
   122   done
   120   done
   123 
   121 
   124 end
   122 end