src/HOL/List.thy
changeset 71935 82b00b8f1871
parent 71860 86cfb9fa3da8
child 71991 8bff286878bf
equal deleted inserted replaced
71934:914baafb3da4 71935:82b00b8f1871
  6324     by (simp add: assms wf_lexn)
  6324     by (simp add: assms wf_lexn)
  6325   show "\<And>i j. lexn r i \<noteq> lexn r j \<Longrightarrow> Domain (lexn r i) \<inter> Range (lexn r j) = {}"
  6325   show "\<And>i j. lexn r i \<noteq> lexn r j \<Longrightarrow> Domain (lexn r i) \<inter> Range (lexn r j) = {}"
  6326     by (metis DomainE Int_emptyI RangeE lexn_length)
  6326     by (metis DomainE Int_emptyI RangeE lexn_length)
  6327 qed
  6327 qed
  6328 
  6328 
  6329 
       
  6330 lemma lexn_conv:
  6329 lemma lexn_conv:
  6331   "lexn r n =
  6330   "lexn r n =
  6332     {(xs,ys). length xs = n \<and> length ys = n \<and>
  6331     {(xs,ys). length xs = n \<and> length ys = n \<and>
  6333     (\<exists>xys x y xs' ys'. xs= xys @ x#xs' \<and> ys= xys @ y # ys' \<and> (x, y) \<in> r)}"
  6332     (\<exists>xys x y xs' ys'. xs= xys @ x#xs' \<and> ys= xys @ y # ys' \<and> (x, y) \<in> r)}"
  6334 proof (induction n)
  6333 proof (induction n)
  6514 
  6513 
  6515 lemma irrefl_lex: "irrefl r \<Longrightarrow> irrefl (lex r)"
  6514 lemma irrefl_lex: "irrefl r \<Longrightarrow> irrefl (lex r)"
  6516   by (meson irrefl_def lex_take_index)
  6515   by (meson irrefl_def lex_take_index)
  6517 
  6516 
  6518 
  6517 
  6519 
       
  6520 subsubsection \<open>Lexicographic Ordering\<close>
  6518 subsubsection \<open>Lexicographic Ordering\<close>
  6521 
  6519 
  6522 text \<open>Classical lexicographic ordering on lists, ie. "a" < "ab" < "b".
  6520 text \<open>Classical lexicographic ordering on lists, ie. "a" < "ab" < "b".
  6523     This ordering does \emph{not} preserve well-foundedness.
  6521     This ordering does \emph{not} preserve well-foundedness.
  6524      Author: N. Voelker, March 2005.\<close>
  6522      Author: N. Voelker, March 2005.\<close>
  6616   have "(x,z) \<in> r \<or> x = z \<and> (xs,zs) \<in> lexord r" by blast
  6614   have "(x,z) \<in> r \<or> x = z \<and> (xs,zs) \<in> lexord r" by blast
  6617   thus ?case unfolding zzs by auto
  6615   thus ?case unfolding zzs by auto
  6618 qed
  6616 qed
  6619 
  6617 
  6620 lemma lexord_trans:
  6618 lemma lexord_trans:
  6621     "\<lbrakk> (x, y) \<in> lexord r; (y, z) \<in> lexord r; trans r \<rbrakk> \<Longrightarrow> (x, z) \<in> lexord r"
  6619   "\<lbrakk> (x, y) \<in> lexord r; (y, z) \<in> lexord r; trans r \<rbrakk> \<Longrightarrow> (x, z) \<in> lexord r"
  6622 by(auto simp: trans_def intro:lexord_partial_trans)
  6620   by(auto simp: trans_def intro:lexord_partial_trans)
  6623 
  6621 
  6624 lemma lexord_transI:  "trans r \<Longrightarrow> trans (lexord r)"
  6622 lemma lexord_transI:  "trans r \<Longrightarrow> trans (lexord r)"
  6625 by (rule transI, drule lexord_trans, blast)
  6623   by (meson lexord_trans transI)
  6626 
  6624 
  6627 lemma total_lexord: "total r \<Longrightarrow> total (lexord r)"
  6625 lemma total_lexord: "total r \<Longrightarrow> total (lexord r)"
  6628   unfolding total_on_def
  6626   unfolding total_on_def
  6629 proof clarsimp
  6627 proof clarsimp
  6630   fix x y
  6628   fix x y
  6651 by (simp add: irrefl_def lexord_irreflexive)
  6649 by (simp add: irrefl_def lexord_irreflexive)
  6652 
  6650 
  6653 lemma lexord_asym:
  6651 lemma lexord_asym:
  6654   assumes "asym R"
  6652   assumes "asym R"
  6655   shows "asym (lexord R)"
  6653   shows "asym (lexord R)"
  6656 proof
  6654 proof 
  6657   from assms obtain "irrefl R" by (blast elim: asym.cases)
       
  6658   then show "irrefl (lexord R)" by (rule lexord_irrefl)
       
  6659 next
       
  6660   fix xs ys
  6655   fix xs ys
  6661   assume "(xs, ys) \<in> lexord R"
  6656   assume "(xs, ys) \<in> lexord R"
  6662   then show "(ys, xs) \<notin> lexord R"
  6657   then show "(ys, xs) \<notin> lexord R"
  6663   proof (induct xs arbitrary: ys)
  6658   proof (induct xs arbitrary: ys)
  6664     case Nil
  6659     case Nil
  6677 proof -
  6672 proof -
  6678   from \<open>asym R\<close> have "asym (lexord R)" by (rule lexord_asym)
  6673   from \<open>asym R\<close> have "asym (lexord R)" by (rule lexord_asym)
  6679   then show ?thesis by (rule asym.cases) (auto simp add: hyp)
  6674   then show ?thesis by (rule asym.cases) (auto simp add: hyp)
  6680 qed
  6675 qed
  6681 
  6676 
       
  6677 lemma asym_lex: "asym R \<Longrightarrow> asym (lex R)"
       
  6678   by (meson asym.simps irrefl_lex lexord_asym lexord_lex)
       
  6679 
       
  6680 lemma asym_lenlex: "asym R \<Longrightarrow> asym (lenlex R)"
       
  6681   by (simp add: lenlex_def asym_inv_image asym_less_than asym_lex asym_lex_prod)
       
  6682 
       
  6683 lemma lenlex_append1:
       
  6684   assumes len: "(us,xs) \<in> lenlex R" and eq: "length vs = length ys" 
       
  6685   shows "(us @ vs, xs @ ys) \<in> lenlex R"
       
  6686   using len
       
  6687 proof (induction us)
       
  6688   case Nil
       
  6689   then show ?case 
       
  6690     by (simp add: lenlex_def eq)
       
  6691 next
       
  6692   case (Cons u us)
       
  6693   with lex_append_rightI show ?case
       
  6694     by (fastforce simp add: lenlex_def eq)
       
  6695 qed
       
  6696 
       
  6697 lemma lenlex_append2 [simp]:
       
  6698   assumes "irrefl R"
       
  6699   shows "(us @ xs, us @ ys) \<in> lenlex R \<longleftrightarrow> (xs, ys) \<in> lenlex R"
       
  6700 proof (induction us)
       
  6701   case Nil
       
  6702   then show ?case 
       
  6703     by (simp add: lenlex_def)
       
  6704 next
       
  6705   case (Cons u us)
       
  6706   with assms show ?case
       
  6707     by (auto simp: lenlex_def irrefl_def)
       
  6708 qed
  6682 
  6709 
  6683 text \<open>
  6710 text \<open>
  6684   Predicate version of lexicographic order integrated with Isabelle's order type classes.
  6711   Predicate version of lexicographic order integrated with Isabelle's order type classes.
  6685   Author: Andreas Lochbihler
  6712   Author: Andreas Lochbihler
  6686 \<close>
  6713 \<close>