src/HOL/Library/Diagonal_Subsequence.thy
author Andreas Lochbihler
Fri Sep 20 10:09:16 2013 +0200 (2013-09-20)
changeset 53745 788730ab7da4
parent 52681 8cc7f76b827a
child 57862 8f074e6e22fc
permissions -rw-r--r--
prefer Code.abort over code_abort
     1 (* Author: Fabian Immler, TUM *)
     2 
     3 header {* Sequence of Properties on Subsequences *}
     4 
     5 theory Diagonal_Subsequence
     6 imports Complex_Main
     7 begin
     8 
     9 locale subseqs =
    10   fixes P::"nat\<Rightarrow>(nat\<Rightarrow>nat)\<Rightarrow>bool"
    11   assumes ex_subseq: "\<And>n s. subseq s \<Longrightarrow> \<exists>r'. subseq r' \<and> P n (s o r')"
    12 begin
    13 
    14 definition reduce where "reduce s n = (SOME r'. subseq r' \<and> P n (s o r'))"
    15 
    16 lemma subseq_reduce[intro, simp]:
    17   "subseq s \<Longrightarrow> subseq (reduce s n)"
    18   unfolding reduce_def by (rule someI2_ex[OF ex_subseq]) auto
    19 
    20 lemma reduce_holds:
    21   "subseq s \<Longrightarrow> P n (s o reduce s n)"
    22   unfolding reduce_def by (rule someI2_ex[OF ex_subseq]) (auto simp: o_def)
    23 
    24 primrec seqseq where
    25   "seqseq 0 = id"
    26 | "seqseq (Suc n) = seqseq n o reduce (seqseq n) n"
    27 
    28 lemma subseq_seqseq[intro, simp]: "subseq (seqseq n)"
    29 proof (induct n)
    30   case (Suc n) thus ?case by (subst seqseq.simps) (auto simp: subseq_reduce intro!: subseq_o)
    31 qed (simp add: subseq_def)
    32 
    33 lemma seqseq_holds:
    34   "P n (seqseq (Suc n))"
    35 proof -
    36   have "P n (seqseq n o reduce (seqseq n) n)"
    37     by (intro reduce_holds subseq_seqseq)
    38   thus ?thesis by simp
    39 qed
    40 
    41 definition diagseq where "diagseq i = seqseq i i"
    42 
    43 lemma subseq_mono: "subseq f \<Longrightarrow> a \<le> b \<Longrightarrow> f a \<le> f b"
    44   by (metis le_eq_less_or_eq subseq_mono)
    45 
    46 lemma subseq_strict_mono: "subseq f \<Longrightarrow> a < b \<Longrightarrow> f a < f b"
    47   by (simp add: subseq_def)
    48 
    49 lemma diagseq_mono: "diagseq n < diagseq (Suc n)"
    50 proof -
    51   have "diagseq n < seqseq n (Suc n)"
    52     using subseq_seqseq[of n] by (simp add: diagseq_def subseq_def)
    53   also have "\<dots> \<le> seqseq n (reduce (seqseq n) n (Suc n))"
    54     by (auto intro: subseq_mono seq_suble)
    55   also have "\<dots> = diagseq (Suc n)" by (simp add: diagseq_def)
    56   finally show ?thesis .
    57 qed
    58 
    59 lemma subseq_diagseq: "subseq diagseq"
    60   using diagseq_mono by (simp add: subseq_Suc_iff diagseq_def)
    61 
    62 primrec fold_reduce where
    63   "fold_reduce n 0 = id"
    64 | "fold_reduce n (Suc k) = fold_reduce n k o reduce (seqseq (n + k)) (n + k)"
    65 
    66 lemma subseq_fold_reduce[intro, simp]: "subseq (fold_reduce n k)"
    67 proof (induct k)
    68   case (Suc k) from subseq_o[OF this subseq_reduce] show ?case by (simp add: o_def)
    69 qed (simp add: subseq_def)
    70 
    71 lemma ex_subseq_reduce_index: "seqseq (n + k) = seqseq n o fold_reduce n k"
    72   by (induct k) simp_all
    73 
    74 lemma seqseq_fold_reduce: "seqseq n = fold_reduce 0 n"
    75   by (induct n) (simp_all)
    76 
    77 lemma diagseq_fold_reduce: "diagseq n = fold_reduce 0 n n"
    78   using seqseq_fold_reduce by (simp add: diagseq_def)
    79 
    80 lemma fold_reduce_add: "fold_reduce 0 (m + n) = fold_reduce 0 m o fold_reduce m n"
    81   by (induct n) simp_all
    82 
    83 lemma diagseq_add: "diagseq (k + n) = (seqseq k o (fold_reduce k n)) (k + n)"
    84 proof -
    85   have "diagseq (k + n) = fold_reduce 0 (k + n) (k + n)"
    86     by (simp add: diagseq_fold_reduce)
    87   also have "\<dots> = (seqseq k o fold_reduce k n) (k + n)"
    88     unfolding fold_reduce_add seqseq_fold_reduce ..
    89   finally show ?thesis .
    90 qed
    91 
    92 lemma diagseq_sub:
    93   assumes "m \<le> n" shows "diagseq n = (seqseq m o (fold_reduce m (n - m))) n"
    94   using diagseq_add[of m "n - m"] assms by simp
    95 
    96 lemma subseq_diagonal_rest: "subseq (\<lambda>x. fold_reduce k x (k + x))"
    97   unfolding subseq_Suc_iff fold_reduce.simps o_def
    98 proof
    99   fix n
   100   have "fold_reduce k n (k + n) < fold_reduce k n (k + Suc n)" (is "?lhs < _")
   101     by (auto intro: subseq_strict_mono)
   102   also have "\<dots> \<le> fold_reduce k n (reduce (seqseq (k + n)) (k + n) (k + Suc n))"
   103     by (rule subseq_mono) (auto intro!: seq_suble subseq_mono)
   104   finally show "?lhs < \<dots>" .
   105 qed
   106 
   107 lemma diagseq_seqseq: "diagseq o (op + k) = (seqseq k o (\<lambda>x. fold_reduce k x (k + x)))"
   108   by (auto simp: o_def diagseq_add)
   109 
   110 lemma diagseq_holds:
   111   assumes subseq_stable: "\<And>r s n. subseq r \<Longrightarrow> P n s \<Longrightarrow> P n (s o r)"
   112   shows "P k (diagseq o (op + (Suc k)))"
   113   unfolding diagseq_seqseq by (intro subseq_stable subseq_diagonal_rest seqseq_holds)
   114 
   115 end
   116 
   117 end