src/HOL/Library/Formal_Power_Series.thy
author huffman
Sat, 14 Feb 2009 15:30:26 -0800
changeset 29913 89eadbe71e97
parent 29912 f4ac160d2e77
child 29914 c9ced4f54e82
permissions -rw-r--r--
add mult_delta lemmas; simplify some proofs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     1
(*  Title:      Formal_Power_Series.thy
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     2
    ID:         
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     3
    Author:     Amine Chaieb, University of Cambridge
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     4
*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     5
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     6
header{* A formalization of formal power series *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     7
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     8
theory Formal_Power_Series
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     9
  imports Main Fact Parity
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    10
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    11
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
    12
subsection {* The type of formal power series*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    13
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    14
typedef (open) 'a fps = "{f :: nat \<Rightarrow> 'a. True}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    15
  morphisms fps_nth Abs_fps
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    16
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    17
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    18
notation fps_nth (infixl "$" 75)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    19
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    20
lemma expand_fps_eq: "p = q \<longleftrightarrow> (\<forall>n. p $ n = q $ n)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    21
  by (simp add: fps_nth_inject [symmetric] expand_fun_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    22
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    23
lemma fps_ext: "(\<And>n. p $ n = q $ n) \<Longrightarrow> p = q"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    24
  by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    25
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    26
lemma fps_nth_Abs_fps [simp]: "Abs_fps f $ n = f n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    27
  by (simp add: Abs_fps_inverse)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    28
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    29
text{* Definition of the basic elements 0 and 1 and the basic operations of addition, negation and multiplication *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    30
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    31
instantiation fps :: (zero)  zero
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    32
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    33
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    34
definition fps_zero_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    35
  "0 = Abs_fps (\<lambda>n. 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    36
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    37
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    38
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    39
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    40
lemma fps_zero_nth [simp]: "0 $ n = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    41
  unfolding fps_zero_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    42
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    43
instantiation fps :: ("{one,zero}")  one
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    44
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    45
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    46
definition fps_one_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    47
  "1 = Abs_fps (\<lambda>n. if n = 0 then 1 else 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    48
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    49
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    50
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    51
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    52
lemma fps_one_nth [simp]: "1 $ n = (if n = 0 then 1 else 0)" 
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    53
  unfolding fps_one_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    54
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    55
instantiation fps :: (plus)  plus
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    56
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    57
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    58
definition fps_plus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    59
  "op + = (\<lambda>f g. Abs_fps (\<lambda>n. f $ n + g $ n))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    60
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    61
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    62
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    63
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    64
lemma fps_add_nth [simp]: "(f + g) $ n = f $ n + g $ n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    65
  unfolding fps_plus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    66
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    67
instantiation fps :: (minus) minus
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    68
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    69
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    70
definition fps_minus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    71
  "op - = (\<lambda>f g. Abs_fps (\<lambda>n. f $ n - g $ n))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    72
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    73
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    74
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    75
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    76
lemma fps_sub_nth [simp]: "(f - g) $ n = f $ n - g $ n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    77
  unfolding fps_minus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    78
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    79
instantiation fps :: (uminus) uminus
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    80
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    81
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    82
definition fps_uminus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    83
  "uminus = (\<lambda>f. Abs_fps (\<lambda>n. - (f $ n)))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    84
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    85
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    86
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    87
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    88
lemma fps_neg_nth [simp]: "(- f) $ n = - (f $ n)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    89
  unfolding fps_uminus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    90
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    91
instantiation fps :: ("{comm_monoid_add, times}")  times
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    92
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    93
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    94
definition fps_times_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    95
  "op * = (\<lambda>f g. Abs_fps (\<lambda>n. \<Sum>i=0..n. f $ i * g $ (n - i)))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    96
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    97
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    98
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    99
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   100
lemma fps_mult_nth: "(f * g) $ n = (\<Sum>i=0..n. f$i * g$(n - i))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   101
  unfolding fps_times_def by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   102
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   103
declare atLeastAtMost_iff[presburger]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   104
declare Bex_def[presburger]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   105
declare Ball_def[presburger]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   106
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
29906
80369da39838 section -> subsection
huffman
parents: 29692
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
4d934a895d11 A formalization of formal power series
chaieb
parents:
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)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   333
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   334
lemma fps_const_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
   335
  by (simp add: fps_eq_iff fps_mult_nth setsum_0')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   336
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   337
lemma fps_const_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
   338
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   339
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   340
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
   341
  by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   342
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   343
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
   344
  unfolding fps_eq_iff fps_mult_nth
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   345
  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
   346
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   347
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
   348
  unfolding fps_eq_iff fps_mult_nth
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   349
  by (simp add: fps_const_def mult_delta_right setsum_delta')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   350
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   351
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
   352
  by (simp add: fps_mult_nth mult_delta_left setsum_delta)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   353
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   354
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
   355
  by (simp add: fps_mult_nth mult_delta_right setsum_delta')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   356
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   357
subsection {* Formal power series form an integral domain*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   358
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   359
instance fps :: (ring) ring ..
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   360
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   361
instance fps :: (ring_1) ring_1
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   362
  by (intro_classes, auto simp add: diff_minus left_distrib)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   363
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   364
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
   365
  by (intro_classes, auto simp add: diff_minus left_distrib)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   366
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   367
instance fps :: (ring_no_zero_divisors) ring_no_zero_divisors
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   368
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   369
  fix a b :: "'a fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   370
  assume a0: "a \<noteq> 0" and b0: "b \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   371
  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
   372
    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
   373
    by blast+
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   374
  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
   375
    by (rule fps_mult_nth)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   376
  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
   377
    by (rule setsum_diff1') simp_all
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   378
  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
   379
    proof (rule setsum_0' [rule_format])
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   380
      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
   381
      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
   382
      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
   383
    qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   384
  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
   385
  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
   386
  finally have "(a*b) $ (i+j) \<noteq> 0" .
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   387
  then show "a*b \<noteq> 0" unfolding fps_nonzero_nth by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   388
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   389
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   390
instance fps :: (idom) idom ..
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   391
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   392
subsection{* Inverses of formal power series *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   393
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   394
declare setsum_cong[fundef_cong]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   395
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   396
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   397
instantiation fps :: ("{comm_monoid_add,inverse, times, uminus}") inverse
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   398
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   399
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   400
fun natfun_inverse:: "'a fps \<Rightarrow> nat \<Rightarrow> 'a" where 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   401
  "natfun_inverse f 0 = inverse (f$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   402
| "natfun_inverse f n = - inverse (f$0) * setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   403
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   404
definition fps_inverse_def: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   405
  "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
   406
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
   407
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   408
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   409
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   410
lemma fps_inverse_zero[simp]: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   411
  "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
   412
  by (simp add: fps_ext fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   413
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   414
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
   415
  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
   416
  by (case_tac n, auto)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   417
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   418
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
   419
  by default (rule fps_inverse_zero)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   420
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   421
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
   422
  shows "inverse f * f = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   423
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   424
  have c: "inverse f * f = f * inverse f" by (simp add: mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   425
  from f0 have ifn: "\<And>n. inverse f $ n = natfun_inverse f n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   426
    by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   427
  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
   428
    by (simp add: fps_mult_nth fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   429
  {fix n::nat assume np: "n >0 "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   430
    from np have eq: "{0..n} = {0} \<union> {1 .. n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   431
    have d: "{0} \<inter> {1 .. n} = {}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   432
    have f: "finite {0::nat}" "finite {1..n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   433
    from f0 np have th0: "- (inverse f$n) = 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   434
      (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
   435
      by (cases n, simp, simp add: divide_inverse fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   436
    from th0[symmetric, unfolded nonzero_divide_eq_eq[OF f0]]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   437
    have th1: "setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n} = 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   438
      - (f$0) * (inverse f)$n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   439
      by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   440
    have "(f * inverse f) $ n = (\<Sum>i = 0..n. f $i * natfun_inverse f (n - i))" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   441
      unfolding fps_mult_nth ifn ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   442
    also have "\<dots> = f$0 * natfun_inverse f n 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   443
      + (\<Sum>i = 1..n. f$i * natfun_inverse f (n-i))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   444
      unfolding setsum_Un_disjoint[OF f d, unfolded eq[symmetric]]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   445
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   446
    also have "\<dots> = 0" unfolding th1 ifn by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   447
    finally have "(inverse f * f)$n = 0" unfolding c . }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   448
  with th0 show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   449
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   450
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   451
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
   452
  by (simp add: fps_inverse_def nonzero_imp_inverse_nonzero)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   453
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   454
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
   455
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   456
  {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
   457
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   458
  {assume h: "inverse f = 0" and c: "f $0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   459
    from inverse_mult_eq_1[OF c] h have False by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   460
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   461
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   462
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   463
lemma fps_inverse_idempotent[intro]: assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   464
  shows "inverse (inverse f) = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   465
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   466
  from f0 have if0: "inverse f $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   467
  from inverse_mult_eq_1[OF f0] inverse_mult_eq_1[OF if0] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   468
  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
   469
  then show ?thesis using f0 unfolding mult_cancel_left by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   470
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   471
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   472
lemma fps_inverse_unique: assumes f0: "f$0 \<noteq> (0::'a::field)" and fg: "f*g = 1" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   473
  shows "inverse f = g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   474
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   475
  from inverse_mult_eq_1[OF f0] fg
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   476
  have th0: "inverse f * f = g * f" by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   477
  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
   478
    by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   479
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   480
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   481
lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field))) 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   482
  = 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
   483
  apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   484
  apply simp
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   485
  apply (simp add: fps_eq_iff fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   486
proof(clarsimp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   487
  fix n::nat assume n: "n > 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   488
  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
   489
  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
   490
  let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   491
  have th1: "setsum ?f {0..n} = setsum ?g {0..n}"  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   492
    by (rule setsum_cong2) auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   493
  have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}"  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   494
    using n apply - by (rule setsum_cong2) auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   495
  have eq: "{0 .. n} = {0.. n - 1} \<union> {n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   496
  from n have d: "{0.. n - 1} \<inter> {n} = {}" by auto 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   497
  have f: "finite {0.. n - 1}" "finite {n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   498
  show "setsum ?f {0..n} = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   499
    unfolding th1 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   500
    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
   501
    unfolding th2
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   502
    by(simp add: setsum_delta)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   503
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   504
29912
f4ac160d2e77 fix spelling
huffman
parents: 29911
diff changeset
   505
subsection{* Formal Derivatives, and the MacLaurin theorem around 0*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   506
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   507
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
   508
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   509
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
   510
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   511
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
   512
  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
   513
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   514
lemma fps_deriv_mult[simp]: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   515
  fixes f :: "('a :: comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   516
  shows "fps_deriv (f * g) = f * fps_deriv g + fps_deriv f * g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   517
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   518
  let ?D = "fps_deriv"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   519
  {fix n::nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   520
    let ?Zn = "{0 ..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   521
    let ?Zn1 = "{0 .. n + 1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   522
    let ?f = "\<lambda>i. i + 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   523
    have fi: "inj_on ?f {0..n}" by (simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   524
    have eq: "{1.. n+1} = ?f ` {0..n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   525
    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
   526
        of_nat (i+1)* f $ (i+1) * g $ (n - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   527
    let ?h = "\<lambda>i. of_nat i * g $ i * f $ ((n+1) - i) +
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   528
        of_nat i* f $ i * g $ ((n + 1) - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   529
    {fix k assume k: "k \<in> {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   530
      have "?h (k + 1) = ?g k" using k by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   531
    note th0 = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   532
    have eq': "{0..n +1}- {1 .. n+1} = {0}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   533
    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
   534
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   535
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   536
      apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   537
      apply (rule set_ext)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   538
      apply (presburger add: image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   539
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   540
    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
   541
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   542
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   543
      apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   544
      apply (rule set_ext)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   545
      apply (presburger add: image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   546
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   547
    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
   548
    also have "\<dots> = (\<Sum>i = 0..n. ?g i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   549
      by (simp add: fps_mult_nth setsum_addf[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   550
    also have "\<dots> = setsum ?h {1..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   551
      using th0 setsum_reindex_cong[OF fi eq, of "?g" "?h"] by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   552
    also have "\<dots> = setsum ?h {0..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   553
      apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   554
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   555
      apply (simp add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   556
      unfolding eq'
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   557
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   558
    also have "\<dots> = (fps_deriv (f * g)) $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   559
      apply (simp only: fps_deriv_nth fps_mult_nth setsum_addf)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   560
      unfolding s0 s1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   561
      unfolding setsum_addf[symmetric] setsum_right_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   562
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   563
      by (auto simp add: of_nat_diff ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   564
    finally have "(f * ?D g + ?D f * g) $ n = ?D (f*g) $ n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   565
  then show ?thesis unfolding fps_eq_iff by auto 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   566
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   567
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   568
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
   569
  by (simp add: fps_eq_iff fps_deriv_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   570
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
   571
  using fps_deriv_linear[of 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   572
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   573
lemma fps_deriv_sub[simp]: "fps_deriv ((f:: ('a::comm_ring_1) fps) - g) = fps_deriv f - fps_deriv g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   574
  unfolding diff_minus by simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   575
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   576
lemma fps_deriv_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
   577
  by (simp add: fps_ext fps_deriv_def fps_const_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   578
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   579
lemma fps_deriv_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
   580
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   581
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   582
lemma fps_deriv_0[simp]: "fps_deriv 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   583
  by (simp add: fps_deriv_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   584
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   585
lemma fps_deriv_1[simp]: "fps_deriv 1 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   586
  by (simp add: fps_deriv_def fps_eq_iff )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   587
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   588
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
   589
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   590
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   591
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
   592
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   593
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   594
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   595
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   596
    have ?thesis  by (induct rule: finite_induct[OF fS], simp_all)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   597
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   598
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   599
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   600
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
   601
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   602
  {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
   603
    hence "fps_deriv f = 0" by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   604
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   605
  {assume z: "fps_deriv f = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   606
    hence "\<forall>n. (fps_deriv f)$n = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   607
    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
   608
    hence "f = fps_const (f$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   609
      apply (clarsimp simp add: fps_eq_iff fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   610
      apply (erule_tac x="n - 1" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   611
      by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   612
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   613
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   614
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   615
lemma fps_deriv_eq_iff: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   616
  fixes f:: "('a::{idom,semiring_char_0}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   617
  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
   618
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   619
  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
   620
  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
   621
  finally show ?thesis by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   622
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   623
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   624
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
   625
  apply auto unfolding fps_deriv_eq_iff by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   626
  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   627
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   628
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
   629
  "fps_nth_deriv 0 f = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   630
| "fps_nth_deriv (Suc n) f = fps_nth_deriv n (fps_deriv f)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   631
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   632
lemma fps_nth_deriv_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
   633
  by (induct n arbitrary: f, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   634
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   635
lemma fps_nth_deriv_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
   636
  by (induct n arbitrary: f g, auto simp add: fps_nth_deriv_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   637
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   638
lemma fps_nth_deriv_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
   639
  by (induct n arbitrary: f, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   640
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   641
lemma fps_nth_deriv_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
   642
  using fps_nth_deriv_linear[of n 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   643
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   644
lemma fps_nth_deriv_sub[simp]: "fps_nth_deriv n ((f:: ('a::comm_ring_1) fps) - g) = fps_nth_deriv n f - fps_nth_deriv n g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   645
  unfolding diff_minus fps_nth_deriv_add by simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   646
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   647
lemma fps_nth_deriv_0[simp]: "fps_nth_deriv n 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   648
  by (induct n, simp_all )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   649
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   650
lemma fps_nth_deriv_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
   651
  by (induct n, simp_all )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   652
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   653
lemma fps_nth_deriv_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
   654
  by (cases n, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   655
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   656
lemma fps_nth_deriv_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
   657
  using fps_nth_deriv_linear[of n "c" f 0 0 ] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   658
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   659
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
   660
  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
   661
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   662
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
   663
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   664
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   665
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   666
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   667
    have ?thesis  by (induct rule: finite_induct[OF fS], simp_all)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   668
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   669
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   670
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   671
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
   672
  by (induct k arbitrary: f) (auto simp add: ring_simps of_nat_mult)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   673
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   674
subsection {* Powers*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   675
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   676
instantiation fps :: (semiring_1) power
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   677
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   678
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   679
fun fps_pow :: "nat \<Rightarrow> 'a fps \<Rightarrow> 'a fps" where
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   680
  "fps_pow 0 f = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   681
| "fps_pow (Suc n) f = f * fps_pow n f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   682
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   683
definition fps_power_def: "power (f::'a fps) n = fps_pow n f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   684
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   685
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   686
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   687
instantiation fps :: (comm_ring_1) recpower
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   688
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   689
instance
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   690
  apply (intro_classes)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   691
  by (simp_all add: fps_power_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   692
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   693
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   694
lemma eq_neg_iff_add_eq_0: "(a::'a::ring) = -b \<longleftrightarrow> a + b = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   695
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   696
  {assume "a = -b" hence "b + a = b + -b" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   697
    hence "a + b = 0" by (simp add: ring_simps)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   698
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   699
  {assume "a + b = 0" hence "a + b - b = -b" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   700
    hence "a = -b" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   701
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   702
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   703
29912
f4ac160d2e77 fix spelling
huffman
parents: 29911
diff changeset
   704
lemma fps_square_eq_iff: "(a:: 'a::idom fps)^ 2 = b^2  \<longleftrightarrow> (a = b \<or> a = -b)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   705
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   706
  {assume "a = b \<or> a = -b" hence "a^2 = b^2" by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   707
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   708
  {assume "a^2 = b^2 "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   709
    hence "a^2 - b^2 = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   710
    hence "(a-b) * (a+b) = 0" by (simp add: power2_eq_square ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   711
    hence "a = b \<or> a = -b" by (simp add: eq_neg_iff_add_eq_0)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   712
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   713
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   714
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   715
lemma fps_power_zeroth_eq_one: "a$0 =1 \<Longrightarrow> a^n $ 0 = (1::'a::semiring_1)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   716
  by (induct n, auto simp add: fps_power_def expand_fps_eq fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   717
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   718
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
   719
proof(induct n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   720
  case 0 thus ?case by (simp add: fps_power_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   721
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   722
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   723
  note h = Suc.hyps[OF `a$0 = 1`]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   724
  show ?case unfolding power_Suc fps_mult_nth 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   725
    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
   726
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   727
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   728
lemma startsby_one_power:"a $ 0 = (1::'a::comm_ring_1) \<Longrightarrow> a^n $ 0 = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   729
  by (induct n, auto simp add: fps_power_def fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   730
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   731
lemma startsby_zero_power:"a $0 = (0::'a::comm_ring_1) \<Longrightarrow> n > 0 \<Longrightarrow> a^n $0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   732
  by (induct n, auto simp add: fps_power_def fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   733
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   734
lemma startsby_power:"a $0 = (v::'a::{comm_ring_1, recpower}) \<Longrightarrow> a^n $0 = v^n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   735
  by (induct n, auto simp add: fps_power_def fps_mult_nth power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   736
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   737
lemma startsby_zero_power_iff[simp]:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   738
  "a^n $0 = (0::'a::{idom, recpower}) \<longleftrightarrow> (n \<noteq> 0 \<and> a$0 = 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   739
apply (rule iffI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   740
apply (induct n, auto simp add: power_Suc fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   741
by (rule startsby_zero_power, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   742
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   743
lemma startsby_zero_power_prefix: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   744
  assumes a0: "a $0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   745
  shows "\<forall>n < k. a ^ k $ n = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   746
  using a0 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   747
proof(induct k rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   748
  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
   749
  let ?ths = "\<forall>m<k. a ^ k $ m = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   750
  {assume "k = 0" then have ?ths by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   751
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   752
  {fix l assume k: "k = Suc l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   753
    {fix m assume mk: "m < k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   754
      {assume "m=0" hence "a^k $ m = 0" using startsby_zero_power[of a k] k a0 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   755
	  by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   756
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   757
      {assume m0: "m \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   758
	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
   759
	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
   760
	also have "\<dots> = 0" apply (rule setsum_0')
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   761
	  apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   762
	  apply (case_tac "aa = m")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   763
	  using a0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   764
	  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   765
	  apply (rule H[rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   766
	  using a0 k mk by auto 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   767
	finally have "a^k $ m = 0" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   768
    ultimately have "a^k $ m = 0" by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   769
    hence ?ths by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   770
  ultimately show ?ths by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   771
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   772
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   773
lemma startsby_zero_setsum_depends: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   774
  assumes a0: "a $0 = (0::'a::idom)" and kn: "n \<ge> k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   775
  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
   776
  apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   777
  using kn apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   778
  apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   779
  by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   780
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   781
lemma startsby_zero_power_nth_same: assumes a0: "a$0 = (0::'a::{recpower, idom})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   782
  shows "a^n $ n = (a$1) ^ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   783
proof(induct n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   784
  case 0 thus ?case by (simp add: power_0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   785
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   786
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   787
  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
   788
  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
   789
  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
   790
    apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   791
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   792
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   793
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   794
    apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   795
    apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   796
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   797
  also have "\<dots> = a^n $ n * a$1" using a0 by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   798
  finally show ?case using Suc.hyps by (simp add: power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   799
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   800
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   801
lemma fps_inverse_power:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   802
  fixes a :: "('a::{field, recpower}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   803
  shows "inverse (a^n) = inverse a ^ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   804
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   805
  {assume a0: "a$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   806
    hence eq: "inverse a = 0" by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   807
    {assume "n = 0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   808
    moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   809
    {assume n: "n > 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   810
      from startsby_zero_power[OF a0 n] eq a0 n have ?thesis 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   811
	by (simp add: fps_inverse_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   812
    ultimately have ?thesis by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   813
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   814
  {assume a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   815
    have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   816
      apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   817
      apply (simp add: a0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   818
      unfolding power_mult_distrib[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   819
      apply (rule ssubst[where t = "a * inverse a" and s= 1])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   820
      apply simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   821
      apply (subst mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   822
      by (rule inverse_mult_eq_1[OF a0])}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   823
  ultimately show ?thesis by blast
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
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   826
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
   827
  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
   828
  by (case_tac n, auto simp add: power_Suc ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   829
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   830
lemma fps_inverse_deriv: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   831
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   832
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   833
  shows "fps_deriv (inverse a) = - fps_deriv a * inverse a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   834
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   835
  from inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   836
  have "fps_deriv (inverse a * a) = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   837
  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
   838
  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
   839
  with inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   840
  have "inverse a ^ 2 * fps_deriv a + fps_deriv (inverse a) = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   841
    unfolding power2_eq_square
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   842
    apply (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   843
    by (simp add: mult_assoc[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   844
  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
   845
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   846
  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
   847
qed
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_inverse_mult: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   850
  fixes a::"('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   851
  shows "inverse (a * b) = inverse a * inverse b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   852
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   853
  {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
   854
    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
   855
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   856
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   857
  {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
   858
    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
   859
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   860
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   861
  {assume a0: "a$0 \<noteq> 0" and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   862
    from a0 b0 have ab0:"(a*b) $ 0 \<noteq> 0" by (simp  add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   863
    from inverse_mult_eq_1[OF ab0] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   864
    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
   865
    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
   866
      by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   867
    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
   868
ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   869
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   870
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   871
lemma fps_inverse_deriv': 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   872
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   873
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   874
  shows "fps_deriv (inverse a) = - fps_deriv a / a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   875
  using fps_inverse_deriv[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   876
  unfolding power2_eq_square fps_divide_def
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   877
    fps_inverse_mult by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   878
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   879
lemma inverse_mult_eq_1': assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   880
  shows "f * inverse f= 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   881
  by (metis mult_commute inverse_mult_eq_1 f0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   882
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   883
lemma fps_divide_deriv:   fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   884
  assumes a0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   885
  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
   886
  using fps_inverse_deriv[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   887
  by (simp add: fps_divide_def ring_simps power2_eq_square fps_inverse_mult inverse_mult_eq_1'[OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   888
  
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   889
subsection{* The eXtractor series X*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   890
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   891
lemma minus_one_power_iff: "(- (1::'a :: {recpower, comm_ring_1})) ^ n = (if even n then 1 else - 1)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   892
  by (induct n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   893
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   894
definition "X = Abs_fps (\<lambda>n. if n = 1 then 1 else 0)"
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_inverse_gp': "inverse (Abs_fps(\<lambda>n. (1::'a::field))) 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   897
  = 1 - X"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   898
  by (simp add: fps_inverse_gp fps_eq_iff X_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   899
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   900
lemma X_mult_nth[simp]: "(X * (f :: ('a::semiring_1) fps)) $n = (if n = 0 then 0 else f $ (n - 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   901
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   902
  {assume n: "n \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   903
    have fN: "finite {0 .. n}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   904
    have "(X * f) $n = (\<Sum>i = 0..n. X $ i * f $ (n - i))" by (simp add: fps_mult_nth)
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   905
    also have "\<dots> = f $ (n - 1)"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   906
      using n by (simp add: X_def mult_delta_left setsum_delta [OF fN])
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   907
  finally have ?thesis using n by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   908
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   909
  {assume n: "n=0" hence ?thesis by (simp add: fps_mult_nth X_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   910
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   911
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   912
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   913
lemma X_mult_right_nth[simp]: "((f :: ('a::comm_semiring_1) fps) * X) $n = (if n = 0 then 0 else f $ (n - 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   914
  by (metis X_mult_nth mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   915
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   916
lemma X_power_iff: "X^k = Abs_fps (\<lambda>n. if n = k then (1::'a::comm_ring_1) else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   917
proof(induct k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   918
  case 0 thus ?case by (simp add: X_def fps_power_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   919
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   920
  case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   921
  {fix m 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   922
    have "(X^Suc k) $ m = (if m = 0 then (0::'a) else (X^k) $ (m - 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   923
      by (simp add: power_Suc del: One_nat_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   924
    then     have "(X^Suc k) $ m = (if m = Suc k then (1::'a) else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   925
      using Suc.hyps by (auto cong del: if_weak_cong)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   926
  then show ?case by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   927
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   928
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   929
lemma X_power_mult_nth: "(X^k * (f :: ('a::comm_ring_1) fps)) $n = (if n < k then 0 else f $ (n - k))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   930
  apply (induct k arbitrary: n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   931
  apply (simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   932
  unfolding power_Suc mult_assoc 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   933
  by (case_tac n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   934
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   935
lemma X_power_mult_right_nth: "((f :: ('a::comm_ring_1) fps) * X^k) $n = (if n < k then 0 else f $ (n - k))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   936
  by (metis X_power_mult_nth mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   937
lemma fps_deriv_X[simp]: "fps_deriv X = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   938
  by (simp add: fps_deriv_def X_def fps_eq_iff)
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_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
   941
  by (cases "n", simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   942
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   943
lemma X_nth[simp]: "X$n = (if n = 1 then 1 else 0)" by (simp add: X_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   944
lemma X_power_nth[simp]: "(X^k) $n = (if n = k then 1 else (0::'a::comm_ring_1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   945
  by (simp add: X_power_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   946
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   947
lemma fps_inverse_X_plus1:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   948
  "inverse (1 + X) = Abs_fps (\<lambda>n. (- (1::'a::{recpower, field})) ^ n)" (is "_ = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   949
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   950
  have eq: "(1 + X) * ?r = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   951
    unfolding minus_one_power_iff
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   952
    apply (auto simp add: ring_simps fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   953
    by presburger+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   954
  show ?thesis by (auto simp add: eq intro: fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   955
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   956
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   957
  
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   958
subsection{* Integration *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   959
definition "fps_integral a a0 = Abs_fps (\<lambda>n. if n = 0 then a0 else (a$(n - 1) / of_nat n))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   960
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   961
lemma fps_deriv_fps_integral: "fps_deriv (fps_integral a (a0 :: 'a :: {field, ring_char_0})) = a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   962
  by (simp add: fps_integral_def fps_deriv_def fps_eq_iff field_simps del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   963
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   964
lemma fps_integral_linear: "fps_integral (fps_const (a::'a::{field, ring_char_0}) * f + fps_const b * g) (a*a0 + b*b0) = fps_const a * fps_integral f a0 + fps_const b * fps_integral g b0" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   965
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   966
  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
   967
  moreover have "?l$0 = ?r$0" by (simp add: fps_integral_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   968
  ultimately show ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   969
    unfolding fps_deriv_eq_iff by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   970
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   971
  
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   972
subsection {* Composition of FPSs *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   973
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
   974
  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
   975
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   976
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
   977
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   978
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
   979
  by (simp add: fps_ext fps_compose_def mult_delta_right setsum_delta')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   980
 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   981
lemma fps_const_compose[simp]: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   982
  "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
   983
  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
   984
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   985
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
   986
  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
   987
                power_Suc not_le)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   988
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   989
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   990
subsection {* Rules from Herbert Wilf's Generatingfunctionology*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   991
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   992
subsubsection {* Rule 1 *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   993
  (* {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
   994
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   995
lemma fps_power_mult_eq_shift: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   996
  "X^Suc k * Abs_fps (\<lambda>n. a (n + Suc k)) = Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a:: field) * X^i) {0 .. k}" (is "?lhs = ?rhs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   997
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   998
  {fix n:: nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   999
    have "?lhs $ n = (if n < Suc k then 0 else a n)" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1000
      unfolding X_power_mult_nth by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1001
    also have "\<dots> = ?rhs $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1002
    proof(induct k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1003
      case 0 thus ?case by (simp add: fps_setsum_nth power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1004
    next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1005
      case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1006
      note th = Suc.hyps[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1007
      have "(Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a:: field) * X^i) {0 .. Suc k})$n = (Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a:: field) * X^i) {0 .. k} - fps_const (a (Suc k)) * X^ Suc k) $ n" by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1008
      also  have "\<dots> = (if n < Suc k then 0 else a n) - (fps_const (a (Suc k)) * X^ Suc k)$n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1009
	using th 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1010
	unfolding fps_sub_nth by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1011
      also have "\<dots> = (if n < Suc (Suc k) then 0 else a n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1012
	unfolding X_power_mult_right_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1013
	apply (auto simp add: not_less fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1014
	apply (rule cong[of a a, OF refl])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1015
	by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1016
      finally show ?case by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1017
    qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1018
    finally have "?lhs $ n = ?rhs $ n"  .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1019
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1020
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1021
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1022
subsubsection{* Rule 2*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1023
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1024
  (* We can not reach the form of Wilf, but still near to it using rewrite rules*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1025
  (* If f reprents {a_n} and P is a polynomial, then 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1026
        P(xD) f represents {P(n) a_n}*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1027
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1028
definition "XD = op * X o fps_deriv"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1029
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1030
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
  1031
  by (simp add: XD_def ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1032
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1033
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
  1034
  by (simp add: XD_def ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1035
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1036
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
  1037
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1038
29689
dd086f26ee4f removed definition of funpow , reusing that of Relation_Power
chaieb
parents: 29687
diff changeset
  1039
lemma XDN_linear: "(XD^n) (fps_const c * a + fps_const d * b) = fps_const c * (XD^n) a + fps_const d * (XD^n) (b :: ('a::comm_ring_1) fps)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1040
  by (induct n, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1041
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1042
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
  1043
29689
dd086f26ee4f removed definition of funpow , reusing that of Relation_Power
chaieb
parents: 29687
diff changeset
  1044
lemma fps_mult_XD_shift: "(XD ^k) (a:: ('a::{comm_ring_1, recpower, ring_char_0}) fps) = Abs_fps (\<lambda>n. (of_nat n ^ k) * a$n)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1045
by (induct k arbitrary: a) (simp_all add: power_Suc XD_def fps_eq_iff ring_simps del: One_nat_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1046
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1047
subsubsection{* Rule 3 is trivial and is given by @{text fps_times_def}*}
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1048
subsubsection{* Rule 5 --- summation and "division" by (1 - X)*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1049
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1050
lemma fps_divide_X_minus1_setsum_lemma:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1051
  "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
  1052
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1053
  let ?X = "X::('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1054
  let ?sa = "Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1055
  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
  1056
  {fix n:: nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1057
    {assume "n=0" hence "a$n = ((1 - ?X) * ?sa) $ n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1058
	by (simp add: fps_mult_nth)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1059
    moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1060
    {assume n0: "n \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1061
      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
  1062
	"{0..n - 1}\<union>{n} = {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1063
	apply (simp_all add: expand_set_eq) by presburger+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1064
      have d: "{0} \<inter> ({1} \<union> {2..n}) = {}" "{1} \<inter> {2..n} = {}" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1065
	"{0..n - 1}\<inter>{n} ={}" using n0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1066
	by (simp_all add: expand_set_eq, presburger+)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1067
      have f: "finite {0}" "finite {1}" "finite {2 .. n}" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1068
	"finite {0 .. n - 1}" "finite {n}" by simp_all 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1069
    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
  1070
      by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1071
    also have "\<dots> = a$n" unfolding th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1072
      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
  1073
      unfolding setsum_Un_disjoint[OF f(2) f(3) d(2)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1074
      apply (simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1075
      unfolding setsum_Un_disjoint[OF f(4,5) d(3), unfolded u(3)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1076
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1077
    finally have "a$n = ((1 - ?X) * ?sa) $ n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1078
  ultimately have "a$n = ((1 - ?X) * ?sa) $ n" by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1079
then show ?thesis 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1080
  unfolding fps_eq_iff by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1081
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1082
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1083
lemma fps_divide_X_minus1_setsum:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1084
  "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
  1085
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1086
  let ?X = "1 - (X::('a::field) fps)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1087
  have th0: "?X $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1088
  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
  1089
    using fps_divide_X_minus1_setsum_lemma[of a, symmetric] th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1090
    by (simp add: fps_divide_def mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1091
  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
  1092
    by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1093
  finally show ?thesis by (simp add: inverse_mult_eq_1[OF th0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1094
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1095
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1096
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
  1097
  finite product of FPS, also the relvant instance of powers of a FPS*}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1098
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1099
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
  1100
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1101
lemma natlist_trivial_1: "natpermute n 1 = {[n]}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1102
  apply (auto simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1103
  apply (case_tac x, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1104
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1105
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1106
lemma foldl_add_start0: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1107
  "foldl op + x xs = x + foldl op + (0::nat) xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1108
  apply (induct xs arbitrary: x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1109
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1110
  unfolding foldl.simps
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1111
  apply atomize
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1112
  apply (subgoal_tac "\<forall>x\<Colon>nat. foldl op + x xs = x + foldl op + (0\<Colon>nat) xs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1113
  apply (erule_tac x="x + a" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1114
  apply (erule_tac x="a" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1115
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1116
  apply assumption
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1117
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1118
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1119
lemma foldl_add_append: "foldl op + (x::nat) (xs@ys) = foldl op + x xs + foldl op + 0 ys"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1120
  apply (induct ys arbitrary: x xs)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1121
  apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1122
  apply (subst (2) foldl_add_start0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1123
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1124
  apply (subst (2) foldl_add_start0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1125
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1126
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1127
lemma foldl_add_setsum: "foldl op + (x::nat) xs = x + setsum (nth xs) {0..<length xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1128
proof(induct xs arbitrary: x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1129
  case Nil thus ?case by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1130
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1131
  case (Cons a as x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1132
  have eq: "setsum (op ! (a#as)) {1..<length (a#as)} = setsum (op ! as) {0..<length as}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1133
    apply (rule setsum_reindex_cong [where f=Suc])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1134
    by (simp_all add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1135
  have f: "finite {0}" "finite {1 ..< length (a#as)}" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1136
  have d: "{0} \<inter> {1..<length (a#as)} = {}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1137
  have seq: "{0} \<union> {1..<length(a#as)} = {0 ..<length (a#as)}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1138
  have "foldl op + x (a#as) = x + foldl op + a as "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1139
    apply (subst foldl_add_start0)    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1140
  also have "\<dots> = x + a + setsum (op ! as) {0..<length as}" unfolding Cons.hyps by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1141
  also have "\<dots> = x + setsum (op ! (a#as)) {0..<length (a#as)}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1142
    unfolding eq[symmetric] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1143
    unfolding setsum_Un_disjoint[OF f d, unfolded seq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1144
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1145
  finally show ?case  .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1146
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1147
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1148
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1149
lemma append_natpermute_less_eq:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1150
  assumes h: "xs@ys \<in> natpermute n k" shows "foldl op + 0 xs \<le> n" and "foldl op + 0 ys \<le> n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1151
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1152
  {from h have "foldl op + 0 (xs@ ys) = n" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1153
    hence "foldl op + 0 xs + foldl op + 0 ys = n" unfolding foldl_add_append .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1154
  note th = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1155
  {from th show "foldl op + 0 xs \<le> n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1156
  {from th show "foldl op + 0 ys \<le> n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1157
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1158
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1159
lemma natpermute_split:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1160
  assumes mn: "h \<le> k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1161
  shows "natpermute n k = (\<Union>m \<in>{0..n}. {l1 @ l2 |l1 l2. l1 \<in> natpermute m h \<and> l2 \<in> natpermute (n - m) (k - h)})" (is "?L = ?R" is "?L = (\<Union>m \<in>{0..n}. ?S m)")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1162
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1163
  {fix l assume l: "l \<in> ?R" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1164
    from l obtain m xs ys where h: "m \<in> {0..n}" and xs: "xs \<in> natpermute m h" and ys: "ys \<in> natpermute (n - m) (k - h)"  and leq: "l = xs@ys" by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1165
    from xs have xs': "foldl op + 0 xs = m" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1166
    from ys have ys': "foldl op + 0 ys = n - m" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1167
    have "l \<in> ?L" using leq xs ys h 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1168
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1169
      apply (clarsimp simp add: natpermute_def simp del: foldl_append)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1170
      apply (simp add: foldl_add_append[unfolded foldl_append])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1171
      unfolding xs' ys'
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1172
      using mn xs ys 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1173
      unfolding natpermute_def by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1174
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1175
  {fix l assume l: "l \<in> natpermute n k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1176
    let ?xs = "take h l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1177
    let ?ys = "drop h l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1178
    let ?m = "foldl op + 0 ?xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1179
    from l have ls: "foldl op + 0 (?xs @ ?ys) = n" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1180
    have xs: "?xs \<in> natpermute ?m h" using l mn by (simp add: natpermute_def)     
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1181
    have ys: "?ys \<in> natpermute (n - ?m) (k - h)" using l mn ls[unfolded foldl_add_append]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1182
      by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1183
    from ls have m: "?m \<in> {0..n}"  unfolding foldl_add_append by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1184
    from xs ys ls have "l \<in> ?R" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1185
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1186
      apply (rule bexI[where x = "?m"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1187
      apply (rule exI[where x = "?xs"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1188
      apply (rule exI[where x = "?ys"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1189
      using ls l unfolding foldl_add_append 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1190
      by (auto simp add: natpermute_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1191
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1192
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1193
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1194
lemma natpermute_0: "natpermute n 0 = (if n = 0 then {[]} else {})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1195
  by (auto simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1196
lemma natpermute_0'[simp]: "natpermute 0 k = (if k = 0 then {[]} else {replicate k 0})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1197
  apply (auto simp add: set_replicate_conv_if natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1198
  apply (rule nth_equalityI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1199
  by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1200
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1201
lemma natpermute_finite: "finite (natpermute n k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1202
proof(induct k arbitrary: n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1203
  case 0 thus ?case 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1204
    apply (subst natpermute_split[of 0 0, simplified])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1205
    by (simp add: natpermute_0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1206
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1207
  case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1208
  then show ?case unfolding natpermute_split[of k "Suc k", simplified]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1209
    apply -
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1210
    apply (rule finite_UN_I)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1211
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1212
    unfolding One_nat_def[symmetric] natlist_trivial_1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1213
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1214
    unfolding image_Collect[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1215
    unfolding Collect_def mem_def
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1216
    apply (rule finite_imageI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1217
    apply blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1218
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1219
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1220
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1221
lemma natpermute_contain_maximal:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1222
  "{xs \<in> natpermute n (k+1). n \<in> set xs} = UNION {0 .. k} (\<lambda>i. {(replicate (k+1) 0) [i:=n]})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1223
  (is "?A = ?B")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1224
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1225
  {fix xs assume H: "xs \<in> natpermute n (k+1)" and n: "n \<in> set xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1226
    from n obtain i where i: "i \<in> {0.. k}" "xs!i = n" using H
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1227
      unfolding in_set_conv_nth by (auto simp add: less_Suc_eq_le natpermute_def) 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1228
    have eqs: "({0..k} - {i}) \<union> {i} = {0..k}" using i by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1229
    have f: "finite({0..k} - {i})" "finite {i}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1230
    have d: "({0..k} - {i}) \<inter> {i} = {}" using i by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1231
    from H have "n = setsum (nth xs) {0..k}" apply (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1232
      unfolding foldl_add_setsum by (auto simp add: atLeastLessThanSuc_atLeastAtMost)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1233
    also have "\<dots> = n + setsum (nth xs) ({0..k} - {i})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1234
      unfolding setsum_Un_disjoint[OF f d, unfolded eqs] using i by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1235
    finally have zxs: "\<forall> j\<in> {0..k} - {i}. xs!j = 0" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1236
    from H have xsl: "length xs = k+1" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1237
    from i have i': "i < length (replicate (k+1) 0)"   "i < k+1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1238
      unfolding length_replicate  by arith+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1239
    have "xs = replicate (k+1) 0 [i := n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1240
      apply (rule nth_equalityI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1241
      unfolding xsl length_list_update length_replicate
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1242
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1243
      apply clarify
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1244
      unfolding nth_list_update[OF i'(1)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1245
      using i zxs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1246
      by (case_tac "ia=i", auto simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1247
    then have "xs \<in> ?B" using i by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1248
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1249
  {fix i assume i: "i \<in> {0..k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1250
    let ?xs = "replicate (k+1) 0 [i:=n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1251
    have nxs: "n \<in> set ?xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1252
      apply (rule set_update_memI) using i by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1253
    have xsl: "length ?xs = k+1" by (simp only: length_replicate length_list_update)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1254
    have "foldl op + 0 ?xs = setsum (nth ?xs) {0..<k+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1255
      unfolding foldl_add_setsum add_0 length_replicate length_list_update ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1256
    also have "\<dots> = setsum (\<lambda>j. if j = i then n else 0) {0..< k+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1257
      apply (rule setsum_cong2) by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1258
    also have "\<dots> = n" using i by (simp add: setsum_delta)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1259
    finally 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1260
    have "?xs \<in> natpermute n (k+1)" using xsl unfolding natpermute_def Collect_def mem_def
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1261
      by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1262
    then have "?xs \<in> ?A"  using nxs  by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1263
  ultimately show ?thesis by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1264
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1265
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1266
    (* The general form *)	
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1267
lemma fps_setprod_nth:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1268
  fixes m :: nat and a :: "nat \<Rightarrow> ('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1269
  shows "(setprod a {0 .. m})$n = setsum (\<lambda>v. setprod (\<lambda>j. (a j) $ (v!j)) {0..m}) (natpermute n (m+1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1270
  (is "?P m n")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1271
proof(induct m arbitrary: n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1272
  fix m n assume H: "\<forall>m' < m. \<forall>n. ?P m' n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1273
  {assume m0: "m = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1274
    hence "?P m n" apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1275
      unfolding natlist_trivial_1[where n = n, unfolded One_nat_def] by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1276
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1277
  {fix k assume k: "m = Suc k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1278
    have km: "k < m" using k by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1279
    have u0: "{0 .. k} \<union> {m} = {0..m}" using k apply (simp add: expand_set_eq) by presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1280
    have f0: "finite {0 .. k}" "finite {m}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1281
    have d0: "{0 .. k} \<inter> {m} = {}" using k by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1282
    have "(setprod a {0 .. m}) $ n = (setprod a {0 .. k} * a m) $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1283
      unfolding setprod_Un_disjoint[OF f0 d0, unfolded u0] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1284
    also have "\<dots> = (\<Sum>i = 0..n. (\<Sum>v\<in>natpermute i (k + 1). \<Prod>j\<in>{0..k}. a j $ v ! j) * a m $ (n - i))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1285
      unfolding fps_mult_nth H[rule_format, OF km] ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1286
    also have "\<dots> = (\<Sum>v\<in>natpermute n (m + 1). \<Prod>j\<in>{0..m}. a j $ v ! j)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1287
      apply (simp add: k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1288
      unfolding natpermute_split[of m "m + 1", simplified, of n, unfolded natlist_trivial_1[unfolded One_nat_def] k]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1289
      apply (subst setsum_UN_disjoint)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1290
      apply simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1291
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1292
      unfolding image_Collect[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1293
      apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1294
      apply (rule finite_imageI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1295
      apply (rule natpermute_finite)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1296
      apply (clarsimp simp add: expand_set_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1297
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1298
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1299
      unfolding setsum_left_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1300
      apply (rule sym)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1301
      apply (rule_tac f="\<lambda>xs. xs @[n - x]" in  setsum_reindex_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1302
      apply (simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1303
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1304
      unfolding setprod_Un_disjoint[OF f0 d0, unfolded u0, unfolded k]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1305
      apply (clarsimp simp add: natpermute_def nth_append)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1306
      apply (rule_tac f="\<lambda>x. x * a (Suc k) $ (n - foldl op + 0 aa)" in cong[OF refl])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1307
      apply (rule setprod_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1308
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1309
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1310
      done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1311
    finally have "?P m n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1312
  ultimately show "?P m n " by (cases m, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1313
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1314
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1315
text{* The special form for powers *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1316
lemma fps_power_nth_Suc:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1317
  fixes m :: nat and a :: "('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1318
  shows "(a ^ Suc m)$n = setsum (\<lambda>v. setprod (\<lambda>j. a $ (v!j)) {0..m}) (natpermute n (m+1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1319
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1320
  have f: "finite {0 ..m}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1321
  have th0: "a^Suc m = setprod (\<lambda>i. a) {0..m}" unfolding setprod_constant[OF f, of a] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1322
  show ?thesis unfolding th0 fps_setprod_nth ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1323
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1324
lemma fps_power_nth:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1325
  fixes m :: nat and a :: "('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1326
  shows "(a ^m)$n = (if m=0 then 1$n else setsum (\<lambda>v. setprod (\<lambda>j. a $ (v!j)) {0..m - 1}) (natpermute n m))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1327
  by (cases m, simp_all add: fps_power_nth_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1328
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1329
lemma fps_nth_power_0: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1330
  fixes m :: nat and a :: "('a::{comm_ring_1, recpower}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1331
  shows "(a ^m)$0 = (a$0) ^ m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1332
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1333
  {assume "m=0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1334
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1335
  {fix n assume m: "m = Suc n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1336
    have c: "m = card {0..n}" using m by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1337
   have "(a ^m)$0 = setprod (\<lambda>i. a$0) {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1338
     apply (simp add: m fps_power_nth del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1339
     apply (rule setprod_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1340
     by (simp_all del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1341
   also have "\<dots> = (a$0) ^ m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1342
     unfolding c by (rule setprod_constant, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1343
   finally have ?thesis .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1344
 ultimately show ?thesis by (cases m, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1345
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1346
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1347
lemma fps_compose_inj_right: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1348
  assumes a0: "a$0 = (0::'a::{recpower,idom})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1349
  and a1: "a$1 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1350
  shows "(b oo a = c oo a) \<longleftrightarrow> b = c" (is "?lhs \<longleftrightarrow>?rhs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1351
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1352
  {assume ?rhs then have "?lhs" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1353
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1354
  {assume h: ?lhs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1355
    {fix n have "b$n = c$n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1356
      proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1357
	fix n assume H: "\<forall>m<n. b$m = c$m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1358
	{assume n0: "n=0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1359
	  from h have "(b oo a)$n = (c oo a)$n" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1360
	  hence "b$n = c$n" using n0 by (simp add: fps_compose_nth)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1361
	moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1362
	{fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1363
	  have f: "finite {0 .. n1}" "finite {n}" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1364
	  have eq: "{0 .. n1} \<union> {n} = {0 .. n}" using n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1365
	  have d: "{0 .. n1} \<inter> {n} = {}" using n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1366
	  have seq: "(\<Sum>i = 0..n1. b $ i * a ^ i $ n) = (\<Sum>i = 0..n1. c $ i * a ^ i $ n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1367
	    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1368
	    using H n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1369
	  have th0: "(b oo a) $n = (\<Sum>i = 0..n1. c $ i * a ^ i $ n) + b$n * (a$1)^n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1370
	    unfolding fps_compose_nth setsum_Un_disjoint[OF f d, unfolded eq] seq
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1371
	    using startsby_zero_power_nth_same[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1372
	    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1373
	  have th1: "(c oo a) $n = (\<Sum>i = 0..n1. c $ i * a ^ i $ n) + c$n * (a$1)^n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1374
	    unfolding fps_compose_nth setsum_Un_disjoint[OF f d, unfolded eq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1375
	    using startsby_zero_power_nth_same[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1376
	    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1377
	  from h[unfolded fps_eq_iff, rule_format, of n] th0 th1 a1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1378
	  have "b$n = c$n" by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1379
	ultimately show "b$n = c$n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1380
      qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1381
    then have ?rhs by (simp add: fps_eq_iff)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1382
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1383
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1384
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1385
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1386
subsection {* Radicals *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1387
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1388
declare setprod_cong[fundef_cong]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1389
function radical :: "(nat \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> ('a::{field, recpower}) fps \<Rightarrow> nat \<Rightarrow> 'a" where
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1390
  "radical r 0 a 0 = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1391
| "radical r 0 a (Suc n) = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1392
| "radical r (Suc k) a 0 = r (Suc k) (a$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1393
| "radical r (Suc k) a (Suc n) = (a$ Suc n - setsum (\<lambda>xs. setprod (\<lambda>j. radical r (Suc k) a (xs ! j)) {0..k}) {xs. xs \<in> natpermute (Suc n) (Suc k) \<and> Suc n \<notin> set xs}) / (of_nat (Suc k) * (radical r (Suc k) a 0)^k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1394
by pat_completeness auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1395
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1396
termination radical
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1397
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1398
  let ?R = "measure (\<lambda>(r, k, a, n). n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1399
  {
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1400
    show "wf ?R" by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1401
  {fix r k a n xs i
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1402
    assume xs: "xs \<in> {xs \<in> natpermute (Suc n) (Suc k). Suc n \<notin> set xs}" and i: "i \<in> {0..k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1403
    {assume c: "Suc n \<le> xs ! i"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1404
      from xs i have "xs !i \<noteq> Suc n" by (auto simp add: in_set_conv_nth natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1405
      with c have c': "Suc n < xs!i" by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1406
      have fths: "finite {0 ..< i}" "finite {i}" "finite {i+1..<Suc k}" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1407
      have d: "{0 ..< i} \<inter> ({i} \<union> {i+1 ..< Suc k}) = {}" "{i} \<inter> {i+1..< Suc k} = {}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1408
      have eqs: "{0..<Suc k} = {0 ..< i} \<union> ({i} \<union> {i+1 ..< Suc k})" using i by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1409
      from xs have "Suc n = foldl op + 0 xs" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1410
      also have "\<dots> = setsum (nth xs) {0..<Suc k}" unfolding foldl_add_setsum using xs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1411
	by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1412
      also have "\<dots> = xs!i + setsum (nth xs) {0..<i} + setsum (nth xs) {i+1..<Suc k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1413
	unfolding eqs  setsum_Un_disjoint[OF fths(1) finite_UnI[OF fths(2,3)] d(1)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1414
	unfolding setsum_Un_disjoint[OF fths(2) fths(3) d(2)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1415
	by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1416
      finally have False using c' by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1417
    then show "((r,Suc k,a,xs!i), r, Suc k, a, Suc n) \<in> ?R" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1418
      apply auto by (metis not_less)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1419
  {fix r k a n 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1420
    show "((r,Suc k, a, 0),r, Suc k, a, Suc n) \<in> ?R" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1421
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1422
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1423
definition "fps_radical r n a = Abs_fps (radical r n a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1424
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1425
lemma fps_radical0[simp]: "fps_radical r 0 a = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1426
  apply (auto simp add: fps_eq_iff fps_radical_def)  by (case_tac n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1427
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1428
lemma fps_radical_nth_0[simp]: "fps_radical r n a $ 0 = (if n=0 then 1 else r n (a$0))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1429
  by (cases n, simp_all add: fps_radical_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1430
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1431
lemma fps_radical_power_nth[simp]: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1432
  assumes r: "(r k (a$0)) ^ k = a$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1433
  shows "fps_radical r k a ^ k $ 0 = (if k = 0 then 1 else a$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1434
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1435
  {assume "k=0" hence ?thesis by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1436
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1437
  {fix h assume h: "k = Suc h" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1438
    have fh: "finite {0..h}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1439
    have eq1: "fps_radical r k a ^ k $ 0 = (\<Prod>j\<in>{0..h}. fps_radical r k a $ (replicate k 0) ! j)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1440
      unfolding fps_power_nth h by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1441
    also have "\<dots> = (\<Prod>j\<in>{0..h}. r k (a$0))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1442
      apply (rule setprod_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1443
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1444
      using h
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1445
      apply (subgoal_tac "replicate k (0::nat) ! x = 0")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1446
      by (auto intro: nth_replicate simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1447
    also have "\<dots> = a$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1448
      unfolding setprod_constant[OF fh] using r by (simp add: h)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1449
    finally have ?thesis using h by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1450
  ultimately show ?thesis by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1451
qed 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1452
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1453
lemma natpermute_max_card: assumes n0: "n\<noteq>0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1454
  shows "card {xs \<in> natpermute n (k+1). n \<in> set xs} = k+1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1455
  unfolding natpermute_contain_maximal
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1456
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1457
  let ?A= "\<lambda>i. {replicate (k + 1) 0[i := n]}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1458
  let ?K = "{0 ..k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1459
  have fK: "finite ?K" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1460
  have fAK: "\<forall>i\<in>?K. finite (?A i)" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1461
  have d: "\<forall>i\<in> ?K. \<forall>j\<in> ?K. i \<noteq> j \<longrightarrow> {replicate (k + 1) 0[i := n]} \<inter> {replicate (k + 1) 0[j := n]} = {}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1462
  proof(clarify)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1463
    fix i j assume i: "i \<in> ?K" and j: "j\<in> ?K" and ij: "i\<noteq>j"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1464
    {assume eq: "replicate (k+1) 0 [i:=n] = replicate (k+1) 0 [j:= n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1465
      have "(replicate (k+1) 0 [i:=n] ! i) = n" using i by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1466
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1467
      have "(replicate (k+1) 0 [j:=n] ! i) = 0" using i ij by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1468
      ultimately have False using eq n0 by (simp del: replicate.simps)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1469
    then show "{replicate (k + 1) 0[i := n]} \<inter> {replicate (k + 1) 0[j := n]} = {}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1470
      by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1471
  qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1472
  from card_UN_disjoint[OF fK fAK d] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1473
  show "card (\<Union>i\<in>{0..k}. {replicate (k + 1) 0[i := n]}) = k+1" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1474
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1475
  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1476
lemma power_radical: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1477
  fixes a:: "'a ::{field, ring_char_0, recpower} fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1478
  assumes r0: "(r (Suc k) (a$0)) ^ Suc k = a$0" and a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1479
  shows "(fps_radical r (Suc k) a) ^ (Suc k) = a" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1480
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1481
  let ?r = "fps_radical r (Suc k) a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1482
  from a0 r0 have r00: "r (Suc k) (a$0) \<noteq> 0" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1483
  {fix z have "?r ^ Suc k $ z = a$z"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1484
    proof(induct z rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1485
      fix n assume H: "\<forall>m<n. ?r ^ Suc k $ m = a$m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1486
      {assume "n = 0" hence "?r ^ Suc k $ n = a $n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1487
	  using fps_radical_power_nth[of r "Suc k" a, OF r0] by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1488
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1489
      {fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1490
	have fK: "finite {0..k}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1491
	have nz: "n \<noteq> 0" using n1 by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1492
	let ?Pnk = "natpermute n (k + 1)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1493
	let ?Pnkn = "{xs \<in> ?Pnk. n \<in> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1494
	let ?Pnknn = "{xs \<in> ?Pnk. n \<notin> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1495
	have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1496
	have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1497
	have f: "finite ?Pnkn" "finite ?Pnknn" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1498
	  using finite_Un[of ?Pnkn ?Pnknn, unfolded eq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1499
	  by (metis natpermute_finite)+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1500
	let ?f = "\<lambda>v. \<Prod>j\<in>{0..k}. ?r $ v ! j"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1501
	have "setsum ?f ?Pnkn = setsum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1502
	proof(rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1503
	  fix v assume v: "v \<in> {xs \<in> natpermute n (k + 1). n \<in> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1504
	  let ?ths = "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) = fps_radical r (Suc k) a $ n * r (Suc k) (a $ 0) ^ k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1505
	  from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1506
	    unfolding natpermute_contain_maximal by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1507
	  have "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) = (\<Prod>j\<in>{0..k}. if j = i then fps_radical r (Suc k) a $ n else r (Suc k) (a$0))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1508
	    apply (rule setprod_cong, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1509
	    using i r0 by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1510
	  also have "\<dots> = (fps_radical r (Suc k) a $ n) * r (Suc k) (a$0) ^ k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1511
	    unfolding setprod_gen_delta[OF fK] using i r0 by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1512
	  finally show ?ths .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1513
	qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1514
	then have "setsum ?f ?Pnkn = of_nat (k+1) * ?r $ n * r (Suc k) (a $ 0) ^ k"  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1515
	  by (simp add: natpermute_max_card[OF nz, simplified]) 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1516
	also have "\<dots> = a$n - setsum ?f ?Pnknn"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1517
	  unfolding n1 using r00 a0 by (simp add: field_simps fps_radical_def del: of_nat_Suc )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1518
	finally have fn: "setsum ?f ?Pnkn = a$n - setsum ?f ?Pnknn" .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1519
	have "(?r ^ Suc k)$n = setsum ?f ?Pnkn + setsum ?f ?Pnknn" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1520
	  unfolding fps_power_nth_Suc setsum_Un_disjoint[OF f d, unfolded eq] ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1521
	also have "\<dots> = a$n" unfolding fn by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1522
	finally have "?r ^ Suc k $ n = a $n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1523
      ultimately  show "?r ^ Suc k $ n = a $n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1524
  qed }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1525
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1526
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1527
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1528
lemma eq_divide_imp': assumes c0: "(c::'a::field) ~= 0" and eq: "a * c = b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1529
  shows "a = b / c" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1530
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1531
  from eq have "a * c * inverse c = b * inverse c" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1532
  hence "a * (inverse c * c) = b/c" by (simp only: field_simps divide_inverse)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1533
  then show "a = b/c" unfolding  field_inverse[OF c0] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1534
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1535
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1536
lemma radical_unique:  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1537
  assumes r0: "(r (Suc k) (b$0)) ^ Suc k = b$0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1538
  and a0: "r (Suc k) (b$0 ::'a::{field, ring_char_0, recpower}) = a$0" and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1539
  shows "a^(Suc k) = b \<longleftrightarrow> a = fps_radical r (Suc k) b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1540
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1541
  let ?r = "fps_radical r (Suc k) b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1542
  have r00: "r (Suc k) (b$0) \<noteq> 0" using b0 r0 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1543
  {assume H: "a = ?r"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1544
    from H have "a^Suc k = b" using power_radical[of r k, OF r0 b0] by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1545
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1546
  {assume H: "a^Suc k = b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1547
    (* Generally a$0 would need to be the k+1 st root of b$0 *)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1548
    have ceq: "card {0..k} = Suc k" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1549
    have fk: "finite {0..k}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1550
    from a0 have a0r0: "a$0 = ?r$0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1551
    {fix n have "a $ n = ?r $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1552
      proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1553
	fix n assume h: "\<forall>m<n. a$m = ?r $m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1554
	{assume "n = 0" hence "a$n = ?r $n" using a0 by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1555
	moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1556
	{fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1557
	  have fK: "finite {0..k}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1558
	have nz: "n \<noteq> 0" using n1 by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1559
	let ?Pnk = "natpermute n (Suc k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1560
	let ?Pnkn = "{xs \<in> ?Pnk. n \<in> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1561
	let ?Pnknn = "{xs \<in> ?Pnk. n \<notin> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1562
	have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1563
	have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1564
	have f: "finite ?Pnkn" "finite ?Pnknn" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1565
	  using finite_Un[of ?Pnkn ?Pnknn, unfolded eq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1566
	  by (metis natpermute_finite)+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1567
	let ?f = "\<lambda>v. \<Prod>j\<in>{0..k}. ?r $ v ! j"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1568
	let ?g = "\<lambda>v. \<Prod>j\<in>{0..k}. a $ v ! j"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1569
	have "setsum ?g ?Pnkn = setsum (\<lambda>v. a $ n * (?r$0)^k) ?Pnkn" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1570
	proof(rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1571
	  fix v assume v: "v \<in> {xs \<in> natpermute n (Suc k). n \<in> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1572
	  let ?ths = "(\<Prod>j\<in>{0..k}. a $ v ! j) = a $ n * (?r$0)^k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1573
	  from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1574
	    unfolding Suc_plus1 natpermute_contain_maximal by (auto simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1575
	  have "(\<Prod>j\<in>{0..k}. a $ v ! j) = (\<Prod>j\<in>{0..k}. if j = i then a $ n else r (Suc k) (b$0))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1576
	    apply (rule setprod_cong, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1577
	    using i a0 by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1578
	  also have "\<dots> = a $ n * (?r $ 0)^k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1579
	    unfolding  setprod_gen_delta[OF fK] using i by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1580
	  finally show ?ths .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1581
	qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1582
	then have th0: "setsum ?g ?Pnkn = of_nat (k+1) * a $ n * (?r $ 0)^k"  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1583
	  by (simp add: natpermute_max_card[OF nz, simplified])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1584
	have th1: "setsum ?g ?Pnknn = setsum ?f ?Pnknn"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1585
	proof (rule setsum_cong2, rule setprod_cong, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1586
	  fix xs i assume xs: "xs \<in> ?Pnknn" and i: "i \<in> {0..k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1587
	  {assume c: "n \<le> xs ! i"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1588
	    from xs i have "xs !i \<noteq> n" by (auto simp add: in_set_conv_nth natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1589
	    with c have c': "n < xs!i" by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1590
	    have fths: "finite {0 ..< i}" "finite {i}" "finite {i+1..<Suc k}" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1591
	    have d: "{0 ..< i} \<inter> ({i} \<union> {i+1 ..< Suc k}) = {}" "{i} \<inter> {i+1..< Suc k} = {}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1592
	    have eqs: "{0..<Suc k} = {0 ..< i} \<union> ({i} \<union> {i+1 ..< Suc k})" using i by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1593
	    from xs have "n = foldl op + 0 xs" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1594
	    also have "\<dots> = setsum (nth xs) {0..<Suc k}" unfolding foldl_add_setsum using xs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1595
	      by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1596
	    also have "\<dots> = xs!i + setsum (nth xs) {0..<i} + setsum (nth xs) {i+1..<Suc k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1597
	      unfolding eqs  setsum_Un_disjoint[OF fths(1) finite_UnI[OF fths(2,3)] d(1)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1598
	      unfolding setsum_Un_disjoint[OF fths(2) fths(3) d(2)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1599
	      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1600
	    finally have False using c' by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1601
	  then have thn: "xs!i < n" by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1602
	  from h[rule_format, OF thn]  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1603
	  show "a$(xs !i) = ?r$(xs!i)" .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1604
	qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1605
	have th00: "\<And>(x::'a). of_nat (Suc k) * (x * inverse (of_nat (Suc k))) = x"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1606
	  by (simp add: field_simps del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1607
	from H have "b$n = a^Suc k $ n" by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1608
	also have "a ^ Suc k$n = setsum ?g ?Pnkn + setsum ?g ?Pnknn"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1609
	  unfolding fps_power_nth_Suc 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1610
	  using setsum_Un_disjoint[OF f d, unfolded Suc_plus1[symmetric], 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1611
	    unfolded eq, of ?g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1612
	also have "\<dots> = of_nat (k+1) * a $ n * (?r $ 0)^k + setsum ?f ?Pnknn" unfolding th0 th1 ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1613
	finally have "of_nat (k+1) * a $ n * (?r $ 0)^k = b$n - setsum ?f ?Pnknn" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1614
	then have "a$n = (b$n - setsum ?f ?Pnknn) / (of_nat (k+1) * (?r $ 0)^k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1615
	  apply - 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1616
	  apply (rule eq_divide_imp')
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1617
	  using r00
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1618
	  apply (simp del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1619
	  by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1620
	then have "a$n = ?r $n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1621
	  apply (simp del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1622
	  unfolding fps_radical_def n1
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  1623
	  by (simp add: field_simps n1 th00 del: of_nat_Suc)}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1624
	ultimately show "a$n = ?r $ n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1625
      qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1626
    then have "a = ?r" by (simp add: fps_eq_iff)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1627
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1628
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1629
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1630
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1631
lemma radical_power: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1632
  assumes r0: "r (Suc k) ((a$0) ^ Suc k) = a$0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1633
  and a0: "(a$0 ::'a::{field, ring_char_0, recpower}) \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1634
  shows "(fps_radical r (Suc k) (a ^ Suc k)) = a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1635
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1636
  let ?ak = "a^ Suc k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1637
  have ak0: "?ak $ 0 = (a$0) ^ Suc k" by (simp add: fps_nth_power_0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1638
  from r0 have th0: "r (Suc k) (a ^ Suc k $ 0) ^ Suc k = a ^ Suc k $ 0" using ak0 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1639
  from r0 ak0 have th1: "r (Suc k) (a ^ Suc k $ 0) = a $ 0" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1640
  from ak0 a0 have ak00: "?ak $ 0 \<noteq>0 " by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1641
  from radical_unique[of r k ?ak a, OF th0 th1 ak00] show ?thesis by metis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1642
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1643
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1644
lemma fps_deriv_radical: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1645
  fixes a:: "'a ::{field, ring_char_0, recpower} fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1646
  assumes r0: "(r (Suc k) (a$0)) ^ Suc k = a$0" and a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1647
  shows "fps_deriv (fps_radical r (Suc k) a) = fps_deriv a / (fps_const (of_nat (Suc k)) * (fps_radical r (Suc k) a) ^ k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1648
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1649
  let ?r= "fps_radical r (Suc k) a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1650
  let ?w = "(fps_const (of_nat (Suc k)) * ?r ^ k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1651
  from a0 r0 have r0': "r (Suc k) (a$0) \<noteq> 0" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1652
  from r0' have w0: "?w $ 0 \<noteq> 0" by (simp del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1653
  note th0 = inverse_mult_eq_1[OF w0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1654
  let ?iw = "inverse ?w"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1655
  from power_radical[of r, OF r0 a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1656
  have "fps_deriv (?r ^ Suc k) = fps_deriv a" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1657
  hence "fps_deriv ?r * ?w = fps_deriv a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1658
    by (simp add: fps_deriv_power mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1659
  hence "?iw * fps_deriv ?r * ?w = ?iw * fps_deriv a" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1660
  hence "fps_deriv ?r * (?iw * ?w) = fps_deriv a / ?w"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1661
    by (simp add: fps_divide_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1662
  then show ?thesis unfolding th0 by simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1663
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1664
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1665
lemma radical_mult_distrib: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1666
  fixes a:: "'a ::{field, ring_char_0, recpower} fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1667
  assumes 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1668
  ra0: "r (k) (a $ 0) ^ k = a $ 0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1669
  and rb0: "r (k) (b $ 0) ^ k = b $ 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1670
  and r0': "r (k) ((a * b) $ 0) = r (k) (a $ 0) * r (k) (b $ 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1671
  and a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1672
  and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1673
  shows "fps_radical r (k) (a*b) = fps_radical r (k) a * fps_radical r (k) (b)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1674
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1675
  from r0' have r0: "(r (k) ((a*b)$0)) ^ k = (a*b)$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1676
    by (simp add: fps_mult_nth ra0 rb0 power_mult_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1677
  {assume "k=0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1678
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1679
  {fix h assume k: "k = Suc h"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1680
  let ?ra = "fps_radical r (Suc h) a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1681
  let ?rb = "fps_radical r (Suc h) b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1682
  have th0: "r (Suc h) ((a * b) $ 0) = (fps_radical r (Suc h) a * fps_radical r (Suc h) b) $ 0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1683
    using r0' k by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1684
  have ab0: "(a*b) $ 0 \<noteq> 0" using a0 b0 by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1685
  from radical_unique[of r h "a*b" "fps_radical r (Suc h) a * fps_radical r (Suc h) b", OF r0[unfolded k] th0 ab0, symmetric] 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1686
    power_radical[of r, OF ra0[unfolded k] a0] power_radical[of r, OF rb0[unfolded k] b0] k
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1687
  have ?thesis by (auto simp add: power_mult_distrib)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1688
ultimately show ?thesis by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1689
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1690
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1691
lemma radical_inverse:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1692
  fixes a:: "'a ::{field, ring_char_0, recpower} fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1693
  assumes 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1694
  ra0: "r (k) (a $ 0) ^ k = a $ 0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1695
  and ria0: "r (k) (inverse (a $ 0)) = inverse (r (k) (a $ 0))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1696
  and r1: "(r (k) 1) = 1" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1697
  and a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1698
  shows "fps_radical r (k) (inverse a) = inverse (fps_radical r (k) a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1699
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1700
  {assume "k=0" then have ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1701
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1702
  {fix h assume k[simp]: "k = Suc h"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1703
    let ?ra = "fps_radical r (Suc h) a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1704
    let ?ria = "fps_radical r (Suc h) (inverse a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1705
    from ra0 a0 have th00: "r (Suc h) (a$0) \<noteq> 0" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1706
    have ria0': "r (Suc h) (inverse a $ 0) ^ Suc h = inverse a$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1707
    using ria0 ra0 a0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1708
    by (simp add: fps_inverse_def  nonzero_power_inverse[OF th00, symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1709
  from inverse_mult_eq_1[OF a0] have th0: "a * inverse a = 1" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1710
    by (simp add: mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1711
  from radical_unique[where a=1 and b=1 and r=r and k=h, simplified, OF r1[unfolded k]]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1712
  have th01: "fps_radical r (Suc h) 1 = 1" .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1713
  have th1: "r (Suc h) ((a * inverse a) $ 0) ^ Suc h = (a * inverse a) $ 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1714
    "r (Suc h) ((a * inverse a) $ 0) =
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1715
r (Suc h) (a $ 0) * r (Suc h) (inverse a $ 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1716
    using r1 unfolding th0  apply (simp_all add: ria0[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1717
    apply (simp add: fps_inverse_def a0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1718
    unfolding ria0[unfolded k]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1719
    using th00 by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1720
  from nonzero_imp_inverse_nonzero[OF a0] a0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1721
  have th2: "inverse a $ 0 \<noteq> 0" by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1722
  from radical_mult_distrib[of r "Suc h" a "inverse a", OF ra0[unfolded k] ria0' th1(2) a0 th2]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1723
  have th3: "?ra * ?ria = 1" unfolding th0 th01 by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1724
  from th00 have ra0: "?ra $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1725
  from fps_inverse_unique[OF ra0 th3] have ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1726
ultimately show ?thesis by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1727
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1728
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1729
lemma fps_divide_inverse: "(a::('a::field) fps) / b = a * inverse b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1730
  by (simp add: fps_divide_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1731
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1732
lemma radical_divide:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1733
  fixes a:: "'a ::{field, ring_char_0, recpower} fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1734
  assumes 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1735
      ra0: "r k (a $ 0) ^ k = a $ 0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1736
  and rb0: "r k (b $ 0) ^ k = b $ 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1737
  and r1: "r k 1 = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1738
  and rb0': "r k (inverse (b $ 0)) = inverse (r k (b $ 0))" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1739
  and raib': "r k (a$0 / (b$0)) = r k (a$0) / r k (b$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1740
  and a0: "a$0 \<noteq> 0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1741
  and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1742
  shows "fps_radical r k (a/b) = fps_radical r k a / fps_radical r k b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1743
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1744
  from raib'
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1745
  have raib: "r k (a$0 / (b$0)) = r k (a$0) * r k (inverse (b$0))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1746
    by (simp add: divide_inverse rb0'[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1747
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1748
  {assume "k=0" hence ?thesis by (simp add: fps_divide_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1749
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1750
  {assume k0: "k\<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1751
    from b0 k0 rb0 have rbn0: "r k (b $0) \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1752
      by (auto simp add: power_0_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1753
    
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1754
    from rb0 rb0' have rib0: "(r k (inverse (b $ 0)))^k = inverse (b$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1755
    by (simp add: nonzero_power_inverse[OF rbn0, symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1756
  from rib0 have th0: "r k (inverse b $ 0) ^ k = inverse b $ 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1757
    by (simp add:fps_inverse_def b0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1758
  from raib 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1759
  have th1: "r k ((a * inverse b) $ 0) = r k (a $ 0) * r k (inverse b $ 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1760
    by (simp add: divide_inverse fps_inverse_def  b0 fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1761
  from nonzero_imp_inverse_nonzero[OF b0] b0 have th2: "inverse b $ 0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1762
    by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1763
  from radical_mult_distrib[of r k a "inverse b", OF ra0 th0 th1 a0 th2]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1764
  have th: "fps_radical r k (a/b) = fps_radical r k a * fps_radical r k (inverse b)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1765
    by (simp add: fps_divide_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1766
  with radical_inverse[of r k b, OF rb0 rb0' r1 b0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1767
  have ?thesis by (simp add: fps_divide_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1768
ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1769
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1770
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1771
subsection{* Derivative of composition *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1772
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1773
lemma fps_compose_deriv: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1774
  fixes a:: "('a::idom) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1775
  assumes b0: "b$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1776
  shows "fps_deriv (a oo b) = ((fps_deriv a) oo b) * (fps_deriv b)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1777
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1778
  {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1779
    have "(fps_deriv (a oo b))$n = setsum (\<lambda>i. a $ i * (fps_deriv (b^i))$n) {0.. Suc n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1780
      by (simp add: fps_compose_def ring_simps setsum_right_distrib del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1781
    also have "\<dots> = setsum (\<lambda>i. a$i * ((fps_const (of_nat i)) * (fps_deriv b * (b^(i - 1))))$n) {0.. Suc n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1782
      by (simp add: ring_simps fps_deriv_power del: fps_mult_left_const_nth of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1783
  also have "\<dots> = setsum (\<lambda>i. of_nat i * a$i * (((b^(i - 1)) * fps_deriv b))$n) {0.. Suc n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1784
    unfolding fps_mult_left_const_nth  by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1785
  also have "\<dots> = setsum (\<lambda>i. of_nat i * a$i * (setsum (\<lambda>j. (b^ (i - 1))$j * (fps_deriv b)$(n - j)) {0..n})) {0.. Suc n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1786
    unfolding fps_mult_nth ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1787
  also have "\<dots> = setsum (\<lambda>i. of_nat i * a$i * (setsum (\<lambda>j. (b^ (i - 1))$j * (fps_deriv b)$(n - j)) {0..n})) {1.. Suc n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1788
    apply (rule setsum_mono_zero_right)
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1789
    apply (auto simp add: mult_delta_left setsum_delta not_le)
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1790
    done
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1791
  also have "\<dots> = setsum (\<lambda>i. of_nat (i + 1) * a$(i+1) * (setsum (\<lambda>j. (b^ i)$j * of_nat (n - j + 1) * b$(n - j + 1)) {0..n})) {0.. n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1792
    unfolding fps_deriv_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1793
    apply (rule setsum_reindex_cong[where f="Suc"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1794
    by (auto simp add: mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1795
  finally have th0: "(fps_deriv (a oo b))$n = setsum (\<lambda>i. of_nat (i + 1) * a$(i+1) * (setsum (\<lambda>j. (b^ i)$j * of_nat (n - j + 1) * b$(n - j + 1)) {0..n})) {0.. n}" .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1796
  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1797
  have "(((fps_deriv a) oo b) * (fps_deriv b))$n = setsum (\<lambda>i. (fps_deriv b)$ (n - i) * ((fps_deriv a) oo b)$i) {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1798
    unfolding fps_mult_nth by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1799
  also have "\<dots> = setsum (\<lambda>i. setsum (\<lambda>j. of_nat (n - i +1) * b$(n - i + 1) * of_nat (j + 1) * a$(j+1) * (b^j)$i) {0..n}) {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1800
    unfolding fps_deriv_nth fps_compose_nth setsum_right_distrib mult_assoc
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1801
    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1802
    apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1803
    apply (simp_all add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1804
    apply clarify
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1805
    apply (subgoal_tac "b^i$x = 0")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1806
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1807
    apply (rule startsby_zero_power_prefix[OF b0, rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1808
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1809
  also have "\<dots> = setsum (\<lambda>i. of_nat (i + 1) * a$(i+1) * (setsum (\<lambda>j. (b^ i)$j * of_nat (n - j + 1) * b$(n - j + 1)) {0..n})) {0.. n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1810
    unfolding setsum_right_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1811
    apply (subst setsum_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1812
    by ((rule setsum_cong2)+) simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1813
  finally have "(fps_deriv (a oo b))$n = (((fps_deriv a) oo b) * (fps_deriv b)) $n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1814
    unfolding th0 by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1815
then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1816
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1817
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1818
lemma fps_mult_X_plus_1_nth:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1819
  "((1+X)*a) $n = (if n = 0 then (a$n :: 'a::comm_ring_1) else a$n + a$(n - 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1820
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1821
  {assume "n = 0" hence ?thesis by (simp add: fps_mult_nth )}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1822
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1823
  {fix m assume m: "n = Suc m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1824
    have "((1+X)*a) $n = setsum (\<lambda>i. (1+X)$i * a$(n-i)) {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1825
      by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1826
    also have "\<dots> = setsum (\<lambda>i. (1+X)$i * a$(n-i)) {0.. 1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1827
      unfolding m
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1828
      apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1829
      by (auto simp add: )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1830
    also have "\<dots> = (if n = 0 then (a$n :: 'a::comm_ring_1) else a$n + a$(n - 1))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1831
      unfolding m
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1832
      by (simp add: )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1833
    finally have ?thesis .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1834
  ultimately show ?thesis by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1835
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1836
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1837
subsection{* Finite FPS (i.e. polynomials) and X *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1838
lemma fps_poly_sum_X:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1839
  assumes z: "\<forall>i > n. a$i = (0::'a::comm_ring_1)" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1840
  shows "a = setsum (\<lambda>i. fps_const (a$i) * X^i) {0..n}" (is "a = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1841
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1842
  {fix i
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1843
    have "a$i = ?r$i" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1844
      unfolding fps_setsum_nth fps_mult_left_const_nth X_power_nth
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1845
      by (simp add: mult_delta_right setsum_delta' z)
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1846
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1847
  then show ?thesis unfolding fps_eq_iff by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1848
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1849
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1850
subsection{* Compositional inverses *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1851
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1852
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1853
fun compinv :: "'a fps \<Rightarrow> nat \<Rightarrow> 'a::{recpower,field}" where
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1854
  "compinv a 0 = X$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1855
| "compinv a (Suc n) = (X$ Suc n - setsum (\<lambda>i. (compinv a i) * (a^i)$Suc n) {0 .. n}) / (a$1) ^ Suc n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1856
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1857
definition "fps_inv a = Abs_fps (compinv a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1858
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1859
lemma fps_inv: assumes a0: "a$0 = 0" and a1: "a$1 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1860
  shows "fps_inv a oo a = X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1861
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1862
  let ?i = "fps_inv a oo a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1863
  {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1864
    have "?i $n = X$n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1865
    proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1866
      fix n assume h: "\<forall>m<n. ?i$m = X$m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1867
      {assume "n=0" hence "?i $n = X$n" using a0 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1868
	  by (simp add: fps_compose_nth fps_inv_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1869
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1870
      {fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1871
	have "?i $ n = setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1} + fps_inv a $ Suc n1 * (a $ 1)^ Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1872
	  by (simp add: fps_compose_nth n1 startsby_zero_power_nth_same[OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1873
	also have "\<dots> = setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1} + (X$ Suc n1 - setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1})"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  1874
	  using a0 a1 n1 by (simp add: fps_inv_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1875
	also have "\<dots> = X$n" using n1 by simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1876
	finally have "?i $ n = X$n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1877
      ultimately show "?i $ n = X$n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1878
    qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1879
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1880
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1881
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1882
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1883
fun gcompinv :: "'a fps \<Rightarrow> 'a fps \<Rightarrow> nat \<Rightarrow> 'a::{recpower,field}" where
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1884
  "gcompinv b a 0 = b$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1885
| "gcompinv b a (Suc n) = (b$ Suc n - setsum (\<lambda>i. (gcompinv b a i) * (a^i)$Suc n) {0 .. n}) / (a$1) ^ Suc n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1886
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1887
definition "fps_ginv b a = Abs_fps (gcompinv b a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1888
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1889
lemma fps_ginv: assumes a0: "a$0 = 0" and a1: "a$1 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1890
  shows "fps_ginv b a oo a = b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1891
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1892
  let ?i = "fps_ginv b a oo a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1893
  {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1894
    have "?i $n = b$n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1895
    proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1896
      fix n assume h: "\<forall>m<n. ?i$m = b$m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1897
      {assume "n=0" hence "?i $n = b$n" using a0 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1898
	  by (simp add: fps_compose_nth fps_ginv_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1899
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1900
      {fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1901
	have "?i $ n = setsum (\<lambda>i. (fps_ginv b a $ i) * (a^i)$n) {0 .. n1} + fps_ginv b a $ Suc n1 * (a $ 1)^ Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1902
	  by (simp add: fps_compose_nth n1 startsby_zero_power_nth_same[OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1903
	also have "\<dots> = setsum (\<lambda>i. (fps_ginv b a $ i) * (a^i)$n) {0 .. n1} + (b$ Suc n1 - setsum (\<lambda>i. (fps_ginv b a $ i) * (a^i)$n) {0 .. n1})"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  1904
	  using a0 a1 n1 by (simp add: fps_ginv_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1905
	also have "\<dots> = b$n" using n1 by simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1906
	finally have "?i $ n = b$n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1907
      ultimately show "?i $ n = b$n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1908
    qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1909
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1910
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1911
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1912
lemma fps_inv_ginv: "fps_inv = fps_ginv X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1913
  apply (auto simp add: expand_fun_eq fps_eq_iff fps_inv_def fps_ginv_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1914
  apply (induct_tac n rule: nat_less_induct, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1915
  apply (case_tac na)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1916
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1917
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1918
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1919
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1920
lemma fps_compose_1[simp]: "1 oo a = 1"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1921
  by (simp add: fps_eq_iff fps_compose_nth fps_power_def mult_delta_left setsum_delta)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1922
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1923
lemma fps_compose_0[simp]: "0 oo a = 0"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1924
  by (simp add: fps_eq_iff fps_compose_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1925
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1926
lemma fps_pow_0: "fps_pow n 0 = (if n = 0 then 1 else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1927
  by (induct n, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1928
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1929
lemma fps_compose_0_right[simp]: "a oo 0 = fps_const (a$0)"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1930
  by (auto simp add: fps_eq_iff fps_compose_nth fps_power_def fps_pow_0 setsum_0')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1931
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1932
lemma fps_compose_add_distrib: "(a + b) oo c = (a oo c) + (b oo c)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1933
  by (simp add: fps_eq_iff fps_compose_nth  ring_simps setsum_addf)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1934
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1935
lemma fps_compose_setsum_distrib: "(setsum f S) oo a = setsum (\<lambda>i. f i oo a) S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1936
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1937
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1938
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1939
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1940
    have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1941
    proof(rule finite_induct[OF fS])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1942
      show "setsum f {} oo a = (\<Sum>i\<in>{}. f i oo a)" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1943
    next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1944
      fix x F assume fF: "finite F" and xF: "x \<notin> F" and h: "setsum f F oo a = setsum (\<lambda>i. f i oo a) F"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1945
      show "setsum f (insert x F) oo a  = setsum (\<lambda>i. f i oo a) (insert x F)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1946
	using fF xF h by (simp add: fps_compose_add_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1947
    qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1948
  ultimately show ?thesis by blast 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1949
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1950
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1951
lemma convolution_eq: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1952
  "setsum (%i. a (i :: nat) * b (n - i)) {0 .. n} = setsum (%(i,j). a i * b j) {(i,j). i <= n \<and> j \<le> n \<and> i + j = n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1953
  apply (rule setsum_reindex_cong[where f=fst])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1954
  apply (clarsimp simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1955
  apply (auto simp add: expand_set_eq image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1956
  apply (rule_tac x= "x" in exI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1957
  apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1958
  apply (rule_tac x="n - x" in exI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1959
  apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1960
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1961
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1962
lemma product_composition_lemma:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1963
  assumes c0: "c$0 = (0::'a::idom)" and d0: "d$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1964
  shows "((a oo c) * (b oo d))$n = setsum (%(k,m). a$k * b$m * (c^k * d^m) $ n) {(k,m). k + m \<le> n}" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1965
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1966
  let ?S = "{(k\<Colon>nat, m\<Colon>nat). k + m \<le> n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1967
  have s: "?S \<subseteq> {0..n} <*> {0..n}" by (auto simp add: subset_eq)  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1968
  have f: "finite {(k\<Colon>nat, m\<Colon>nat). k + m \<le> n}" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1969
    apply (rule finite_subset[OF s])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1970
    by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1971
  have "?r =  setsum (%i. setsum (%(k,m). a$k * (c^k)$i * b$m * (d^m) $ (n - i)) {(k,m). k + m \<le> n}) {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1972
    apply (simp add: fps_mult_nth setsum_right_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1973
    apply (subst setsum_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1974
    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1975
    by (auto simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1976
  also have "\<dots> = ?l" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1977
    apply (simp add: fps_mult_nth fps_compose_nth setsum_product)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1978
    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1979
    apply (simp add: setsum_cartesian_product mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1980
    apply (rule setsum_mono_zero_right[OF f])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1981
    apply (simp add: subset_eq) apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1982
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1983
    apply (rule ccontr)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1984
    apply (clarsimp simp add: not_le)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1985
    apply (case_tac "x < aa")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1986
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1987
    apply (frule_tac startsby_zero_power_prefix[rule_format, OF c0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1988
    apply blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1989
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1990
    apply (frule_tac startsby_zero_power_prefix[rule_format, OF d0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1991
    apply blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1992
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1993
  finally show ?thesis by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1994
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1995
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1996
lemma product_composition_lemma':
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1997
  assumes c0: "c$0 = (0::'a::idom)" and d0: "d$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1998
  shows "((a oo c) * (b oo d))$n = setsum (%k. setsum (%m. a$k * b$m * (c^k * d^m) $ n) {0..n}) {0..n}" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1999
  unfolding product_composition_lemma[OF c0 d0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2000
  unfolding setsum_cartesian_product
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2001
  apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2002
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2003
  apply (clarsimp simp add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2004
  apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2005
  apply (rule ccontr)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2006
  apply (subgoal_tac "(c^aa * d^ba) $ n = 0")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2007
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2008
  unfolding fps_mult_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2009
  apply (rule setsum_0')
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2010
  apply (clarsimp simp add: not_le)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2011
  apply (case_tac "aaa < aa")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2012
  apply (rule startsby_zero_power_prefix[OF c0, rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2013
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2014
  apply (subgoal_tac "n - aaa < ba")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2015
  apply (frule_tac k = "ba" in startsby_zero_power_prefix[OF d0, rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2016
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2017
  apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2018
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2019
  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2020
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2021
lemma setsum_pair_less_iff: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2022
  "setsum (%((k::nat),m). a k * b m * c (k + m)) {(k,m). k + m \<le> n} = setsum (%s. setsum (%i. a i * b (s - i) * c s) {0..s}) {0..n}" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2023
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2024
  let ?KM=  "{(k,m). k + m \<le> n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2025
  let ?f = "%s. UNION {(0::nat)..s} (%i. {(i,s - i)})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2026
  have th0: "?KM = UNION {0..n} ?f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2027
    apply (simp add: expand_set_eq)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2028
    apply arith (* FIXME: VERY slow! *)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2029
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2030
  show "?l = ?r "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2031
    unfolding th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2032
    apply (subst setsum_UN_disjoint)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2033
    apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2034
    apply (subst setsum_UN_disjoint)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2035
    apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2036
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2037
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2038
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2039
lemma fps_compose_mult_distrib_lemma:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2040
  assumes c0: "c$0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2041
  shows "((a oo c) * (b oo c))$n = setsum (%s. setsum (%i. a$i * b$(s - i) * (c^s) $ n) {0..s}) {0..n}" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2042
  unfolding product_composition_lemma[OF c0 c0] power_add[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2043
  unfolding setsum_pair_less_iff[where a = "%k. a$k" and b="%m. b$m" and c="%s. (c ^ s)$n" and n = n] ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2044
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2045
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2046
lemma fps_compose_mult_distrib: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2047
  assumes c0: "c$0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2048
  shows "(a * b) oo c = (a oo c) * (b oo c)" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2049
  apply (simp add: fps_eq_iff fps_compose_mult_distrib_lemma[OF c0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2050
  by (simp add: fps_compose_nth fps_mult_nth setsum_left_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2051
lemma fps_compose_setprod_distrib: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2052
  assumes c0: "c$0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2053
  shows "(setprod a S) oo c = setprod (%k. a k oo c) S" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2054
  apply (cases "finite S")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2055
  apply simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2056
  apply (induct S rule: finite_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2057
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2058
  apply (simp add: fps_compose_mult_distrib[OF c0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2059
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2060
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2061
lemma fps_compose_power:   assumes c0: "c$0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2062
  shows "(a oo c)^n = a^n oo c" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2063
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2064
  {assume "n=0" then have ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2065
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2066
  {fix m assume m: "n = Suc m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2067
    have th0: "a^n = setprod (%k. a) {0..m}" "(a oo c) ^ n = setprod (%k. a oo c) {0..m}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2068
      by (simp_all add: setprod_constant m)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2069
    then have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2070
      by (simp add: fps_compose_setprod_distrib[OF c0])}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2071
  ultimately show ?thesis by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2072
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2073
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2074
lemma fps_const_mult_apply_left:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2075
  "fps_const c * (a oo b) = (fps_const c * a) oo b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2076
  by (simp add: fps_eq_iff fps_compose_nth setsum_right_distrib mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2077
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2078
lemma fps_const_mult_apply_right:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2079
  "(a oo b) * fps_const (c::'a::comm_semiring_1) = (fps_const c * a) oo b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2080
  by (auto simp add: fps_const_mult_apply_left mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2081
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2082
lemma fps_compose_assoc: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2083
  assumes c0: "c$0 = (0::'a::idom)" and b0: "b$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2084
  shows "a oo (b oo c) = a oo b oo c" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2085
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2086
  {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2087
    have "?l$n = (setsum (\<lambda>i. (fps_const (a$i) * b^i) oo c) {0..n})$n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2088
      by (simp add: fps_compose_nth fps_compose_power[OF c0] fps_const_mult_apply_left setsum_right_distrib mult_assoc fps_setsum_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2089
    also have "\<dots> = ((setsum (\<lambda>i. fps_const (a$i) * b^i) {0..n}) oo c)$n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2090
      by (simp add: fps_compose_setsum_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2091
    also have "\<dots> = ?r$n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2092
      apply (simp add: fps_compose_nth fps_setsum_nth setsum_left_distrib mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2093
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2094
      apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2095
      apply (auto simp add: not_le)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2096
      by (erule startsby_zero_power_prefix[OF b0, rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2097
    finally have "?l$n = ?r$n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2098
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2099
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2100
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2101
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2102
lemma fps_X_power_compose:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2103
  assumes a0: "a$0=0" shows "X^k oo a = (a::('a::idom fps))^k" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2104
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2105
  {assume "k=0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2106
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2107
  {fix h assume h: "k = Suc h"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2108
    {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2109
      {assume kn: "k>n" hence "?l $ n = ?r $n" using a0 startsby_zero_power_prefix[OF a0] h 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2110
	  by (simp add: fps_compose_nth)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2111
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2112
      {assume kn: "k \<le> n"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  2113
	hence "?l$n = ?r$n"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  2114
          by (simp add: fps_compose_nth mult_delta_left setsum_delta)}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2115
      moreover have "k >n \<or> k\<le> n"  by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2116
      ultimately have "?l$n = ?r$n"  by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2117
    then have ?thesis unfolding fps_eq_iff by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2118
  ultimately show ?thesis by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2119
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2120
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2121
lemma fps_inv_right: assumes a0: "a$0 = 0" and a1: "a$1 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2122
  shows "a oo fps_inv a = X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2123
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2124
  let ?ia = "fps_inv a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2125
  let ?iaa = "a oo fps_inv a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2126
  have th0: "?ia $ 0 = 0" by (simp add: fps_inv_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2127
  have th1: "?iaa $ 0 = 0" using a0 a1 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2128
    by (simp add: fps_inv_def fps_compose_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2129
  have th2: "X$0 = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2130
  from fps_inv[OF a0 a1] have "a oo (fps_inv a oo a) = a oo X" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2131
  then have "(a oo fps_inv a) oo a = X oo a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2132
    by (simp add: fps_compose_assoc[OF a0 th0] X_fps_compose_startby0[OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2133
  with fps_compose_inj_right[OF a0 a1]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2134
  show ?thesis by simp 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2135
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2136
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2137
lemma fps_inv_deriv:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2138
  assumes a0:"a$0 = (0::'a::{recpower,field})" and a1: "a$1 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2139
  shows "fps_deriv (fps_inv a) = inverse (fps_deriv a oo fps_inv a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2140
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2141
  let ?ia = "fps_inv a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2142
  let ?d = "fps_deriv a oo ?ia"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2143
  let ?dia = "fps_deriv ?ia"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2144
  have ia0: "?ia$0 = 0" by (simp add: fps_inv_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2145
  have th0: "?d$0 \<noteq> 0" using a1 by (simp add: fps_compose_nth fps_deriv_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2146
  from fps_inv_right[OF a0 a1] have "?d * ?dia = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2147
    by (simp add: fps_compose_deriv[OF ia0, of a, symmetric] )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2148
  hence "inverse ?d * ?d * ?dia = inverse ?d * 1" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2149
  with inverse_mult_eq_1[OF th0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2150
  show "?dia = inverse ?d" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2151
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2152
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  2153
subsection{* Elementary series *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2154
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  2155
subsubsection{* Exponential series *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2156
definition "E x = Abs_fps (\<lambda>n. x^n / of_nat (fact n))"   
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2157
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2158
lemma E_deriv[simp]: "fps_deriv (E a) = fps_const (a::'a::{field, recpower, ring_char_0}) * E a" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2159
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2160
  {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2161
    have "?l$n = ?r $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2162
  apply (auto simp add: E_def field_simps power_Suc[symmetric]simp del: fact_Suc of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2163
  by (simp add: of_nat_mult ring_simps)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2164
then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2165
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2166
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2167
lemma E_unique_ODE: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2168
  "fps_deriv a = fps_const c * a \<longleftrightarrow> a = fps_const (a$0) * E (c :: 'a::{field, ring_char_0, recpower})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2169
  (is "?lhs \<longleftrightarrow> ?rhs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2170
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2171
  {assume d: ?lhs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2172
  from d have th: "\<And>n. a $ Suc n = c * a$n / of_nat (Suc n)" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2173
    by (simp add: fps_deriv_def fps_eq_iff field_simps del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2174
  {fix n have "a$n = a$0 * c ^ n/ (of_nat (fact n))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2175
      apply (induct n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2176
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2177
      unfolding th 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2178
      using fact_gt_zero
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2179
      apply (simp add: field_simps del: of_nat_Suc fact.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2180
      apply (drule sym)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2181
      by (simp add: ring_simps of_nat_mult power_Suc)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2182
  note th' = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2183
  have ?rhs 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2184
    by (auto simp add: fps_eq_iff fps_const_mult_left E_def intro : th')}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2185
moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2186
{assume h: ?rhs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2187
  have ?lhs 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2188
    apply (subst h)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2189
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2190
    apply (simp only: h[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2191
  by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2192
ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2193
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2194
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2195
lemma E_add_mult: "E (a + b) = E (a::'a::{ring_char_0, field, recpower}) * E b" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2196
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2197
  have "fps_deriv (?r) = fps_const (a+b) * ?r"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2198
    by (simp add: fps_const_add[symmetric] ring_simps del: fps_const_add)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2199
  then have "?r = ?l" apply (simp only: E_unique_ODE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2200
    by (simp add: fps_mult_nth E_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2201
  then show ?thesis ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2202
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2203
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2204
lemma E_nth[simp]: "E a $ n = a^n / of_nat (fact n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2205
  by (simp add: E_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2206
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2207
lemma E0[simp]: "E (0::'a::{field, recpower}) = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2208
  by (simp add: fps_eq_iff power_0_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2209
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2210
lemma E_neg: "E (- a) = inverse (E (a::'a::{ring_char_0, field, recpower}))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2211
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2212
  from E_add_mult[of a "- a"] have th0: "E a * E (- a) = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2213
    by (simp )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2214
  have th1: "E a $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2215
  from fps_inverse_unique[OF th1 th0] show ?thesis by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2216
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2217
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2218
lemma E_nth_deriv[simp]: "fps_nth_deriv n (E (a::'a::{field, recpower, ring_char_0})) = (fps_const a)^n * (E a)"  
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2219
  by (induct n, auto simp add: power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2220
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2221
lemma fps_compose_uminus: "- (a::'a::ring_1 fps) oo c = - (a oo c)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2222
  by (simp add: fps_eq_iff fps_compose_nth ring_simps setsum_negf[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2223
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2224
lemma fps_compose_sub_distrib: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2225
  shows "(a - b) oo (c::'a::ring_1 fps) = (a oo c) - (b oo c)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2226
  unfolding diff_minus fps_compose_uminus fps_compose_add_distrib ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2227
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2228
lemma X_fps_compose:"X oo a = Abs_fps (\<lambda>n. if n = 0 then (0::'a::comm_ring_1) else a$n)"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  2229
  by (simp add: fps_eq_iff fps_compose_nth mult_delta_left setsum_delta power_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2230
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2231
lemma X_compose_E[simp]: "X oo E (a::'a::{field, recpower}) = E a - 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2232
  by (simp add: fps_eq_iff X_fps_compose)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2233
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2234
lemma LE_compose: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2235
  assumes a: "a\<noteq>0" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2236
  shows "fps_inv (E a - 1) oo (E a - 1) = X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2237
  and "(E a - 1) oo fps_inv (E a - 1) = X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2238
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2239
  let ?b = "E a - 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2240
  have b0: "?b $ 0 = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2241
  have b1: "?b $ 1 \<noteq> 0" by (simp add: a)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2242
  from fps_inv[OF b0 b1] show "fps_inv (E a - 1) oo (E a - 1) = X" .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2243
  from fps_inv_right[OF b0 b1] show "(E a - 1) oo fps_inv (E a - 1) = X" .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2244
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2245
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2246
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2247
lemma fps_const_inverse: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2248
  "inverse (fps_const (a::'a::{field, division_by_zero})) = fps_const (inverse a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2249
  apply (auto simp add: fps_eq_iff fps_inverse_def) by (case_tac "n", auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2250
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2251
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2252
lemma inverse_one_plus_X: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2253
  "inverse (1 + X) = Abs_fps (\<lambda>n. (- 1 ::'a::{field, recpower})^n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2254
  (is "inverse ?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2255
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2256
  have th: "?l * ?r = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2257
    apply (auto simp add: ring_simps fps_eq_iff X_mult_nth  minus_one_power_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2258
    apply presburger+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2259
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2260
  have th': "?l $ 0 \<noteq> 0" by (simp add: )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2261
  from fps_inverse_unique[OF th' th] show ?thesis .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2262
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2263
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2264
lemma E_power_mult: "(E (c::'a::{field,recpower,ring_char_0}))^n = E (of_nat n * c)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2265
  by (induct n, auto simp add: ring_simps E_add_mult power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2266
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  2267
subsubsection{* Logarithmic series *}  
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2268
definition "(L::'a::{field, ring_char_0,recpower} fps) 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2269
  = Abs_fps (\<lambda>n. (- 1) ^ Suc n / of_nat n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2270
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2271
lemma fps_deriv_L: "fps_deriv L = inverse (1 + X)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2272
  unfolding inverse_one_plus_X
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2273
  by (simp add: L_def fps_eq_iff power_Suc del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2274
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2275
lemma L_nth: "L $ n = (- 1) ^ Suc n / of_nat n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2276
  by (simp add: L_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2277
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2278
lemma L_E_inv:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2279
  assumes a: "a\<noteq> (0::'a::{field,division_by_zero,ring_char_0,recpower})" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2280
  shows "L = fps_const a * fps_inv (E a - 1)" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2281
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2282
  let ?b = "E a - 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2283
  have b0: "?b $ 0 = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2284
  have b1: "?b $ 1 \<noteq> 0" by (simp add: a)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2285
  have "fps_deriv (E a - 1) oo fps_inv (E a - 1) = (fps_const a * (E a - 1) + fps_const a) oo fps_inv (E a - 1)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2286
    by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2287
  also have "\<dots> = fps_const a * (X + 1)" apply (simp add: fps_compose_add_distrib fps_const_mult_apply_left[symmetric] fps_inv_right[OF b0 b1])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2288
    by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2289
  finally have eq: "fps_deriv (E a - 1) oo fps_inv (E a - 1) = fps_const a * (X + 1)" .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2290
  from fps_inv_deriv[OF b0 b1, unfolded eq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2291
  have "fps_deriv (fps_inv ?b) = fps_const (inverse a) / (X + 1)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2292
    by (simp add: fps_const_inverse eq fps_divide_def fps_inverse_mult)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2293
  hence "fps_deriv (fps_const a * fps_inv ?b) = inverse (X + 1)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2294
    using a by (simp add: fps_divide_def field_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2295
  hence "fps_deriv ?l = fps_deriv ?r" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2296
    by (simp add: fps_deriv_L add_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2297
  then show ?thesis unfolding fps_deriv_eq_iff
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2298
    by (simp add: L_nth fps_inv_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2299
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2300
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  2301
subsubsection{* Formal trigonometric functions  *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2302
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2303
definition "fps_sin (c::'a::{field, recpower, ring_char_0}) = 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2304
  Abs_fps (\<lambda>n. if even n then 0 else (- 1) ^((n - 1) div 2) * c^n /(of_nat (fact n)))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2305
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2306
definition "fps_cos (c::'a::{field, recpower, ring_char_0}) = Abs_fps (\<lambda>n. if even n then (- 1) ^ (n div 2) * c^n / (of_nat (fact n)) else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2307
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2308
lemma fps_sin_deriv: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2309
  "fps_deriv (fps_sin c) = fps_const c * fps_cos c"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2310
  (is "?lhs = ?rhs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2311
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2312
  {fix n::nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2313
    {assume en: "even n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2314
      have "?lhs$n = of_nat (n+1) * (fps_sin c $ (n+1))" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2315
      also have "\<dots> = of_nat (n+1) * ((- 1)^(n div 2) * c^Suc n / of_nat (fact (Suc n)))" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2316
	using en by (simp add: fps_sin_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2317
      also have "\<dots> = (- 1)^(n div 2) * c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2318
	unfolding fact_Suc of_nat_mult
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2319
	by (simp add: field_simps del: of_nat_add of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2320
      also have "\<dots> = (- 1)^(n div 2) *c^Suc n / of_nat (fact n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2321
	by (simp add: field_simps del: of_nat_add of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2322
      finally have "?lhs $n = ?rhs$n" using en 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2323
	by (simp add: fps_cos_def ring_simps power_Suc )}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2324
    then have "?lhs $ n = ?rhs $ n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2325
      by (cases "even n", simp_all add: fps_deriv_def fps_sin_def fps_cos_def) }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2326
  then show ?thesis by (auto simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2327
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2328
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2329
lemma fps_cos_deriv: 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2330
  "fps_deriv (fps_cos c) = fps_const (- c)* (fps_sin c)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2331
  (is "?lhs = ?rhs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2332
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2333
  have th0: "\<And>n. - ((- 1::'a) ^ n) = (- 1)^Suc n" by (simp add: power_Suc)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2334
  have th1: "\<And>n. odd n\<Longrightarrow> Suc ((n - 1) div 2) = Suc n div 2" by presburger (* FIXME: VERY slow! *)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2335
  {fix n::nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2336
    {assume en: "odd n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2337
      from en have n0: "n \<noteq>0 " by presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2338
      have "?lhs$n = of_nat (n+1) * (fps_cos c $ (n+1))" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2339
      also have "\<dots> = of_nat (n+1) * ((- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact (Suc n)))" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2340
	using en by (simp add: fps_cos_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2341
      also have "\<dots> = (- 1)^((n + 1) div 2)*c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2342
	unfolding fact_Suc of_nat_mult
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2343
	by (simp add: field_simps del: of_nat_add of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2344
      also have "\<dots> = (- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2345
	by (simp add: field_simps del: of_nat_add of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2346
      also have "\<dots> = (- ((- 1)^((n - 1) div 2))) * c^Suc n / of_nat (fact n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2347
	unfolding th0 unfolding th1[OF en] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2348
      finally have "?lhs $n = ?rhs$n" using en 
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2349
	by (simp add: fps_sin_def ring_simps power_Suc)}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2350
    then have "?lhs $ n = ?rhs $ n" 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2351
      by (cases "even n", simp_all add: fps_deriv_def fps_sin_def 
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2352
	fps_cos_def) }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2353
  then show ?thesis by (auto simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2354
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2355
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2356
lemma fps_sin_cos_sum_of_squares:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2357
  "fps_cos c ^ 2 + fps_sin c ^ 2 = 1" (is "?lhs = 1")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2358
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2359
  have "fps_deriv ?lhs = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2360
    apply (simp add:  fps_deriv_power fps_sin_deriv fps_cos_deriv power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2361
    by (simp add: fps_power_def ring_simps fps_const_neg[symmetric] del: fps_const_neg)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2362
  then have "?lhs = fps_const (?lhs $ 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2363
    unfolding fps_deriv_eq_0_iff .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2364
  also have "\<dots> = 1"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2365
    by (auto simp add: fps_eq_iff fps_power_def numeral_2_eq_2 fps_mult_nth fps_cos_def fps_sin_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2366
  finally show ?thesis .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2367
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2368
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2369
definition "fps_tan c = fps_sin c / fps_cos c"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2370
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2371
lemma fps_tan_deriv: "fps_deriv(fps_tan c) = fps_const c/ (fps_cos c ^ 2)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2372
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2373
  have th0: "fps_cos c $ 0 \<noteq> 0" by (simp add: fps_cos_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2374
  show ?thesis 
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2375
    using fps_sin_cos_sum_of_squares[of c]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2376
    apply (simp add: fps_tan_def fps_divide_deriv[OF th0] fps_sin_deriv fps_cos_deriv add: fps_const_neg[symmetric] ring_simps power2_eq_square del: fps_const_neg)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2377
    unfolding right_distrib[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2378
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2379
qed
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2380
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2381
end