src/HOL/Library/Formal_Power_Series.thy
author chaieb
Thu, 09 Jul 2009 10:34:51 +0200
changeset 31968 0314441a53a6
parent 31790 05c92381363c
child 32042 df28ead1cf19
child 32157 adea7a729c7a
permissions -rw-r--r--
FPS form a metric space, which justifies the infinte sum notation
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
    Author:     Amine Chaieb, University of Cambridge
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     3
*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     4
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     5
header{* A formalization of formal power series *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     6
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     7
theory Formal_Power_Series
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
     8
imports Complex_Main
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     9
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    10
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
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
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
    52
lemma fps_one_nth [simp]: "1 $ n = (if n = 0 then 1 else 0)"
29911
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
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   107
lemma mult_delta_left:
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   108
  fixes x y :: "'a::mult_zero"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   109
  shows "(if b then x else 0) * y = (if b then x * y else 0)"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   110
  by simp
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   111
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   112
lemma mult_delta_right:
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   113
  fixes x y :: "'a::mult_zero"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   114
  shows "x * (if b then y else 0) = (if b then x * y else 0)"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   115
  by simp
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   116
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   117
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
   118
  by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   119
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
   120
  by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   121
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   122
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
   123
  they represent is a commutative ring with unity*}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   124
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   125
instance fps :: (semigroup_add) semigroup_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   126
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   127
  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
   128
    by (simp add: fps_ext add_assoc)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   129
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   130
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   131
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
   132
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   133
  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
   134
    by (simp add: fps_ext add_commute)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   135
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   136
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   137
lemma fps_mult_assoc_lemma:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   138
  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
   139
  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
   140
         (\<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
   141
proof (induct k)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   142
  case 0 show ?case by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   143
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   144
  case (Suc k) thus ?case
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   145
    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
   146
             cong: strong_setsum_cong)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   147
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   148
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   149
instance fps :: (semiring_0) semigroup_mult
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   150
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   151
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   152
  show "(a * b) * c = a * (b * c)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   153
  proof (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   154
    fix n :: nat
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   155
    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
   156
          (\<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
   157
      by (rule fps_mult_assoc_lemma)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   158
    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
   159
      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
   160
                    setsum_left_distrib mult_assoc)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   161
  qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   162
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   163
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   164
lemma fps_mult_commute_lemma:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   165
  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
   166
  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
   167
proof (rule setsum_reindex_cong)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   168
  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
   169
    by (rule inj_onI) simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   170
  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
   171
    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
   172
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   173
  fix i assume "i \<in> {0..n}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   174
  hence "n - (n - i) = i" by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   175
  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
   176
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   177
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   178
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
   179
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   180
  fix a b :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   181
  show "a * b = b * a"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   182
  proof (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   183
    fix n :: nat
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   184
    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
   185
      by (rule fps_mult_commute_lemma)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   186
    thus "(a * b) $ n = (b * a) $ n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   187
      by (simp add: fps_mult_nth mult_commute)
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
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   190
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   191
instance fps :: (monoid_add) monoid_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   192
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   193
  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
   194
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   195
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   196
  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
   197
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   198
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   199
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   200
instance fps :: (comm_monoid_add) comm_monoid_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   201
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   202
  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
   203
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   204
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   205
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   206
instance fps :: (semiring_1) monoid_mult
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   207
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   208
  fix a :: "'a fps" show "1 * a = a"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   209
    by (simp add: fps_ext fps_mult_nth mult_delta_left setsum_delta)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   210
next
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   211
  fix a :: "'a fps" show "a * 1 = a"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   212
    by (simp add: fps_ext fps_mult_nth mult_delta_right setsum_delta')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   213
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   214
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   215
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
   216
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   217
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   218
  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
   219
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   220
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   221
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   222
  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
   223
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   224
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   225
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   226
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
   227
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   228
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   229
  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
   230
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   231
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   232
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   233
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
   234
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   235
instance fps :: (group_add) group_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   236
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   237
  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
   238
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   239
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   240
  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
   241
    by (simp add: fps_ext diff_minus)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   242
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   243
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   244
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
   245
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   246
  fix a :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   247
  show "- a + a = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   248
    by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   249
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   250
  fix a b :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   251
  show "a - b = a + - b"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   252
    by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   253
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   254
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   255
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
   256
  by default (simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   257
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   258
instance fps :: (semiring_0) semiring
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   259
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   260
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   261
  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
   262
    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
   263
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   264
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   265
  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
   266
    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
   267
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   268
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   269
instance fps :: (semiring_0) semiring_0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   270
proof
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   271
  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
   272
    by (simp add: fps_ext fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   273
next
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   274
  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
   275
    by (simp add: fps_ext fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   276
qed
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   277
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   278
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
   279
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   280
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
   281
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   282
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
   283
  by (simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   284
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   285
lemma fps_nonzero_nth_minimal:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   286
  "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
   287
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   288
  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
   289
  assume "f \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   290
  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
   291
    by (simp add: fps_nonzero_nth)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   292
  then have "f $ ?n \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   293
    by (rule LeastI_ex)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   294
  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
   295
    by (auto dest: not_less_Least)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   296
  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
   297
  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
   298
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   299
  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
   300
  then show "f \<noteq> 0" by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   301
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   302
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   303
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
   304
  by (rule expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   305
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   306
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
   307
proof (cases "finite S")
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   308
  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
   309
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   310
  assume "finite S"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   311
  then show ?thesis by (induct set: finite) auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   312
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   313
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   314
subsection{* Injection of the basic ring elements and multiplication by scalars *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   315
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   316
definition
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   317
  "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
   318
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   319
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
   320
  unfolding fps_const_def by simp
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_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
   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_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
   326
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   327
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   328
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
   329
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   330
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   331
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
   332
  by (simp add: fps_ext)
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   333
lemma fps_const_sub [simp]: "fps_const (c::'a\<Colon>group_add) - fps_const d = fps_const (c - d)"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   334
  by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   335
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
   336
  by (simp add: fps_eq_iff fps_mult_nth setsum_0')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   337
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   338
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
   339
  by (simp add: fps_ext)
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_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
   342
  by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   343
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   344
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
   345
  unfolding fps_eq_iff fps_mult_nth
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   346
  by (simp add: fps_const_def mult_delta_left setsum_delta)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   347
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   348
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
   349
  unfolding fps_eq_iff fps_mult_nth
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   350
  by (simp add: fps_const_def mult_delta_right setsum_delta')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   351
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   352
lemma fps_mult_left_const_nth [simp]: "(fps_const (c::'a::semiring_1) * f)$n = c* f$n"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   353
  by (simp add: fps_mult_nth mult_delta_left setsum_delta)
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
lemma fps_mult_right_const_nth [simp]: "(f * fps_const (c::'a::semiring_1))$n = f$n * c"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   356
  by (simp add: fps_mult_nth mult_delta_right setsum_delta')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   357
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   358
subsection {* Formal power series form an integral domain*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   359
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   360
instance fps :: (ring) ring ..
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   361
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   362
instance fps :: (ring_1) ring_1
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   363
  by (intro_classes, auto simp add: diff_minus left_distrib)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   364
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   365
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
   366
  by (intro_classes, auto simp add: diff_minus left_distrib)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   367
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   368
instance fps :: (ring_no_zero_divisors) ring_no_zero_divisors
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   369
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   370
  fix a b :: "'a fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   371
  assume a0: "a \<noteq> 0" and b0: "b \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   372
  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
   373
    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
   374
    by blast+
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   375
  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
   376
    by (rule fps_mult_nth)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   377
  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
   378
    by (rule setsum_diff1') simp_all
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   379
  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
   380
    proof (rule setsum_0' [rule_format])
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   381
      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
   382
      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
   383
      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
   384
    qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   385
  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
   386
  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
   387
  finally have "(a*b) $ (i+j) \<noteq> 0" .
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   388
  then show "a*b \<noteq> 0" unfolding fps_nonzero_nth by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   389
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   390
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   391
instance fps :: (idom) idom ..
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   392
30746
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   393
instantiation fps :: (comm_ring_1) number_ring
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   394
begin
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   395
definition number_of_fps_def: "(number_of k::'a fps) = of_int k"
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   396
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   397
instance proof
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   398
qed (rule number_of_fps_def)
30746
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   399
end
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   400
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   401
lemma number_of_fps_const: "(number_of k::('a::comm_ring_1) fps) = fps_const (of_int k)"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   402
  
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   403
proof(induct k rule: int_induct[where k=0])
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   404
  case base thus ?case unfolding number_of_fps_def of_int_0 by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   405
next
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   406
  case (step1 i) thus ?case unfolding number_of_fps_def 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   407
    by (simp add: fps_const_add[symmetric] del: fps_const_add)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   408
next
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   409
  case (step2 i) thus ?case unfolding number_of_fps_def 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   410
    by (simp add: fps_const_sub[symmetric] del: fps_const_sub)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   411
qed
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   412
subsection{* The eXtractor series X*}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   413
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   414
lemma minus_one_power_iff: "(- (1::'a :: {comm_ring_1})) ^ n = (if even n then 1 else - 1)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   415
  by (induct n, auto)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   416
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   417
definition "X = Abs_fps (\<lambda>n. if n = 1 then 1 else 0)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   418
lemma X_mult_nth[simp]: "(X * (f :: ('a::semiring_1) fps)) $n = (if n = 0 then 0 else f $ (n - 1))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   419
proof-
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   420
  {assume n: "n \<noteq> 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   421
    have fN: "finite {0 .. n}" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   422
    have "(X * f) $n = (\<Sum>i = 0..n. X $ i * f $ (n - i))" by (simp add: fps_mult_nth)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   423
    also have "\<dots> = f $ (n - 1)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   424
      using n by (simp add: X_def mult_delta_left setsum_delta [OF fN])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   425
  finally have ?thesis using n by simp }
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   426
  moreover
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   427
  {assume n: "n=0" hence ?thesis by (simp add: fps_mult_nth X_def)}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   428
  ultimately show ?thesis by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   429
qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   430
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   431
lemma X_mult_right_nth[simp]: "((f :: ('a::comm_semiring_1) fps) * X) $n = (if n = 0 then 0 else f $ (n - 1))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   432
  by (metis X_mult_nth mult_commute)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   433
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   434
lemma X_power_iff: "X^k = Abs_fps (\<lambda>n. if n = k then (1::'a::comm_ring_1) else 0)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   435
proof(induct k)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   436
  case 0 thus ?case by (simp add: X_def fps_eq_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   437
next
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   438
  case (Suc k)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   439
  {fix m
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   440
    have "(X^Suc k) $ m = (if m = 0 then (0::'a) else (X^k) $ (m - 1))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   441
      by (simp add: power_Suc del: One_nat_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   442
    then     have "(X^Suc k) $ m = (if m = Suc k then (1::'a) else 0)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   443
      using Suc.hyps by (auto cong del: if_weak_cong)}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   444
  then show ?case by (simp add: fps_eq_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   445
qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   446
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   447
lemma X_power_mult_nth: "(X^k * (f :: ('a::comm_ring_1) fps)) $n = (if n < k then 0 else f $ (n - k))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   448
  apply (induct k arbitrary: n)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   449
  apply (simp)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   450
  unfolding power_Suc mult_assoc
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   451
  by (case_tac n, auto)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   452
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   453
lemma X_power_mult_right_nth: "((f :: ('a::comm_ring_1) fps) * X^k) $n = (if n < k then 0 else f $ (n - k))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   454
  by (metis X_power_mult_nth mult_commute)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   455
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   456
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   457
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   458
  
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   459
subsection{* Formal Power series form a metric space *}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   460
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   461
definition (in dist) ball_def: "ball x r = {y. dist y x < r}"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   462
instantiation fps :: (comm_ring_1) dist
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   463
begin
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   464
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   465
definition dist_fps_def: "dist (a::'a fps) b = (if (\<exists>n. a$n \<noteq> b$n) then inverse (2 ^ The (leastP (\<lambda>n. a$n \<noteq> b$n))) else 0)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   466
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   467
lemma dist_fps_ge0: "dist (a::'a fps) b \<ge> 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   468
  by (simp add: dist_fps_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   469
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   470
lemma dist_fps_sym: "dist (a::'a fps) b = dist b a"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   471
  apply (auto simp add: dist_fps_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   472
  thm cong[OF refl]
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   473
  apply (rule cong[OF refl, where x="(\<lambda>n\<Colon>nat. a $ n \<noteq> b $ n)"])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   474
  apply (rule ext)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   475
  by auto
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   476
instance ..
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   477
end
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   478
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   479
lemma fps_nonzero_least_unique: assumes a0: "a \<noteq> 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   480
  shows "\<exists>! n. leastP (\<lambda>n. a$n \<noteq> 0) n"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   481
proof-
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   482
  from fps_nonzero_nth_minimal[of a] a0
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   483
  obtain n where n: "a$n \<noteq> 0" "\<forall>m < n. a$m = 0" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   484
  from n have ln: "leastP (\<lambda>n. a$n \<noteq> 0) n" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   485
    by (auto simp add: leastP_def setge_def not_le[symmetric])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   486
  moreover
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   487
  {fix m assume "leastP (\<lambda>n. a$n \<noteq> 0) m"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   488
    then have "m = n" using ln
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   489
      apply (auto simp add: leastP_def setge_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   490
      apply (erule allE[where x=n])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   491
      apply (erule allE[where x=m])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   492
      by simp}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   493
  ultimately show ?thesis by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   494
qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   495
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   496
lemma fps_eq_least_unique: assumes ab: "(a::('a::ab_group_add) fps) \<noteq> b"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   497
  shows "\<exists>! n. leastP (\<lambda>n. a$n \<noteq> b$n) n"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   498
using fps_nonzero_least_unique[of "a - b"] ab
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   499
by auto
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   500
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   501
instantiation fps :: (comm_ring_1) metric_space
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   502
begin
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   503
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   504
definition open_fps_def: "open (S :: 'a fps set) = (\<forall>a \<in> S. \<exists>r. r >0 \<and> ball a r \<subseteq> S)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   505
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   506
instance
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   507
proof
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   508
  fix S :: "'a fps set" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   509
  show "open S = (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   510
    by (auto simp add: open_fps_def ball_def subset_eq)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   511
next
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   512
{  fix a b :: "'a fps"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   513
  {assume ab: "a = b"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   514
   then have "\<not> (\<exists>n. a$n \<noteq> b$n)" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   515
   then have "dist a b = 0" by (simp add: dist_fps_def)}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   516
 moreover
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   517
 {assume d: "dist a b = 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   518
   then have "\<forall>n. a$n = b$n" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   519
     by - (rule ccontr, simp add: dist_fps_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   520
   then have "a = b" by (simp add: fps_eq_iff)}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   521
 ultimately show "dist a b =0 \<longleftrightarrow> a = b" by blast}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   522
note th = this
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   523
from th have th'[simp]: "\<And>a::'a fps. dist a a = 0" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   524
  fix a b c :: "'a fps"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   525
  {assume ab: "a = b" then have d0: "dist a b = 0"  unfolding th .
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   526
    then have "dist a b \<le> dist a c + dist b c" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   527
      using dist_fps_ge0[of a c] dist_fps_ge0[of b c] by simp}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   528
  moreover
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   529
  {assume c: "c = a \<or> c = b" then have "dist a b \<le> dist a c + dist b c"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   530
      by (cases "c=a", simp_all add: th dist_fps_sym) }
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   531
  moreover
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   532
  {assume ab: "a \<noteq> b" and ac: "a \<noteq> c" and bc: "b \<noteq> c"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   533
    let ?P = "\<lambda>a b n. a$n \<noteq> b$n"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   534
    from fps_eq_least_unique[OF ab] fps_eq_least_unique[OF ac] 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   535
      fps_eq_least_unique[OF bc]
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   536
    obtain nab nac nbc where nab: "leastP (?P a b) nab" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   537
      and nac: "leastP (?P a c) nac" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   538
      and nbc: "leastP (?P b c) nbc" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   539
    from nab have nab': "\<And>m. m < nab \<Longrightarrow> a$m = b$m" "a$nab \<noteq> b$nab"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   540
      by (auto simp add: leastP_def setge_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   541
    from nac have nac': "\<And>m. m < nac \<Longrightarrow> a$m = c$m" "a$nac \<noteq> c$nac"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   542
      by (auto simp add: leastP_def setge_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   543
    from nbc have nbc': "\<And>m. m < nbc \<Longrightarrow> b$m = c$m" "b$nbc \<noteq> c$nbc"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   544
      by (auto simp add: leastP_def setge_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   545
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   546
    have th0: "\<And>(a::'a fps) b. a \<noteq> b \<longleftrightarrow> (\<exists>n. a$n \<noteq> b$n)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   547
      by (simp add: fps_eq_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   548
    from ab ac bc nab nac nbc 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   549
    have dab: "dist a b = inverse (2 ^ nab)" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   550
      and dac: "dist a c = inverse (2 ^ nac)" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   551
      and dbc: "dist b c = inverse (2 ^ nbc)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   552
      unfolding th0
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   553
      apply (simp_all add: dist_fps_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   554
      apply (erule the1_equality[OF fps_eq_least_unique[OF ab]])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   555
      apply (erule the1_equality[OF fps_eq_least_unique[OF ac]])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   556
      by (erule the1_equality[OF fps_eq_least_unique[OF bc]])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   557
    from ab ac bc have nz: "dist a b \<noteq> 0" "dist a c \<noteq> 0" "dist b c \<noteq> 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   558
      unfolding th by simp_all
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   559
    from nz have pos: "dist a b > 0" "dist a c > 0" "dist b c > 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   560
      using dist_fps_ge0[of a b] dist_fps_ge0[of a c] dist_fps_ge0[of b c] 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   561
      by auto
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   562
    have th1: "\<And>n. (2::real)^n >0" by auto
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   563
    {assume h: "dist a b > dist a c + dist b c"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   564
      then have gt: "dist a b > dist a c" "dist a b > dist b c"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   565
	using pos by auto
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   566
      from gt have gtn: "nab < nbc" "nab < nac"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   567
	unfolding dab dbc dac by (auto simp add: th1)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   568
      from nac'(1)[OF gtn(2)] nbc'(1)[OF gtn(1)]
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   569
      have "a$nab = b$nab" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   570
      with nab'(2) have False  by simp}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   571
    then have "dist a b \<le> dist a c + dist b c"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   572
      by (auto simp add: not_le[symmetric]) }
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   573
  ultimately show "dist a b \<le> dist a c + dist b c" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   574
qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   575
  
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   576
end
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   577
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   578
text{* The infinite sums and justification of the notation in textbooks*}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   579
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   580
lemma reals_power_lt_ex: assumes xp: "x > 0" and y1: "(y::real) > 1"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   581
  shows "\<exists>k>0. (1/y)^k < x"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   582
proof-
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   583
  have yp: "y > 0" using y1 by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   584
  from reals_Archimedean2[of "max 0 (- log y x) + 1"]
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   585
  obtain k::nat where k: "real k > max 0 (- log y x) + 1" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   586
  from k have kp: "k > 0" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   587
  from k have "real k > - log y x" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   588
  then have "ln y * real k > - ln x" unfolding log_def
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   589
    using ln_gt_zero_iff[OF yp] y1
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   590
    by (simp add: minus_divide_left field_simps del:minus_divide_left[symmetric] )
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   591
  then have "ln y * real k + ln x > 0" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   592
  then have "exp (real k * ln y + ln x) > exp 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   593
    by (simp add: mult_ac)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   594
  then have "y ^ k * x > 1"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   595
    unfolding exp_zero exp_add exp_real_of_nat_mult
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   596
    exp_ln[OF xp] exp_ln[OF yp] by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   597
  then have "x > (1/y)^k" using yp 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   598
    by (simp add: field_simps nonzero_power_divide )
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   599
  then show ?thesis using kp by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   600
qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   601
lemma X_nth[simp]: "X$n = (if n = 1 then 1 else 0)" by (simp add: X_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   602
lemma X_power_nth[simp]: "(X^k) $n = (if n = k then 1 else (0::'a::comm_ring_1))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   603
  by (simp add: X_power_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   604
 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   605
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   606
lemma fps_sum_rep_nth: "(setsum (%i. fps_const(a$i)*X^i) {0..m})$n = (if n \<le> m then a$n else (0::'a::comm_ring_1))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   607
  apply (auto simp add: fps_eq_iff fps_setsum_nth X_power_nth cond_application_beta cond_value_iff  cong del: if_weak_cong)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   608
  by (simp add: setsum_delta')
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   609
  
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   610
lemma fps_notation: 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   611
  "(%n. setsum (%i. fps_const(a$i) * X^i) {0..n}) ----> a" (is "?s ----> a")
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   612
proof-
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   613
    {fix r:: real
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   614
      assume rp: "r > 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   615
      have th0: "(2::real) > 1" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   616
      from reals_power_lt_ex[OF rp th0] 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   617
      obtain n0 where n0: "(1/2)^n0 < r" "n0 > 0" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   618
      {fix n::nat
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   619
	assume nn0: "n \<ge> n0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   620
	then have thnn0: "(1/2)^n <= (1/2 :: real)^n0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   621
	  by (auto intro: power_decreasing)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   622
	{assume "?s n = a" then have "dist (?s n) a < r" 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   623
	    unfolding dist_eq_0_iff[of "?s n" a, symmetric]
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   624
	    using rp by (simp del: dist_eq_0_iff)}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   625
	moreover
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   626
	{assume neq: "?s n \<noteq> a"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   627
	  from fps_eq_least_unique[OF neq] 
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   628
	  obtain k where k: "leastP (\<lambda>i. ?s n $ i \<noteq> a$i) k" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   629
	  have th0: "\<And>(a::'a fps) b. a \<noteq> b \<longleftrightarrow> (\<exists>n. a$n \<noteq> b$n)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   630
	    by (simp add: fps_eq_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   631
	  from neq have dth: "dist (?s n) a = (1/2)^k"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   632
	    unfolding th0 dist_fps_def
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   633
	    unfolding the1_equality[OF fps_eq_least_unique[OF neq], OF k]
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   634
	    by (auto simp add: inverse_eq_divide power_divide)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   635
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   636
	  from k have kn: "k > n"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   637
	    apply (simp add: leastP_def setge_def fps_sum_rep_nth)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   638
	    by (cases "k \<le> n", auto)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   639
	  then have "dist (?s n) a < (1/2)^n" unfolding dth
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   640
	    by (auto intro: power_strict_decreasing)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   641
	  also have "\<dots> <= (1/2)^n0" using nn0
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   642
	    by (auto intro: power_decreasing)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   643
	  also have "\<dots> < r" using n0 by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   644
	  finally have "dist (?s n) a < r" .}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   645
	ultimately have "dist (?s n) a < r" by blast}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   646
      then have "\<exists>n0. \<forall> n \<ge> n0. dist (?s n) a < r " by blast}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   647
    then show ?thesis  unfolding  LIMSEQ_def by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   648
  qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   649
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   650
subsection{* Inverses of formal power series *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   651
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   652
declare setsum_cong[fundef_cong]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   653
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   654
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   655
instantiation fps :: ("{comm_monoid_add,inverse, times, uminus}") inverse
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   656
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   657
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   658
fun natfun_inverse:: "'a fps \<Rightarrow> nat \<Rightarrow> 'a" where
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   659
  "natfun_inverse f 0 = inverse (f$0)"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   660
| "natfun_inverse f n = - inverse (f$0) * setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   661
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   662
definition fps_inverse_def:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   663
  "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
   664
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
   665
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   666
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   667
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   668
lemma fps_inverse_zero[simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   669
  "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
   670
  by (simp add: fps_ext fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   671
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   672
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
   673
  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
   674
  by (case_tac n, auto)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   675
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   676
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
   677
  by default (rule fps_inverse_zero)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   678
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   679
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
   680
  shows "inverse f * f = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   681
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   682
  have c: "inverse f * f = f * inverse f" by (simp add: mult_commute)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   683
  from f0 have ifn: "\<And>n. inverse f $ n = natfun_inverse f n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   684
    by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   685
  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
   686
    by (simp add: fps_mult_nth fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   687
  {fix n::nat assume np: "n >0 "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   688
    from np have eq: "{0..n} = {0} \<union> {1 .. n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   689
    have d: "{0} \<inter> {1 .. n} = {}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   690
    have f: "finite {0::nat}" "finite {1..n}" by auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   691
    from f0 np have th0: "- (inverse f$n) =
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   692
      (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
   693
      by (cases n, simp, simp add: divide_inverse fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   694
    from th0[symmetric, unfolded nonzero_divide_eq_eq[OF f0]]
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   695
    have th1: "setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n} =
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   696
      - (f$0) * (inverse f)$n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   697
      by (simp add: ring_simps)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   698
    have "(f * inverse f) $ n = (\<Sum>i = 0..n. f $i * natfun_inverse f (n - i))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   699
      unfolding fps_mult_nth ifn ..
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   700
    also have "\<dots> = f$0 * natfun_inverse f n
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   701
      + (\<Sum>i = 1..n. f$i * natfun_inverse f (n-i))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   702
      unfolding setsum_Un_disjoint[OF f d, unfolded eq[symmetric]]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   703
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   704
    also have "\<dots> = 0" unfolding th1 ifn by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   705
    finally have "(inverse f * f)$n = 0" unfolding c . }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   706
  with th0 show ?thesis by (simp add: fps_eq_iff)
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_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
   710
  by (simp add: fps_inverse_def nonzero_imp_inverse_nonzero)
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_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
   713
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   714
  {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
   715
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   716
  {assume h: "inverse f = 0" and c: "f $0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   717
    from inverse_mult_eq_1[OF c] h have False by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   718
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   719
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   720
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   721
lemma fps_inverse_idempotent[intro]: assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   722
  shows "inverse (inverse f) = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   723
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   724
  from f0 have if0: "inverse f $ 0 \<noteq> 0" by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   725
  from inverse_mult_eq_1[OF f0] inverse_mult_eq_1[OF if0]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   726
  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
   727
  then show ?thesis using f0 unfolding mult_cancel_left by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   728
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   729
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   730
lemma fps_inverse_unique: assumes f0: "f$0 \<noteq> (0::'a::field)" and fg: "f*g = 1"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   731
  shows "inverse f = g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   732
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   733
  from inverse_mult_eq_1[OF f0] fg
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   734
  have th0: "inverse f * f = g * f" by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   735
  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
   736
    by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   737
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   738
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   739
lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field)))
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   740
  = 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
   741
  apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   742
  apply simp
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   743
  apply (simp add: fps_eq_iff fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   744
proof(clarsimp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   745
  fix n::nat assume n: "n > 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   746
  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
   747
  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
   748
  let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   749
  have th1: "setsum ?f {0..n} = setsum ?g {0..n}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   750
    by (rule setsum_cong2) auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   751
  have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   752
    using n apply - by (rule setsum_cong2) auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   753
  have eq: "{0 .. n} = {0.. n - 1} \<union> {n}" by auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   754
  from n have d: "{0.. n - 1} \<inter> {n} = {}" by auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   755
  have f: "finite {0.. n - 1}" "finite {n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   756
  show "setsum ?f {0..n} = 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   757
    unfolding th1
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   758
    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
   759
    unfolding th2
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   760
    by(simp add: setsum_delta)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   761
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   762
29912
f4ac160d2e77 fix spelling
huffman
parents: 29911
diff changeset
   763
subsection{* Formal Derivatives, and the MacLaurin theorem around 0*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   764
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   765
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
   766
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   767
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
   768
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   769
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
   770
  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
   771
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   772
lemma fps_deriv_mult[simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   773
  fixes f :: "('a :: comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   774
  shows "fps_deriv (f * g) = f * fps_deriv g + fps_deriv f * g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   775
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   776
  let ?D = "fps_deriv"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   777
  {fix n::nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   778
    let ?Zn = "{0 ..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   779
    let ?Zn1 = "{0 .. n + 1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   780
    let ?f = "\<lambda>i. i + 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   781
    have fi: "inj_on ?f {0..n}" by (simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   782
    have eq: "{1.. n+1} = ?f ` {0..n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   783
    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
   784
        of_nat (i+1)* f $ (i+1) * g $ (n - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   785
    let ?h = "\<lambda>i. of_nat i * g $ i * f $ ((n+1) - i) +
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   786
        of_nat i* f $ i * g $ ((n + 1) - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   787
    {fix k assume k: "k \<in> {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   788
      have "?h (k + 1) = ?g k" using k by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   789
    note th0 = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   790
    have eq': "{0..n +1}- {1 .. n+1} = {0}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   791
    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
   792
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   793
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   794
      apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   795
      apply (rule set_ext)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   796
      apply (presburger add: image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   797
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   798
    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
   799
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   800
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   801
      apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   802
      apply (rule set_ext)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   803
      apply (presburger add: image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   804
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   805
    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
   806
    also have "\<dots> = (\<Sum>i = 0..n. ?g i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   807
      by (simp add: fps_mult_nth setsum_addf[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   808
    also have "\<dots> = setsum ?h {1..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   809
      using th0 setsum_reindex_cong[OF fi eq, of "?g" "?h"] by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   810
    also have "\<dots> = setsum ?h {0..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   811
      apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   812
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   813
      apply (simp add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   814
      unfolding eq'
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   815
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   816
    also have "\<dots> = (fps_deriv (f * g)) $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   817
      apply (simp only: fps_deriv_nth fps_mult_nth setsum_addf)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   818
      unfolding s0 s1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   819
      unfolding setsum_addf[symmetric] setsum_right_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   820
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   821
      by (auto simp add: of_nat_diff ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   822
    finally have "(f * ?D g + ?D f * g) $ n = ?D (f*g) $ n" .}
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   823
  then show ?thesis unfolding fps_eq_iff by auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   824
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   825
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   826
lemma fps_deriv_X[simp]: "fps_deriv X = 1"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   827
  by (simp add: fps_deriv_def X_def fps_eq_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   828
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   829
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
   830
  by (simp add: fps_eq_iff fps_deriv_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   831
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
   832
  using fps_deriv_linear[of 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   833
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   834
lemma fps_deriv_sub[simp]: "fps_deriv ((f:: ('a::comm_ring_1) fps) - g) = fps_deriv f - fps_deriv g"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   835
  unfolding diff_minus by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   836
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   837
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
   838
  by (simp add: fps_ext fps_deriv_def fps_const_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   839
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   840
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
   841
  by simp
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_deriv_0[simp]: "fps_deriv 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   844
  by (simp add: fps_deriv_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   845
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   846
lemma fps_deriv_1[simp]: "fps_deriv 1 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   847
  by (simp add: fps_deriv_def fps_eq_iff )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   848
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   849
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
   850
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   851
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   852
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
   853
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   854
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   855
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   856
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   857
    have ?thesis  by (induct rule: finite_induct[OF fS], simp_all)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   858
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   859
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   860
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   861
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
   862
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   863
  {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
   864
    hence "fps_deriv f = 0" by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   865
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   866
  {assume z: "fps_deriv f = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   867
    hence "\<forall>n. (fps_deriv f)$n = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   868
    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
   869
    hence "f = fps_const (f$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   870
      apply (clarsimp simp add: fps_eq_iff fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   871
      apply (erule_tac x="n - 1" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   872
      by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   873
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   874
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   875
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   876
lemma fps_deriv_eq_iff:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   877
  fixes f:: "('a::{idom,semiring_char_0}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   878
  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
   879
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   880
  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
   881
  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
   882
  finally show ?thesis by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   883
qed
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 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
   886
  apply auto unfolding fps_deriv_eq_iff by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   887
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   888
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   889
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
   890
  "fps_nth_deriv 0 f = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   891
| "fps_nth_deriv (Suc n) f = fps_nth_deriv n (fps_deriv f)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   892
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   893
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
   894
  by (induct n arbitrary: f, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   895
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   896
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
   897
  by (induct n arbitrary: f g, auto simp add: fps_nth_deriv_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   898
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   899
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
   900
  by (induct n arbitrary: f, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   901
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   902
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
   903
  using fps_nth_deriv_linear[of n 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   904
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   905
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"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   906
  unfolding diff_minus fps_nth_deriv_add by simp
29687
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 fps_nth_deriv_0[simp]: "fps_nth_deriv n 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   909
  by (induct n, simp_all )
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 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
   912
  by (induct n, simp_all )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   913
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   914
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
   915
  by (cases n, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   916
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   917
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
   918
  using fps_nth_deriv_linear[of n "c" f 0 0 ] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   919
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   920
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
   921
  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
   922
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   923
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
   924
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   925
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   926
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   927
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   928
    have ?thesis  by (induct rule: finite_induct[OF fS], simp_all)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   929
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   930
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   931
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   932
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
   933
  by (induct k arbitrary: f) (auto simp add: ring_simps of_nat_mult)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   934
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   935
subsection {* Powers*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   936
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   937
lemma fps_power_zeroth_eq_one: "a$0 =1 \<Longrightarrow> a^n $ 0 = (1::'a::semiring_1)"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   938
  by (induct n, auto simp add: expand_fps_eq fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   939
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   940
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
   941
proof(induct n)
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   942
  case 0 thus ?case by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   943
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   944
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   945
  note h = Suc.hyps[OF `a$0 = 1`]
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   946
  show ?case unfolding power_Suc fps_mult_nth
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   947
    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
   948
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   949
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   950
lemma startsby_one_power:"a $ 0 = (1::'a::comm_ring_1) \<Longrightarrow> a^n $ 0 = 1"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   951
  by (induct n, auto simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   952
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   953
lemma startsby_zero_power:"a $0 = (0::'a::comm_ring_1) \<Longrightarrow> n > 0 \<Longrightarrow> a^n $0 = 0"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   954
  by (induct n, auto simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   955
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
   956
lemma startsby_power:"a $0 = (v::'a::{comm_ring_1}) \<Longrightarrow> a^n $0 = v^n"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   957
  by (induct n, auto simp add: fps_mult_nth power_Suc)
29687
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 startsby_zero_power_iff[simp]:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
   960
  "a^n $0 = (0::'a::{idom}) \<longleftrightarrow> (n \<noteq> 0 \<and> a$0 = 0)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   961
apply (rule iffI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   962
apply (induct n, auto simp add: power_Suc fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   963
by (rule startsby_zero_power, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   964
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   965
lemma startsby_zero_power_prefix:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   966
  assumes a0: "a $0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   967
  shows "\<forall>n < k. a ^ k $ n = 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   968
  using a0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   969
proof(induct k rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   970
  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
   971
  let ?ths = "\<forall>m<k. a ^ k $ m = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   972
  {assume "k = 0" then have ?ths by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   973
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   974
  {fix l assume k: "k = Suc l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   975
    {fix m assume mk: "m < k"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   976
      {assume "m=0" hence "a^k $ m = 0" using startsby_zero_power[of a k] k a0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   977
	  by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   978
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   979
      {assume m0: "m \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   980
	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
   981
	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
   982
	also have "\<dots> = 0" apply (rule setsum_0')
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   983
	  apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   984
	  apply (case_tac "aa = m")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   985
	  using a0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   986
	  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   987
	  apply (rule H[rule_format])
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   988
	  using a0 k mk by auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   989
	finally have "a^k $ m = 0" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   990
    ultimately have "a^k $ m = 0" by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   991
    hence ?ths by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   992
  ultimately show ?ths by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   993
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   994
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   995
lemma startsby_zero_setsum_depends:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   996
  assumes a0: "a $0 = (0::'a::idom)" and kn: "n \<ge> k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   997
  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
   998
  apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   999
  using kn apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1000
  apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1001
  by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1002
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1003
lemma startsby_zero_power_nth_same: assumes a0: "a$0 = (0::'a::{idom})"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1004
  shows "a^n $ n = (a$1) ^ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1005
proof(induct n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1006
  case 0 thus ?case by (simp add: power_0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1007
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1008
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1009
  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
  1010
  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
  1011
  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
  1012
    apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1013
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1014
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1015
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1016
    apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1017
    apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1018
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1019
  also have "\<dots> = a^n $ n * a$1" using a0 by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1020
  finally show ?case using Suc.hyps by (simp add: power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1021
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1022
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1023
lemma fps_inverse_power:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1024
  fixes a :: "('a::{field}) fps"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1025
  shows "inverse (a^n) = inverse a ^ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1026
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1027
  {assume a0: "a$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1028
    hence eq: "inverse a = 0" by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1029
    {assume "n = 0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1030
    moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1031
    {assume n: "n > 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1032
      from startsby_zero_power[OF a0 n] eq a0 n have ?thesis
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1033
	by (simp add: fps_inverse_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1034
    ultimately have ?thesis by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1035
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1036
  {assume a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1037
    have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1038
      apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1039
      apply (simp add: a0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1040
      unfolding power_mult_distrib[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1041
      apply (rule ssubst[where t = "a * inverse a" and s= 1])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1042
      apply simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1043
      apply (subst mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1044
      by (rule inverse_mult_eq_1[OF a0])}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1045
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1046
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1047
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1048
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
  1049
  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
  1050
  by (case_tac n, auto simp add: power_Suc ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1051
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1052
lemma fps_inverse_deriv:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1053
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1054
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1055
  shows "fps_deriv (inverse a) = - fps_deriv a * inverse a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1056
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1057
  from inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1058
  have "fps_deriv (inverse a * a) = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1059
  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
  1060
  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
  1061
  with inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1062
  have "inverse a ^ 2 * fps_deriv a + fps_deriv (inverse a) = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1063
    unfolding power2_eq_square
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1064
    apply (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1065
    by (simp add: mult_assoc[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1066
  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
  1067
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1068
  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
  1069
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1070
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1071
lemma fps_inverse_mult:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1072
  fixes a::"('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1073
  shows "inverse (a * b) = inverse a * inverse b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1074
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1075
  {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
  1076
    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
  1077
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1078
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1079
  {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
  1080
    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
  1081
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1082
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1083
  {assume a0: "a$0 \<noteq> 0" and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1084
    from a0 b0 have ab0:"(a*b) $ 0 \<noteq> 0" by (simp  add: fps_mult_nth)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1085
    from inverse_mult_eq_1[OF ab0]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1086
    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
  1087
    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
  1088
      by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1089
    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
  1090
ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1091
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1092
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1093
lemma fps_inverse_deriv':
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1094
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1095
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1096
  shows "fps_deriv (inverse a) = - fps_deriv a / a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1097
  using fps_inverse_deriv[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1098
  unfolding power2_eq_square fps_divide_def
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1099
    fps_inverse_mult by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1100
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1101
lemma inverse_mult_eq_1': assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1102
  shows "f * inverse f= 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1103
  by (metis mult_commute inverse_mult_eq_1 f0)
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 fps_divide_deriv:   fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1106
  assumes a0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1107
  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
  1108
  using fps_inverse_deriv[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1109
  by (simp add: fps_divide_def ring_simps power2_eq_square fps_inverse_mult inverse_mult_eq_1'[OF a0])
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1110
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1111
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1112
lemma fps_inverse_gp': "inverse (Abs_fps(\<lambda>n. (1::'a::field)))
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1113
  = 1 - X"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  1114
  by (simp add: fps_inverse_gp fps_eq_iff X_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1115
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1116
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
  1117
  by (cases "n", simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1118
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1119
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1120
lemma fps_inverse_X_plus1:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1121
  "inverse (1 + X) = Abs_fps (\<lambda>n. (- (1::'a::{field})) ^ n)" (is "_ = ?r")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1122
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1123
  have eq: "(1 + X) * ?r = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1124
    unfolding minus_one_power_iff
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31075
diff changeset
  1125
    by (auto simp add: ring_simps fps_eq_iff)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1126
  show ?thesis by (auto simp add: eq intro: fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1127
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1128
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1129
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1130
subsection{* Integration *}
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1131
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1132
definition
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1133
  fps_integral :: "'a::field_char_0 fps \<Rightarrow> 'a \<Rightarrow> 'a fps" where
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1134
  "fps_integral a a0 = Abs_fps (\<lambda>n. if n = 0 then a0 else (a$(n - 1) / of_nat n))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1135
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1136
lemma fps_deriv_fps_integral: "fps_deriv (fps_integral a a0) = a"
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1137
  unfolding fps_integral_def fps_deriv_def
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1138
  by (simp add: fps_eq_iff del: of_nat_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1139
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1140
lemma fps_integral_linear:
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1141
  "fps_integral (fps_const a * f + fps_const b * g) (a*a0 + b*b0) =
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1142
    fps_const a * fps_integral f a0 + fps_const b * fps_integral g b0"
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1143
  (is "?l = ?r")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1144
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1145
  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
  1146
  moreover have "?l$0 = ?r$0" by (simp add: fps_integral_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1147
  ultimately show ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1148
    unfolding fps_deriv_eq_iff by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1149
qed
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1150
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1151
subsection {* Composition of FPSs *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1152
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
  1153
  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
  1154
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1155
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
  1156
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1157
lemma fps_compose_X[simp]: "a oo X = (a :: ('a :: comm_ring_1) fps)"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1158
  by (simp add: fps_ext fps_compose_def mult_delta_right setsum_delta')
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1159
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1160
lemma fps_const_compose[simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1161
  "fps_const (a::'a::{comm_ring_1}) oo b = fps_const (a)"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1162
  by (simp add: fps_eq_iff fps_compose_nth mult_delta_left setsum_delta)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1163
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  1164
lemma number_of_compose[simp]: "(number_of k::('a::{comm_ring_1}) fps) oo b = number_of k"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  1165
  unfolding number_of_fps_const by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  1166
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1167
lemma X_fps_compose_startby0[simp]: "a$0 = 0 \<Longrightarrow> X oo a = (a :: ('a :: comm_ring_1) fps)"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1168
  by (simp add: fps_eq_iff fps_compose_def mult_delta_left setsum_delta
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1169
                power_Suc not_le)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1170
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1171
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1172
subsection {* Rules from Herbert Wilf's Generatingfunctionology*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1173
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1174
subsubsection {* Rule 1 *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1175
  (* {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
  1176
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1177
lemma fps_power_mult_eq_shift:
30992
3b143758dfe9 more general statements
chaieb
parents: 30837
diff changeset
  1178
  "X^Suc k * Abs_fps (\<lambda>n. a (n + Suc k)) = Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a:: comm_ring_1) * X^i) {0 .. k}" (is "?lhs = ?rhs")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1179
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1180
  {fix n:: nat
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1181
    have "?lhs $ n = (if n < Suc k then 0 else a n)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1182
      unfolding X_power_mult_nth by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1183
    also have "\<dots> = ?rhs $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1184
    proof(induct k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1185
      case 0 thus ?case by (simp add: fps_setsum_nth power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1186
    next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1187
      case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1188
      note th = Suc.hyps[symmetric]
30992
3b143758dfe9 more general statements
chaieb
parents: 30837
diff changeset
  1189
      have "(Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a) * X^i) {0 .. Suc k})$n = (Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a) * X^i) {0 .. k} - fps_const (a (Suc k)) * X^ Suc k) $ n" by (simp add: ring_simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1190
      also  have "\<dots> = (if n < Suc k then 0 else a n) - (fps_const (a (Suc k)) * X^ Suc k)$n"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1191
	using th
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1192
	unfolding fps_sub_nth by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1193
      also have "\<dots> = (if n < Suc (Suc k) then 0 else a n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1194
	unfolding X_power_mult_right_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1195
	apply (auto simp add: not_less fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1196
	apply (rule cong[of a a, OF refl])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1197
	by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1198
      finally show ?case by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1199
    qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1200
    finally have "?lhs $ n = ?rhs $ n"  .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1201
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1202
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1203
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1204
subsubsection{* Rule 2*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1205
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1206
  (* We can not reach the form of Wilf, but still near to it using rewrite rules*)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1207
  (* If f reprents {a_n} and P is a polynomial, then
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1208
        P(xD) f represents {P(n) a_n}*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1209
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1210
definition "XD = op * X o fps_deriv"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1211
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1212
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
  1213
  by (simp add: XD_def ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1214
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1215
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
  1216
  by (simp add: XD_def ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1217
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1218
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
  1219
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1220
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 30837
diff changeset
  1221
lemma XDN_linear:
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30960
diff changeset
  1222
  "(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
  1223
  by (induct n, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1224
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1225
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
  1226
30994
chaieb
parents: 30971 30992
diff changeset
  1227
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 30837
diff changeset
  1228
lemma fps_mult_XD_shift:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1229
  "(XD ^^ k) (a:: ('a::{comm_ring_1}) fps) = Abs_fps (\<lambda>n. (of_nat n ^ k) * a$n)"
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 30837
diff changeset
  1230
  by (induct k arbitrary: a) (simp_all add: power_Suc XD_def fps_eq_iff ring_simps del: One_nat_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1231
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1232
subsubsection{* Rule 3 is trivial and is given by @{text fps_times_def}*}
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1233
subsubsection{* Rule 5 --- summation and "division" by (1 - X)*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1234
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1235
lemma fps_divide_X_minus1_setsum_lemma:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1236
  "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
  1237
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1238
  let ?X = "X::('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1239
  let ?sa = "Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1240
  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
  1241
  {fix n:: nat
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1242
    {assume "n=0" hence "a$n = ((1 - ?X) * ?sa) $ n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1243
	by (simp add: fps_mult_nth)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1244
    moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1245
    {assume n0: "n \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1246
      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
  1247
	"{0..n - 1}\<union>{n} = {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1248
	apply (simp_all add: expand_set_eq) by presburger+
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1249
      have d: "{0} \<inter> ({1} \<union> {2..n}) = {}" "{1} \<inter> {2..n} = {}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1250
	"{0..n - 1}\<inter>{n} ={}" using n0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1251
	by (simp_all add: expand_set_eq, presburger+)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1252
      have f: "finite {0}" "finite {1}" "finite {2 .. n}"
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1253
	"finite {0 .. n - 1}" "finite {n}" by simp_all
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1254
    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
  1255
      by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1256
    also have "\<dots> = a$n" unfolding th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1257
      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
  1258
      unfolding setsum_Un_disjoint[OF f(2) f(3) d(2)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1259
      apply (simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1260
      unfolding setsum_Un_disjoint[OF f(4,5) d(3), unfolded u(3)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1261
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1262
    finally have "a$n = ((1 - ?X) * ?sa) $ n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1263
  ultimately have "a$n = ((1 - ?X) * ?sa) $ n" by blast}
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1264
then show ?thesis
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1265
  unfolding fps_eq_iff by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1266
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1267
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1268
lemma fps_divide_X_minus1_setsum:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1269
  "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
  1270
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1271
  let ?X = "1 - (X::('a::field) fps)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1272
  have th0: "?X $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1273
  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
  1274
    using fps_divide_X_minus1_setsum_lemma[of a, symmetric] th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1275
    by (simp add: fps_divide_def mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1276
  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
  1277
    by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1278
  finally show ?thesis by (simp add: inverse_mult_eq_1[OF th0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1279
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1280
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1281
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
  1282
  finite product of FPS, also the relvant instance of powers of a FPS*}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1283
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1284
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
  1285
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1286
lemma natlist_trivial_1: "natpermute n 1 = {[n]}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1287
  apply (auto simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1288
  apply (case_tac x, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1289
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1290
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1291
lemma foldl_add_start0:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1292
  "foldl op + x xs = x + foldl op + (0::nat) xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1293
  apply (induct xs arbitrary: x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1294
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1295
  unfolding foldl.simps
4d934a895d11 A formalization o