src/HOL/Library/Formal_Power_Series.thy
author huffman
Sat, 14 Feb 2009 11:11:30 -0800
changeset 29911 c790a70a3d19
parent 29906 80369da39838
child 29912 f4ac160d2e77
permissions -rw-r--r--
declare fps_nth as a typedef morphism; clean up instance proofs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     1
(*  Title:      Formal_Power_Series.thy
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     2
    ID:         
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     3
    Author:     Amine Chaieb, University of Cambridge
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     4
*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     5
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     6
header{* A formalization of formal power series *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     7
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     8
theory Formal_Power_Series
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     9
  imports Main Fact Parity
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    10
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    11
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
    12
subsection {* The type of formal power series*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    13
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    14
typedef (open) 'a fps = "{f :: nat \<Rightarrow> 'a. True}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    15
  morphisms fps_nth Abs_fps
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    16
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    17
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    18
notation fps_nth (infixl "$" 75)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    19
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    20
lemma expand_fps_eq: "p = q \<longleftrightarrow> (\<forall>n. p $ n = q $ n)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    21
  by (simp add: fps_nth_inject [symmetric] expand_fun_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    22
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    23
lemma fps_ext: "(\<And>n. p $ n = q $ n) \<Longrightarrow> p = q"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    24
  by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    25
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    26
lemma fps_nth_Abs_fps [simp]: "Abs_fps f $ n = f n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    27
  by (simp add: Abs_fps_inverse)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    28
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    29
text{* Definition of the basic elements 0 and 1 and the basic operations of addition, negation and multiplication *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    30
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    31
instantiation fps :: (zero)  zero
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    32
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    33
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    34
definition fps_zero_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    35
  "0 = Abs_fps (\<lambda>n. 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    36
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    37
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    38
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    39
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    40
lemma fps_zero_nth [simp]: "0 $ n = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    41
  unfolding fps_zero_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    42
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    43
instantiation fps :: ("{one,zero}")  one
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    44
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    45
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    46
definition fps_one_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    47
  "1 = Abs_fps (\<lambda>n. if n = 0 then 1 else 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    48
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    49
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    50
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    51
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    52
lemma fps_one_nth [simp]: "1 $ n = (if n = 0 then 1 else 0)" 
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    53
  unfolding fps_one_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    54
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    55
instantiation fps :: (plus)  plus
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    56
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    57
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    58
definition fps_plus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    59
  "op + = (\<lambda>f g. Abs_fps (\<lambda>n. f $ n + g $ n))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    60
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    61
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    62
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    63
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    64
lemma fps_add_nth [simp]: "(f + g) $ n = f $ n + g $ n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    65
  unfolding fps_plus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    66
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    67
instantiation fps :: (minus) minus
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    68
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    69
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    70
definition fps_minus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    71
  "op - = (\<lambda>f g. Abs_fps (\<lambda>n. f $ n - g $ n))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    72
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    73
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    74
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    75
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    76
lemma fps_sub_nth [simp]: "(f - g) $ n = f $ n - g $ n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    77
  unfolding fps_minus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    78
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    79
instantiation fps :: (uminus) uminus
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    80
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    81
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    82
definition fps_uminus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    83
  "uminus = (\<lambda>f. Abs_fps (\<lambda>n. - (f $ n)))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    84
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    85
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    86
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    87
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    88
lemma fps_neg_nth [simp]: "(- f) $ n = - (f $ n)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    89
  unfolding fps_uminus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    90
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    91
instantiation fps :: ("{comm_monoid_add, times}")  times
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    92
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    93
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    94
definition fps_times_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    95
  "op * = (\<lambda>f g. Abs_fps (\<lambda>n. \<Sum>i=0..n. f $ i * g $ (n - i)))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    96
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    97
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    98
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    99
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   100
lemma fps_mult_nth: "(f * g) $ n = (\<Sum>i=0..n. f$i * g$(n - i))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   101
  unfolding fps_times_def by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   102
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   103
declare atLeastAtMost_iff[presburger]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   104
declare Bex_def[presburger]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   105
declare Ball_def[presburger]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   106
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   107
lemma cond_value_iff: "f (if b then x else y) = (if b then f x else f y)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   108
  by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   109
lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   110
  by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   111
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   112
subsection{* Formal power series form a commutative ring with unity, if the range of sequences 
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   113
  they represent is a commutative ring with unity*}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   114
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   115
instance fps :: (semigroup_add) semigroup_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   116
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   117
  fix a b c :: "'a fps" show "a + b + c = a + (b + c)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   118
    by (simp add: fps_ext add_assoc)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   119
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   120
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   121
instance fps :: (ab_semigroup_add) ab_semigroup_add
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   122
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   123
  fix a b :: "'a fps" show "a + b = b + a"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   124
    by (simp add: fps_ext add_commute)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   125
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   126
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   127
lemma fps_mult_assoc_lemma:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   128
  fixes k :: nat and f :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a::comm_monoid_add"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   129
  shows "(\<Sum>j=0..k. \<Sum>i=0..j. f i (j - i) (n - j)) =
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   130
         (\<Sum>j=0..k. \<Sum>i=0..k - j. f j i (n - j - i))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   131
proof (induct k)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   132
  case 0 show ?case by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   133
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   134
  case (Suc k) thus ?case
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   135
    by (simp add: Suc_diff_le setsum_addf add_assoc
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   136
             cong: strong_setsum_cong)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   137
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   138
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   139
instance fps :: (semiring_0) semigroup_mult
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   140
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   141
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   142
  show "(a * b) * c = a * (b * c)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   143
  proof (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   144
    fix n :: nat
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   145
    have "(\<Sum>j=0..n. \<Sum>i=0..j. a$i * b$(j - i) * c$(n - j)) =
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   146
          (\<Sum>j=0..n. \<Sum>i=0..n - j. a$j * b$i * c$(n - j - i))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   147
      by (rule fps_mult_assoc_lemma)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   148
    thus "((a * b) * c) $ n = (a * (b * c)) $ n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   149
      by (simp add: fps_mult_nth setsum_right_distrib
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   150
                    setsum_left_distrib mult_assoc)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   151
  qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   152
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   153
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   154
lemma fps_mult_commute_lemma:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   155
  fixes n :: nat and f :: "nat \<Rightarrow> nat \<Rightarrow> 'a::comm_monoid_add"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   156
  shows "(\<Sum>i=0..n. f i (n - i)) = (\<Sum>i=0..n. f (n - i) i)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   157
proof (rule setsum_reindex_cong)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   158
  show "inj_on (\<lambda>i. n - i) {0..n}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   159
    by (rule inj_onI) simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   160
  show "{0..n} = (\<lambda>i. n - i) ` {0..n}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   161
    by (auto, rule_tac x="n - x" in image_eqI, simp_all)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   162
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   163
  fix i assume "i \<in> {0..n}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   164
  hence "n - (n - i) = i" by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   165
  thus "f (n - i) i = f (n - i) (n - (n - i))" by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   166
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   167
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   168
instance fps :: (comm_semiring_0) ab_semigroup_mult
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   169
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   170
  fix a b :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   171
  show "a * b = b * a"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   172
  proof (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   173
    fix n :: nat
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   174
    have "(\<Sum>i=0..n. a$i * b$(n - i)) = (\<Sum>i=0..n. a$(n - i) * b$i)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   175
      by (rule fps_mult_commute_lemma)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   176
    thus "(a * b) $ n = (b * a) $ n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   177
      by (simp add: fps_mult_nth mult_commute)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   178
  qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   179
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   180
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   181
instance fps :: (monoid_add) monoid_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   182
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   183
  fix a :: "'a fps" show "0 + a = a "
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   184
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   185
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   186
  fix a :: "'a fps" show "a + 0 = a "
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   187
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   188
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   189
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   190
instance fps :: (comm_monoid_add) comm_monoid_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   191
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   192
  fix a :: "'a fps" show "0 + a = a "
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   193
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   194
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   195
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   196
instance fps :: (semiring_1) monoid_mult
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   197
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   198
  fix a :: "'a fps" show "1 * a = a"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   199
    apply (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   200
    apply (simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   201
    by (simp add: cond_value_iff cond_application_beta setsum_delta cong del: if_weak_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   202
next
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   203
  fix a :: "'a fps" show "a * 1 = a"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   204
    apply (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   205
    apply (simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   206
    by (simp add: cond_value_iff cond_application_beta setsum_delta' cong del: if_weak_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   207
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   208
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   209
instance fps :: (cancel_semigroup_add) cancel_semigroup_add
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   210
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   211
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   212
  assume "a + b = a + c" then show "b = c"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   213
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   214
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   215
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   216
  assume "b + a = c + a" then show "b = c"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   217
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   218
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   219
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   220
instance fps :: (cancel_ab_semigroup_add) cancel_ab_semigroup_add
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   221
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   222
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   223
  assume "a + b = a + c" then show "b = c"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   224
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   225
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   226
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   227
instance fps :: (cancel_comm_monoid_add) cancel_comm_monoid_add ..
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   228
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   229
instance fps :: (group_add) group_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   230
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   231
  fix a :: "'a fps" show "- a + a = 0"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   232
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   233
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   234
  fix a b :: "'a fps" show "a - b = a + - b"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   235
    by (simp add: fps_ext diff_minus)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   236
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   237
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   238
instance fps :: (ab_group_add) ab_group_add
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   239
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   240
  fix a :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   241
  show "- a + a = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   242
    by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   243
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   244
  fix a b :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   245
  show "a - b = a + - b"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   246
    by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   247
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   248
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   249
instance fps :: (zero_neq_one) zero_neq_one
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   250
  by default (simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   251
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   252
instance fps :: (semiring_0) semiring
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   253
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   254
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   255
  show "(a + b) * c = a * c + b * c"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   256
    by (simp add: expand_fps_eq fps_mult_nth left_distrib setsum_addf)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   257
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   258
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   259
  show "a * (b + c) = a * b + a * c"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   260
    by (simp add: expand_fps_eq fps_mult_nth right_distrib setsum_addf)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   261
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   262
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   263
instance fps :: (semiring_0) semiring_0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   264
proof
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   265
  fix a:: "'a fps" show "0 * a = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   266
    by (simp add: fps_ext fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   267
next
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   268
  fix a:: "'a fps" show "a * 0 = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   269
    by (simp add: fps_ext fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   270
qed
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   271
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   272
instance fps :: (semiring_0_cancel) semiring_0_cancel ..
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   273
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   274
subsection {* Selection of the nth power of the implicit variable in the infinite sum*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   275
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   276
lemma fps_nonzero_nth: "f \<noteq> 0 \<longleftrightarrow> (\<exists> n. f $n \<noteq> 0)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   277
  by (simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   278
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   279
lemma fps_nonzero_nth_minimal:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   280
  "f \<noteq> 0 \<longleftrightarrow> (\<exists>n. f $ n \<noteq> 0 \<and> (\<forall>m<n. f $ m = 0))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   281
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   282
  let ?n = "LEAST n. f $ n \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   283
  assume "f \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   284
  then have "\<exists>n. f $ n \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   285
    by (simp add: fps_nonzero_nth)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   286
  then have "f $ ?n \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   287
    by (rule LeastI_ex)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   288
  moreover have "\<forall>m<?n. f $ m = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   289
    by (auto dest: not_less_Least)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   290
  ultimately have "f $ ?n \<noteq> 0 \<and> (\<forall>m<?n. f $ m = 0)" ..
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   291
  then show "\<exists>n. f $ n \<noteq> 0 \<and> (\<forall>m<n. f $ m = 0)" ..
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   292
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   293
  assume "\<exists>n. f $ n \<noteq> 0 \<and> (\<forall>m<n. f $ m = 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   294
  then show "f \<noteq> 0" by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   295
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   296
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   297
lemma fps_eq_iff: "f = g \<longleftrightarrow> (\<forall>n. f $ n = g $n)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   298
  by (rule expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   299
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   300
lemma fps_setsum_nth: "(setsum f S) $ n = setsum (\<lambda>k. (f k) $ n) S" 
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   301
proof (cases "finite S")
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   302
  assume "\<not> finite S" then show ?thesis by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   303
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   304
  assume "finite S"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   305
  then show ?thesis by (induct set: finite) auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   306
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   307
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   308
subsection{* Injection of the basic ring elements and multiplication by scalars *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   309
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   310
definition
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   311
  "fps_const c = Abs_fps (\<lambda>n. if n = 0 then c else 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   312
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   313
lemma fps_nth_fps_const [simp]: "fps_const c $ n = (if n = 0 then c else 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   314
  unfolding fps_const_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   315
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   316
lemma fps_const_0_eq_0 [simp]: "fps_const 0 = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   317
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   318
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   319
lemma fps_const_1_eq_1 [simp]: "fps_const 1 = 1"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   320
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   321
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   322
lemma fps_const_neg [simp]: "- (fps_const (c::'a::ring)) = fps_const (- c)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   323
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   324
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   325
lemma fps_const_add [simp]: "fps_const (c::'a\<Colon>monoid_add) + fps_const d = fps_const (c + d)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   326
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   327
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   328
lemma fps_const_mult[simp]: "fps_const (c::'a\<Colon>ring) * fps_const d = fps_const (c * d)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   329
  by (simp add: fps_eq_iff fps_mult_nth setsum_0')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   330
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   331
lemma fps_const_add_left: "fps_const (c::'a\<Colon>monoid_add) + f = Abs_fps (\<lambda>n. if n = 0 then c + f$0 else f$n)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   332
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   333
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   334
lemma fps_const_add_right: "f + fps_const (c::'a\<Colon>monoid_add) = Abs_fps (\<lambda>n. if n = 0 then f$0 + c else f$n)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   335
  by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   336
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   337
lemma fps_const_mult_left: "fps_const (c::'a\<Colon>semiring_0) * f = Abs_fps (\<lambda>n. c * f$n)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   338
  unfolding fps_eq_iff fps_mult_nth
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   339
  by (simp add: fps_const_def cond_application_beta cond_value_iff setsum_delta cong del: if_weak_cong)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   340
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   341
lemma fps_const_mult_right: "f * fps_const (c::'a\<Colon>semiring_0) = Abs_fps (\<lambda>n. f$n * c)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   342
  unfolding fps_eq_iff fps_mult_nth
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   343
  by (simp add: fps_const_def cond_application_beta cond_value_iff setsum_delta' cong del: if_weak_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   344
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   345
lemma fps_mult_left_const_nth [simp]: "(fps_const (c::'a::semiring_1) * f)$n = c* f$n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   346
  by (simp add: fps_mult_nth cond_application_beta cond_value_iff setsum_delta cong del: if_weak_cong)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   347
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   348
lemma fps_mult_right_const_nth [simp]: "(f * fps_const (c::'a::semiring_1))$n = f$n * c"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   349
  by (simp add: fps_mult_nth cond_application_beta cond_value_iff setsum_delta' cong del: if_weak_cong)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   350
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   351
subsection {* Formal power series form an integral domain*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   352
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   353
instance fps :: (ring) ring ..
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   354
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   355
instance fps :: (ring_1) ring_1
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   356
  by (intro_classes, auto simp add: diff_minus left_distrib)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   357
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   358
instance fps :: (comm_ring_1) comm_ring_1
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   359
  by (intro_classes, auto simp add: diff_minus left_distrib)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   360
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   361
instance fps :: (ring_no_zero_divisors) ring_no_zero_divisors
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   362
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   363
  fix a b :: "'a fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   364
  assume a0: "a \<noteq> 0" and b0: "b \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   365
  then obtain i j where i: "a$i\<noteq>0" "\<forall>k<i. a$k=0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   366
    and j: "b$j \<noteq>0" "\<forall>k<j. b$k =0" unfolding fps_nonzero_nth_minimal
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   367
    by blast+
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   368
  have "(a * b) $ (i+j) = (\<Sum>k=0..i+j. a$k * b$(i+j-k))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   369
    by (rule fps_mult_nth)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   370
  also have "\<dots> = (a$i * b$(i+j-i)) + (\<Sum>k\<in>{0..i+j}-{i}. a$k * b$(i+j-k))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   371
    by (rule setsum_diff1') simp_all
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   372
  also have "(\<Sum>k\<in>{0..i+j}-{i}. a$k * b$(i+j-k)) = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   373
    proof (rule setsum_0' [rule_format])
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   374
      fix k assume "k \<in> {0..i+j} - {i}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   375
      then have "k < i \<or> i+j-k < j" by auto
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   376
      then show "a$k * b$(i+j-k) = 0" using i j by auto
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   377
    qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   378
  also have "a$i * b$(i+j-i) + 0 = a$i * b$j" by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   379
  also have "a$i * b$j \<noteq> 0" using i j by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   380
  finally have "(a*b) $ (i+j) \<noteq> 0" .
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   381
  then show "a*b \<noteq> 0" unfolding fps_nonzero_nth by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   382
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   383
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   384
instance fps :: (idom) idom ..
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   385
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   386
subsection{* Inverses of formal power series *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   387
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   388
declare setsum_cong[fundef_cong]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   389
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   390
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   391
instantiation fps :: ("{comm_monoid_add,inverse, times, uminus}") inverse
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   392
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   393
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   394
fun natfun_inverse:: "'a fps \<Rightarrow> nat \<Rightarrow> 'a" where 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   395
  "natfun_inverse f 0 = inverse (f$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   396
| "natfun_inverse f n = - inverse (f$0) * setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   397
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   398
definition fps_inverse_def: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   399
  "inverse f = (if f$0 = 0 then 0 else Abs_fps (natfun_inverse f))"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   400
definition fps_divide_def: "divide = (\<lambda>(f::'a fps) g. f * inverse g)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   401
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   402
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   403
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   404
lemma fps_inverse_zero[simp]: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   405
  "inverse (0 :: 'a::{comm_monoid_add,inverse, times, uminus} fps) = 0"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   406
  by (simp add: fps_ext fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   407
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   408
lemma fps_inverse_one[simp]: "inverse (1 :: 'a::{division_ring,zero_neq_one} fps) = 1"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   409
  apply (auto simp add: expand_fps_eq fps_inverse_def)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   410
  by (case_tac n, auto)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   411
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   412
instance fps :: ("{comm_monoid_add,inverse, times, uminus}")  division_by_zero
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   413
  by default (rule fps_inverse_zero)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   414
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   415
lemma inverse_mult_eq_1[intro]: assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   416
  shows "inverse f * f = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   417
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   418
  have c: "inverse f * f = f * inverse f" by (simp add: mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   419
  from f0 have ifn: "\<And>n. inverse f $ n = natfun_inverse f n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   420
    by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   421
  from f0 have th0: "(inverse f * f) $ 0 = 1"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   422
    by (simp add: fps_mult_nth fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   423
  {fix n::nat assume np: "n >0 "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   424
    from np have eq: "{0..n} = {0} \<union> {1 .. n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   425
    have d: "{0} \<inter> {1 .. n} = {}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   426
    have f: "finite {0::nat}" "finite {1..n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   427
    from f0 np have th0: "- (inverse f$n) = 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   428
      (setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}) / (f$0)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   429
      by (cases n, simp, simp add: divide_inverse fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   430
    from th0[symmetric, unfolded nonzero_divide_eq_eq[OF f0]]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   431
    have th1: "setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n} = 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   432
      - (f$0) * (inverse f)$n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   433
      by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   434
    have "(f * inverse f) $ n = (\<Sum>i = 0..n. f $i * natfun_inverse f (n - i))" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   435
      unfolding fps_mult_nth ifn ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   436
    also have "\<dots> = f$0 * natfun_inverse f n 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   437
      + (\<Sum>i = 1..n. f$i * natfun_inverse f (n-i))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   438
      unfolding setsum_Un_disjoint[OF f d, unfolded eq[symmetric]]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   439
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   440
    also have "\<dots> = 0" unfolding th1 ifn by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   441
    finally have "(inverse f * f)$n = 0" unfolding c . }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   442
  with th0 show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   443
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   444
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   445
lemma fps_inverse_0_iff[simp]: "(inverse f)$0 = (0::'a::division_ring) \<longleftrightarrow> f$0 = 0"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   446
  by (simp add: fps_inverse_def nonzero_imp_inverse_nonzero)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   447
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   448
lemma fps_inverse_eq_0_iff[simp]: "inverse f = (0:: ('a::field) fps) \<longleftrightarrow> f $0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   449
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   450
  {assume "f$0 = 0" hence "inverse f = 0" by (simp add: fps_inverse_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   451
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   452
  {assume h: "inverse f = 0" and c: "f $0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   453
    from inverse_mult_eq_1[OF c] h have False by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   454
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   455
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   456
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   457
lemma fps_inverse_idempotent[intro]: assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   458
  shows "inverse (inverse f) = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   459
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   460
  from f0 have if0: "inverse f $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   461
  from inverse_mult_eq_1[OF f0] inverse_mult_eq_1[OF if0] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   462
  have th0: "inverse f * f = inverse f * inverse (inverse f)"   by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   463
  then show ?thesis using f0 unfolding mult_cancel_left by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   464
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   465
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   466
lemma fps_inverse_unique: assumes f0: "f$0 \<noteq> (0::'a::field)" and fg: "f*g = 1" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   467
  shows "inverse f = g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   468
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   469
  from inverse_mult_eq_1[OF f0] fg
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   470
  have th0: "inverse f * f = g * f" by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   471
  then show ?thesis using f0  unfolding mult_cancel_right
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   472
    by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   473
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   474
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   475
lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field))) 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   476
  = Abs_fps (\<lambda>n. if n= 0 then 1 else if n=1 then - 1 else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   477
  apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   478
  apply simp
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   479
  apply (simp add: fps_eq_iff fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   480
proof(clarsimp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   481
  fix n::nat assume n: "n > 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   482
  let ?f = "\<lambda>i. if n = i then (1\<Colon>'a) else if n - i = 1 then - 1 else 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   483
  let ?g = "\<lambda>i. if i = n then 1 else if i=n - 1 then - 1 else 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   484
  let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   485
  have th1: "setsum ?f {0..n} = setsum ?g {0..n}"  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   486
    by (rule setsum_cong2) auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   487
  have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}"  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   488
    using n apply - by (rule setsum_cong2) auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   489
  have eq: "{0 .. n} = {0.. n - 1} \<union> {n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   490
  from n have d: "{0.. n - 1} \<inter> {n} = {}" by auto 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   491
  have f: "finite {0.. n - 1}" "finite {n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   492
  show "setsum ?f {0..n} = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   493
    unfolding th1 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   494
    apply (simp add: setsum_Un_disjoint[OF f d, unfolded eq[symmetric]] del: One_nat_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   495
    unfolding th2
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   496
    by(simp add: setsum_delta)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   497
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   498
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   499
subsection{* Formal Derivatives, and the McLaurin theorem around 0*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   500
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   501
definition "fps_deriv f = Abs_fps (\<lambda>n. of_nat (n + 1) * f $ (n + 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   502
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   503
lemma fps_deriv_nth[simp]: "fps_deriv f $ n = of_nat (n +1) * f $ (n+1)" by (simp add: fps_deriv_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   504
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   505
lemma fps_deriv_linear[simp]: "fps_deriv (fps_const (a::'a::comm_semiring_1) * f + fps_const b * g) = fps_const a * fps_deriv f + fps_const b * fps_deriv g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   506
  unfolding fps_eq_iff fps_add_nth  fps_const_mult_left fps_deriv_nth by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   507
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   508
lemma fps_deriv_mult[simp]: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   509
  fixes f :: "('a :: comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   510
  shows "fps_deriv (f * g) = f * fps_deriv g + fps_deriv f * g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   511
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   512
  let ?D = "fps_deriv"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   513
  {fix n::nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   514
    let ?Zn = "{0 ..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   515
    let ?Zn1 = "{0 .. n + 1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   516
    let ?f = "\<lambda>i. i + 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   517
    have fi: "inj_on ?f {0..n}" by (simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   518
    have eq: "{1.. n+1} = ?f ` {0..n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   519
    let ?g = "\<lambda>i. of_nat (i+1) * g $ (i+1) * f $ (n - i) +
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   520
        of_nat (i+1)* f $ (i+1) * g $ (n - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   521
    let ?h = "\<lambda>i. of_nat i * g $ i * f $ ((n+1) - i) +
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   522
        of_nat i* f $ i * g $ ((n + 1) - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   523
    {fix k assume k: "k \<in> {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   524
      have "?h (k + 1) = ?g k" using k by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   525
    note th0 = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   526
    have eq': "{0..n +1}- {1 .. n+1} = {0}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   527
    have s0: "setsum (\<lambda>i. of_nat i * f $ i * g $ (n + 1 - i)) ?Zn1 = setsum (\<lambda>i. of_nat (n + 1 - i) * f $ (n + 1 - i) * g $ i) ?Zn1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   528
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   529
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   530
      apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   531
      apply (rule set_ext)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   532
      apply (presburger add: image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   533
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   534
    have s1: "setsum (\<lambda>i. f $ i * g $ (n + 1 - i)) ?Zn1 = setsum (\<lambda>i. f $ (n + 1 - i) * g $ i) ?Zn1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   535
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   536
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   537
      apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   538
      apply (rule set_ext)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   539
      apply (presburger add: image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   540
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   541
    have "(f * ?D g + ?D f * g)$n = (?D g * f + ?D f * g)$n" by (simp only: mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   542
    also have "\<dots> = (\<Sum>i = 0..n. ?g i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   543
      by (simp add: fps_mult_nth setsum_addf[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   544
    also have "\<dots> = setsum ?h {1..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   545
      using th0 setsum_reindex_cong[OF fi eq, of "?g" "?h"] by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   546
    also have "\<dots> = setsum ?h {0..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   547
      apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   548
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   549
      apply (simp add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   550
      unfolding eq'
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   551
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   552
    also have "\<dots> = (fps_deriv (f * g)) $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   553
      apply (simp only: fps_deriv_nth fps_mult_nth setsum_addf)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   554
      unfolding s0 s1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   555
      unfolding setsum_addf[symmetric] setsum_right_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   556
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   557
      by (auto simp add: of_nat_diff ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   558
    finally have "(f * ?D g + ?D f * g) $ n = ?D (f*g) $ n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   559
  then show ?thesis unfolding fps_eq_iff by auto 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   560
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   561
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   562
lemma fps_deriv_neg[simp]: "fps_deriv (- (f:: ('a:: comm_ring_1) fps)) = - (fps_deriv f)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   563
  by (simp add: fps_eq_iff fps_deriv_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   564
lemma fps_deriv_add[simp]: "fps_deriv ((f:: ('a::comm_ring_1) fps) + g) = fps_deriv f + fps_deriv g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   565
  using fps_deriv_linear[of 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   566
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   567
lemma fps_deriv_sub[simp]: "fps_deriv ((f:: ('a::comm_ring_1) fps) - g) = fps_deriv f - fps_deriv g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   568
  unfolding diff_minus by simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   569
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   570
lemma fps_deriv_const[simp]: "fps_deriv (fps_const c) = 0"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   571
  by (simp add: fps_ext fps_deriv_def fps_const_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   572
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   573
lemma fps_deriv_mult_const_left[simp]: "fps_deriv (fps_const (c::'a::comm_ring_1) * f) = fps_const c * fps_deriv f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   574
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   575
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   576
lemma fps_deriv_0[simp]: "fps_deriv 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   577
  by (simp add: fps_deriv_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   578
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   579
lemma fps_deriv_1[simp]: "fps_deriv 1 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   580
  by (simp add: fps_deriv_def fps_eq_iff )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   581
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   582
lemma fps_deriv_mult_const_right[simp]: "fps_deriv (f * fps_const (c::'a::comm_ring_1)) = fps_deriv f * fps_const c"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   583
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   584
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   585
lemma fps_deriv_setsum: "fps_deriv (setsum f S) = setsum (\<lambda>i. fps_deriv (f i :: ('a::comm_ring_1) fps)) S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   586
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   587
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   588
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   589
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   590
    have ?thesis  by (induct rule: finite_induct[OF fS], simp_all)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   591
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   592
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   593
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   594
lemma fps_deriv_eq_0_iff[simp]: "fps_deriv f = 0 \<longleftrightarrow> (f = fps_const (f$0 :: 'a::{idom,semiring_char_0}))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   595
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   596
  {assume "f= fps_const (f$0)" hence "fps_deriv f = fps_deriv (fps_const (f$0))" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   597
    hence "fps_deriv f = 0" by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   598
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   599
  {assume z: "fps_deriv f = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   600
    hence "\<forall>n. (fps_deriv f)$n = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   601
    hence "\<forall>n. f$(n+1) = 0" by (simp del: of_nat_Suc of_nat_add One_nat_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   602
    hence "f = fps_const (f$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   603
      apply (clarsimp simp add: fps_eq_iff fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   604
      apply (erule_tac x="n - 1" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   605
      by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   606
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   607
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   608
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   609
lemma fps_deriv_eq_iff: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   610
  fixes f:: "('a::{idom,semiring_char_0}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   611
  shows "fps_deriv f = fps_deriv g \<longleftrightarrow> (f = fps_const(f$0 - g$0) + g)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   612
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   613
  have "fps_deriv f = fps_deriv g \<longleftrightarrow> fps_deriv (f - g) = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   614
  also have "\<dots> \<longleftrightarrow> f - g = fps_const ((f-g)$0)" unfolding fps_deriv_eq_0_iff ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   615
  finally show ?thesis by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   616
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   617
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   618
lemma fps_deriv_eq_iff_ex: "(fps_deriv f = fps_deriv g) \<longleftrightarrow> (\<exists>(c::'a::{idom,semiring_char_0}). f = fps_const c + g)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   619
  apply auto unfolding fps_deriv_eq_iff by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   620
  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   621
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   622
fun fps_nth_deriv :: "nat \<Rightarrow> ('a::semiring_1) fps \<Rightarrow> 'a fps" where
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   623
  "fps_nth_deriv 0 f = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   624
| "fps_nth_deriv (Suc n) f = fps_nth_deriv n (fps_deriv f)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   625
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   626
lemma fps_nth_deriv_commute: "fps_nth_deriv (Suc n) f = fps_deriv (fps_nth_deriv n f)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   627
  by (induct n arbitrary: f, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   628
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   629
lemma fps_nth_deriv_linear[simp]: "fps_nth_deriv n (fps_const (a::'a::comm_semiring_1) * f + fps_const b * g) = fps_const a * fps_nth_deriv n f + fps_const b * fps_nth_deriv n g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   630
  by (induct n arbitrary: f g, auto simp add: fps_nth_deriv_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   631
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   632
lemma fps_nth_deriv_neg[simp]: "fps_nth_deriv n (- (f:: ('a:: comm_ring_1) fps)) = - (fps_nth_deriv n f)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   633
  by (induct n arbitrary: f, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   634
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   635
lemma fps_nth_deriv_add[simp]: "fps_nth_deriv n ((f:: ('a::comm_ring_1) fps) + g) = fps_nth_deriv n f + fps_nth_deriv n g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   636
  using fps_nth_deriv_linear[of n 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   637
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   638
lemma fps_nth_deriv_sub[simp]: "fps_nth_deriv n ((f:: ('a::comm_ring_1) fps) - g) = fps_nth_deriv n f - fps_nth_deriv n g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   639
  unfolding diff_minus fps_nth_deriv_add by simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   640
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   641
lemma fps_nth_deriv_0[simp]: "fps_nth_deriv n 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   642
  by (induct n, simp_all )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   643
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   644
lemma fps_nth_deriv_1[simp]: "fps_nth_deriv n 1 = (if n = 0 then 1 else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   645
  by (induct n, simp_all )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   646
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   647
lemma fps_nth_deriv_const[simp]: "fps_nth_deriv n (fps_const c) = (if n = 0 then fps_const c else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   648
  by (cases n, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   649
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   650
lemma fps_nth_deriv_mult_const_left[simp]: "fps_nth_deriv n (fps_const (c::'a::comm_ring_1) * f) = fps_const c * fps_nth_deriv n f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   651
  using fps_nth_deriv_linear[of n "c" f 0 0 ] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   652
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   653
lemma fps_nth_deriv_mult_const_right[simp]: "fps_nth_deriv n (f * fps_const (c::'a::comm_ring_1)) = fps_nth_deriv n f * fps_const c"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   654
  using fps_nth_deriv_linear[of n "c" f 0 0] by (simp add: mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   655
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   656
lemma fps_nth_deriv_setsum: "fps_nth_deriv n (setsum f S) = setsum (\<lambda>i. fps_nth_deriv n (f i :: ('a::comm_ring_1) fps)) S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   657
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   658
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   659
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   660
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   661
    have ?thesis  by (induct rule: finite_induct[OF fS], simp_all)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   662
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   663
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   664
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   665
lemma fps_deriv_maclauren_0: "(fps_nth_deriv k (f:: ('a::comm_semiring_1) fps)) $ 0 = of_nat (fact k) * f$(k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   666
  by (induct k arbitrary: f) (auto simp add: ring_simps of_nat_mult)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   667
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   668
subsection {* Powers*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   669
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   670
instantiation fps :: (semiring_1) power
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   671
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   672
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   673
fun fps_pow :: "nat \<Rightarrow> 'a fps \<Rightarrow> 'a fps" where
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   674
  "fps_pow 0 f = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   675
| "fps_pow (Suc n) f = f * fps_pow n f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   676
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   677
definition fps_power_def: "power (f::'a fps) n = fps_pow n f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   678
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   679
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   680
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   681
instantiation fps :: (comm_ring_1) recpower
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   682
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   683
instance
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   684
  apply (intro_classes)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   685
  by (simp_all add: fps_power_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   686
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   688
lemma eq_neg_iff_add_eq_0: "(a::'a::ring) = -b \<longleftrightarrow> a + b = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   689
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   690
  {assume "a = -b" hence "b + a = b + -b" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   691
    hence "a + b = 0" by (simp add: ring_simps)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   692
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   693
  {assume "a + b = 0" hence "a + b - b = -b" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   694
    hence "a = -b" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   695
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   696
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   697
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   698
lemma fps_sqrare_eq_iff: "(a:: 'a::idom fps)^ 2 = b^2  \<longleftrightarrow> (a = b \<or> a = -b)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   699
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   700
  {assume "a = b \<or> a = -b" hence "a^2 = b^2" by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   701
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   702
  {assume "a^2 = b^2 "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   703
    hence "a^2 - b^2 = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   704
    hence "(a-b) * (a+b) = 0" by (simp add: power2_eq_square ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   705
    hence "a = b \<or> a = -b" by (simp add: eq_neg_iff_add_eq_0)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   706
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   707
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   708
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   709
lemma fps_power_zeroth_eq_one: "a$0 =1 \<Longrightarrow> a^n $ 0 = (1::'a::semiring_1)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   710
  by (induct n, auto simp add: fps_power_def expand_fps_eq fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   711
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   712
lemma fps_power_first_eq: "(a:: 'a::comm_ring_1 fps)$0 =1 \<Longrightarrow> a^n $ 1 = of_nat n * a$1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   713
proof(induct n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   714
  case 0 thus ?case by (simp add: fps_power_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   715
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   716
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   717
  note h = Suc.hyps[OF `a$0 = 1`]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   718
  show ?case unfolding power_Suc fps_mult_nth 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   719
    using h `a$0 = 1`  fps_power_zeroth_eq_one[OF `a$0=1`] by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   720
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   721
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   722
lemma startsby_one_power:"a $ 0 = (1::'a::comm_ring_1) \<Longrightarrow> a^n $ 0 = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   723
  by (induct n, auto simp add: fps_power_def fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   724
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   725
lemma startsby_zero_power:"a $0 = (0::'a::comm_ring_1) \<Longrightarrow> n > 0 \<Longrightarrow> a^n $0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   726
  by (induct n, auto simp add: fps_power_def fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   727
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   728
lemma startsby_power:"a $0 = (v::'a::{comm_ring_1, recpower}) \<Longrightarrow> a^n $0 = v^n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   729
  by (induct n, auto simp add: fps_power_def fps_mult_nth power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   730
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   731
lemma startsby_zero_power_iff[simp]:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   732
  "a^n $0 = (0::'a::{idom, recpower}) \<longleftrightarrow> (n \<noteq> 0 \<and> a$0 = 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   733
apply (rule iffI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   734
apply (induct n, auto simp add: power_Suc fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   735
by (rule startsby_zero_power, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   736
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   737
lemma startsby_zero_power_prefix: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   738
  assumes a0: "a $0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   739
  shows "\<forall>n < k. a ^ k $ n = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   740
  using a0 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   741
proof(induct k rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   742
  fix k assume H: "\<forall>m<k. a $0 =  0 \<longrightarrow> (\<forall>n<m. a ^ m $ n = 0)" and a0: "a $0 = (0\<Colon>'a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   743
  let ?ths = "\<forall>m<k. a ^ k $ m = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   744
  {assume "k = 0" then have ?ths by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   745
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   746
  {fix l assume k: "k = Suc l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   747
    {fix m assume mk: "m < k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   748
      {assume "m=0" hence "a^k $ m = 0" using startsby_zero_power[of a k] k a0 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   749
	  by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   750
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   751
      {assume m0: "m \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   752
	have "a ^k $ m = (a^l * a) $m" by (simp add: k power_Suc mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   753
	also have "\<dots> = (\<Sum>i = 0..m. a ^ l $ i * a $ (m - i))" by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   754
	also have "\<dots> = 0" apply (rule setsum_0')
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   755
	  apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   756
	  apply (case_tac "aa = m")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   757
	  using a0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   758
	  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   759
	  apply (rule H[rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   760
	  using a0 k mk by auto 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   761
	finally have "a^k $ m = 0" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   762
    ultimately have "a^k $ m = 0" by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   763
    hence ?ths by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   764
  ultimately show ?ths by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   765
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   766
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   767
lemma startsby_zero_setsum_depends: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   768
  assumes a0: "a $0 = (0::'a::idom)" and kn: "n \<ge> k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   769
  shows "setsum (\<lambda>i. (a ^ i)$k) {0 .. n} = setsum (\<lambda>i. (a ^ i)$k) {0 .. k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   770
  apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   771
  using kn apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   772
  apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   773
  by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   774
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   775
lemma startsby_zero_power_nth_same: assumes a0: "a$0 = (0::'a::{recpower, idom})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   776
  shows "a^n $ n = (a$1) ^ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   777
proof(induct n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   778
  case 0 thus ?case by (simp add: power_0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   779
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   780
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   781
  have "a ^ Suc n $ (Suc n) = (a^n * a)$(Suc n)" by (simp add: ring_simps power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   782
  also have "\<dots> = setsum (\<lambda>i. a^n$i * a $ (Suc n - i)) {0.. Suc n}" by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   783
  also have "\<dots> = setsum (\<lambda>i. a^n$i * a $ (Suc n - i)) {n .. Suc n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   784
    apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   785
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   786
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   787
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   788
    apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   789
    apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   790
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   791
  also have "\<dots> = a^n $ n * a$1" using a0 by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   792
  finally show ?case using Suc.hyps by (simp add: power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   793
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   794
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   795
lemma fps_inverse_power:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   796
  fixes a :: "('a::{field, recpower}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   797
  shows "inverse (a^n) = inverse a ^ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   798
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   799
  {assume a0: "a$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   800
    hence eq: "inverse a = 0" by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   801
    {assume "n = 0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   802
    moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   803
    {assume n: "n > 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   804
      from startsby_zero_power[OF a0 n] eq a0 n have ?thesis 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   805
	by (simp add: fps_inverse_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   806
    ultimately have ?thesis by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   807
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   808
  {assume a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   809
    have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   810
      apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   811
      apply (simp add: a0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   812
      unfolding power_mult_distrib[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   813
      apply (rule ssubst[where t = "a * inverse a" and s= 1])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   814
      apply simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   815
      apply (subst mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   816
      by (rule inverse_mult_eq_1[OF a0])}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   817
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   818
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   819
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   820
lemma fps_deriv_power: "fps_deriv (a ^ n) = fps_const (of_nat n :: 'a:: comm_ring_1) * fps_deriv a * a ^ (n - 1)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   821
  apply (induct n, auto simp add: power_Suc ring_simps fps_const_add[symmetric] simp del: fps_const_add)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   822
  by (case_tac n, auto simp add: power_Suc ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   823
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   824
lemma fps_inverse_deriv: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   825
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   826
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   827
  shows "fps_deriv (inverse a) = - fps_deriv a * inverse a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   828
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   829
  from inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   830
  have "fps_deriv (inverse a * a) = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   831
  hence "inverse a * fps_deriv a + fps_deriv (inverse a) * a = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   832
  hence "inverse a * (inverse a * fps_deriv a + fps_deriv (inverse a) * a) = 0"  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   833
  with inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   834
  have "inverse a ^ 2 * fps_deriv a + fps_deriv (inverse a) = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   835
    unfolding power2_eq_square
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   836
    apply (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   837
    by (simp add: mult_assoc[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   838
  hence "inverse a ^ 2 * fps_deriv a + fps_deriv (inverse a) - fps_deriv a * inverse a ^ 2 = 0 - fps_deriv a * inverse a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   839
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   840
  then show "fps_deriv (inverse a) = - fps_deriv a * inverse a ^ 2" by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   841
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   842
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   843
lemma fps_inverse_mult: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   844
  fixes a::"('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   845
  shows "inverse (a * b) = inverse a * inverse b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   846
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   847
  {assume a0: "a$0 = 0" hence ab0: "(a*b)$0 = 0" by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   848
    from a0 ab0 have th: "inverse a = 0" "inverse (a*b) = 0" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   849
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   850
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   851
  {assume b0: "b$0 = 0" hence ab0: "(a*b)$0 = 0" by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   852
    from b0 ab0 have th: "inverse b = 0" "inverse (a*b) = 0" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   853
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   854
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   855
  {assume a0: "a$0 \<noteq> 0" and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   856
    from a0 b0 have ab0:"(a*b) $ 0 \<noteq> 0" by (simp  add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   857
    from inverse_mult_eq_1[OF ab0] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   858
    have "inverse (a*b) * (a*b) * inverse a * inverse b = 1 * inverse a * inverse b" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   859
    then have "inverse (a*b) * (inverse a * a) * (inverse b * b) = inverse a * inverse b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   860
      by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   861
    then have ?thesis using inverse_mult_eq_1[OF a0] inverse_mult_eq_1[OF b0] by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   862
ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   863
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   864
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   865
lemma fps_inverse_deriv': 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   866
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   867
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   868
  shows "fps_deriv (inverse a) = - fps_deriv a / a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   869
  using fps_inverse_deriv[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   870
  unfolding power2_eq_square fps_divide_def
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   871
    fps_inverse_mult by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   872
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   873
lemma inverse_mult_eq_1': assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   874
  shows "f * inverse f= 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   875
  by (metis mult_commute inverse_mult_eq_1 f0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   876
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   877
lemma fps_divide_deriv:   fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   878
  assumes a0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   879
  shows "fps_deriv (a / b) = (fps_deriv a * b - a * fps_deriv b) / b ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   880
  using fps_inverse_deriv[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   881
  by (simp add: fps_divide_def ring_simps power2_eq_square fps_inverse_mult inverse_mult_eq_1'[OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   882
  
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   883
subsection{* The eXtractor series X*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   884
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   885
lemma minus_one_power_iff: "(- (1::'a :: {recpower, comm_ring_1})) ^ n = (if even n then 1 else - 1)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   886
  by (induct n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   887
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   888
definition "X = Abs_fps (\<lambda>n. if n = 1 then 1 else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   889
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   890
lemma fps_inverse_gp': "inverse (Abs_fps(\<lambda>n. (1::'a::field))) 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   891
  = 1 - X"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   892
  by (simp add: fps_inverse_gp fps_eq_iff X_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   893
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   894
lemma X_mult_nth[simp]: "(X * (f :: ('a::semiring_1) fps)) $n = (if n = 0 then 0 else f $ (n - 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   895
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   896
  {assume n: "n \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   897
    have fN: "finite {0 .. n}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   898
    have "(X * f) $n = (\<Sum>i = 0..n. X $ i * f $ (n - i))" by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   899
    also have "\<dots> = f $ (n - 1)" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   900
      using n by (simp add: X_def cond_value_iff cond_application_beta setsum_delta[OF fN] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   901
	del: One_nat_def cong del:  if_weak_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   902
  finally have ?thesis using n by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   903
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   904
  {assume n: "n=0" hence ?thesis by (simp add: fps_mult_nth X_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   905
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   906
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   907
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   908
lemma X_mult_right_nth[simp]: "((f :: ('a::comm_semiring_1) fps) * X) $n = (if n = 0 then 0 else f $ (n - 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   909
  by (metis X_mult_nth mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   910
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   911
lemma X_power_iff: "X^k = Abs_fps (\<lambda>n. if n = k then (1::'a::comm_ring_1) else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   912
proof(induct k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   913
  case 0 thus ?case by (simp add: X_def fps_power_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   914
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   915
  case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   916
  {fix m 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   917
    have "(X^Suc k) $ m = (if m = 0 then (0::'a) else (X^k) $ (m - 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   918
      by (simp add: power_Suc del: One_nat_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   919
    then     have "(X^Suc k) $ m = (if m = Suc k then (1::'a) else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   920
      using Suc.hyps by (auto cong del: if_weak_cong)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   921
  then show ?case by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   922
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   923
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   924
lemma X_power_mult_nth: "(X^k * (f :: ('a::comm_ring_1) fps)) $n = (if n < k then 0 else f $ (n - k))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   925
  apply (induct k arbitrary: n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   926
  apply (simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   927
  unfolding power_Suc mult_assoc 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   928
  by (case_tac n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   929
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   930
lemma X_power_mult_right_nth: "((f :: ('a::comm_ring_1) fps) * X^k) $n = (if n < k then 0 else f $ (n - k))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   931
  by (metis X_power_mult_nth mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   932
lemma fps_deriv_X[simp]: "fps_deriv X = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   933
  by (simp add: fps_deriv_def X_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   934
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   935
lemma fps_nth_deriv_X[simp]: "fps_nth_deriv n X = (if n = 0 then X else if n=1 then 1 else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   936
  by (cases "n", simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   937
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   938
lemma X_nth[simp]: "X$n = (if n = 1 then 1 else 0)" by (simp add: X_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   939
lemma X_power_nth[simp]: "(X^k) $n = (if n = k then 1 else (0::'a::comm_ring_1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   940
  by (simp add: X_power_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   941
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   942
lemma fps_inverse_X_plus1:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   943
  "inverse (1 + X) = Abs_fps (\<lambda>n. (- (1::'a::{recpower, field})) ^ n)" (is "_ = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   944
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   945
  have eq: "(1 + X) * ?r = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   946
    unfolding minus_one_power_iff
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   947
    apply (auto simp add: ring_simps fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   948
    by presburger+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   949
  show ?thesis by (auto simp add: eq intro: fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   950
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   951
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   952
  
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   953
subsection{* Integration *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   954
definition "fps_integral a a0 = Abs_fps (\<lambda>n. if n = 0 then a0 else (a$(n - 1) / of_nat n))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   955
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   956
lemma fps_deriv_fps_integral: "fps_deriv (fps_integral a (a0 :: 'a :: {field, ring_char_0})) = a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   957
  by (simp add: fps_integral_def fps_deriv_def fps_eq_iff field_simps del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   958
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   959
lemma fps_integral_linear: "fps_integral (fps_const (a::'a::{field, ring_char_0}) * f + fps_const b * g) (a*a0 + b*b0) = fps_const a * fps_integral f a0 + fps_const b * fps_integral g b0" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   960
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   961
  have "fps_deriv ?l = fps_deriv ?r" by (simp add: fps_deriv_fps_integral)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   962
  moreover have "?l$0 = ?r$0" by (simp add: fps_integral_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   963
  ultimately show ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   964
    unfolding fps_deriv_eq_iff by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   965
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   966
  
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   967
subsection {* Composition of FPSs *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   968
definition fps_compose :: "('a::semiring_1) fps \<Rightarrow> 'a fps \<Rightarrow> 'a fps" (infixl "oo" 55) where
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   969
  fps_compose_def: "a oo b = Abs_fps (\<lambda>n. setsum (\<lambda>i. a$i * (b^i$n)) {0..n})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   970
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   971
lemma fps_compose_nth: "(a oo b)$n = setsum (\<lambda>i. a$i * (b^i$n)) {0..n}" by (simp add: fps_compose_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   972
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   973
lemma fps_compose_X[simp]: "a oo X = (a :: ('a :: comm_ring_1) fps)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   974
  by (auto simp add: fps_compose_def X_power_iff fps_eq_iff cond_application_beta cond_value_iff setsum_delta' cong del: if_weak_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   975
 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   976
lemma fps_const_compose[simp]: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   977
  "fps_const (a::'a::{comm_ring_1}) oo b = fps_const (a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   978
  apply (auto simp add: fps_eq_iff fps_compose_nth fps_mult_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   979
  cond_application_beta cond_value_iff cong del: if_weak_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   980
  by (simp add: setsum_delta )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   981
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   982
lemma X_fps_compose_startby0[simp]: "a$0 = 0 \<Longrightarrow> X oo a = (a :: ('a :: comm_ring_1) fps)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   983
  apply (auto simp add: fps_compose_def fps_eq_iff cond_application_beta cond_value_iff setsum_delta cong del: if_weak_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   984
  apply (simp add: power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   985
  apply (subgoal_tac "n = 0")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   986
  by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   987
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   988
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   989
subsection {* Rules from Herbert Wilf's Generatingfunctionology*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   990
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   991
subsubsection {* Rule 1 *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   992
  (* {a_{n+k}}_0^infty Corresponds to (f - setsum (\<lambda>i. a_i * x^i))/x^h, for h>0*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   993
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   994
lemma fps_power_mult_eq_shift: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   995
  "X^Suc k * Abs_fps (\<lambda>n. a (n + Suc k)) = Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a:: field) * X^i) {0 .. k}" (is "?lhs = ?rhs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   996
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   997
  {fix n:: nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   998
    have "?lhs $ n = (if n < Suc k then 0 else a n)" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   999
      unfolding X_power_mult_nth by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1000
    also have "\<dots> = ?rhs $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1001
    proof(induct k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1002
      case 0 thus ?case by (simp add: fps_setsum_nth power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1003
    next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1004
      case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1005
      note th = Suc.hyps[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1006
      have "(Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a:: field) * X^i) {0 .. Suc k})$n = (Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a:: field) * X^i) {0 .. k} - fps_const (a (Suc k)) * X^ Suc k) $ n" by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1007
      also  have "\<dots> = (if n < Suc k then 0 else a n) - (fps_const (a (Suc k)) * X^ Suc k)$n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1008
	using th 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1009
	unfolding fps_sub_nth by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1010
      also have "\<dots> = (if n < Suc (Suc k) then 0 else a n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1011
	unfolding X_power_mult_right_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1012
	apply (auto simp add: not_less fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1013
	apply (rule cong[of a a, OF refl])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1014
	by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1015
      finally show ?case by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1016
    qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1017
    finally have "?lhs $ n = ?rhs $ n"  .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1018
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1019
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1020
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1021
subsubsection{* Rule 2*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1022
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1023
  (* We can not reach the form of Wilf, but still near to it using rewrite rules*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1024
  (* If f reprents {a_n} and P is a polynomial, then 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1025
        P(xD) f represents {P(n) a_n}*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1026
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1027
definition "XD = op * X o fps_deriv"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1028
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1029
lemma XD_add[simp]:"XD (a + b) = XD a + XD (b :: ('a::comm_ring_1) fps)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1030
  by (simp add: XD_def ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1031
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1032
lemma XD_mult_const[simp]:"XD (fps_const (c::'a::comm_ring_1) * a) = fps_const c * XD a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1033
  by (simp add: XD_def ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1034
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1035
lemma XD_linear[simp]: "XD (fps_const c * a + fps_const d * b) = fps_const c * XD a + fps_const d * XD (b :: ('a::comm_ring_1) fps)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1036
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1037
29689
dd086f26ee4f removed definition of funpow , reusing that of Relation_Power
chaieb
parents: 29687
diff changeset
  1038
lemma XDN_linear: "(XD^n) (fps_const c * a + fps_const d * b) = fps_const c * (XD^n) a + fps_const d * (XD^n) (b :: ('a::comm_ring_1) fps)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1039
  by (induct n, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1040
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1041
lemma fps_mult_X_deriv_shift: "X* fps_deriv a = Abs_fps (\<lambda>n. of_nat n* a$n)" by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1042
29689
dd086f26ee4f removed definition of funpow , reusing that of Relation_Power
chaieb
parents: 29687
diff changeset
  1043
lemma fps_mult_XD_shift: "(XD ^k) (a:: ('a::{comm_ring_1, recpower, ring_char_0}) fps) = Abs_fps (\<lambda>n. (of_nat n ^ k) * a$n)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1044
by (induct k arbitrary: a) (simp_all add: power_Suc XD_def fps_eq_iff ring_simps del: One_nat_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1045
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1046
subsubsection{* Rule 3 is trivial and is given by @{text fps_times_def}*}
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1047
subsubsection{* Rule 5 --- summation and "division" by (1 - X)*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1048
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1049
lemma fps_divide_X_minus1_setsum_lemma:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1050
  "a = ((1::('a::comm_ring_1) fps) - X) * Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1051
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1052
  let ?X = "X::('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1053
  let ?sa = "Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1054
  have th0: "\<And>i. (1 - (X::'a fps)) $ i = (if i = 0 then 1 else if i = 1 then - 1 else 0)" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1055
  {fix n:: nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1056
    {assume "n=0" hence "a$n = ((1 - ?X) * ?sa) $ n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1057
	by (simp add: fps_mult_nth)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1058
    moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1059
    {assume n0: "n \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1060
      then have u: "{0} \<union> ({1} \<union> {2..n}) = {0..n}" "{1}\<union>{2..n} = {1..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1061
	"{0..n - 1}\<union>{n} = {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1062
	apply (simp_all add: expand_set_eq) by presburger+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1063
      have d: "{0} \<inter> ({1} \<union> {2..n}) = {}" "{1} \<inter> {2..n} = {}" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1064
	"{0..n - 1}\<inter>{n} ={}" using n0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1065
	by (simp_all add: expand_set_eq, presburger+)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1066
      have f: "finite {0}" "finite {1}" "finite {2 .. n}" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1067
	"finite {0 .. n - 1}" "finite {n}" by simp_all 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1068
    have "((1 - ?X) * ?sa) $ n = setsum (\<lambda>i. (1 - ?X)$ i * ?sa $ (n - i)) {0 .. n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1069
      by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1070
    also have "\<dots> = a$n" unfolding th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1071
      unfolding setsum_Un_disjoint[OF f(1) finite_UnI[OF f(2,3)] d(1), unfolded u(1)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1072
      unfolding setsum_Un_disjoint[OF f(2) f(3) d(2)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1073
      apply (simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1074
      unfolding setsum_Un_disjoint[OF f(4,5) d(3), unfolded u(3)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1075
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1076
    finally have "a$n = ((1 - ?X) * ?sa) $ n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1077
  ultimately have "a$n = ((1 - ?X) * ?sa) $ n" by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1078
then show ?thesis 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1079
  unfolding fps_eq_iff by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1080
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1081
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1082
lemma fps_divide_X_minus1_setsum:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1083
  "a /((1::('a::field) fps) - X)  = Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1084
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1085
  let ?X = "1 - (X::('a::field) fps)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1086
  have th0: "?X $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1087
  have "a /?X = ?X *  Abs_fps (\<lambda>n\<Colon>nat. setsum (op $ a) {0..n}) * inverse ?X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1088
    using fps_divide_X_minus1_setsum_lemma[of a, symmetric] th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1089
    by (simp add: fps_divide_def mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1090
  also have "\<dots> = (inverse ?X * ?X) * Abs_fps (\<lambda>n\<Colon>nat. setsum (op $ a) {0..n}) "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1091
    by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1092
  finally show ?thesis by (simp add: inverse_mult_eq_1[OF th0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1093
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1094
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1095
subsubsection{* Rule 4 in its more general form: generalizes Rule 3 for an arbitrary 
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1096
  finite product of FPS, also the relvant instance of powers of a FPS*}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1097
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1098
definition "natpermute n k = {l:: nat list. length l = k \<and> foldl op + 0 l = n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1099
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1100
lemma natlist_trivial_1: "natpermute n 1 = {[n]}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1101
  apply (auto simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1102
  apply (case_tac x, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1103
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1104
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1105
lemma foldl_add_start0: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1106
  "foldl op + x xs = x + foldl op + (0::nat) xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1107
  apply (induct xs arbitrary: x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1108
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1109
  unfolding foldl.simps
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1110
  apply atomize
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1111
  apply (subgoal_tac "\<forall>x\<Colon>nat. foldl op + x xs = x + foldl op + (0\<Colon>nat) xs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1112
  apply (erule_tac x="x + a" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1113
  apply (erule_tac x="a" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1114
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1115
  apply assumption
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1116
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1117
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1118
lemma foldl_add_append: "foldl op + (x::nat) (xs@ys) = foldl op + x xs + foldl op + 0 ys"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1119
  apply (induct ys arbitrary: x xs)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1120
  apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1121
  apply (subst (2) foldl_add_start0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1122
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1123
  apply (subst (2) foldl_add_start0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1124
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1125
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1126
lemma foldl_add_setsum: "foldl op + (x::nat) xs = x + setsum (nth xs) {0..<length xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1127
proof(induct xs arbitrary: x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1128
  case Nil thus ?case by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1129
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1130
  case (Cons a as x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1131
  have eq: "setsum (op ! (a#as)) {1..<length (a#as)} = setsum (op ! as) {0..<length as}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1132
    apply (rule setsum_reindex_cong [where f=Suc])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1133
    by (simp_all add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1134
  have f: "finite {0}" "finite {1 ..< length (a#as)}" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1135
  have d: "{0} \<inter> {1..<length (a#as)} = {}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1136
  have seq: "{0} \<union> {1..<length(a#as)} = {0 ..<length (a#as)}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1137
  have "foldl op + x (a#as) = x + foldl op + a as "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1138
    apply (subst foldl_add_start0)    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1139
  also have "\<dots> = x + a + setsum (op ! as) {0..<length as}" unfolding Cons.hyps by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1140
  also have "\<dots> = x + setsum (op ! (a#as)) {0..<length (a#as)}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1141
    unfolding eq[symmetric] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1142
    unfolding setsum_Un_disjoint[OF f d, unfolded seq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1143
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1144
  finally show ?case  .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1145
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1146
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1147
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1148
lemma append_natpermute_less_eq:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1149
  assumes h: "xs@ys \<in> natpermute n k" shows "foldl op + 0 xs \<le> n" and "foldl op + 0 ys \<le> n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1150
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1151
  {from h have "foldl op + 0 (xs@ ys) = n" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1152
    hence "foldl op + 0 xs + foldl op + 0 ys = n" unfolding foldl_add_append .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1153
  note th = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1154
  {from th show "foldl op + 0 xs \<le> n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1155
  {from th show "foldl op + 0 ys \<le> n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1156
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1157
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1158
lemma natpermute_split:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1159
  assumes mn: "h \<le> k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1160
  shows "natpermute n k = (\<Union>m \<in>{0..n}. {l1 @ l2 |l1 l2. l1 \<in> natpermute m h \<and> l2 \<in> natpermute (n - m) (k - h)})" (is "?L = ?R" is "?L = (\<Union>m \<in>{0..n}. ?S m)")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1161
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1162
  {fix l assume l: "l \<in> ?R" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1163
    from l obtain m xs ys where h: "m \<in> {0..n}" and xs: "xs \<in> natpermute m h" and ys: "ys \<in> natpermute (n - m) (k - h)"  and leq: "l = xs@ys" by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1164
    from xs have xs': "foldl op + 0 xs = m" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1165
    from ys have ys': "foldl op + 0 ys = n - m" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1166
    have "l \<in> ?L" using leq xs ys h 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1167
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1168
      apply (clarsimp simp add: natpermute_def simp del: foldl_append)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1169
      apply (simp add: foldl_add_append[unfolded foldl_append])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1170
      unfolding xs' ys'
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1171
      using mn xs ys 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1172
      unfolding natpermute_def by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1173
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1174
  {fix l assume l: "l \<in> natpermute n k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1175
    let ?xs = "take h l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1176
    let ?ys = "drop h l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1177
    let ?m = "foldl op + 0 ?xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1178
    from l have ls: "foldl op + 0 (?xs @ ?ys) = n" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1179
    have xs: "?xs \<in> natpermute ?m h" using l mn by (simp add: natpermute_def)     
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1180
    have ys: "?ys \<in> natpermute (n - ?m) (k - h)" using l mn ls[unfolded foldl_add_append]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1181
      by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1182
    from ls have m: "?m \<in> {0..n}"  unfolding foldl_add_append by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1183
    from xs ys ls have "l \<in> ?R" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1184
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1185
      apply (rule bexI[where x = "?m"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1186
      apply (rule exI[where x = "?xs"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1187
      apply (rule exI[where x = "?ys"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1188
      using ls l unfolding foldl_add_append 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1189
      by (auto simp add: natpermute_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1190
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1191
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1192
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1193
lemma natpermute_0: "natpermute n 0 = (if n = 0 then {[]} else {})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1194
  by (auto simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1195
lemma natpermute_0'[simp]: "natpermute 0 k = (if k = 0 then {[]} else {replicate k 0})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1196
  apply (auto simp add: set_replicate_conv_if natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1197
  apply (rule nth_equalityI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1198
  by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1199
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1200
lemma natpermute_finite: "finite (natpermute n k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1201
proof(induct k arbitrary: n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1202
  case 0 thus ?case 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1203
    apply (subst natpermute_split[of 0 0, simplified])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1204
    by (simp add: natpermute_0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1205
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1206
  case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1207
  then show ?case unfolding natpermute_split[of k "Suc k", simplified]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1208
    apply -
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1209
    apply (rule finite_UN_I)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1210
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1211
    unfolding One_nat_def[symmetric] natlist_trivial_1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1212
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1213
    unfolding image_Collect[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1214
    unfolding Collect_def mem_def
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1215
    apply (rule finite_imageI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1216
    apply blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1217
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1218
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1219
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1220
lemma natpermute_contain_maximal:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1221
  "{xs \<in> natpermute n (k+1). n \<in> set xs} = UNION {0 .. k} (\<lambda>i. {(replicate (k+1) 0) [i:=n]})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1222
  (is "?A = ?B")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1223
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1224
  {fix xs assume H: "xs \<in> natpermute n (k+1)" and n: "n \<in> set xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1225
    from n obtain i where i: "i \<in> {0.. k}" "xs!i = n" using H
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1226
      unfolding in_set_conv_nth by (auto simp add: less_Suc_eq_le natpermute_def) 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1227
    have eqs: "({0..k} - {i}) \<union> {i} = {0..k}" using i by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1228
    have f: "finite({0..k} - {i})" "finite {i}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1229
    have d: "({0..k} - {i}) \<inter> {i} = {}" using i by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1230
    from H have "n = setsum (nth xs) {0..k}" apply (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1231
      unfolding foldl_add_setsum by (auto simp add: atLeastLessThanSuc_atLeastAtMost)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1232
    also have "\<dots> = n + setsum (nth xs) ({0..k} - {i})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1233
      unfolding setsum_Un_disjoint[OF f d, unfolded eqs] using i by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1234
    finally have zxs: "\<forall> j\<in> {0..k} - {i}. xs!j = 0" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1235
    from H have xsl: "length xs = k+1" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1236
    from i have i': "i < length (replicate (k+1) 0)"   "i < k+1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1237
      unfolding length_replicate  by arith+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1238
    have "xs = replicate (k+1) 0 [i := n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1239
      apply (rule nth_equalityI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1240
      unfolding xsl length_list_update length_replicate
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1241
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1242
      apply clarify
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1243
      unfolding nth_list_update[OF i'(1)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1244
      using i zxs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1245
      by (case_tac "ia=i", auto simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1246
    then have "xs \<in> ?B" using i by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1247
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1248
  {fix i assume i: "i \<in> {0..k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1249
    let ?xs = "replicate (k+1) 0 [i:=n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1250
    have nxs: "n \<in> set ?xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1251
      apply (rule set_update_memI) using i by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1252
    have xsl: "length ?xs = k+1" by (simp only: length_replicate length_list_update)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1253
    have "foldl op + 0 ?xs = setsum (nth ?xs) {0..<k+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1254
      unfolding foldl_add_setsum add_0 length_replicate length_list_update ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1255
    also have "\<dots> = setsum (\<lambda>j. if j = i then n else 0) {0..< k+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1256
      apply (rule setsum_cong2) by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1257
    also have "\<dots> = n" using i by (simp add: setsum_delta)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1258
    finally 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1259
    have "?xs \<in> natpermute n (k+1)" using xsl unfolding natpermute_def Collect_def mem_def
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1260
      by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1261
    then have "?xs \<in> ?A"  using nxs  by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1262
  ultimately show ?thesis by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1263
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1264
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1265
    (* The general form *)	
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1266
lemma fps_setprod_nth:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1267
  fixes m :: nat and a :: "nat \<Rightarrow> ('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1268
  shows "(setprod a {0 .. m})$n = setsum (\<lambda>v. setprod (\<lambda>j. (a j) $ (v!j)) {0..m}) (natpermute n (m+1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1269
  (is "?P m n")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1270
proof(induct m arbitrary: n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1271
  fix m n assume H: "\<forall>m' < m. \<forall>n. ?P m' n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1272
  {assume m0: "m = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1273
    hence "?P m n" apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1274
      unfolding natlist_trivial_1[where n = n, unfolded One_nat_def] by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1275
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1276
  {fix k assume k: "m = Suc k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1277
    have km: "k < m" using k by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1278
    have u0: "{0 .. k} \<union> {m} = {0..m}" using k apply (simp add: expand_set_eq) by presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1279
    have f0: "finite {0 .. k}" "finite {m}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1280
    have d0: "{0 .. k} \<inter> {m} = {}" using k by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1281
    have "(setprod a {0 .. m}) $ n = (setprod a {0 .. k} * a m) $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1282
      unfolding setprod_Un_disjoint[OF f0 d0, unfolded u0] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1283
    also have "\<dots> = (\<Sum>i = 0..n. (\<Sum>v\<in>natpermute i (k + 1). \<Prod>j\<in>{0..k}. a j $ v ! j) * a m $ (n - i))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1284
      unfolding fps_mult_nth H[rule_format, OF km] ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1285
    also have "\<dots> = (\<Sum>v\<in>natpermute n (m + 1). \<Prod>j\<in>{0..m}. a j $ v ! j)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1286
      apply (simp add: k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1287
      unfolding natpermute_split[of m "m + 1", simplified, of n, unfolded natlist_trivial_1[unfolded One_nat_def] k]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1288
      apply (subst setsum_UN_disjoint)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1289
      apply simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1290
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1291
      unfolding image_Collect[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1292
      apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1293
      apply (rule finite_imageI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1294
      apply (rule natpermute_finite)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1295
      apply (clarsimp simp add: expand_set_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1296
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1297
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1298
      unfolding setsum_left_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1299
      apply (rule sym)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1300
      apply (rule_tac f="\<lambda>xs. xs @[n - x]" in  setsum_reindex_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1301
      apply (simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1302
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1303
      unfolding setprod_Un_disjoint[OF f0 d0, unfolded u0, unfolded k]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1304
      apply (clarsimp simp add: natpermute_def nth_append)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1305
      apply (rule_tac f="\<lambda>x. x * a (Suc k) $ (n - foldl op + 0 aa)" in cong[OF refl])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1306
      apply (rule setprod_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1307
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1308
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1309
      done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1310
    finally have "?P m n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1311
  ultimately show "?P m n " by (cases m, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1312
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1313
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1314
text{* The special form for powers *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1315
lemma fps_power_nth_Suc:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1316
  fixes m :: nat and a :: "('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1317
  shows "(a ^ Suc m)$n = setsum (\<lambda>v. setprod (\<lambda>j. a $ (v!j)) {0..m}) (natpermute n (m+1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1318
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1319
  have f: "finite {0 ..m}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1320
  have th0: "a^Suc m = setprod (\<lambda>i. a) {0..m}" unfolding setprod_constant[OF f, of a] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1321
  show ?thesis unfolding th0 fps_setprod_nth ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1322
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1323
lemma fps_power_nth:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1324
  fixes m :: nat and a :: "('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1325
  shows "(a ^m)$n = (if m=0 then 1$n else setsum (\<lambda>v. setprod (\<lambda>j. a $ (v!j)) {0..m - 1}) (natpermute n m))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1326
  by (cases m, simp_all add: fps_power_nth_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1327
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1328
lemma fps_nth_power_0: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1329
  fixes m :: nat and a :: "('a::{comm_ring_1, recpower}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1330
  shows "(a ^m)$0 = (a$0) ^ m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1331
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1332
  {assume "m=0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1333
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1334
  {fix n assume m: "m = Suc n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1335
    have c: "m = card {0..n}" using m by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1336
   have "(a ^m)$0 = setprod (\<lambda>i. a$0) {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1337
     apply (simp add: m fps_power_nth del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1338
     apply (rule setprod_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1339
     by (simp_all del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1340
   also have "\<dots> = (a$0) ^ m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1341
     unfolding c by (rule setprod_constant, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1342
   finally have ?thesis .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1343
 ultimately show ?thesis by (cases m, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1344
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1345
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1346
lemma fps_compose_inj_right: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1347
  assumes a0: "a$0 = (0::'a::{recpower,idom})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1348
  and a1: "a$1 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1349
  shows "(b oo a = c oo a) \<longleftrightarrow> b = c" (is "?lhs \<longleftrightarrow>?rhs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1350
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1351
  {assume ?rhs then have "?lhs" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1352
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1353
  {assume h: ?lhs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1354
    {fix n have "b$n = c$n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1355
      proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1356
	fix n assume H: "\<forall>m<n. b$m = c$m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1357
	{assume n0: "n=0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1358
	  from h have "(b oo a)$n = (c oo a)$n" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1359
	  hence "b$n = c$n" using n0 by (simp add: fps_compose_nth)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1360
	moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1361
	{fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1362
	  have f: "finite {0 .. n1}" "finite {n}" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1363
	  have eq: "{0 .. n1} \<union> {n} = {0 .. n}" using n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1364
	  have d: "{0 .. n1} \<inter> {n} = {}" using n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1365
	  have seq: "(\<Sum>i = 0..n1. b $ i * a ^ i $ n) = (\<Sum>i = 0..n1. c $ i * a ^ i $ n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1366
	    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1367
	    using H n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1368
	  have th0: "(b oo a) $n = (\<Sum>i = 0..n1. c $ i * a ^ i $ n) + b$n * (a$1)^n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1369
	    unfolding fps_compose_nth setsum_Un_disjoint[OF f d, unfolded eq] seq
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1370
	    using startsby_zero_power_nth_same[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1371
	    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1372
	  have th1: "(c oo a) $n = (\<Sum>i = 0..n1. c $ i * a ^ i $ n) + c$n * (a$1)^n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset