src/HOL/Library/Formal_Power_Series.thy
author nipkow
Wed, 24 Jun 2009 09:41:14 +0200
changeset 31790 05c92381363c
parent 31776 151c3f5f28f9
child 31968 0314441a53a6
permissions -rw-r--r--
corrected and unified thm names
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     1
(*  Title:      Formal_Power_Series.thy
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     2
    Author:     Amine Chaieb, University of Cambridge
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     3
*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     4
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     5
header{* A formalization of formal power series *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     6
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     7
theory Formal_Power_Series
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
     8
imports Main Fact Parity Rational
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     9
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    10
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
    11
subsection {* The type of formal power series*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    12
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    13
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
    14
  morphisms fps_nth Abs_fps
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    15
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    16
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    17
notation fps_nth (infixl "$" 75)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    18
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    19
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
    20
  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
    21
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    22
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
    23
  by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    24
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    25
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
    26
  by (simp add: Abs_fps_inverse)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    27
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    28
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
    29
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    30
instantiation fps :: (zero)  zero
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    31
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    32
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    33
definition fps_zero_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    34
  "0 = Abs_fps (\<lambda>n. 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    35
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    36
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    37
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    38
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    39
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
    40
  unfolding fps_zero_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    41
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    42
instantiation fps :: ("{one,zero}")  one
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    43
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    44
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    45
definition fps_one_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    46
  "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
    47
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    48
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    49
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    50
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
    51
lemma fps_one_nth [simp]: "1 $ n = (if n = 0 then 1 else 0)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    52
  unfolding fps_one_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    53
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    54
instantiation fps :: (plus)  plus
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    55
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    56
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    57
definition fps_plus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    58
  "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
    59
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    60
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    61
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    62
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    63
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
    64
  unfolding fps_plus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    65
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    66
instantiation fps :: (minus) minus
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    67
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    68
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    69
definition fps_minus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    70
  "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
    71
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    72
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    73
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    74
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    75
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
    76
  unfolding fps_minus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    77
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    78
instantiation fps :: (uminus) uminus
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    79
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    80
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    81
definition fps_uminus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    82
  "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
    83
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    84
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    85
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    86
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    87
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
    88
  unfolding fps_uminus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    89
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    90
instantiation fps :: ("{comm_monoid_add, times}")  times
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    91
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    92
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    93
definition fps_times_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    94
  "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
    95
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    96
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    97
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    98
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    99
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
   100
  unfolding fps_times_def by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   101
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   102
declare atLeastAtMost_iff[presburger]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   103
declare Bex_def[presburger]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   104
declare Ball_def[presburger]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   105
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   106
lemma mult_delta_left:
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   107
  fixes x y :: "'a::mult_zero"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   108
  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
   109
  by simp
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   110
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   111
lemma mult_delta_right:
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   112
  fixes x y :: "'a::mult_zero"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   113
  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
   114
  by simp
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   115
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   116
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
   117
  by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   118
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
   119
  by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   120
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   121
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
   122
  they represent is a commutative ring with unity*}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   123
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   124
instance fps :: (semigroup_add) semigroup_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   125
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   126
  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
   127
    by (simp add: fps_ext add_assoc)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   128
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   129
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   130
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
   131
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   132
  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
   133
    by (simp add: fps_ext add_commute)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   134
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   135
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   136
lemma fps_mult_assoc_lemma:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   137
  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
   138
  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
   139
         (\<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
   140
proof (induct k)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   141
  case 0 show ?case by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   142
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   143
  case (Suc k) thus ?case
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   144
    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
   145
             cong: strong_setsum_cong)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   146
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   147
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   148
instance fps :: (semiring_0) semigroup_mult
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   149
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   150
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   151
  show "(a * b) * c = a * (b * c)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   152
  proof (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   153
    fix n :: nat
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   154
    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
   155
          (\<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
   156
      by (rule fps_mult_assoc_lemma)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   157
    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
   158
      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
   159
                    setsum_left_distrib mult_assoc)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   160
  qed
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
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   163
lemma fps_mult_commute_lemma:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   164
  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
   165
  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
   166
proof (rule setsum_reindex_cong)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   167
  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
   168
    by (rule inj_onI) simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   169
  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
   170
    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
   171
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   172
  fix i assume "i \<in> {0..n}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   173
  hence "n - (n - i) = i" by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   174
  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
   175
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   176
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   177
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
   178
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   179
  fix a b :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   180
  show "a * b = b * a"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   181
  proof (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   182
    fix n :: nat
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   183
    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
   184
      by (rule fps_mult_commute_lemma)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   185
    thus "(a * b) $ n = (b * a) $ n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   186
      by (simp add: fps_mult_nth mult_commute)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   187
  qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   188
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   189
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   190
instance fps :: (monoid_add) monoid_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   191
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   192
  fix a :: "'a fps" show "0 + a = a "
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   193
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   194
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   195
  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
   196
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   197
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   198
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   199
instance fps :: (comm_monoid_add) comm_monoid_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   200
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   201
  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
   202
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   203
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   204
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   205
instance fps :: (semiring_1) monoid_mult
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   206
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   207
  fix a :: "'a fps" show "1 * a = a"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   208
    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
   209
next
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   210
  fix a :: "'a fps" show "a * 1 = a"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   211
    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
   212
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   213
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   214
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
   215
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   216
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   217
  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
   218
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   219
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   220
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   221
  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
   222
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   223
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   224
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   225
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
   226
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   227
  fix a b c :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   228
  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
   229
    by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   230
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   231
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   232
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
   233
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   234
instance fps :: (group_add) group_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   235
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   236
  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
   237
    by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   238
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   239
  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
   240
    by (simp add: fps_ext diff_minus)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   241
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   242
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   243
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
   244
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   245
  fix a :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   246
  show "- a + a = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   247
    by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   248
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   249
  fix a b :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   250
  show "a - b = a + - b"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   251
    by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   252
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   253
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   254
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
   255
  by default (simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   256
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   257
instance fps :: (semiring_0) semiring
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   258
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   259
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   260
  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
   261
    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
   262
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   263
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   264
  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
   265
    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
   266
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   267
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   268
instance fps :: (semiring_0) semiring_0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   269
proof
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   270
  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
   271
    by (simp add: fps_ext fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   272
next
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   273
  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
   274
    by (simp add: fps_ext fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   275
qed
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   276
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   277
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
   278
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   279
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
   280
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   281
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
   282
  by (simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   283
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   284
lemma fps_nonzero_nth_minimal:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   285
  "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
   286
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   287
  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
   288
  assume "f \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   289
  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
   290
    by (simp add: fps_nonzero_nth)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   291
  then have "f $ ?n \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   292
    by (rule LeastI_ex)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   293
  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
   294
    by (auto dest: not_less_Least)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   295
  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
   296
  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
   297
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   298
  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
   299
  then show "f \<noteq> 0" by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   300
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   301
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   302
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
   303
  by (rule expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   304
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   305
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
   306
proof (cases "finite S")
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   307
  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
   308
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   309
  assume "finite S"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   310
  then show ?thesis by (induct set: finite) auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   311
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   312
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   313
subsection{* Injection of the basic ring elements and multiplication by scalars *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   314
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   315
definition
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   316
  "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
   317
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   318
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
   319
  unfolding fps_const_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   320
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   321
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
   322
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   323
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   324
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
   325
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   326
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   327
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
   328
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   329
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   330
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
   331
  by (simp add: fps_ext)
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   332
lemma fps_const_sub [simp]: "fps_const (c::'a\<Colon>group_add) - fps_const d = fps_const (c - d)"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   333
  by (simp add: fps_ext)
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
30746
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   392
instantiation fps :: (comm_ring_1) number_ring
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   393
begin
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   394
definition number_of_fps_def: "(number_of k::'a fps) = of_int k"
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   395
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   396
instance proof
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   397
qed (rule number_of_fps_def)
30746
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   398
end
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   399
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   400
lemma number_of_fps_const: "(number_of k::('a::comm_ring_1) fps) = fps_const (of_int k)"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   401
  
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   402
proof(induct k rule: int_induct[where k=0])
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   403
  case base thus ?case unfolding number_of_fps_def of_int_0 by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   404
next
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   405
  case (step1 i) thus ?case unfolding number_of_fps_def 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   406
    by (simp add: fps_const_add[symmetric] del: fps_const_add)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   407
next
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   408
  case (step2 i) thus ?case unfolding number_of_fps_def 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   409
    by (simp add: fps_const_sub[symmetric] del: fps_const_sub)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   410
qed
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   411
  
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   412
subsection{* Inverses of formal power series *}
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
declare setsum_cong[fundef_cong]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   415
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   416
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   417
instantiation fps :: ("{comm_monoid_add,inverse, times, uminus}") inverse
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   418
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   419
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   420
fun natfun_inverse:: "'a fps \<Rightarrow> nat \<Rightarrow> 'a" where
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   421
  "natfun_inverse f 0 = inverse (f$0)"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   422
| "natfun_inverse f n = - inverse (f$0) * setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   423
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   424
definition fps_inverse_def:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   425
  "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
   426
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
   427
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   428
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   429
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   430
lemma fps_inverse_zero[simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   431
  "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
   432
  by (simp add: fps_ext fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   433
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   434
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
   435
  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
   436
  by (case_tac n, auto)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   437
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   438
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
   439
  by default (rule fps_inverse_zero)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   440
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   441
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
   442
  shows "inverse f * f = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   443
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   444
  have c: "inverse f * f = f * inverse f" by (simp add: mult_commute)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   445
  from f0 have ifn: "\<And>n. inverse f $ n = natfun_inverse f n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   446
    by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   447
  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
   448
    by (simp add: fps_mult_nth fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   449
  {fix n::nat assume np: "n >0 "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   450
    from np have eq: "{0..n} = {0} \<union> {1 .. n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   451
    have d: "{0} \<inter> {1 .. n} = {}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   452
    have f: "finite {0::nat}" "finite {1..n}" by auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   453
    from f0 np have th0: "- (inverse f$n) =
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   454
      (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
   455
      by (cases n, simp, simp add: divide_inverse fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   456
    from th0[symmetric, unfolded nonzero_divide_eq_eq[OF f0]]
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   457
    have th1: "setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n} =
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   458
      - (f$0) * (inverse f)$n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   459
      by (simp add: ring_simps)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   460
    have "(f * inverse f) $ n = (\<Sum>i = 0..n. f $i * natfun_inverse f (n - i))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   461
      unfolding fps_mult_nth ifn ..
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   462
    also have "\<dots> = f$0 * natfun_inverse f n
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   463
      + (\<Sum>i = 1..n. f$i * natfun_inverse f (n-i))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   464
      unfolding setsum_Un_disjoint[OF f d, unfolded eq[symmetric]]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   465
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   466
    also have "\<dots> = 0" unfolding th1 ifn by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   467
    finally have "(inverse f * f)$n = 0" unfolding c . }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   468
  with th0 show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   469
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   470
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   471
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
   472
  by (simp add: fps_inverse_def nonzero_imp_inverse_nonzero)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   473
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   474
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
   475
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   476
  {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
   477
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   478
  {assume h: "inverse f = 0" and c: "f $0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   479
    from inverse_mult_eq_1[OF c] h have False by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   480
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   481
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   482
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   483
lemma fps_inverse_idempotent[intro]: assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   484
  shows "inverse (inverse f) = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   485
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   486
  from f0 have if0: "inverse f $ 0 \<noteq> 0" by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   487
  from inverse_mult_eq_1[OF f0] inverse_mult_eq_1[OF if0]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   488
  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
   489
  then show ?thesis using f0 unfolding mult_cancel_left by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   490
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   491
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   492
lemma fps_inverse_unique: assumes f0: "f$0 \<noteq> (0::'a::field)" and fg: "f*g = 1"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   493
  shows "inverse f = g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   494
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   495
  from inverse_mult_eq_1[OF f0] fg
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   496
  have th0: "inverse f * f = g * f" by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   497
  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
   498
    by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   499
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   500
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   501
lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field)))
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   502
  = 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
   503
  apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   504
  apply simp
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   505
  apply (simp add: fps_eq_iff fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   506
proof(clarsimp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   507
  fix n::nat assume n: "n > 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   508
  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
   509
  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
   510
  let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   511
  have th1: "setsum ?f {0..n} = setsum ?g {0..n}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   512
    by (rule setsum_cong2) auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   513
  have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   514
    using n apply - by (rule setsum_cong2) auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   515
  have eq: "{0 .. n} = {0.. n - 1} \<union> {n}" by auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   516
  from n have d: "{0.. n - 1} \<inter> {n} = {}" by auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   517
  have f: "finite {0.. n - 1}" "finite {n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   518
  show "setsum ?f {0..n} = 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   519
    unfolding th1
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   520
    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
   521
    unfolding th2
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   522
    by(simp add: setsum_delta)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   523
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   524
29912
f4ac160d2e77 fix spelling
huffman
parents: 29911
diff changeset
   525
subsection{* Formal Derivatives, and the MacLaurin theorem around 0*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   526
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   527
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
   528
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   529
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
   530
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   531
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
   532
  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
   533
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   534
lemma fps_deriv_mult[simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   535
  fixes f :: "('a :: comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   536
  shows "fps_deriv (f * g) = f * fps_deriv g + fps_deriv f * g"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   537
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   538
  let ?D = "fps_deriv"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   539
  {fix n::nat
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   540
    let ?Zn = "{0 ..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   541
    let ?Zn1 = "{0 .. n + 1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   542
    let ?f = "\<lambda>i. i + 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   543
    have fi: "inj_on ?f {0..n}" by (simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   544
    have eq: "{1.. n+1} = ?f ` {0..n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   545
    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
   546
        of_nat (i+1)* f $ (i+1) * g $ (n - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   547
    let ?h = "\<lambda>i. of_nat i * g $ i * f $ ((n+1) - i) +
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   548
        of_nat i* f $ i * g $ ((n + 1) - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   549
    {fix k assume k: "k \<in> {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   550
      have "?h (k + 1) = ?g k" using k by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   551
    note th0 = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   552
    have eq': "{0..n +1}- {1 .. n+1} = {0}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   553
    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
   554
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   555
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   556
      apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   557
      apply (rule set_ext)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   558
      apply (presburger add: image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   559
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   560
    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
   561
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   562
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   563
      apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   564
      apply (rule set_ext)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   565
      apply (presburger add: image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   566
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   567
    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
   568
    also have "\<dots> = (\<Sum>i = 0..n. ?g i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   569
      by (simp add: fps_mult_nth setsum_addf[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   570
    also have "\<dots> = setsum ?h {1..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   571
      using th0 setsum_reindex_cong[OF fi eq, of "?g" "?h"] by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   572
    also have "\<dots> = setsum ?h {0..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   573
      apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   574
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   575
      apply (simp add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   576
      unfolding eq'
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   577
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   578
    also have "\<dots> = (fps_deriv (f * g)) $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   579
      apply (simp only: fps_deriv_nth fps_mult_nth setsum_addf)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   580
      unfolding s0 s1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   581
      unfolding setsum_addf[symmetric] setsum_right_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   582
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   583
      by (auto simp add: of_nat_diff ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   584
    finally have "(f * ?D g + ?D f * g) $ n = ?D (f*g) $ n" .}
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   585
  then show ?thesis unfolding fps_eq_iff by auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   586
qed
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_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
   589
  by (simp add: fps_eq_iff fps_deriv_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   590
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
   591
  using fps_deriv_linear[of 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   592
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   593
lemma fps_deriv_sub[simp]: "fps_deriv ((f:: ('a::comm_ring_1) fps) - g) = fps_deriv f - fps_deriv g"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   594
  unfolding diff_minus by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   595
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   596
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
   597
  by (simp add: fps_ext fps_deriv_def fps_const_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   598
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   599
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
   600
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   601
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   602
lemma fps_deriv_0[simp]: "fps_deriv 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   603
  by (simp add: fps_deriv_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   604
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   605
lemma fps_deriv_1[simp]: "fps_deriv 1 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   606
  by (simp add: fps_deriv_def fps_eq_iff )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   607
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   608
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
   609
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   610
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   611
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
   612
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   613
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   614
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   615
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   616
    have ?thesis  by (induct rule: finite_induct[OF fS], simp_all)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   617
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   618
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   619
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   620
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
   621
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   622
  {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
   623
    hence "fps_deriv f = 0" by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   624
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   625
  {assume z: "fps_deriv f = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   626
    hence "\<forall>n. (fps_deriv f)$n = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   627
    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
   628
    hence "f = fps_const (f$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   629
      apply (clarsimp simp add: fps_eq_iff fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   630
      apply (erule_tac x="n - 1" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   631
      by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   632
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   633
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   634
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   635
lemma fps_deriv_eq_iff:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   636
  fixes f:: "('a::{idom,semiring_char_0}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   637
  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
   638
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   639
  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
   640
  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
   641
  finally show ?thesis by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   642
qed
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_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
   645
  apply auto unfolding fps_deriv_eq_iff by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   646
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   647
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   648
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
   649
  "fps_nth_deriv 0 f = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   650
| "fps_nth_deriv (Suc n) f = fps_nth_deriv n (fps_deriv f)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   651
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   652
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
   653
  by (induct n arbitrary: f, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   654
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   655
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
   656
  by (induct n arbitrary: f g, auto simp add: fps_nth_deriv_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   657
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   658
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
   659
  by (induct n arbitrary: f, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   660
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   661
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
   662
  using fps_nth_deriv_linear[of n 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   663
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   664
lemma fps_nth_deriv_sub[simp]: "fps_nth_deriv n ((f:: ('a::comm_ring_1) fps) - g) = fps_nth_deriv n f - fps_nth_deriv n g"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   665
  unfolding diff_minus fps_nth_deriv_add by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   666
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   667
lemma fps_nth_deriv_0[simp]: "fps_nth_deriv n 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   668
  by (induct n, simp_all )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   669
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   670
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
   671
  by (induct n, simp_all )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   672
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   673
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
   674
  by (cases n, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   675
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   676
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
   677
  using fps_nth_deriv_linear[of n "c" f 0 0 ] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   678
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   679
lemma 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
   680
  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
   681
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   682
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
   683
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   684
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   685
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   686
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   687
    have ?thesis  by (induct rule: finite_induct[OF fS], simp_all)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   688
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   689
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   690
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   691
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
   692
  by (induct k arbitrary: f) (auto simp add: ring_simps of_nat_mult)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   693
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   694
subsection {* Powers*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   695
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   696
lemma fps_power_zeroth_eq_one: "a$0 =1 \<Longrightarrow> a^n $ 0 = (1::'a::semiring_1)"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   697
  by (induct n, auto simp add: expand_fps_eq fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   698
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   699
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
   700
proof(induct n)
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   701
  case 0 thus ?case by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   702
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   703
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   704
  note h = Suc.hyps[OF `a$0 = 1`]
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   705
  show ?case unfolding power_Suc fps_mult_nth
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   706
    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
   707
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   708
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   709
lemma startsby_one_power:"a $ 0 = (1::'a::comm_ring_1) \<Longrightarrow> a^n $ 0 = 1"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   710
  by (induct n, auto simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   711
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   712
lemma startsby_zero_power:"a $0 = (0::'a::comm_ring_1) \<Longrightarrow> n > 0 \<Longrightarrow> a^n $0 = 0"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   713
  by (induct n, auto simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   714
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
   715
lemma startsby_power:"a $0 = (v::'a::{comm_ring_1}) \<Longrightarrow> a^n $0 = v^n"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   716
  by (induct n, auto simp add: fps_mult_nth power_Suc)
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 startsby_zero_power_iff[simp]:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
   719
  "a^n $0 = (0::'a::{idom}) \<longleftrightarrow> (n \<noteq> 0 \<and> a$0 = 0)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   720
apply (rule iffI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   721
apply (induct n, auto simp add: power_Suc fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   722
by (rule startsby_zero_power, simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   723
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   724
lemma startsby_zero_power_prefix:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   725
  assumes a0: "a $0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   726
  shows "\<forall>n < k. a ^ k $ n = 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   727
  using a0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   728
proof(induct k rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   729
  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
   730
  let ?ths = "\<forall>m<k. a ^ k $ m = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   731
  {assume "k = 0" then have ?ths by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   732
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   733
  {fix l assume k: "k = Suc l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   734
    {fix m assume mk: "m < k"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   735
      {assume "m=0" hence "a^k $ m = 0" using startsby_zero_power[of a k] k a0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   736
	  by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   737
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   738
      {assume m0: "m \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   739
	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
   740
	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
   741
	also have "\<dots> = 0" apply (rule setsum_0')
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   742
	  apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   743
	  apply (case_tac "aa = m")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   744
	  using a0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   745
	  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   746
	  apply (rule H[rule_format])
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   747
	  using a0 k mk by auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   748
	finally have "a^k $ m = 0" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   749
    ultimately have "a^k $ m = 0" by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   750
    hence ?ths by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   751
  ultimately show ?ths by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   752
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   753
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   754
lemma startsby_zero_setsum_depends:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   755
  assumes a0: "a $0 = (0::'a::idom)" and kn: "n \<ge> k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   756
  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
   757
  apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   758
  using kn apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   759
  apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   760
  by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   761
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
   762
lemma startsby_zero_power_nth_same: assumes a0: "a$0 = (0::'a::{idom})"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   763
  shows "a^n $ n = (a$1) ^ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   764
proof(induct n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   765
  case 0 thus ?case by (simp add: power_0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   766
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   767
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   768
  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
   769
  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
   770
  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
   771
    apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   772
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   773
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   774
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   775
    apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   776
    apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   777
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   778
  also have "\<dots> = a^n $ n * a$1" using a0 by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   779
  finally show ?case using Suc.hyps by (simp add: power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   780
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   781
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   782
lemma fps_inverse_power:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
   783
  fixes a :: "('a::{field}) fps"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   784
  shows "inverse (a^n) = inverse a ^ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   785
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   786
  {assume a0: "a$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   787
    hence eq: "inverse a = 0" by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   788
    {assume "n = 0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   789
    moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   790
    {assume n: "n > 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   791
      from startsby_zero_power[OF a0 n] eq a0 n have ?thesis
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   792
	by (simp add: fps_inverse_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   793
    ultimately have ?thesis by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   794
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   795
  {assume a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   796
    have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   797
      apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   798
      apply (simp add: a0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   799
      unfolding power_mult_distrib[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   800
      apply (rule ssubst[where t = "a * inverse a" and s= 1])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   801
      apply simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   802
      apply (subst mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   803
      by (rule inverse_mult_eq_1[OF a0])}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   804
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   805
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   806
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   807
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
   808
  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
   809
  by (case_tac n, auto simp add: power_Suc ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   810
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   811
lemma fps_inverse_deriv:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   812
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   813
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   814
  shows "fps_deriv (inverse a) = - fps_deriv a * inverse a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   815
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   816
  from inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   817
  have "fps_deriv (inverse a * a) = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   818
  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
   819
  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
   820
  with inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   821
  have "inverse a ^ 2 * fps_deriv a + fps_deriv (inverse a) = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   822
    unfolding power2_eq_square
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   823
    apply (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   824
    by (simp add: mult_assoc[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   825
  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
   826
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   827
  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
   828
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   829
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   830
lemma fps_inverse_mult:
29687
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
  shows "inverse (a * b) = inverse a * inverse b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   833
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   834
  {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
   835
    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
   836
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   837
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   838
  {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
   839
    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
   840
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   841
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   842
  {assume a0: "a$0 \<noteq> 0" and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   843
    from a0 b0 have ab0:"(a*b) $ 0 \<noteq> 0" by (simp  add: fps_mult_nth)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   844
    from inverse_mult_eq_1[OF ab0]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   845
    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
   846
    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
   847
      by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   848
    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
   849
ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   850
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   851
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   852
lemma fps_inverse_deriv':
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   853
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   854
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   855
  shows "fps_deriv (inverse a) = - fps_deriv a / a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   856
  using fps_inverse_deriv[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   857
  unfolding power2_eq_square fps_divide_def
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   858
    fps_inverse_mult by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   859
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   860
lemma inverse_mult_eq_1': assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   861
  shows "f * inverse f= 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   862
  by (metis mult_commute inverse_mult_eq_1 f0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   863
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   864
lemma fps_divide_deriv:   fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   865
  assumes a0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   866
  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
   867
  using fps_inverse_deriv[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   868
  by (simp add: fps_divide_def ring_simps power2_eq_square fps_inverse_mult inverse_mult_eq_1'[OF a0])
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   869
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   870
subsection{* The eXtractor series X*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   871
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
   872
lemma minus_one_power_iff: "(- (1::'a :: {comm_ring_1})) ^ n = (if even n then 1 else - 1)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   873
  by (induct n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   874
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   875
definition "X = Abs_fps (\<lambda>n. if n = 1 then 1 else 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   876
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   877
lemma fps_inverse_gp': "inverse (Abs_fps(\<lambda>n. (1::'a::field)))
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   878
  = 1 - X"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   879
  by (simp add: fps_inverse_gp fps_eq_iff X_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   880
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   881
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
   882
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   883
  {assume n: "n \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   884
    have fN: "finite {0 .. n}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   885
    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
   886
    also have "\<dots> = f $ (n - 1)"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   887
      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
   888
  finally have ?thesis using n by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   889
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   890
  {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
   891
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   892
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   893
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   894
lemma X_mult_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
   895
  by (metis X_mult_nth mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   896
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   897
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
   898
proof(induct k)
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
   899
  case 0 thus ?case by (simp add: X_def fps_eq_iff)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   900
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   901
  case (Suc k)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   902
  {fix m
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   903
    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
   904
      by (simp add: power_Suc del: One_nat_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   905
    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
   906
      using Suc.hyps by (auto cong del: if_weak_cong)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   907
  then show ?case by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   908
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   909
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   910
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
   911
  apply (induct k arbitrary: n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   912
  apply (simp)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   913
  unfolding power_Suc mult_assoc
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   914
  by (case_tac n, auto)
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_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
   917
  by (metis X_power_mult_nth mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   918
lemma fps_deriv_X[simp]: "fps_deriv X = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   919
  by (simp add: fps_deriv_def X_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   920
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   921
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
   922
  by (cases "n", simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   923
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   924
lemma X_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
   925
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
   926
  by (simp add: X_power_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   927
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   928
lemma fps_inverse_X_plus1:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
   929
  "inverse (1 + X) = Abs_fps (\<lambda>n. (- (1::'a::{field})) ^ n)" (is "_ = ?r")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   930
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   931
  have eq: "(1 + X) * ?r = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   932
    unfolding minus_one_power_iff
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31075
diff changeset
   933
    by (auto simp add: ring_simps fps_eq_iff)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   934
  show ?thesis by (auto simp add: eq intro: fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   935
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   936
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   937
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   938
subsection{* Integration *}
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   939
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   940
definition
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   941
  fps_integral :: "'a::field_char_0 fps \<Rightarrow> 'a \<Rightarrow> 'a fps" where
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   942
  "fps_integral a a0 = Abs_fps (\<lambda>n. if n = 0 then a0 else (a$(n - 1) / of_nat n))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   943
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   944
lemma fps_deriv_fps_integral: "fps_deriv (fps_integral a a0) = a"
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   945
  unfolding fps_integral_def fps_deriv_def
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   946
  by (simp add: fps_eq_iff del: of_nat_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   947
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   948
lemma fps_integral_linear:
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   949
  "fps_integral (fps_const a * f + fps_const b * g) (a*a0 + b*b0) =
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   950
    fps_const a * fps_integral f a0 + fps_const b * fps_integral g b0"
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
   951
  (is "?l = ?r")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   952
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   953
  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
   954
  moreover have "?l$0 = ?r$0" by (simp add: fps_integral_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   955
  ultimately show ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   956
    unfolding fps_deriv_eq_iff by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   957
qed
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   958
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   959
subsection {* Composition of FPSs *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   960
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
   961
  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
   962
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   963
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
   964
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   965
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
   966
  by (simp add: fps_ext fps_compose_def mult_delta_right setsum_delta')
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   967
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   968
lemma fps_const_compose[simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   969
  "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
   970
  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
   971
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   972
lemma number_of_compose[simp]: "(number_of k::('a::{comm_ring_1}) fps) oo b = number_of k"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   973
  unfolding number_of_fps_const by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   974
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   975
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
   976
  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
   977
                power_Suc not_le)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   978
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   979
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   980
subsection {* Rules from Herbert Wilf's Generatingfunctionology*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   981
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   982
subsubsection {* Rule 1 *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   983
  (* {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
   984
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   985
lemma fps_power_mult_eq_shift:
30992
3b143758dfe9 more general statements
chaieb
parents: 30837
diff changeset
   986
  "X^Suc k * Abs_fps (\<lambda>n. a (n + Suc k)) = Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a:: comm_ring_1) * X^i) {0 .. k}" (is "?lhs = ?rhs")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   987
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   988
  {fix n:: nat
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   989
    have "?lhs $ n = (if n < Suc k then 0 else a n)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   990
      unfolding X_power_mult_nth by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   991
    also have "\<dots> = ?rhs $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   992
    proof(induct k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   993
      case 0 thus ?case by (simp add: fps_setsum_nth power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   994
    next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   995
      case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   996
      note th = Suc.hyps[symmetric]
30992
3b143758dfe9 more general statements
chaieb
parents: 30837
diff changeset
   997
      have "(Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a) * X^i) {0 .. Suc k})$n = (Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a) * X^i) {0 .. k} - fps_const (a (Suc k)) * X^ Suc k) $ n" by (simp add: ring_simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   998
      also  have "\<dots> = (if n < Suc k then 0 else a n) - (fps_const (a (Suc k)) * X^ Suc k)$n"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   999
	using th
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1000
	unfolding fps_sub_nth by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1001
      also have "\<dots> = (if n < Suc (Suc k) then 0 else a n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1002
	unfolding X_power_mult_right_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1003
	apply (auto simp add: not_less fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1004
	apply (rule cong[of a a, OF refl])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1005
	by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1006
      finally show ?case by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1007
    qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1008
    finally have "?lhs $ n = ?rhs $ n"  .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1009
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1010
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1011
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1012
subsubsection{* Rule 2*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1013
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1014
  (* We can not reach the form of Wilf, but still near to it using rewrite rules*)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1015
  (* If f reprents {a_n} and P is a polynomial, then
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1016
        P(xD) f represents {P(n) a_n}*)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1017
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1018
definition "XD = op * X o fps_deriv"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1019
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1020
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
  1021
  by (simp add: XD_def ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1022
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1023
lemma 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
  1024
  by (simp add: XD_def ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1025
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1026
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
  1027
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1028
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 30837
diff changeset
  1029
lemma XDN_linear:
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30960
diff changeset
  1030
  "(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
  1031
  by (induct n, simp_all)
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 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
  1034
30994
chaieb
parents: 30971 30992
diff changeset
  1035
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 30837
diff changeset
  1036
lemma fps_mult_XD_shift:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1037
  "(XD ^^ k) (a:: ('a::{comm_ring_1}) fps) = Abs_fps (\<lambda>n. (of_nat n ^ k) * a$n)"
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 30837
diff changeset
  1038
  by (induct k arbitrary: a) (simp_all add: power_Suc XD_def fps_eq_iff ring_simps del: One_nat_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1039
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1040
subsubsection{* Rule 3 is trivial and is given by @{text fps_times_def}*}
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1041
subsubsection{* Rule 5 --- summation and "division" by (1 - X)*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1042
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1043
lemma fps_divide_X_minus1_setsum_lemma:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1044
  "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
  1045
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1046
  let ?X = "X::('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1047
  let ?sa = "Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1048
  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
  1049
  {fix n:: nat
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1050
    {assume "n=0" hence "a$n = ((1 - ?X) * ?sa) $ n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1051
	by (simp add: fps_mult_nth)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1052
    moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1053
    {assume n0: "n \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1054
      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
  1055
	"{0..n - 1}\<union>{n} = {0..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1056
	apply (simp_all add: expand_set_eq) by presburger+
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1057
      have d: "{0} \<inter> ({1} \<union> {2..n}) = {}" "{1} \<inter> {2..n} = {}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1058
	"{0..n - 1}\<inter>{n} ={}" using n0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1059
	by (simp_all add: expand_set_eq, presburger+)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1060
      have f: "finite {0}" "finite {1}" "finite {2 .. n}"
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1061
	"finite {0 .. n - 1}" "finite {n}" by simp_all
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1062
    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
  1063
      by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1064
    also have "\<dots> = a$n" unfolding th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1065
      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
  1066
      unfolding setsum_Un_disjoint[OF f(2) f(3) d(2)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1067
      apply (simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1068
      unfolding setsum_Un_disjoint[OF f(4,5) d(3), unfolded u(3)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1069
      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1070
    finally have "a$n = ((1 - ?X) * ?sa) $ n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1071
  ultimately have "a$n = ((1 - ?X) * ?sa) $ n" by blast}
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1072
then show ?thesis
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1073
  unfolding fps_eq_iff by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1074
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1075
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1076
lemma fps_divide_X_minus1_setsum:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1077
  "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
  1078
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1079
  let ?X = "1 - (X::('a::field) fps)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1080
  have th0: "?X $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1081
  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
  1082
    using fps_divide_X_minus1_setsum_lemma[of a, symmetric] th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1083
    by (simp add: fps_divide_def mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1084
  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
  1085
    by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1086
  finally show ?thesis by (simp add: inverse_mult_eq_1[OF th0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1087
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1088
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1089
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
  1090
  finite product of FPS, also the relvant instance of powers of a FPS*}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1091
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1092
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
  1093
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1094
lemma natlist_trivial_1: "natpermute n 1 = {[n]}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1095
  apply (auto simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1096
  apply (case_tac x, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1097
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1098
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1099
lemma foldl_add_start0:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1100
  "foldl op + x xs = x + foldl op + (0::nat) xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1101
  apply (induct xs arbitrary: x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1102
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1103
  unfolding foldl.simps
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1104
  apply atomize
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1105
  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
  1106
  apply (erule_tac x="x + a" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1107
  apply (erule_tac x="a" in allE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1108
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1109
  apply assumption
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1110
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1111
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1112
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
  1113
  apply (induct ys arbitrary: x xs)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1114
  apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1115
  apply (subst (2) foldl_add_start0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1116
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1117
  apply (subst (2) foldl_add_start0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1118
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1119
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1120
lemma 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
  1121
proof(induct xs arbitrary: x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1122
  case Nil thus ?case by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1123
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1124
  case (Cons a as x)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1125
  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
  1126
    apply (rule setsum_reindex_cong [where f=Suc])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1127
    by (simp_all add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1128
  have f: "finite {0}" "finite {1 ..< length (a#as)}" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1129
  have d: "{0} \<inter> {1..<length (a#as)} = {}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1130
  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
  1131
  have "foldl op + x (a#as) = x + foldl op + a as "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1132
    apply (subst foldl_add_start0)    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1133
  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
  1134
  also have "\<dots> = x + setsum (op ! (a#as)) {0..<length (a#as)}"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1135
    unfolding eq[symmetric]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1136
    unfolding setsum_Un_disjoint[OF f d, unfolded seq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1137
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1138
  finally show ?case  .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1139
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1140
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1141
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1142
lemma append_natpermute_less_eq:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1143
  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
  1144
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1145
  {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
  1146
    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
  1147
  note th = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1148
  {from th show "foldl op + 0 xs \<le> n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1149
  {from th show "foldl op + 0 ys \<le> n" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1150
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1151
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1152
lemma natpermute_split:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1153
  assumes mn: "h \<le> k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1154
  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
  1155
proof-
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1156
  {fix l assume l: "l \<in> ?R"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1157
    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
  1158
    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
  1159
    from ys have ys': "foldl op + 0 ys = n - m" by (simp add: natpermute_def)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1160
    have "l \<in> ?L" using leq xs ys h
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1161
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1162
      apply (clarsimp simp add: natpermute_def simp del: foldl_append)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1163
      apply (simp add: foldl_add_append[unfolded foldl_append])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1164
      unfolding xs' ys'
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1165
      using mn xs ys
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1166
      unfolding natpermute_def by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1167
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1168
  {fix l assume l: "l \<in> natpermute n k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1169
    let ?xs = "take h l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1170
    let ?ys = "drop h l"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1171
    let ?m = "foldl op + 0 ?xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1172
    from l have ls: "foldl op + 0 (?xs @ ?ys) = n" by (simp add: natpermute_def)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1173
    have xs: "?xs \<in> natpermute ?m h" using l mn by (simp add: natpermute_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1174
    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
  1175
      by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1176
    from ls have m: "?m \<in> {0..n}"  unfolding foldl_add_append by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1177
    from xs ys ls have "l \<in> ?R"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1178
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1179
      apply (rule bexI[where x = "?m"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1180
      apply (rule exI[where x = "?xs"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1181
      apply (rule exI[where x = "?ys"])
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1182
      using ls l unfolding foldl_add_append
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1183
      by (auto simp add: natpermute_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1184
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1185
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1186
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1187
lemma natpermute_0: "natpermute n 0 = (if n = 0 then {[]} else {})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1188
  by (auto simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1189
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
  1190
  apply (auto simp add: set_replicate_conv_if natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1191
  apply (rule nth_equalityI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1192
  by simp_all
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_finite: "finite (natpermute n k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1195
proof(induct k arbitrary: n)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1196
  case 0 thus ?case
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1197
    apply (subst natpermute_split[of 0 0, simplified])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1198
    by (simp add: natpermute_0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1199
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1200
  case (Suc k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1201
  then show ?case unfolding natpermute_split[of k "Suc k", simplified]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1202
    apply -
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1203
    apply (rule finite_UN_I)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1204
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1205
    unfolding One_nat_def[symmetric] natlist_trivial_1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1206
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1207
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1208
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1209
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1210
lemma natpermute_contain_maximal:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1211
  "{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
  1212
  (is "?A = ?B")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1213
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1214
  {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
  1215
    from n obtain i where i: "i \<in> {0.. k}" "xs!i = n" using H
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1216
      unfolding in_set_conv_nth by (auto simp add: less_Suc_eq_le natpermute_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1217
    have eqs: "({0..k} - {i}) \<union> {i} = {0..k}" using i by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1218
    have f: "finite({0..k} - {i})" "finite {i}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1219
    have d: "({0..k} - {i}) \<inter> {i} = {}" using i by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1220
    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
  1221
      unfolding foldl_add_setsum by (auto simp add: atLeastLessThanSuc_atLeastAtMost)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1222
    also have "\<dots> = n + setsum (nth xs) ({0..k} - {i})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1223
      unfolding setsum_Un_disjoint[OF f d, unfolded eqs] using i by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1224
    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
  1225
    from H have xsl: "length xs = k+1" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1226
    from i have i': "i < length (replicate (k+1) 0)"   "i < k+1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1227
      unfolding length_replicate  by arith+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1228
    have "xs = replicate (k+1) 0 [i := n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1229
      apply (rule nth_equalityI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1230
      unfolding xsl length_list_update length_replicate
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1231
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1232
      apply clarify
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1233
      unfolding nth_list_update[OF i'(1)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1234
      using i zxs
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1235
      by (case_tac "ia=i", auto simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1236
    then have "xs \<in> ?B" using i by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1237
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1238
  {fix i assume i: "i \<in> {0..k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1239
    let ?xs = "replicate (k+1) 0 [i:=n]"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1240
    have nxs: "n \<in> set ?xs"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1241
      apply (rule set_update_memI) using i by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1242
    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
  1243
    have "foldl op + 0 ?xs = setsum (nth ?xs) {0..<k+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1244
      unfolding foldl_add_setsum add_0 length_replicate length_list_update ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1245
    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
  1246
      apply (rule setsum_cong2) by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1247
    also have "\<dots> = n" using i by (simp add: setsum_delta)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1248
    finally
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1249
    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
  1250
      by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1251
    then have "?xs \<in> ?A"  using nxs  by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1252
  ultimately show ?thesis by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1253
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1254
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1255
    (* The general form *)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1256
lemma fps_setprod_nth:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1257
  fixes m :: nat and a :: "nat \<Rightarrow> ('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1258
  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
  1259
  (is "?P m n")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1260
proof(induct m arbitrary: n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1261
  fix m n assume H: "\<forall>m' < m. \<forall>n. ?P m' n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1262
  {assume m0: "m = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1263
    hence "?P m n" apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1264
      unfolding natlist_trivial_1[where n = n, unfolded One_nat_def] by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1265
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1266
  {fix k assume k: "m = Suc k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1267
    have km: "k < m" using k by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1268
    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
  1269
    have f0: "finite {0 .. k}" "finite {m}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1270
    have d0: "{0 .. k} \<inter> {m} = {}" using k by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1271
    have "(setprod a {0 .. m}) $ n = (setprod a {0 .. k} * a m) $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1272
      unfolding setprod_Un_disjoint[OF f0 d0, unfolded u0] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1273
    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
  1274
      unfolding fps_mult_nth H[rule_format, OF km] ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1275
    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
  1276
      apply (simp add: k)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1277
      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
  1278
      apply (subst setsum_UN_disjoint)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1279
      apply simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1280
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1281
      unfolding image_Collect[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1282
      apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1283
      apply (rule finite_imageI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1284
      apply (rule natpermute_finite)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1285
      apply (clarsimp simp add: expand_set_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1286
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1287
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1288
      unfolding setsum_left_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1289
      apply (rule sym)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1290
      apply (rule_tac f="\<lambda>xs. xs @[n - x]" in  setsum_reindex_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1291
      apply (simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1292
      apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1293
      unfolding setprod_Un_disjoint[OF f0 d0, unfolded u0, unfolded k]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1294
      apply (clarsimp simp add: natpermute_def nth_append)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1295
      done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1296
    finally have "?P m n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1297
  ultimately show "?P m n " by (cases m, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1298
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1299
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1300
text{* The special form for powers *}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1301
lemma fps_power_nth_Suc:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1302
  fixes m :: nat and a :: "('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1303
  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
  1304
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1305
  have f: "finite {0 ..m}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1306
  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
  1307
  show ?thesis unfolding th0 fps_setprod_nth ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1308
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1309
lemma fps_power_nth:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1310
  fixes m :: nat and a :: "('a::comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1311
  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))"
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  1312
  by (cases m, simp_all add: fps_power_nth_Suc del: power_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1313
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1314
lemma fps_nth_power_0:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1315
  fixes m :: nat and a :: "('a::{comm_ring_1}) fps"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1316
  shows "(a ^m)$0 = (a$0) ^ m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1317
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1318
  {assume "m=0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1319
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1320
  {fix n assume m: "m = Suc n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1321
    have c: "m = card {0..n}" using m by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1322
   have "(a ^m)$0 = setprod (\<lambda>i. a$0) {0..n}"
30837
3d4832d9f7e4 added strong_setprod_cong[cong] (in analogy with setsum)
nipkow
parents: 30747
diff changeset
  1323
     by (simp add: m fps_power_nth del: replicate.simps power_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1324
   also have "\<dots> = (a$0) ^ m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1325
     unfolding c by (rule setprod_constant, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1326
   finally have ?thesis .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1327
 ultimately show ?thesis by (cases m, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1328
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1329
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1330
lemma fps_compose_inj_right:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1331
  assumes a0: "a$0 = (0::'a::{idom})"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1332
  and a1: "a$1 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1333
  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
  1334
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1335
  {assume ?rhs then have "?lhs" by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1336
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1337
  {assume h: ?lhs
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1338
    {fix n have "b$n = c$n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1339
      proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1340
	fix n assume H: "\<forall>m<n. b$m = c$m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1341
	{assume n0: "n=0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1342
	  from h have "(b oo a)$n = (c oo a)$n" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1343
	  hence "b$n = c$n" using n0 by (simp add: fps_compose_nth)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1344
	moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1345
	{fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1346
	  have f: "finite {0 .. n1}" "finite {n}" by simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1347
	  have eq: "{0 .. n1} \<union> {n} = {0 .. n}" using n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1348
	  have d: "{0 .. n1} \<inter> {n} = {}" using n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1349
	  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
  1350
	    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1351
	    using H n1 by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1352
	  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
  1353
	    unfolding fps_compose_nth setsum_Un_disjoint[OF f d, unfolded eq] seq
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1354
	    using startsby_zero_power_nth_same[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1355
	    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1356
	  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
  1357
	    unfolding fps_compose_nth setsum_Un_disjoint[OF f d, unfolded eq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1358
	    using startsby_zero_power_nth_same[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1359
	    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1360
	  from h[unfolded fps_eq_iff, rule_format, of n] th0 th1 a1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1361
	  have "b$n = c$n" by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1362
	ultimately show "b$n = c$n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1363
      qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1364
    then have ?rhs by (simp add: fps_eq_iff)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1365
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1366
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1367
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1368
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1369
subsection {* Radicals *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1370
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1371
declare setprod_cong[fundef_cong]
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1372
function radical :: "(nat \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> ('a::{field}) fps \<Rightarrow> nat \<Rightarrow> 'a" where
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1373
  "radical r 0 a 0 = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1374
| "radical r 0 a (Suc n) = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1375
| "radical r (Suc k) a 0 = r (Suc k) (a$0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1376
| "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
  1377
by pat_completeness auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1378
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1379
termination radical
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1380
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1381
  let ?R = "measure (\<lambda>(r, k, a, n). n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1382
  {
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1383
    show "wf ?R" by auto}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1384
  {fix r k a n xs i
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1385
    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
  1386
    {assume c: "Suc n \<le> xs ! i"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1387
      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
  1388
      with c have c': "Suc n < xs!i" by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1389
      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
  1390
      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
  1391
      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
  1392
      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
  1393
      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
  1394
	by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1395
      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
  1396
	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
  1397
	unfolding setsum_Un_disjoint[OF fths(2) fths(3) d(2)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1398
	by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1399
      finally have False using c' by simp}
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1400
    then show "((r,Suc k,a,xs!i), r, Suc k, a, Suc n) \<in> ?R"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1401
      apply auto by (metis not_less)}
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1402
  {fix r k a n
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1403
    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
  1404
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1405
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1406
definition "fps_radical r n a = Abs_fps (radical r n a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1407
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1408
lemma fps_radical0[simp]: "fps_radical r 0 a = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1409
  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
  1410
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1411
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
  1412
  by (cases n, simp_all add: fps_radical_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1413
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1414
lemma fps_radical_power_nth[simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1415
  assumes r: "(r k (a$0)) ^ k = a$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1416
  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
  1417
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1418
  {assume "k=0" hence ?thesis by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1419
  moreover
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1420
  {fix h assume h: "k = Suc h"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1421
    have fh: "finite {0..h}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1422
    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
  1423
      unfolding fps_power_nth h by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1424
    also have "\<dots> = (\<Prod>j\<in>{0..h}. r k (a$0))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1425
      apply (rule setprod_cong)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1426
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1427
      using h
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1428
      apply (subgoal_tac "replicate k (0::nat) ! x = 0")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1429
      by (auto intro: nth_replicate simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1430
    also have "\<dots> = a$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1431
      unfolding setprod_constant[OF fh] using r by (simp add: h)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1432
    finally have ?thesis using h by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1433
  ultimately show ?thesis by (cases k, auto)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1434
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1435
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1436
lemma natpermute_max_card: assumes n0: "n\<noteq>0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1437
  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
  1438
  unfolding natpermute_contain_maximal
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1439
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1440
  let ?A= "\<lambda>i. {replicate (k + 1) 0[i := n]}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1441
  let ?K = "{0 ..k}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1442
  have fK: "finite ?K" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1443
  have fAK: "\<forall>i\<in>?K. finite (?A i)" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1444
  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
  1445
  proof(clarify)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1446
    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
  1447
    {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
  1448
      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
  1449
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1450
      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
  1451
      ultimately have False using eq n0 by (simp del: replicate.simps)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1452
    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
  1453
      by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1454
  qed
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1455
  from card_UN_disjoint[OF fK fAK d]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1456
  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
  1457
qed
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1458
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1459
lemma power_radical:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1460
  fixes a:: "'a::field_char_0 fps"
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1461
  assumes a0: "a$0 \<noteq> 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1462
  shows "(r (Suc k) (a$0)) ^ Suc k = a$0 \<longleftrightarrow> (fps_radical r (Suc k) a) ^ (Suc k) = a"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1463
proof-
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1464
  let ?r = "fps_radical r (Suc k) a"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1465
  {assume r0: "(r (Suc k) (a$0)) ^ Suc k = a$0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1466
    from a0 r0 have r00: "r (Suc k) (a$0) \<noteq> 0" by auto
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1467
    {fix z have "?r ^ Suc k $ z = a$z"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1468
      proof(induct z rule: nat_less_induct)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1469
	fix n assume H: "\<forall>m<n. ?r ^ Suc k $ m = a$m"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1470
	{assume "n = 0" hence "?r ^ Suc k $ n = a $n"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1471
	    using fps_radical_power_nth[of r "Suc k" a, OF r0] by simp}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1472
	moreover
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1473
	{fix n1 assume n1: "n = Suc n1"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1474
	  have fK: "finite {0..k}" by simp
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1475
	  have nz: "n \<noteq> 0" using n1 by arith
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1476
	  let ?Pnk = "natpermute n (k + 1)"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1477
	  let ?Pnkn = "{xs \<in> ?Pnk. n \<in> set xs}"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1478
	  let ?Pnknn = "{xs \<in> ?Pnk. n \<notin> set xs}"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1479
	  have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1480
	  have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1481
	  have f: "finite ?Pnkn" "finite ?Pnknn"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1482
	    using finite_Un[of ?Pnkn ?Pnknn, unfolded eq]
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1483
	    by (metis natpermute_finite)+
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1484
	  let ?f = "\<lambda>v. \<Prod>j\<in>{0..k}. ?r $ v ! j"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1485
	  have "setsum ?f ?Pnkn = setsum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1486
	  proof(rule setsum_cong2)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1487
	    fix v assume v: "v \<in> {xs \<in> natpermute n (k + 1). n \<in> set xs}"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1488
	    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"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1489
	  from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1490
	    unfolding natpermute_contain_maximal by auto
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1491
	  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))"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1492
	    apply (rule setprod_cong, simp)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1493
	    using i r0 by (simp del: replicate.simps)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1494
	  also have "\<dots> = (fps_radical r (Suc k) a $ n) * r (Suc k) (a$0) ^ k"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1495
	    unfolding setprod_gen_delta[OF fK] using i r0 by simp
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1496
	  finally show ?ths .
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1497
	qed
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1498
	then have "setsum ?f ?Pnkn = of_nat (k+1) * ?r $ n * r (Suc k) (a $ 0) ^ k"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1499
	  by (simp add: natpermute_max_card[OF nz, simplified])
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1500
	also have "\<dots> = a$n - setsum ?f ?Pnknn"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1501
	  unfolding n1 using r00 a0 by (simp add: field_simps fps_radical_def del: of_nat_Suc )
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1502
	finally have fn: "setsum ?f ?Pnkn = a$n - setsum ?f ?Pnknn" .
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1503
	have "(?r ^ Suc k)$n = setsum ?f ?Pnkn + setsum ?f ?Pnknn"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1504
	  unfolding fps_power_nth_Suc setsum_Un_disjoint[OF f d, unfolded eq] ..
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1505
	also have "\<dots> = a$n" unfolding fn by simp
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1506
	finally have "?r ^ Suc k $ n = a $n" .}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1507
      ultimately  show "?r ^ Suc k $ n = a $n" by (cases n, auto)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1508
    qed }
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1509
  then have ?thesis using r0 by (simp add: fps_eq_iff)}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1510
moreover 
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1511
{ assume h: "(fps_radical r (Suc k) a) ^ (Suc k) = a"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1512
  hence "((fps_radical r (Suc k) a) ^ (Suc k))$0 = a$0" by simp
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1513
  then have "(r (Suc k) (a$0)) ^ Suc k = a$0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1514
    unfolding fps_power_nth_Suc
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1515
    by (simp add: setprod_constant del: replicate.simps)}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1516
ultimately show ?thesis by blast
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1517
qed
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1518
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1519
(*
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1520
lemma power_radical:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1521
  fixes a:: "'a::field_char_0 fps"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1522
  assumes r0: "(r (Suc k) (a$0)) ^ Suc k = a$0" and a0: "a$0 \<noteq> 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1523
  shows "(fps_radical r (Suc k) a) ^ (Suc k) = a"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1524
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1525
  let ?r = "fps_radical r (Suc k) a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1526
  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
  1527
  {fix z have "?r ^ Suc k $ z = a$z"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1528
    proof(induct z rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1529
      fix n assume H: "\<forall>m<n. ?r ^ Suc k $ m = a$m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1530
      {assume "n = 0" hence "?r ^ Suc k $ n = a $n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1531
	  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
  1532
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1533
      {fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1534
	have fK: "finite {0..k}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1535
	have nz: "n \<noteq> 0" using n1 by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1536
	let ?Pnk = "natpermute n (k + 1)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1537
	let ?Pnkn = "{xs \<in> ?Pnk. n \<in> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1538
	let ?Pnknn = "{xs \<in> ?Pnk. n \<notin> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1539
	have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1540
	have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1541
	have f: "finite ?Pnkn" "finite ?Pnknn"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1542
	  using finite_Un[of ?Pnkn ?Pnknn, unfolded eq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1543
	  by (metis natpermute_finite)+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1544
	let ?f = "\<lambda>v. \<Prod>j\<in>{0..k}. ?r $ v ! j"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1545
	have "setsum ?f ?Pnkn = setsum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1546
	proof(rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1547
	  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
  1548
	  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
  1549
	  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
  1550
	    unfolding natpermute_contain_maximal by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1551
	  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
  1552
	    apply (rule setprod_cong, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1553
	    using i r0 by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1554
	  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
  1555
	    unfolding setprod_gen_delta[OF fK] using i r0 by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1556
	  finally show ?ths .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1557
	qed
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1558
	then have "setsum ?f ?Pnkn = of_nat (k+1) * ?r $ n * r (Suc k) (a $ 0) ^ k"
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1559
	  by (simp add: natpermute_max_card[OF nz, simplified])
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1560
	also have "\<dots> = a$n - setsum ?f ?Pnknn"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1561
	  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
  1562
	finally have fn: "setsum ?f ?Pnkn = a$n - setsum ?f ?Pnknn" .
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1563
	have "(?r ^ Suc k)$n = setsum ?f ?Pnkn + setsum ?f ?Pnknn"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1564
	  unfolding fps_power_nth_Suc setsum_Un_disjoint[OF f d, unfolded eq] ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1565
	also have "\<dots> = a$n" unfolding fn by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1566
	finally have "?r ^ Suc k $ n = a $n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1567
      ultimately  show "?r ^ Suc k $ n = a $n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1568
  qed }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1569
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1570
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1571
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1572
*)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1573
lemma eq_divide_imp': assumes c0: "(c::'a::field) ~= 0" and eq: "a * c = b"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1574
  shows "a = b / c"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1575
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1576
  from eq have "a * c * inverse c = b * inverse c" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1577
  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
  1578
  then show "a = b/c" unfolding  field_inverse[OF c0] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1579
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1580
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1581
lemma radical_unique:
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1582
  assumes r0: "(r (Suc k) (b$0)) ^ Suc k = b$0"
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1583
  and a0: "r (Suc k) (b$0 ::'a::field_char_0) = a$0" and b0: "b$0 \<noteq> 0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1584
  shows "a^(Suc k) = b \<longleftrightarrow> a = fps_radical r (Suc k) b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1585
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1586
  let ?r = "fps_radical r (Suc k) b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1587
  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
  1588
  {assume H: "a = ?r"
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1589
    from H have "a^Suc k = b" using power_radical[OF b0, of r k, unfolded r0] by simp}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1590
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1591
  {assume H: "a^Suc k = b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1592
    have ceq: "card {0..k} = Suc k" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1593
    have fk: "finite {0..k}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1594
    from a0 have a0r0: "a$0 = ?r$0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1595
    {fix n have "a $ n = ?r $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1596
      proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1597
	fix n assume h: "\<forall>m<n. a$m = ?r $m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1598
	{assume "n = 0" hence "a$n = ?r $n" using a0 by simp }
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1599
	moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1600
	{fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1601
	  have fK: "finite {0..k}" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1602
	have nz: "n \<noteq> 0" using n1 by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1603
	let ?Pnk = "natpermute n (Suc k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1604
	let ?Pnkn = "{xs \<in> ?Pnk. n \<in> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1605
	let ?Pnknn = "{xs \<in> ?Pnk. n \<notin> set xs}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1606
	have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1607
	have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1608
	have f: "finite ?Pnkn" "finite ?Pnknn"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1609
	  using finite_Un[of ?Pnkn ?Pnknn, unfolded eq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1610
	  by (metis natpermute_finite)+
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1611
	let ?f = "\<lambda>v. \<Prod>j\<in>{0..k}. ?r $ v ! j"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1612
	let ?g = "\<lambda>v. \<Prod>j\<in>{0..k}. a $ v ! j"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1613
	have "setsum ?g ?Pnkn = setsum (\<lambda>v. a $ n * (?r$0)^k) ?Pnkn"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1614
	proof(rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1615
	  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
  1616
	  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
  1617
	  from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
31790
05c92381363c corrected and unified thm names
nipkow
parents: 31776
diff changeset
  1618
	    unfolding Suc_eq_plus1 natpermute_contain_maximal by (auto simp del: replicate.simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1619
	  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
  1620
	    apply (rule setprod_cong, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1621
	    using i a0 by (simp del: replicate.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1622
	  also have "\<dots> = a $ n * (?r $ 0)^k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1623
	    unfolding  setprod_gen_delta[OF fK] using i by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1624
	  finally show ?ths .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1625
	qed
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1626
	then have th0: "setsum ?g ?Pnkn = of_nat (k+1) * a $ n * (?r $ 0)^k"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1627
	  by (simp add: natpermute_max_card[OF nz, simplified])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1628
	have th1: "setsum ?g ?Pnknn = setsum ?f ?Pnknn"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1629
	proof (rule setsum_cong2, rule setprod_cong, simp)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1630
	  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
  1631
	  {assume c: "n \<le> xs ! i"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1632
	    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
  1633
	    with c have c': "n < xs!i" by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1634
	    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
  1635
	    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
  1636
	    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
  1637
	    from xs have "n = foldl op + 0 xs" by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1638
	    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
  1639
	      by (simp add: natpermute_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1640
	    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
  1641
	      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
  1642
	      unfolding setsum_Un_disjoint[OF fths(2) fths(3) d(2)]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1643
	      by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1644
	    finally have False using c' by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1645
	  then have thn: "xs!i < n" by arith
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1646
	  from h[rule_format, OF thn]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1647
	  show "a$(xs !i) = ?r$(xs!i)" .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1648
	qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1649
	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
  1650
	  by (simp add: field_simps del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1651
	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
  1652
	also have "a ^ Suc k$n = setsum ?g ?Pnkn + setsum ?g ?Pnknn"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1653
	  unfolding fps_power_nth_Suc
31790
05c92381363c corrected and unified thm names
nipkow
parents: 31776
diff changeset
  1654
	  using setsum_Un_disjoint[OF f d, unfolded Suc_eq_plus1[symmetric],
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1655
	    unfolded eq, of ?g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1656
	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
  1657
	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
  1658
	then have "a$n = (b$n - setsum ?f ?Pnknn) / (of_nat (k+1) * (?r $ 0)^k)"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1659
	  apply -
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1660
	  apply (rule eq_divide_imp')
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1661
	  using r00
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1662
	  apply (simp del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1663
	  by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1664
	then have "a$n = ?r $n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1665
	  apply (simp del: of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1666
	  unfolding fps_radical_def n1
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  1667
	  by (simp add: field_simps n1 th00 del: of_nat_Suc)}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1668
	ultimately show "a$n = ?r $ n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1669
      qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1670
    then have "a = ?r" by (simp add: fps_eq_iff)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1671
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1672
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1673
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1674
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1675
lemma radical_power:
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1676
  assumes r0: "r (Suc k) ((a$0) ^ Suc k) = a$0"
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1677
  and a0: "(a$0 ::'a::field_char_0) \<noteq> 0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1678
  shows "(fps_radical r (Suc k) (a ^ Suc k)) = a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1679
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1680
  let ?ak = "a^ Suc k"
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  1681
  have ak0: "?ak $ 0 = (a$0) ^ Suc k" by (simp add: fps_nth_power_0 del: power_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1682
  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
  1683
  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
  1684
  from ak0 a0 have ak00: "?ak $ 0 \<noteq>0 " by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1685
  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
  1686
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1687
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1688
lemma fps_deriv_radical:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1689
  fixes a:: "'a::field_char_0 fps"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1690
  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
  1691
  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
  1692
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1693
  let ?r= "fps_radical r (Suc k) a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1694
  let ?w = "(fps_const (of_nat (Suc k)) * ?r ^ k)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1695
  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
  1696
  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
  1697
  note th0 = inverse_mult_eq_1[OF w0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1698
  let ?iw = "inverse ?w"
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1699
  from iffD1[OF power_radical[of a r], OF a0 r0]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1700
  have "fps_deriv (?r ^ Suc k) = fps_deriv a" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1701
  hence "fps_deriv ?r * ?w = fps_deriv a"
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  1702
    by (simp add: fps_deriv_power mult_ac del: power_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1703
  hence "?iw * fps_deriv ?r * ?w = ?iw * fps_deriv a" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1704
  hence "fps_deriv ?r * (?iw * ?w) = fps_deriv a / ?w"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1705
    by (simp add: fps_divide_def)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1706
  then show ?thesis unfolding th0 by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1707
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1708
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1709
lemma radical_mult_distrib:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1710
  fixes a:: "'a::field_char_0 fps"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1711
  assumes
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1712
  k: "k > 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1713
  and ra0: "r k (a $ 0) ^ k = a $ 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1714
  and rb0: "r k (b $ 0) ^ k = b $ 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1715
  and a0: "a$0 \<noteq> 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1716
  and b0: "b$0 \<noteq> 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1717
  shows "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0) \<longleftrightarrow> fps_radical r (k) (a*b) = fps_radical r (k) a * fps_radical r (k) (b)"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1718
proof-
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1719
  {assume  r0': "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0)"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1720
  from r0' have r0: "(r (k) ((a*b)$0)) ^ k = (a*b)$0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1721
    by (simp add: fps_mult_nth ra0 rb0 power_mult_distrib)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1722
  {assume "k=0" hence ?thesis using r0' by simp}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1723
  moreover
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1724
  {fix h assume k: "k = Suc h"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1725
  let ?ra = "fps_radical r (Suc h) a"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1726
  let ?rb = "fps_radical r (Suc h) b"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1727
  have th0: "r (Suc h) ((a * b) $ 0) = (fps_radical r (Suc h) a * fps_radical r (Suc h) b) $ 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1728
    using r0' k by (simp add: fps_mult_nth)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1729
  have ab0: "(a*b) $ 0 \<noteq> 0" using a0 b0 by (simp add: fps_mult_nth)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1730
  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]
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1731
    iffD1[OF power_radical[of _ r], OF a0 ra0[unfolded k]] iffD1[OF power_radical[of _ r], OF b0 rb0[unfolded k]] k r0'
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1732
  have ?thesis by (auto simp add: power_mult_distrib simp del: power_Suc)}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1733
ultimately have ?thesis by (cases k, auto)}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1734
moreover
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1735
{assume h: "fps_radical r k (a*b) = fps_radical r k a * fps_radical r k b"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1736
  hence "(fps_radical r k (a*b))$0 = (fps_radical r k a * fps_radical r k b)$0" by simp
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1737
  then have "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0)"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1738
    using k by (simp add: fps_mult_nth)}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1739
ultimately show ?thesis by blast
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1740
qed
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1741
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1742
(*
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1743
lemma radical_mult_distrib:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1744
  fixes a:: "'a::field_char_0 fps"
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1745
  assumes
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1746
  ra0: "r k (a $ 0) ^ k = a $ 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1747
  and rb0: "r k (b $ 0) ^ k = b $ 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1748
  and r0': "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1749
  and a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1750
  and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1751
  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
  1752
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1753
  from r0' have r0: "(r (k) ((a*b)$0)) ^ k = (a*b)$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1754
    by (simp add: fps_mult_nth ra0 rb0 power_mult_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1755
  {assume "k=0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1756
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1757
  {fix h assume k: "k = Suc h"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1758
  let ?ra = "fps_radical r (Suc h) a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1759
  let ?rb = "fps_radical r (Suc h) b"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1760
  have th0: "r (Suc h) ((a * b) $ 0) = (fps_radical r (Suc h) a * fps_radical r (Suc h) b) $ 0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1761
    using r0' k by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1762
  have ab0: "(a*b) $ 0 \<noteq> 0" using a0 b0 by (simp add: fps_mult_nth)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1763
  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]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1764
    power_radical[of r, OF ra0[unfolded k] a0] power_radical[of r, OF rb0[unfolded k] b0] k
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  1765
  have ?thesis by (auto simp add: power_mult_distrib simp del: power_Suc)}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1766
ultimately show ?thesis by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1767
qed
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1768
*)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1769
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1770
lemma fps_divide_1[simp]: "(a:: ('a::field) fps) / 1 = a"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1771
  by (simp add: fps_divide_def)
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 radical_divide:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1774
  fixes a :: "'a::field_char_0 fps"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1775
  assumes
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1776
  kp: "k>0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1777
  and ra0: "(r k (a $ 0)) ^ k = a $ 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1778
  and rb0: "(r k (b $ 0)) ^ k = b $ 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1779
  and a0: "a$0 \<noteq> 0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1780
  and b0: "b$0 \<noteq> 0"
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1781
  shows "r k ((a $ 0) / (b$0)) = r k (a$0) / r k (b $ 0) \<longleftrightarrow> fps_radical r k (a/b) = fps_radical r k a / fps_radical r k b" (is "?lhs = ?rhs")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1782
proof-
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1783
  let ?r = "fps_radical r k"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1784
  from kp obtain h where k: "k = Suc h" by (cases k, auto)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1785
  have ra0': "r k (a$0) \<noteq> 0" using a0 ra0 k by auto
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1786
  have rb0': "r k (b$0) \<noteq> 0" using b0 rb0 k by auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1787
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1788
  {assume ?rhs
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1789
    then have "?r (a/b) $ 0 = (?r a / ?r b)$0" by simp
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1790
    then have ?lhs using k a0 b0 rb0' 
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1791
      by (simp add: fps_divide_def fps_mult_nth fps_inverse_def divide_inverse) }
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1792
  moreover
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1793
  {assume h: ?lhs
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1794
    from a0 b0 have ab0[simp]: "(a/b)$0 = a$0 / b$0" 
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1795
      by (simp add: fps_divide_def fps_mult_nth divide_inverse fps_inverse_def)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1796
    have th0: "r k ((a/b)$0) ^ k = (a/b)$0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1797
      by (simp add: h nonzero_power_divide[OF rb0'] ra0 rb0 del: k)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1798
    from a0 b0 ra0' rb0' kp h 
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1799
    have th1: "r k ((a / b) $ 0) = (fps_radical r k a / fps_radical r k b) $ 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1800
      by (simp add: fps_divide_def fps_mult_nth fps_inverse_def divide_inverse del: k)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1801
    from a0 b0 ra0' rb0' kp have ab0': "(a / b) $ 0 \<noteq> 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1802
      by (simp add: fps_divide_def fps_mult_nth fps_inverse_def nonzero_imp_inverse_nonzero)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1803
    note tha[simp] = iffD1[OF power_radical[where r=r and k=h], OF a0 ra0[unfolded k], unfolded k[symmetric]]
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1804
    note thb[simp] = iffD1[OF power_radical[where r=r and k=h], OF b0 rb0[unfolded k], unfolded k[symmetric]]
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1805
    have th2: "(?r a / ?r b)^k = a/b"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1806
      by (simp add: fps_divide_def power_mult_distrib fps_inverse_power[symmetric])
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1807
    from iffD1[OF radical_unique[where r=r and a="?r a / ?r b" and b="a/b" and k=h], symmetric, unfolded k[symmetric], OF th0 th1 ab0' th2] have ?rhs .}
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1808
  ultimately show ?thesis by blast
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1809
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1810
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1811
lemma radical_inverse:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1812
  fixes a :: "'a::field_char_0 fps"
31073
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1813
  assumes
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1814
  k: "k>0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1815
  and ra0: "r k (a $ 0) ^ k = a $ 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1816
  and r1: "(r k 1)^k = 1"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1817
  and a0: "a$0 \<noteq> 0"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1818
  shows "r k (inverse (a $ 0)) = r k 1 / (r k (a $ 0)) \<longleftrightarrow> fps_radical r k (inverse a) = fps_radical r k 1 / fps_radical r k a"
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1819
  using radical_divide[where k=k and r=r and a=1 and b=a, OF k ] ra0 r1 a0
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1820
  by (simp add: divide_inverse fps_divide_def)
4b44c4d08aa6 Generalized distributivity theorems of radicals over multiplication, division and inverses
chaieb
parents: 31021
diff changeset
  1821
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1822
subsection{* Derivative of composition *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1823
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1824
lemma fps_compose_deriv:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1825
  fixes a:: "('a::idom) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1826
  assumes b0: "b$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1827
  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
  1828
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1829
  {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1830
    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
  1831
      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
  1832
    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
  1833
      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
  1834
  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
  1835
    unfolding fps_mult_left_const_nth  by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1836
  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
  1837
    unfolding fps_mult_nth ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1838
  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
  1839
    apply (rule setsum_mono_zero_right)
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1840
    apply (auto simp add: mult_delta_left setsum_delta not_le)
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1841
    done
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1842
  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
  1843
    unfolding fps_deriv_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1844
    apply (rule setsum_reindex_cong[where f="Suc"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1845
    by (auto simp add: mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1846
  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}" .
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1847
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1848
  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
  1849
    unfolding fps_mult_nth by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1850
  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
  1851
    unfolding fps_deriv_nth fps_compose_nth setsum_right_distrib mult_assoc
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1852
    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1853
    apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1854
    apply (simp_all add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1855
    apply clarify
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1856
    apply (subgoal_tac "b^i$x = 0")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1857
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1858
    apply (rule startsby_zero_power_prefix[OF b0, rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1859
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1860
  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
  1861
    unfolding setsum_right_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1862
    apply (subst setsum_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1863
    by ((rule setsum_cong2)+) simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1864
  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
  1865
    unfolding th0 by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1866
then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1867
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1868
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1869
lemma fps_mult_X_plus_1_nth:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1870
  "((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
  1871
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1872
  {assume "n = 0" hence ?thesis by (simp add: fps_mult_nth )}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1873
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1874
  {fix m assume m: "n = Suc m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1875
    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
  1876
      by (simp add: fps_mult_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1877
    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
  1878
      unfolding m
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1879
      apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1880
      by (auto simp add: )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1881
    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
  1882
      unfolding m
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1883
      by (simp add: )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1884
    finally have ?thesis .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1885
  ultimately show ?thesis by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1886
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1887
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1888
subsection{* Finite FPS (i.e. polynomials) and X *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1889
lemma fps_poly_sum_X:
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1890
  assumes z: "\<forall>i > n. a$i = (0::'a::comm_ring_1)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1891
  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
  1892
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1893
  {fix i
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1894
    have "a$i = ?r$i"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1895
      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
  1896
      by (simp add: mult_delta_right setsum_delta' z)
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1897
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1898
  then show ?thesis unfolding fps_eq_iff by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1899
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1900
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1901
subsection{* Compositional inverses *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1902
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1903
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1904
fun compinv :: "'a fps \<Rightarrow> nat \<Rightarrow> 'a::{field}" where
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1905
  "compinv a 0 = X$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1906
| "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
  1907
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1908
definition "fps_inv a = Abs_fps (compinv a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1909
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1910
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
  1911
  shows "fps_inv a oo a = X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1912
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1913
  let ?i = "fps_inv a oo a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1914
  {fix n
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1915
    have "?i $n = X$n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1916
    proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1917
      fix n assume h: "\<forall>m<n. ?i$m = X$m"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1918
      {assume "n=0" hence "?i $n = X$n" using a0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1919
	  by (simp add: fps_compose_nth fps_inv_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1920
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1921
      {fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1922
	have "?i $ n = setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1} + fps_inv a $ Suc n1 * (a $ 1)^ Suc n1"
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  1923
	  by (simp add: fps_compose_nth n1 startsby_zero_power_nth_same[OF a0]
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  1924
                   del: power_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1925
	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
  1926
	  using a0 a1 n1 by (simp add: fps_inv_def)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1927
	also have "\<dots> = X$n" using n1 by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1928
	finally have "?i $ n = X$n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1929
      ultimately show "?i $ n = X$n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1930
    qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1931
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1932
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1933
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1934
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1935
fun gcompinv :: "'a fps \<Rightarrow> 'a fps \<Rightarrow> nat \<Rightarrow> 'a::{field}" where
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1936
  "gcompinv b a 0 = b$0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1937
| "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
  1938
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1939
definition "fps_ginv b a = Abs_fps (gcompinv b a)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1940
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1941
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
  1942
  shows "fps_ginv b a oo a = b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1943
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1944
  let ?i = "fps_ginv b a oo a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1945
  {fix n
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1946
    have "?i $n = b$n"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1947
    proof(induct n rule: nat_less_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1948
      fix n assume h: "\<forall>m<n. ?i$m = b$m"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1949
      {assume "n=0" hence "?i $n = b$n" using a0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1950
	  by (simp add: fps_compose_nth fps_ginv_def)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1951
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1952
      {fix n1 assume n1: "n = Suc n1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1953
	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"
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  1954
	  by (simp add: fps_compose_nth n1 startsby_zero_power_nth_same[OF a0]
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  1955
                   del: power_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1956
	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
  1957
	  using a0 a1 n1 by (simp add: fps_ginv_def)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1958
	also have "\<dots> = b$n" using n1 by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1959
	finally have "?i $ n = b$n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1960
      ultimately show "?i $ n = b$n" by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1961
    qed}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1962
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1963
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1964
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1965
lemma fps_inv_ginv: "fps_inv = fps_ginv X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1966
  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
  1967
  apply (induct_tac n rule: nat_less_induct, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1968
  apply (case_tac na)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1969
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1970
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1971
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1972
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1973
lemma fps_compose_1[simp]: "1 oo a = 1"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
  1974
  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
  1975
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1976
lemma fps_compose_0[simp]: "0 oo a = 0"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  1977
  by (simp add: fps_eq_iff fps_compose_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1978
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1979
lemma fps_compose_0_right[simp]: "a oo 0 = fps_const (a$0)"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
  1980
  by (auto simp add: fps_eq_iff fps_compose_nth power_0_left setsum_0')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1981
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1982
lemma fps_compose_add_distrib: "(a + b) oo c = (a oo c) + (b oo c)"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
  1983
  by (simp add: fps_eq_iff fps_compose_nth ring_simps setsum_addf)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1984
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1985
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
  1986
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1987
  {assume "\<not> finite S" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1988
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1989
  {assume fS: "finite S"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1990
    have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1991
    proof(rule finite_induct[OF fS])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1992
      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
  1993
    next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1994
      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
  1995
      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
  1996
	using fF xF h by (simp add: fps_compose_add_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1997
    qed}
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1998
  ultimately show ?thesis by blast
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1999
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2000
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2001
lemma convolution_eq:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2002
  "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
  2003
  apply (rule setsum_reindex_cong[where f=fst])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2004
  apply (clarsimp simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2005
  apply (auto simp add: expand_set_eq image_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2006
  apply (rule_tac x= "x" in exI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2007
  apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2008
  apply (rule_tac x="n - x" in exI)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2009
  apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2010
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2011
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2012
lemma product_composition_lemma:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2013
  assumes c0: "c$0 = (0::'a::idom)" and d0: "d$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2014
  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
  2015
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2016
  let ?S = "{(k\<Colon>nat, m\<Colon>nat). k + m \<le> n}"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2017
  have s: "?S \<subseteq> {0..n} <*> {0..n}" by (auto simp add: subset_eq)
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2018
  have f: "finite {(k\<Colon>nat, m\<Colon>nat). k + m \<le> n}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2019
    apply (rule finite_subset[OF s])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2020
    by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2021
  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
  2022
    apply (simp add: fps_mult_nth setsum_right_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2023
    apply (subst setsum_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2024
    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2025
    by (auto simp add: ring_simps)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2026
  also have "\<dots> = ?l"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2027
    apply (simp add: fps_mult_nth fps_compose_nth setsum_product)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2028
    apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2029
    apply (simp add: setsum_cartesian_product mult_assoc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2030
    apply (rule setsum_mono_zero_right[OF f])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2031
    apply (simp add: subset_eq) apply presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2032
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2033
    apply (rule ccontr)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2034
    apply (clarsimp simp add: not_le)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2035
    apply (case_tac "x < aa")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2036
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2037
    apply (frule_tac startsby_zero_power_prefix[rule_format, OF c0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2038
    apply blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2039
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2040
    apply (frule_tac startsby_zero_power_prefix[rule_format, OF d0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2041
    apply blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2042
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2043
  finally show ?thesis by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2044
qed
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 product_composition_lemma':
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2047
  assumes c0: "c$0 = (0::'a::idom)" and d0: "d$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2048
  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
  2049
  unfolding product_composition_lemma[OF c0 d0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2050
  unfolding setsum_cartesian_product
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2051
  apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2052
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2053
  apply (clarsimp simp add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2054
  apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2055
  apply (rule ccontr)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2056
  apply (subgoal_tac "(c^aa * d^ba) $ n = 0")
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
  unfolding fps_mult_nth
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2059
  apply (rule setsum_0')
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2060
  apply (clarsimp simp add: not_le)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2061
  apply (case_tac "aaa < aa")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2062
  apply (rule startsby_zero_power_prefix[OF c0, rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2063
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2064
  apply (subgoal_tac "n - aaa < ba")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2065
  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
  2066
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2067
  apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2068
  done
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2069
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2070
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2071
lemma setsum_pair_less_iff:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2072
  "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
  2073
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2074
  let ?KM=  "{(k,m). k + m \<le> n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2075
  let ?f = "%s. UNION {(0::nat)..s} (%i. {(i,s - i)})"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2076
  have th0: "?KM = UNION {0..n} ?f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2077
    apply (simp add: expand_set_eq)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2078
    apply arith (* FIXME: VERY slow! *)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2079
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2080
  show "?l = ?r "
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2081
    unfolding th0
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2082
    apply (subst setsum_UN_disjoint)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2083
    apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2084
    apply (subst setsum_UN_disjoint)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2085
    apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2086
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2087
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2088
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2089
lemma fps_compose_mult_distrib_lemma:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2090
  assumes c0: "c$0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2091
  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
  2092
  unfolding product_composition_lemma[OF c0 c0] power_add[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2093
  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
  2094
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2095
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2096
lemma fps_compose_mult_distrib:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2097
  assumes c0: "c$0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2098
  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
  2099
  apply (simp add: fps_eq_iff fps_compose_mult_distrib_lemma[OF c0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2100
  by (simp add: fps_compose_nth fps_mult_nth setsum_left_distrib)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2101
lemma fps_compose_setprod_distrib:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2102
  assumes c0: "c$0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2103
  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
  2104
  apply (cases "finite S")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2105
  apply simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2106
  apply (induct S rule: finite_induct)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2107
  apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2108
  apply (simp add: fps_compose_mult_distrib[OF c0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2109
  done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2110
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2111
lemma fps_compose_power:   assumes c0: "c$0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2112
  shows "(a oo c)^n = a^n oo c" (is "?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2113
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2114
  {assume "n=0" then have ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2115
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2116
  {fix m assume m: "n = Suc m"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2117
    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
  2118
      by (simp_all add: setprod_constant m)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2119
    then have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2120
      by (simp add: fps_compose_setprod_distrib[OF c0])}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2121
  ultimately show ?thesis by (cases n, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2122
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2123
31199
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2124
lemma fps_compose_uminus: "- (a::'a::ring_1 fps) oo c = - (a oo c)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2125
  by (simp add: fps_eq_iff fps_compose_nth ring_simps setsum_negf[symmetric])
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2126
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2127
lemma fps_compose_sub_distrib:
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2128
  shows "(a - b) oo (c::'a::ring_1 fps) = (a oo c) - (b oo c)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2129
  unfolding diff_minus fps_compose_uminus fps_compose_add_distrib ..
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2130
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2131
lemma X_fps_compose:"X oo a = Abs_fps (\<lambda>n. if n = 0 then (0::'a::comm_ring_1) else a$n)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2132
  by (simp add: fps_eq_iff fps_compose_nth mult_delta_left setsum_delta power_Suc)
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2133
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2134
lemma fps_inverse_compose:
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2135
  assumes b0: "(b$0 :: 'a::field) = 0" and a0: "a$0 \<noteq> 0"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2136
  shows "inverse a oo b = inverse (a oo b)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2137
proof-
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2138
  let ?ia = "inverse a"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2139
  let ?ab = "a oo b"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2140
  let ?iab = "inverse ?ab"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2141
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2142
from a0 have ia0: "?ia $ 0 \<noteq> 0" by (simp )
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2143
from a0 have ab0: "?ab $ 0 \<noteq> 0" by (simp add: fps_compose_def)
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2144
thm inverse_mult_eq_1[OF ab0]
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2145
have "(?ia oo b) *  (a oo b) = 1"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2146
unfolding fps_compose_mult_distrib[OF b0, symmetric]
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2147
unfolding inverse_mult_eq_1[OF a0]
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2148
fps_compose_1 ..
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2149
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2150
then have "(?ia oo b) *  (a oo b) * ?iab  = 1 * ?iab" by simp
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2151
then have "(?ia oo b) *  (?iab * (a oo b))  = ?iab" by simp
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2152
then show ?thesis 
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2153
  unfolding inverse_mult_eq_1[OF ab0] by simp
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2154
qed
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2155
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2156
lemma fps_divide_compose:
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2157
  assumes c0: "(c$0 :: 'a::field) = 0" and b0: "b$0 \<noteq> 0"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2158
  shows "(a/b) oo c = (a oo c) / (b oo c)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2159
    unfolding fps_divide_def fps_compose_mult_distrib[OF c0]
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2160
    fps_inverse_compose[OF c0 b0] ..
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2161
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2162
lemma gp: assumes a0: "a$0 = (0::'a::field)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2163
  shows "(Abs_fps (\<lambda>n. 1)) oo a = 1/(1 - a)" (is "?one oo a = _")
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2164
proof-
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2165
  have o0: "?one $ 0 \<noteq> 0" by simp
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2166
  have th0: "(1 - X) $ 0 \<noteq> (0::'a)" by simp  
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2167
  from fps_inverse_gp[where ?'a = 'a]
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2168
  have "inverse ?one = 1 - X" by (simp add: fps_eq_iff)
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2169
  hence "inverse (inverse ?one) = inverse (1 - X)" by simp
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2170
  hence th: "?one = 1/(1 - X)" unfolding fps_inverse_idempotent[OF o0] 
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2171
    by (simp add: fps_divide_def)
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2172
  show ?thesis unfolding th
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2173
    unfolding fps_divide_compose[OF a0 th0]
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2174
    fps_compose_1 fps_compose_sub_distrib X_fps_compose_startby0[OF a0] ..
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2175
qed
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2176
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2177
lemma fps_const_power[simp]: "fps_const (c::'a::ring_1) ^ n = fps_const (c^n)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2178
by (induct n, auto)
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2179
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2180
lemma fps_compose_radical:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2181
  assumes b0: "b$0 = (0::'a::field_char_0)"
31199
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2182
  and ra0: "r (Suc k) (a$0) ^ Suc k = a$0"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2183
  and a0: "a$0 \<noteq> 0"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2184
  shows "fps_radical r (Suc k)  a oo b = fps_radical r (Suc k) (a oo b)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2185
proof-
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2186
  let ?r = "fps_radical r (Suc k)"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2187
  let ?ab = "a oo b"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2188
  have ab0: "?ab $ 0 = a$0" by (simp add: fps_compose_def)
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2189
  from ab0 a0 ra0 have rab0: "?ab $ 0 \<noteq> 0" "r (Suc k) (?ab $ 0) ^ Suc k = ?ab $ 0" by simp_all
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2190
  have th00: "r (Suc k) ((a oo b) $ 0) = (fps_radical r (Suc k) a oo b) $ 0"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2191
    by (simp add: ab0 fps_compose_def)
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2192
  have th0: "(?r a oo b) ^ (Suc k) = a  oo b"
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2193
    unfolding fps_compose_power[OF b0]
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2194
    unfolding iffD1[OF power_radical[of a r k], OF a0 ra0]  .. 
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2195
  from iffD1[OF radical_unique[where r=r and k=k and b= ?ab and a = "?r a oo b", OF rab0(2) th00 rab0(1)], OF th0] show ?thesis  . 
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2196
qed
10d413b08fa7 FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
chaieb
parents: 31148
diff changeset
  2197
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2198
lemma fps_const_mult_apply_left:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2199
  "fps_const c * (a oo b) = (fps_const c * a) oo b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2200
  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
  2201
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2202
lemma fps_const_mult_apply_right:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2203
  "(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
  2204
  by (auto simp add: fps_const_mult_apply_left mult_commute)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2205
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2206
lemma fps_compose_assoc:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2207
  assumes c0: "c$0 = (0::'a::idom)" and b0: "b$0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2208
  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
  2209
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2210
  {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2211
    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
  2212
      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
  2213
    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
  2214
      by (simp add: fps_compose_setsum_distrib)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2215
    also have "\<dots> = ?r$n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2216
      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
  2217
      apply (rule setsum_cong2)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2218
      apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2219
      apply (auto simp add: not_le)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2220
      by (erule startsby_zero_power_prefix[OF b0, rule_format])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2221
    finally have "?l$n = ?r$n" .}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2222
  then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2223
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2224
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2225
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2226
lemma fps_X_power_compose:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2227
  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
  2228
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2229
  {assume "k=0" hence ?thesis by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2230
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2231
  {fix h assume h: "k = Suc h"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2232
    {fix n
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2233
      {assume kn: "k>n" hence "?l $ n = ?r $n" using a0 startsby_zero_power_prefix[OF a0] h
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  2234
	  by (simp add: fps_compose_nth del: power_Suc)}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2235
      moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2236
      {assume kn: "k \<le> n"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  2237
	hence "?l$n = ?r$n"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
  2238
          by (simp add: fps_compose_nth mult_delta_left setsum_delta)}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2239
      moreover have "k >n \<or> k\<le> n"  by arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2240
      ultimately have "?l$n = ?r$n"  by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2241
    then have ?thesis unfolding fps_eq_iff by blast}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2242
  ultimately show ?thesis by (cases k, auto)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2243
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2244
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2245
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
  2246
  shows "a oo fps_inv a = X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2247
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2248
  let ?ia = "fps_inv a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2249
  let ?iaa = "a oo fps_inv a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2250
  have th0: "?ia $ 0 = 0" by (simp add: fps_inv_def)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2251
  have th1: "?iaa $ 0 = 0" using a0 a1
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2252
    by (simp add: fps_inv_def fps_compose_nth)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2253
  have th2: "X$0 = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2254
  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
  2255
  then have "(a oo fps_inv a) oo a = X oo a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2256
    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
  2257
  with fps_compose_inj_right[OF a0 a1]
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2258
  show ?thesis by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2259
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2260
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2261
lemma fps_inv_deriv:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  2262
  assumes a0:"a$0 = (0::'a::{field})" and a1: "a$1 \<noteq> 0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2263
  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
  2264
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2265
  let ?ia = "fps_inv a"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2266
  let ?d = "fps_deriv a oo ?ia"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2267
  let ?dia = "fps_deriv ?ia"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2268
  have ia0: "?ia$0 = 0" by (simp add: fps_inv_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2269
  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
  2270
  from fps_inv_right[OF a0 a1] have "?d * ?dia = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2271
    by (simp add: fps_compose_deriv[OF ia0, of a, symmetric] )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2272
  hence "inverse ?d * ?d * ?dia = inverse ?d * 1" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2273
  with inverse_mult_eq_1[OF th0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2274
  show "?dia = inverse ?d" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2275
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2276
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2277
lemma fps_inv_idempotent: 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2278
  assumes a0: "a$0 = 0" and a1: "a$1 \<noteq> 0"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2279
  shows "fps_inv (fps_inv a) = a"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2280
proof-
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2281
  let ?r = "fps_inv"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2282
  have ra0: "?r a $ 0 = 0" by (simp add: fps_inv_def)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2283
  from a1 have ra1: "?r a $ 1 \<noteq> 0" by (simp add: fps_inv_def field_simps)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2284
  have X0: "X$0 = 0" by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2285
  from fps_inv[OF ra0 ra1] have "?r (?r a) oo ?r a = X" .
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2286
  then have "?r (?r a) oo ?r a oo a = X oo a" by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2287
  then have "?r (?r a) oo (?r a oo a) = a" 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2288
    unfolding X_fps_compose_startby0[OF a0]
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2289
    unfolding fps_compose_assoc[OF a0 ra0, symmetric] .
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2290
  then show ?thesis unfolding fps_inv[OF a0 a1] by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2291
qed
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2292
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2293
lemma fps_ginv_ginv:
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2294
  assumes a0: "a$0 = 0" and a1: "a$1 \<noteq> 0"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2295
  and c0: "c$0 = 0" and  c1: "c$1 \<noteq> 0"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2296
  shows "fps_ginv b (fps_ginv c a) = b oo a oo fps_inv c"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2297
proof-
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2298
  let ?r = "fps_ginv"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2299
  from c0 have rca0: "?r c a $0 = 0" by (simp add: fps_ginv_def)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2300
  from a1 c1 have rca1: "?r c a $ 1 \<noteq> 0" by (simp add: fps_ginv_def field_simps)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2301
  from fps_ginv[OF rca0 rca1] 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2302
  have "?r b (?r c a) oo ?r c a = b" .
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2303
  then have "?r b (?r c a) oo ?r c a oo a = b oo a" by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2304
  then have "?r b (?r c a) oo (?r c a oo a) = b oo a"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2305
    apply (subst fps_compose_assoc)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2306
    using a0 c0 by (auto simp add: fps_ginv_def)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2307
  then have "?r b (?r c a) oo c = b oo a"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2308
    unfolding fps_ginv[OF a0 a1] .
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2309
  then have "?r b (?r c a) oo c oo fps_inv c= b oo a oo fps_inv c" by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2310
  then have "?r b (?r c a) oo (c oo fps_inv c) = b oo a oo fps_inv c"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2311
    apply (subst fps_compose_assoc)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2312
    using a0 c0 by (auto simp add: fps_inv_def)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2313
  then show ?thesis unfolding fps_inv_right[OF c0 c1] by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2314
qed
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2315
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  2316
subsection{* Elementary series *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2317
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  2318
subsubsection{* Exponential series *}
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2319
definition "E x = Abs_fps (\<lambda>n. x^n / of_nat (fact n))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2320
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2321
lemma E_deriv[simp]: "fps_deriv (E a) = fps_const (a::'a::field_char_0) * E a" (is "?l = ?r")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2322
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2323
  {fix n
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2324
    have "?l$n = ?r $ n"
30273
ecd6f0ca62ea declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents: 29915
diff changeset
  2325
  apply (auto simp add: E_def field_simps power_Suc[symmetric]simp del: fact_Suc of_nat_Suc power_Suc)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2326
  by (simp add: of_nat_mult ring_simps)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2327
then show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2328
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2329
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2330
lemma E_unique_ODE:
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2331
  "fps_deriv a = fps_const c * a \<longleftrightarrow> a = fps_const (a$0) * E (c :: 'a::field_char_0)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2332
  (is "?lhs \<longleftrightarrow> ?rhs")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2333
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2334
  {assume d: ?lhs
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2335
  from d have th: "\<And>n. a $ Suc n = c * a$n / of_nat (Suc n)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2336
    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
  2337
  {fix n have "a$n = a$0 * c ^ n/ (of_nat (fact n))"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2338
      apply (induct n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2339
      apply simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2340
      unfolding th
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2341
      using fact_gt_zero
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2342
      apply (simp add: field_simps del: of_nat_Suc fact.simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2343
      apply (drule sym)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2344
      by (simp add: ring_simps of_nat_mult power_Suc)}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2345
  note th' = this
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2346
  have ?rhs
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2347
    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
  2348
moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2349
{assume h: ?rhs
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2350
  have ?lhs
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2351
    apply (subst h)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2352
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2353
    apply (simp only: h[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2354
  by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2355
ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2356
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2357
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2358
lemma E_add_mult: "E (a + b) = E (a::'a::field_char_0) * E b" (is "?l = ?r")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2359
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2360
  have "fps_deriv (?r) = fps_const (a+b) * ?r"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2361
    by (simp add: fps_const_add[symmetric] ring_simps del: fps_const_add)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2362
  then have "?r = ?l" apply (simp only: E_unique_ODE)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2363
    by (simp add: fps_mult_nth E_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2364
  then show ?thesis ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2365
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2366
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2367
lemma E_nth[simp]: "E a $ n = a^n / of_nat (fact n)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2368
  by (simp add: E_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2369
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  2370
lemma E0[simp]: "E (0::'a::{field}) = 1"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2371
  by (simp add: fps_eq_iff power_0_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2372
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2373
lemma E_neg: "E (- a) = inverse (E (a::'a::field_char_0))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2374
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2375
  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
  2376
    by (simp )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2377
  have th1: "E a $ 0 \<noteq> 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2378
  from fps_inverse_unique[OF th1 th0] show ?thesis by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2379
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2380
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2381
lemma E_nth_deriv[simp]: "fps_nth_deriv n (E (a::'a::field_char_0)) = (fps_const a)^n * (E a)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2382
  by (induct n, auto simp add: power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2383
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  2384
lemma X_compose_E[simp]: "X oo E (a::'a::{field}) = E a - 1"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2385
  by (simp add: fps_eq_iff X_fps_compose)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2386
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2387
lemma LE_compose:
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2388
  assumes a: "a\<noteq>0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2389
  shows "fps_inv (E a - 1) oo (E a - 1) = X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2390
  and "(E a - 1) oo fps_inv (E a - 1) = X"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2391
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2392
  let ?b = "E a - 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2393
  have b0: "?b $ 0 = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2394
  have b1: "?b $ 1 \<noteq> 0" by (simp add: a)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2395
  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
  2396
  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
  2397
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2398
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2399
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2400
lemma fps_const_inverse:
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2401
  "a \<noteq> 0 \<Longrightarrow> inverse (fps_const (a::'a::field)) = fps_const (inverse a)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2402
  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
  2403
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2404
lemma inverse_one_plus_X:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  2405
  "inverse (1 + X) = Abs_fps (\<lambda>n. (- 1 ::'a::{field})^n)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2406
  (is "inverse ?l = ?r")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2407
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2408
  have th: "?l * ?r = 1"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31075
diff changeset
  2409
    by (auto simp add: ring_simps fps_eq_iff minus_one_power_iff)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2410
  have th': "?l $ 0 \<noteq> 0" by (simp add: )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2411
  from fps_inverse_unique[OF th' th] show ?thesis .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2412
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2413
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2414
lemma E_power_mult: "(E (c::'a::field_char_0))^n = E (of_nat n * c)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2415
  by (induct n, auto simp add: ring_simps E_add_mult power_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2416
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2417
lemma assumes r: "r (Suc k) 1 = 1" 
31370
chaieb
parents: 31274 31369
diff changeset
  2418
  shows "fps_radical r (Suc k) (E (c::'a::{field_char_0})) = E (c / of_nat (Suc k))"
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2419
proof-
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2420
  let ?ck = "(c / of_nat (Suc k))"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2421
  let ?r = "fps_radical r (Suc k)"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2422
  have eq0[simp]: "?ck * of_nat (Suc k) = c" "of_nat (Suc k) * ?ck = c"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2423
    by (simp_all del: of_nat_Suc)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2424
  have th0: "E ?ck ^ (Suc k) = E c" unfolding E_power_mult eq0 ..
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2425
  have th: "r (Suc k) (E c $0) ^ Suc k = E c $ 0"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2426
    "r (Suc k) (E c $ 0) = E ?ck $ 0" "E c $ 0 \<noteq> 0" using r by simp_all
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2427
  from th0 radical_unique[where r=r and k=k, OF th]
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2428
  show ?thesis by auto 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2429
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2430
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2431
lemma Ec_E1_eq: 
31370
chaieb
parents: 31274 31369
diff changeset
  2432
  "E (1::'a::{field_char_0}) oo (fps_const c * X) = E c"
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2433
  apply (auto simp add: fps_eq_iff E_def fps_compose_def power_mult_distrib)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2434
  by (simp add: cond_value_iff cond_application_beta setsum_delta' cong del: if_weak_cong)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2435
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2436
subsubsection{* Logarithmic series *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2437
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2438
lemma Abs_fps_if_0: 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2439
  "Abs_fps(%n. if n=0 then (v::'a::ring_1) else f n) = fps_const v + X * Abs_fps (%n. f (Suc n))"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2440
  by (auto simp add: fps_eq_iff)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2441
31370
chaieb
parents: 31274 31369
diff changeset
  2442
definition L:: "'a::{field_char_0} \<Rightarrow> 'a fps" where 
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2443
  "L c \<equiv> fps_const (1/c) * Abs_fps (\<lambda>n. if n = 0 then 0 else (- 1) ^ (n - 1) / of_nat n)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2444
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2445
lemma fps_deriv_L: "fps_deriv (L c) = fps_const (1/c) * inverse (1 + X)"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2446
  unfolding inverse_one_plus_X
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2447
  by (simp add: L_def fps_eq_iff del: of_nat_Suc)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2448
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2449
lemma L_nth: "L c $ n = (if n=0 then 0 else 1/c * ((- 1) ^ (n - 1) / of_nat n))"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2450
  by (simp add: L_def field_simps)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2451
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2452
lemma L_0[simp]: "L c $ 0 = 0" by (simp add: L_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2453
lemma L_E_inv:
31370
chaieb
parents: 31274 31369
diff changeset
  2454
  assumes a: "a\<noteq> (0::'a::{field_char_0})"
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2455
  shows "L a = fps_inv (E a - 1)" (is "?l = ?r")
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2456
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2457
  let ?b = "E a - 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2458
  have b0: "?b $ 0 = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2459
  have b1: "?b $ 1 \<noteq> 0" by (simp add: a)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2460
  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
  2461
    by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2462
  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
  2463
    by (simp add: ring_simps)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2464
  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
  2465
  from fps_inv_deriv[OF b0 b1, unfolded eq]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2466
  have "fps_deriv (fps_inv ?b) = fps_const (inverse a) / (X + 1)"
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2467
    using a 
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2468
    by (simp add: fps_const_inverse eq fps_divide_def fps_inverse_mult)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2469
  hence "fps_deriv ?l = fps_deriv ?r"
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2470
    by (simp add: fps_deriv_L add_commute fps_divide_def divide_inverse)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2471
  then show ?thesis unfolding fps_deriv_eq_iff
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2472
    by (simp add: L_nth fps_inv_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2473
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2474
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2475
lemma L_mult_add: 
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2476
  assumes c0: "c\<noteq>0" and d0: "d\<noteq>0"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2477
  shows "L c + L d = fps_const (c+d) * L (c*d)"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2478
  (is "?r = ?l")
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2479
proof-
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2480
  from c0 d0 have eq: "1/c + 1/d = (c+d)/(c*d)" by (simp add: field_simps)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2481
  have "fps_deriv ?r = fps_const (1/c + 1/d) * inverse (1 + X)"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2482
    by (simp add: fps_deriv_L fps_const_add[symmetric] algebra_simps del: fps_const_add)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2483
  also have "\<dots> = fps_deriv ?l"
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2484
    apply (simp add: fps_deriv_L)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2485
    by (simp add: fps_eq_iff eq)
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2486
  finally show ?thesis
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2487
    unfolding fps_deriv_eq_iff by simp
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2488
qed
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
  2489
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  2490
subsubsection{* Formal trigonometric functions  *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2491
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2492
definition "fps_sin (c::'a::field_char_0) =
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2493
  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
  2494
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2495
definition "fps_cos (c::'a::field_char_0) =
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2496
  Abs_fps (\<lambda>n. if even n then (- 1) ^ (n div 2) * c^n / (of_nat (fact n)) else 0)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2497
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2498
lemma fps_sin_deriv:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2499
  "fps_deriv (fps_sin c) = fps_const c * fps_cos c"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2500
  (is "?lhs = ?rhs")
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2501
proof (rule fps_ext)
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2502
  fix n::nat
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2503
    {assume en: "even n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2504
      have "?lhs$n = of_nat (n+1) * (fps_sin c $ (n+1))" by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2505
      also have "\<dots> = of_nat (n+1) * ((- 1)^(n div 2) * c^Suc n / of_nat (fact (Suc n)))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2506
	using en by (simp add: fps_sin_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2507
      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
  2508
	unfolding fact_Suc of_nat_mult
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2509
	by (simp add: field_simps del: of_nat_add of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2510
      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
  2511
	by (simp add: field_simps del: of_nat_add of_nat_Suc)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2512
      finally have "?lhs $n = ?rhs$n" using en
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2513
	by (simp add: fps_cos_def ring_simps power_Suc )}
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2514
    then show "?lhs $ n = ?rhs $ n"
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2515
      by (cases "even n", simp_all add: fps_deriv_def fps_sin_def fps_cos_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2516
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2517
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2518
lemma fps_cos_deriv:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2519
  "fps_deriv (fps_cos c) = fps_const (- c)* (fps_sin c)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2520
  (is "?lhs = ?rhs")
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2521
proof (rule fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2522
  have th0: "\<And>n. - ((- 1::'a) ^ n) = (- 1)^Suc n" by (simp add: power_Suc)
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2523
  have th1: "\<And>n. odd n \<Longrightarrow> Suc ((n - 1) div 2) = Suc n div 2"
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2524
    by (case_tac n, simp_all)
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2525
  fix n::nat
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2526
    {assume en: "odd n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2527
      from en have n0: "n \<noteq>0 " by presburger
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2528
      have "?lhs$n = of_nat (n+1) * (fps_cos c $ (n+1))" by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2529
      also have "\<dots> = of_nat (n+1) * ((- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact (Suc n)))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2530
	using en by (simp add: fps_cos_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2531
      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
  2532
	unfolding fact_Suc of_nat_mult
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2533
	by (simp add: field_simps del: of_nat_add of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2534
      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
  2535
	by (simp add: field_simps del: of_nat_add of_nat_Suc)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2536
      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
  2537
	unfolding th0 unfolding th1[OF en] by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2538
      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
  2539
	by (simp add: fps_sin_def ring_simps power_Suc)}
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2540
    then show "?lhs $ n = ?rhs $ n"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2541
      by (cases "even n", simp_all add: fps_deriv_def fps_sin_def
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  2542
	fps_cos_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2543
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2544
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2545
lemma fps_sin_cos_sum_of_squares:
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2546
  "fps_cos c ^ 2 + fps_sin c ^ 2 = 1" (is "?lhs = 1")
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2547
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2548
  have "fps_deriv ?lhs = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2549
    apply (simp add:  fps_deriv_power fps_sin_deriv fps_cos_deriv power_Suc)
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
  2550
    by (simp add: ring_simps fps_const_neg[symmetric] del: fps_const_neg)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2551
  then have "?lhs = fps_const (?lhs $ 0)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2552
    unfolding fps_deriv_eq_0_iff .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2553
  also have "\<dots> = 1"
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30952
diff changeset
  2554
    by (auto simp add: fps_eq_iff 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
  2555
  finally show ?thesis .
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2556
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2557
31274
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2558
lemma fact_1 [simp]: "fact 1 = 1"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2559
unfolding One_nat_def fact_Suc by simp
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2560
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2561
lemma divide_eq_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x / a = y \<longleftrightarrow> x = y * a"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2562
by auto
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2563
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2564
lemma eq_divide_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x = y / a \<longleftrightarrow> x * a = y"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2565
by auto
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2566
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2567
lemma fps_sin_nth_0 [simp]: "fps_sin c $ 0 = 0"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2568
unfolding fps_sin_def by simp
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2569
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2570
lemma fps_sin_nth_1 [simp]: "fps_sin c $ 1 = c"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2571
unfolding fps_sin_def by simp
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2572
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2573
lemma fps_sin_nth_add_2:
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2574
  "fps_sin c $ (n + 2) = - (c * c * fps_sin c $ n / (of_nat(n+1) * of_nat(n+2)))"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2575
unfolding fps_sin_def
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2576
apply (cases n, simp)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2577
apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2578
apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2579
done
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2580
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2581
lemma fps_cos_nth_0 [simp]: "fps_cos c $ 0 = 1"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2582
unfolding fps_cos_def by simp
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2583
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2584
lemma fps_cos_nth_1 [simp]: "fps_cos c $ 1 = 0"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2585
unfolding fps_cos_def by simp
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2586
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2587
lemma fps_cos_nth_add_2:
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2588
  "fps_cos c $ (n + 2) = - (c * c * fps_cos c $ n / (of_nat(n+1) * of_nat(n+2)))"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2589
unfolding fps_cos_def
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2590
apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2591
apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2592
done
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2593
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2594
lemma nat_induct2:
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2595
  "\<lbrakk>P 0; P 1; \<And>n. P n \<Longrightarrow> P (n + 2)\<rbrakk> \<Longrightarrow> P (n::nat)"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2596
unfolding One_nat_def numeral_2_eq_2
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2597
apply (induct n rule: nat_less_induct)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2598
apply (case_tac n, simp)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2599
apply (rename_tac m, case_tac m, simp)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2600
apply (rename_tac k, case_tac k, simp_all)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2601
done
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2602
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2603
lemma nat_add_1_add_1: "(n::nat) + 1 + 1 = n + 2"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2604
by simp
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2605
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2606
lemma eq_fps_sin:
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2607
  assumes 0: "a $ 0 = 0" and 1: "a $ 1 = c"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2608
  and 2: "fps_deriv (fps_deriv a) = - (fps_const c * fps_const c * a)"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2609
  shows "a = fps_sin c"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2610
apply (rule fps_ext)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2611
apply (induct_tac n rule: nat_induct2)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2612
apply (simp add: fps_sin_nth_0 0)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2613
apply (simp add: fps_sin_nth_1 1 del: One_nat_def)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2614
apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2])
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2615
apply (simp add: nat_add_1_add_1 fps_sin_nth_add_2
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2616
            del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc')
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2617
apply (subst minus_divide_left)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2618
apply (subst eq_divide_iff)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2619
apply (simp del: of_nat_add of_nat_Suc)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2620
apply (simp only: mult_ac)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2621
done
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2622
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2623
lemma eq_fps_cos:
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2624
  assumes 0: "a $ 0 = 1" and 1: "a $ 1 = 0"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2625
  and 2: "fps_deriv (fps_deriv a) = - (fps_const c * fps_const c * a)"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2626
  shows "a = fps_cos c"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2627
apply (rule fps_ext)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2628
apply (induct_tac n rule: nat_induct2)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2629
apply (simp add: fps_cos_nth_0 0)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2630
apply (simp add: fps_cos_nth_1 1 del: One_nat_def)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2631
apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2])
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2632
apply (simp add: nat_add_1_add_1 fps_cos_nth_add_2
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2633
            del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc')
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2634
apply (subst minus_divide_left)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2635
apply (subst eq_divide_iff)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2636
apply (simp del: of_nat_add of_nat_Suc)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2637
apply (simp only: mult_ac)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2638
done
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2639
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2640
lemma mult_nth_0 [simp]: "(a * b) $ 0 = a $ 0 * b $ 0"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2641
by (simp add: fps_mult_nth)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2642
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2643
lemma mult_nth_1 [simp]: "(a * b) $ 1 = a $ 0 * b $ 1 + a $ 1 * b $ 0"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2644
by (simp add: fps_mult_nth)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2645
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2646
lemma fps_sin_add:
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2647
  "fps_sin (a + b) = fps_sin a * fps_cos b + fps_cos a * fps_sin b"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2648
apply (rule eq_fps_sin [symmetric], simp, simp del: One_nat_def)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2649
apply (simp del: fps_const_neg fps_const_add fps_const_mult
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2650
            add: fps_const_add [symmetric] fps_const_neg [symmetric]
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2651
                 fps_sin_deriv fps_cos_deriv algebra_simps)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2652
done
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2653
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2654
lemma fps_cos_add:
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2655
  "fps_cos (a + b) = fps_cos a * fps_cos b - fps_sin a * fps_sin b"
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2656
apply (rule eq_fps_cos [symmetric], simp, simp del: One_nat_def)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2657
apply (simp del: fps_const_neg fps_const_add fps_const_mult
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2658
            add: fps_const_add [symmetric] fps_const_neg [symmetric]
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2659
                 fps_sin_deriv fps_cos_deriv algebra_simps)
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2660
done
d2b5c6b07988 addition formulas for fps_sin, fps_cos
huffman
parents: 31273
diff changeset
  2661
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2662
definition "fps_tan c = fps_sin c / fps_cos c"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2663
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2664
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
  2665
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2666
  have th0: "fps_cos c $ 0 \<noteq> 0" by (simp add: fps_cos_def)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  2667
  show ?thesis
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2668
    using fps_sin_cos_sum_of_squares[of c]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2669
    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
  2670
    unfolding right_distrib[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2671
    by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  2672
qed
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2673
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  2674
end