src/HOL/Library/Diagonal_Subsequence.thy
author eberlm <eberlm@in.tum.de>
Thu Aug 17 14:52:56 2017 +0200 (2017-08-17)
changeset 66447 a1f5c5c26fa6
parent 60500 903bb1495239
child 67091 1393c2340eec
permissions -rw-r--r--
Replaced subseq with strict_mono
     1 (* Author: Fabian Immler, TUM *)
     2 
     3 section \<open>Sequence of Properties on Subsequences\<close>
     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. strict_mono (s::nat\<Rightarrow>nat) \<Longrightarrow> \<exists>r'. strict_mono r' \<and> P n (s o r')"
    12 begin
    13 
    14 definition reduce where "reduce s n = (SOME r'::nat\<Rightarrow>nat. strict_mono r' \<and> P n (s o r'))"
    15 
    16 lemma subseq_reduce[intro, simp]:
    17   "strict_mono s \<Longrightarrow> strict_mono (reduce s n)"
    18   unfolding reduce_def by (rule someI2_ex[OF ex_subseq]) auto
    19 
    20 lemma reduce_holds:
    21   "strict_mono 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 :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
    25   "seqseq 0 = id"
    26 | "seqseq (Suc n) = seqseq n o reduce (seqseq n) n"
    27 
    28 lemma subseq_seqseq[intro, simp]: "strict_mono (seqseq n)"
    29 proof (induct n)
    30   case 0 thus ?case by (simp add: strict_mono_def)
    31 next
    32   case (Suc n) thus ?case by (subst seqseq.simps) (auto intro!: strict_mono_o)
    33 qed
    34 
    35 lemma seqseq_holds:
    36   "P n (seqseq (Suc n))"
    37 proof -
    38   have "P n (seqseq n o reduce (seqseq n) n)"
    39     by (intro reduce_holds subseq_seqseq)
    40   thus ?thesis by simp
    41 qed
    42 
    43 definition diagseq :: "nat \<Rightarrow> nat" where "diagseq i = seqseq i i"
    44 
    45 lemma diagseq_mono: "diagseq n < diagseq (Suc n)"
    46 proof -
    47   have "diagseq n < seqseq n (Suc n)"
    48     using subseq_seqseq[of n] by (simp add: diagseq_def strict_mono_def)
    49   also have "\<dots> \<le> seqseq n (reduce (seqseq n) n (Suc n))"
    50     using strict_mono_less_eq seq_suble by blast
    51   also have "\<dots> = diagseq (Suc n)" by (simp add: diagseq_def)
    52   finally show ?thesis .
    53 qed
    54 
    55 lemma subseq_diagseq: "strict_mono diagseq"
    56   using diagseq_mono by (simp add: strict_mono_Suc_iff diagseq_def)
    57 
    58 primrec fold_reduce where
    59   "fold_reduce n 0 = id"
    60 | "fold_reduce n (Suc k) = fold_reduce n k o reduce (seqseq (n + k)) (n + k)"
    61 
    62 lemma subseq_fold_reduce[intro, simp]: "strict_mono (fold_reduce n k)"
    63 proof (induct k)
    64   case (Suc k) from strict_mono_o[OF this subseq_reduce] show ?case by (simp add: o_def)
    65 qed (simp add: strict_mono_def)
    66 
    67 lemma ex_subseq_reduce_index: "seqseq (n + k) = seqseq n o fold_reduce n k"
    68   by (induct k) simp_all
    69 
    70 lemma seqseq_fold_reduce: "seqseq n = fold_reduce 0 n"
    71   by (induct n) (simp_all)
    72 
    73 lemma diagseq_fold_reduce: "diagseq n = fold_reduce 0 n n"
    74   using seqseq_fold_reduce by (simp add: diagseq_def)
    75 
    76 lemma fold_reduce_add: "fold_reduce 0 (m + n) = fold_reduce 0 m o fold_reduce m n"
    77   by (induct n) simp_all
    78 
    79 lemma diagseq_add: "diagseq (k + n) = (seqseq k o (fold_reduce k n)) (k + n)"
    80 proof -
    81   have "diagseq (k + n) = fold_reduce 0 (k + n) (k + n)"
    82     by (simp add: diagseq_fold_reduce)
    83   also have "\<dots> = (seqseq k o fold_reduce k n) (k + n)"
    84     unfolding fold_reduce_add seqseq_fold_reduce ..
    85   finally show ?thesis .
    86 qed
    87 
    88 lemma diagseq_sub:
    89   assumes "m \<le> n" shows "diagseq n = (seqseq m o (fold_reduce m (n - m))) n"
    90   using diagseq_add[of m "n - m"] assms by simp
    91 
    92 lemma subseq_diagonal_rest: "strict_mono (\<lambda>x. fold_reduce k x (k + x))"
    93   unfolding strict_mono_Suc_iff fold_reduce.simps o_def
    94 proof
    95   fix n
    96   have "fold_reduce k n (k + n) < fold_reduce k n (k + Suc n)" (is "?lhs < _")
    97     by (auto intro: strict_monoD)
    98   also have "\<dots> \<le> fold_reduce k n (reduce (seqseq (k + n)) (k + n) (k + Suc n))"
    99     by (auto intro: less_mono_imp_le_mono seq_suble strict_monoD)
   100   finally show "?lhs < \<dots>" .
   101 qed
   102 
   103 lemma diagseq_seqseq: "diagseq o (op + k) = (seqseq k o (\<lambda>x. fold_reduce k x (k + x)))"
   104   by (auto simp: o_def diagseq_add)
   105 
   106 lemma diagseq_holds:
   107   assumes subseq_stable: "\<And>r s n. strict_mono r \<Longrightarrow> P n s \<Longrightarrow> P n (s o r)"
   108   shows "P k (diagseq o (op + (Suc k)))"
   109   unfolding diagseq_seqseq by (intro subseq_stable subseq_diagonal_rest seqseq_holds)
   110 
   111 end
   112 
   113 end