src/HOL/Library/Formal_Power_Series.thy
author wenzelm
Wed, 07 Aug 2013 14:47:50 +0200
changeset 52891 b8dede3a4f1d
parent 51542 738598beeb26
child 52902 7196e1ce1cd8
permissions -rw-r--r--
tuned proofs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 39302
diff changeset
     1
(*  Title:      HOL/Library/Formal_Power_Series.thy
29687
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
51542
738598beeb26 tuned imports;
wenzelm
parents: 51489
diff changeset
     8
imports Binomial
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
     9
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    10
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
    11
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
    12
subsection {* The type of formal power series*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    13
49834
b27bbb021df1 discontinued obsolete typedef (open) syntax;
wenzelm
parents: 48757
diff changeset
    14
typedef 'a fps = "{f :: nat \<Rightarrow> 'a. True}"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    15
  morphisms fps_nth Abs_fps
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    16
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    17
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    18
notation fps_nth (infixl "$" 75)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    19
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    20
lemma expand_fps_eq: "p = q \<longleftrightarrow> (\<forall>n. p $ n = q $ n)"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
    21
  by (simp add: fps_nth_inject [symmetric] fun_eq_iff)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    22
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    23
lemma fps_ext: "(\<And>n. p $ n = q $ n) \<Longrightarrow> p = q"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    24
  by (simp add: expand_fps_eq)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    25
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    26
lemma fps_nth_Abs_fps [simp]: "Abs_fps f $ n = f n"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    27
  by (simp add: Abs_fps_inverse)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    28
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
    29
text{* Definition of the basic elements 0 and 1 and the basic operations of addition,
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
    30
  negation and multiplication *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    31
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36350
diff changeset
    32
instantiation fps :: (zero) zero
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    33
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    34
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    35
definition fps_zero_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    36
  "0 = Abs_fps (\<lambda>n. 0)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    37
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    38
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    39
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    40
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    41
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
    42
  unfolding fps_zero_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    43
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36350
diff changeset
    44
instantiation fps :: ("{one, zero}") one
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    45
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    46
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    47
definition fps_one_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    48
  "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
    49
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    50
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    51
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    52
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
    53
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
    54
  unfolding fps_one_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    55
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    56
instantiation fps :: (plus)  plus
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    57
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    58
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    59
definition fps_plus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    60
  "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
    61
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    62
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    63
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    64
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    65
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
    66
  unfolding fps_plus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    67
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    68
instantiation fps :: (minus) minus
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    69
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    70
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    71
definition fps_minus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    72
  "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
    73
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    74
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    75
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    76
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    77
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
    78
  unfolding fps_minus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    79
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    80
instantiation fps :: (uminus) uminus
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    81
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    82
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    83
definition fps_uminus_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    84
  "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
    85
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    86
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    87
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    88
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    89
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
    90
  unfolding fps_uminus_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    91
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    92
instantiation fps :: ("{comm_monoid_add, times}")  times
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    93
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    94
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    95
definition fps_times_def:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
    96
  "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
    97
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    98
instance ..
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
    99
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   100
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   101
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
   102
  unfolding fps_times_def by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   103
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   104
declare atLeastAtMost_iff [presburger]
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   105
declare Bex_def [presburger]
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   106
declare Ball_def [presburger]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   107
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   108
lemma mult_delta_left:
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   109
  fixes x y :: "'a::mult_zero"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   110
  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
   111
  by simp
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   112
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   113
lemma mult_delta_right:
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   114
  fixes x y :: "'a::mult_zero"
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   115
  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
   116
  by simp
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   117
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   118
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
   119
  by auto
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   120
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   121
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
   122
  by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   123
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   124
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
   125
  they represent is a commutative ring with unity*}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   126
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   127
instance fps :: (semigroup_add) semigroup_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   128
proof
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   129
  fix a b c :: "'a fps"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   130
  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
   131
    by (simp add: fps_ext add_assoc)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   132
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   133
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   134
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
   135
proof
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   136
  fix a b :: "'a fps"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   137
  show "a + b = b + a"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   138
    by (simp add: fps_ext add_commute)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   139
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   140
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   141
lemma fps_mult_assoc_lemma:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   142
  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
   143
  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
   144
         (\<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
   145
proof (induct k)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   146
  case 0
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   147
  show ?case by simp
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   148
next
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   149
  case (Suc k)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   150
  then show ?case
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   151
    by (simp add: Suc_diff_le setsum_addf add_assoc cong: strong_setsum_cong)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   152
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   153
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   154
instance fps :: (semiring_0) semigroup_mult
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   155
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   156
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   157
  show "(a * b) * c = a * (b * c)"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   158
  proof (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   159
    fix n :: nat
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   160
    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
   161
          (\<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
   162
      by (rule fps_mult_assoc_lemma)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   163
    then show "((a * b) * c) $ n = (a * (b * c)) $ n"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   164
      by (simp add: fps_mult_nth setsum_right_distrib setsum_left_distrib mult_assoc)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   165
  qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   166
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   167
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   168
lemma fps_mult_commute_lemma:
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   169
  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
   170
  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
   171
proof (rule setsum_reindex_cong)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   172
  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
   173
    by (rule inj_onI) simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   174
  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
   175
    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
   176
next
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   177
  fix i
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   178
  assume "i \<in> {0..n}"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   179
  then have "n - (n - i) = i" by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   180
  then show "f (n - i) i = f (n - i) (n - (n - i))" by simp
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   181
qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   182
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   183
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
   184
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   185
  fix a b :: "'a fps"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   186
  show "a * b = b * a"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   187
  proof (rule fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   188
    fix n :: nat
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   189
    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
   190
      by (rule fps_mult_commute_lemma)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   191
    then show "(a * b) $ n = (b * a) $ n"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   192
      by (simp add: fps_mult_nth mult_commute)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   193
  qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   194
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   195
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   196
instance fps :: (monoid_add) monoid_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   197
proof
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   198
  fix a :: "'a fps"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   199
  show "0 + a = a" by (simp add: fps_ext)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   200
  show "a + 0 = a" by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   201
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   202
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   203
instance fps :: (comm_monoid_add) comm_monoid_add
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   204
proof
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   205
  fix a :: "'a fps"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   206
  show "0 + a = a" by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   207
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   208
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   209
instance fps :: (semiring_1) monoid_mult
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   210
proof
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   211
  fix a :: "'a fps"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   212
  show "1 * a = a"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   213
    by (simp add: fps_ext fps_mult_nth mult_delta_left setsum_delta)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   214
  show "a * 1 = a"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   215
    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
   216
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   217
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   218
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
   219
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   220
  fix a b c :: "'a fps"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   221
  { assume "a + b = a + c" then show "b = c" by (simp add: expand_fps_eq) }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   222
  { assume "b + a = c + a" then show "b = c" by (simp add: expand_fps_eq) }
29911
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"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   228
  assume "a + b = a + c"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   229
  then show "b = c" by (simp add: expand_fps_eq)
29911
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
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   236
  fix a b :: "'a fps"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   237
  show "- a + a = 0" by (simp add: fps_ext)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   238
  show "a - b = a + - b" by (simp add: fps_ext diff_minus)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   239
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   240
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   241
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
   242
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   243
  fix a b :: "'a fps"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   244
  show "- a + a = 0" by (simp add: fps_ext)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   245
  show "a - b = a + - b" by (simp add: fps_ext)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   246
qed
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   247
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   248
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
   249
  by default (simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   250
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   251
instance fps :: (semiring_0) semiring
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   252
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   253
  fix a b c :: "'a fps"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   254
  show "(a + b) * c = a * c + b * c"
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 49834
diff changeset
   255
    by (simp add: expand_fps_eq fps_mult_nth distrib_right setsum_addf)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   256
  show "a * (b + c) = a * b + a * c"
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 49834
diff changeset
   257
    by (simp add: expand_fps_eq fps_mult_nth distrib_left setsum_addf)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   258
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   259
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   260
instance fps :: (semiring_0) semiring_0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   261
proof
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   262
  fix a:: "'a fps"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   263
  show "0 * a = 0" by (simp add: fps_ext fps_mult_nth)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   264
  show "a * 0 = 0" by (simp add: fps_ext fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   265
qed
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   266
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   267
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
   268
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   269
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
   270
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   271
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
   272
  by (simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   273
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   274
lemma fps_nonzero_nth_minimal:
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   275
  "f \<noteq> 0 \<longleftrightarrow> (\<exists>n. f $ n \<noteq> 0 \<and> (\<forall>m < n. f $ m = 0))"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   276
proof
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   277
  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
   278
  assume "f \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   279
  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
   280
    by (simp add: fps_nonzero_nth)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   281
  then have "f $ ?n \<noteq> 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   282
    by (rule LeastI_ex)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   283
  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
   284
    by (auto dest: not_less_Least)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   285
  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
   286
  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
   287
next
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   288
  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
   289
  then show "f \<noteq> 0" by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   290
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   291
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   292
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
   293
  by (rule expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   294
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   295
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
   296
proof (cases "finite S")
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   297
  case True
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   298
  then show ?thesis by (induct set: finite) auto
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   299
next
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   300
  case False
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   301
  then show ?thesis by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   302
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   303
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   304
subsection{* Injection of the basic ring elements and multiplication by scalars *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   305
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   306
definition "fps_const c = Abs_fps (\<lambda>n. if n = 0 then c else 0)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   307
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   308
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
   309
  unfolding fps_const_def by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   310
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   311
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
   312
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   313
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   314
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
   315
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   316
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   317
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
   318
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   319
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   320
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
   321
  by (simp add: fps_ext)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   322
31369
8b460fd12100 Reverses idempotent; radical of E; generalized logarithm;
chaieb
parents: 31199
diff changeset
   323
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
   324
  by (simp add: fps_ext)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   325
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   326
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
   327
  by (simp add: fps_eq_iff fps_mult_nth setsum_0')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   328
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   329
lemma fps_const_add_left: "fps_const (c::'a\<Colon>monoid_add) + f =
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   330
    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
   331
  by (simp add: fps_ext)
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   332
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   333
lemma fps_const_add_right: "f + fps_const (c::'a\<Colon>monoid_add) =
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   334
    Abs_fps (\<lambda>n. if n = 0 then f$0 + c else f$n)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   335
  by (simp add: fps_ext)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   336
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   337
lemma fps_const_mult_left: "fps_const (c::'a\<Colon>semiring_0) * f = Abs_fps (\<lambda>n. c * f$n)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   338
  unfolding fps_eq_iff fps_mult_nth
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   339
  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
   340
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   341
lemma fps_const_mult_right: "f * fps_const (c::'a\<Colon>semiring_0) = Abs_fps (\<lambda>n. f$n * c)"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   342
  unfolding fps_eq_iff fps_mult_nth
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   343
  by (simp add: fps_const_def mult_delta_right setsum_delta')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   344
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   345
lemma fps_mult_left_const_nth [simp]: "(fps_const (c::'a::semiring_1) * f)$n = c* f$n"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   346
  by (simp add: fps_mult_nth mult_delta_left setsum_delta)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   347
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   348
lemma fps_mult_right_const_nth [simp]: "(f * fps_const (c::'a::semiring_1))$n = f$n * c"
29913
89eadbe71e97 add mult_delta lemmas; simplify some proofs
huffman
parents: 29912
diff changeset
   349
  by (simp add: fps_mult_nth mult_delta_right setsum_delta')
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   350
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   351
subsection {* Formal power series form an integral domain*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   352
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   353
instance fps :: (ring) ring ..
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   354
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   355
instance fps :: (ring_1) ring_1
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 49834
diff changeset
   356
  by (intro_classes, auto simp add: diff_minus distrib_right)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   357
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   358
instance fps :: (comm_ring_1) comm_ring_1
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 49834
diff changeset
   359
  by (intro_classes, auto simp add: diff_minus distrib_right)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   360
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   361
instance fps :: (ring_no_zero_divisors) ring_no_zero_divisors
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   362
proof
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   363
  fix a b :: "'a fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   364
  assume a0: "a \<noteq> 0" and b0: "b \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   365
  then obtain i j where i: "a$i\<noteq>0" "\<forall>k<i. a$k=0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   366
    and j: "b$j \<noteq>0" "\<forall>k<j. b$k =0" unfolding fps_nonzero_nth_minimal
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   367
    by blast+
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   368
  have "(a * b) $ (i+j) = (\<Sum>k=0..i+j. a$k * b$(i+j-k))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   369
    by (rule fps_mult_nth)
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   370
  also have "\<dots> = (a$i * b$(i+j-i)) + (\<Sum>k\<in>{0..i+j}-{i}. a$k * b$(i+j-k))"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   371
    by (rule setsum_diff1') simp_all
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   372
  also have "(\<Sum>k\<in>{0..i+j}-{i}. a$k * b$(i+j-k)) = 0"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   373
    proof (rule setsum_0' [rule_format])
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   374
      fix k assume "k \<in> {0..i+j} - {i}"
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   375
      then have "k < i \<or> i+j-k < j" by auto
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   376
      then show "a$k * b$(i+j-k) = 0" using i j by auto
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   377
    qed
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   378
  also have "a$i * b$(i+j-i) + 0 = a$i * b$j" by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   379
  also have "a$i * b$j \<noteq> 0" using i j by simp
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   380
  finally have "(a*b) $ (i+j) \<noteq> 0" .
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   381
  then show "a*b \<noteq> 0" unfolding fps_nonzero_nth by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   382
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   383
36311
ed3a87a7f977 epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
haftmann
parents: 36309
diff changeset
   384
instance fps :: (ring_1_no_zero_divisors) ring_1_no_zero_divisors ..
ed3a87a7f977 epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
haftmann
parents: 36309
diff changeset
   385
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   386
instance fps :: (idom) idom ..
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   387
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46757
diff changeset
   388
lemma numeral_fps_const: "numeral k = fps_const (numeral k)"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   389
  by (induct k) (simp_all only: numeral.simps fps_const_1_eq_1
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46757
diff changeset
   390
    fps_const_add [symmetric])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46757
diff changeset
   391
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46757
diff changeset
   392
lemma neg_numeral_fps_const: "neg_numeral k = fps_const (neg_numeral k)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46757
diff changeset
   393
  by (simp only: neg_numeral_def numeral_fps_const fps_const_neg)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46757
diff changeset
   394
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   395
subsection{* The eXtractor series X*}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   396
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   397
lemma minus_one_power_iff: "(- (1::'a :: {comm_ring_1})) ^ n = (if even n then 1 else - 1)"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   398
  by (induct n) auto
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   399
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   400
definition "X = Abs_fps (\<lambda>n. if n = 1 then 1 else 0)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   401
lemma X_mult_nth[simp]: "(X * (f :: ('a::semiring_1) fps)) $n = (if n = 0 then 0 else f $ (n - 1))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   402
proof-
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   403
  {assume n: "n \<noteq> 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   404
    have "(X * f) $n = (\<Sum>i = 0..n. X $ i * f $ (n - i))" by (simp add: fps_mult_nth)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   405
    also have "\<dots> = f $ (n - 1)"
46757
ad878aff9c15 removing finiteness goals
bulwahn
parents: 46131
diff changeset
   406
      using n by (simp add: X_def mult_delta_left setsum_delta)
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   407
  finally have ?thesis using n by simp }
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   408
  moreover
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   409
  {assume n: "n=0" hence ?thesis by (simp add: fps_mult_nth X_def)}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   410
  ultimately show ?thesis by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   411
qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   412
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   413
lemma X_mult_right_nth[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   414
    "((f :: ('a::comm_semiring_1) fps) * X) $n = (if n = 0 then 0 else f $ (n - 1))"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   415
  by (metis X_mult_nth mult_commute)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   416
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   417
lemma X_power_iff: "X^k = Abs_fps (\<lambda>n. if n = k then (1::'a::comm_ring_1) else 0)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   418
proof(induct k)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   419
  case 0 thus ?case by (simp add: X_def fps_eq_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   420
next
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   421
  case (Suc k)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   422
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   423
    fix m
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   424
    have "(X^Suc k) $ m = (if m = 0 then (0::'a) else (X^k) $ (m - 1))"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   425
      by (simp del: One_nat_def)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   426
    then have "(X^Suc k) $ m = (if m = Suc k then (1::'a) else 0)"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   427
      using Suc.hyps by (auto cong del: if_weak_cong)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   428
  }
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   429
  then show ?case by (simp add: fps_eq_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   430
qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   431
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   432
lemma X_power_mult_nth:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   433
    "(X^k * (f :: ('a::comm_ring_1) fps)) $n = (if n < k then 0 else f $ (n - k))"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   434
  apply (induct k arbitrary: n)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   435
  apply simp
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   436
  unfolding power_Suc mult_assoc
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   437
  apply (case_tac n)
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   438
  apply auto
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   439
  done
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   440
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   441
lemma X_power_mult_right_nth:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   442
    "((f :: ('a::comm_ring_1) fps) * X^k) $n = (if n < k then 0 else f $ (n - k))"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   443
  by (metis X_power_mult_nth mult_commute)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   444
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   445
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   446
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   447
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   448
subsection{* Formal Power series form a metric space *}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   449
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   450
definition (in dist) ball_def: "ball x r = {y. dist y x < r}"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   451
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   452
instantiation fps :: (comm_ring_1) dist
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   453
begin
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   454
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   455
definition
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   456
  dist_fps_def: "dist (a::'a fps) b =
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   457
    (if (\<exists>n. a$n \<noteq> b$n) then inverse (2 ^ The (leastP (\<lambda>n. a$n \<noteq> b$n))) else 0)"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   458
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   459
lemma dist_fps_ge0: "dist (a::'a fps) b \<ge> 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   460
  by (simp add: dist_fps_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   461
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   462
lemma dist_fps_sym: "dist (a::'a fps) b = dist b a"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   463
  apply (auto simp add: dist_fps_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   464
  apply (rule cong[OF refl, where x="(\<lambda>n\<Colon>nat. a $ n \<noteq> b $ n)"])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   465
  apply (rule ext)
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   466
  apply auto
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   467
  done
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   468
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   469
instance ..
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   470
30746
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   471
end
d6915b738bd9 fps made instance of number_ring
chaieb
parents: 30488
diff changeset
   472
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   473
lemma fps_nonzero_least_unique: assumes a0: "a \<noteq> 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   474
  shows "\<exists>! n. leastP (\<lambda>n. a$n \<noteq> 0) n"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   475
proof -
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   476
  from fps_nonzero_nth_minimal [of a] a0
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   477
  obtain n where "a$n \<noteq> 0" "\<forall>m < n. a$m = 0" by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   478
  then have ln: "leastP (\<lambda>n. a$n \<noteq> 0) n"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   479
    by (auto simp add: leastP_def setge_def not_le [symmetric])
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   480
  moreover
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   481
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   482
    fix m
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   483
    assume "leastP (\<lambda>n. a $ n \<noteq> 0) m"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   484
    then have "m = n" using ln
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   485
      apply (auto simp add: leastP_def setge_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   486
      apply (erule allE[where x=n])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   487
      apply (erule allE[where x=m])
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   488
      apply simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   489
      done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   490
  }
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   491
  ultimately show ?thesis by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   492
qed
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   493
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   494
lemma fps_eq_least_unique:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   495
  assumes ab: "(a::('a::ab_group_add) fps) \<noteq> b"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   496
  shows "\<exists>! n. leastP (\<lambda>n. a$n \<noteq> b$n) n"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   497
  using fps_nonzero_least_unique[of "a - b"] ab
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   498
  by auto
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   499
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   500
instantiation fps :: (comm_ring_1) metric_space
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   501
begin
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   502
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   503
definition open_fps_def: "open (S :: 'a fps set) = (\<forall>a \<in> S. \<exists>r. r >0 \<and> ball a r \<subseteq> S)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   504
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   505
instance
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   506
proof
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   507
  fix S :: "'a fps set"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   508
  show "open S = (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   509
    by (auto simp add: open_fps_def ball_def subset_eq)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   510
next
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   511
  {
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   512
    fix a b :: "'a fps"
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   513
    {
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   514
      assume "a = b"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   515
      then have "\<not> (\<exists>n. a $ n \<noteq> b $ n)" by simp
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   516
      then have "dist a b = 0" by (simp add: dist_fps_def)
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   517
    }
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   518
    moreover
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   519
    {
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   520
      assume d: "dist a b = 0"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   521
      then have "\<forall>n. a$n = b$n"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   522
        by - (rule ccontr, simp add: dist_fps_def)
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   523
      then have "a = b" by (simp add: fps_eq_iff)
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   524
    }
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   525
    ultimately show "dist a b =0 \<longleftrightarrow> a = b" by blast
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   526
  }
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   527
  note th = this
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   528
  from th have th'[simp]: "\<And>a::'a fps. dist a a = 0" by simp
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   529
  fix a b c :: "'a fps"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   530
  {
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   531
    assume "a = b"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   532
    then have "dist a b = 0" unfolding th .
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   533
    then have "dist a b \<le> dist a c + dist b c"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   534
      using dist_fps_ge0 [of a c] dist_fps_ge0 [of b c] by simp
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   535
  }
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   536
  moreover
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   537
  {
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   538
    assume "c = a \<or> c = b"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   539
    then have "dist a b \<le> dist a c + dist b c"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   540
      by (cases "c = a") (simp_all add: th dist_fps_sym)
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   541
  }
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   542
  moreover
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   543
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   544
    assume ab: "a \<noteq> b" and ac: "a \<noteq> c" and bc: "b \<noteq> c"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   545
    let ?P = "\<lambda>a b n. a$n \<noteq> b$n"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   546
    from fps_eq_least_unique[OF ab] fps_eq_least_unique[OF ac]
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   547
      fps_eq_least_unique[OF bc]
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   548
    obtain nab nac nbc where nab: "leastP (?P a b) nab"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   549
      and nac: "leastP (?P a c) nac"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   550
      and nbc: "leastP (?P b c) nbc" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   551
    from nab have nab': "\<And>m. m < nab \<Longrightarrow> a$m = b$m" "a$nab \<noteq> b$nab"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   552
      by (auto simp add: leastP_def setge_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   553
    from nac have nac': "\<And>m. m < nac \<Longrightarrow> a$m = c$m" "a$nac \<noteq> c$nac"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   554
      by (auto simp add: leastP_def setge_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   555
    from nbc have nbc': "\<And>m. m < nbc \<Longrightarrow> b$m = c$m" "b$nbc \<noteq> c$nbc"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   556
      by (auto simp add: leastP_def setge_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   557
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   558
    have th0: "\<And>(a::'a fps) b. a \<noteq> b \<longleftrightarrow> (\<exists>n. a$n \<noteq> b$n)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   559
      by (simp add: fps_eq_iff)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   560
    from ab ac bc nab nac nbc
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   561
    have dab: "dist a b = inverse (2 ^ nab)"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   562
      and dac: "dist a c = inverse (2 ^ nac)"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   563
      and dbc: "dist b c = inverse (2 ^ nbc)"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   564
      unfolding th0
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   565
      apply (simp_all add: dist_fps_def)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   566
      apply (erule the1_equality[OF fps_eq_least_unique[OF ab]])
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   567
      apply (erule the1_equality[OF fps_eq_least_unique[OF ac]])
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   568
      apply (erule the1_equality[OF fps_eq_least_unique[OF bc]])
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   569
      done
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   570
    from ab ac bc have nz: "dist a b \<noteq> 0" "dist a c \<noteq> 0" "dist b c \<noteq> 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   571
      unfolding th by simp_all
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   572
    from nz have pos: "dist a b > 0" "dist a c > 0" "dist b c > 0"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   573
      using dist_fps_ge0[of a b] dist_fps_ge0[of a c] dist_fps_ge0[of b c]
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   574
      by auto
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   575
    have th1: "\<And>n. (2::real)^n >0" by auto
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   576
    {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   577
      assume h: "dist a b > dist a c + dist b c"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   578
      then have gt: "dist a b > dist a c" "dist a b > dist b c"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   579
        using pos by auto
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   580
      from gt have gtn: "nab < nbc" "nab < nac"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   581
        unfolding dab dbc dac by (auto simp add: th1)
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   582
      from nac'(1)[OF gtn(2)] nbc'(1)[OF gtn(1)]
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   583
      have "a $ nab = b $ nab" by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   584
      with nab'(2) have False  by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   585
    }
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   586
    then have "dist a b \<le> dist a c + dist b c"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   587
      by (auto simp add: not_le[symmetric])
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   588
  }
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   589
  ultimately show "dist a b \<le> dist a c + dist b c" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   590
qed
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   591
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   592
end
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   593
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   594
text{* The infinite sums and justification of the notation in textbooks*}
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   595
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   596
lemma reals_power_lt_ex:
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   597
  assumes xp: "x > 0" and y1: "(y::real) > 1"
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   598
  shows "\<exists>k>0. (1/y)^k < x"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   599
proof -
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   600
  have yp: "y > 0" using y1 by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   601
  from reals_Archimedean2[of "max 0 (- log y x) + 1"]
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   602
  obtain k::nat where k: "real k > max 0 (- log y x) + 1" by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   603
  from k have kp: "k > 0" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   604
  from k have "real k > - log y x" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   605
  then have "ln y * real k > - ln x" unfolding log_def
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   606
    using ln_gt_zero_iff[OF yp] y1
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
   607
    by (simp add: minus_divide_left field_simps del:minus_divide_left[symmetric])
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   608
  then have "ln y * real k + ln x > 0" by simp
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   609
  then have "exp (real k * ln y + ln x) > exp 0"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   610
    by (simp add: mult_ac)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   611
  then have "y ^ k * x > 1"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   612
    unfolding exp_zero exp_add exp_real_of_nat_mult exp_ln [OF xp] exp_ln [OF yp]
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   613
    by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   614
  then have "x > (1 / y)^k" using yp
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
   615
    by (simp add: field_simps nonzero_power_divide)
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   616
  then show ?thesis using kp by blast
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   617
qed
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   618
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   619
lemma X_nth[simp]: "X$n = (if n = 1 then 1 else 0)" by (simp add: X_def)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   620
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   621
lemma X_power_nth[simp]: "(X^k) $n = (if n = k then 1 else (0::'a::comm_ring_1))"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   622
  by (simp add: X_power_iff)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   623
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   624
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   625
lemma fps_sum_rep_nth: "(setsum (%i. fps_const(a$i)*X^i) {0..m})$n =
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   626
    (if n \<le> m then a$n else (0::'a::comm_ring_1))"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   627
  apply (auto simp add: fps_setsum_nth cond_value_iff cong del: if_weak_cong)
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   628
  apply (simp add: setsum_delta')
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   629
  done
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   630
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   631
lemma fps_notation:
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   632
  "(%n. setsum (%i. fps_const(a$i) * X^i) {0..n}) ----> a" (is "?s ----> a")
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   633
proof -
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   634
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   635
    fix r:: real
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   636
    assume rp: "r > 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   637
    have th0: "(2::real) > 1" by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   638
    from reals_power_lt_ex[OF rp th0]
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   639
    obtain n0 where n0: "(1/2)^n0 < r" "n0 > 0" by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   640
    {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   641
      fix n::nat
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   642
      assume nn0: "n \<ge> n0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   643
      then have thnn0: "(1/2)^n <= (1/2 :: real)^n0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   644
        by (auto intro: power_decreasing)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   645
      {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   646
        assume "?s n = a"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   647
        then have "dist (?s n) a < r"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   648
          unfolding dist_eq_0_iff[of "?s n" a, symmetric]
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   649
          using rp by (simp del: dist_eq_0_iff)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   650
      }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   651
      moreover
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   652
      {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   653
        assume neq: "?s n \<noteq> a"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   654
        from fps_eq_least_unique[OF neq]
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   655
        obtain k where k: "leastP (\<lambda>i. ?s n $ i \<noteq> a$i) k" by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   656
        have th0: "\<And>(a::'a fps) b. a \<noteq> b \<longleftrightarrow> (\<exists>n. a$n \<noteq> b$n)"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   657
          by (simp add: fps_eq_iff)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   658
        from neq have dth: "dist (?s n) a = (1/2)^k"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   659
          unfolding th0 dist_fps_def
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   660
          unfolding the1_equality[OF fps_eq_least_unique[OF neq], OF k]
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   661
          by (auto simp add: inverse_eq_divide power_divide)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   662
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   663
        from k have kn: "k > n"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   664
          by (simp add: leastP_def setge_def fps_sum_rep_nth split:split_if_asm)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   665
        then have "dist (?s n) a < (1/2)^n" unfolding dth
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   666
          by (auto intro: power_strict_decreasing)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   667
        also have "\<dots> <= (1/2)^n0" using nn0
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   668
          by (auto intro: power_decreasing)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   669
        also have "\<dots> < r" using n0 by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   670
        finally have "dist (?s n) a < r" .
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   671
      }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   672
      ultimately have "dist (?s n) a < r" by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   673
    }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   674
    then have "\<exists>n0. \<forall> n \<ge> n0. dist (?s n) a < r " by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   675
  }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   676
  then show ?thesis unfolding LIMSEQ_def by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   677
qed
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   678
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
   679
subsection{* Inverses of formal power series *}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   680
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   681
declare setsum_cong[fundef_cong]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   682
36311
ed3a87a7f977 epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
haftmann
parents: 36309
diff changeset
   683
instantiation fps :: ("{comm_monoid_add, inverse, times, uminus}") inverse
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   684
begin
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   685
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   686
fun natfun_inverse:: "'a fps \<Rightarrow> nat \<Rightarrow> 'a"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   687
where
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   688
  "natfun_inverse f 0 = inverse (f$0)"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   689
| "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
   690
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   691
definition
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   692
  fps_inverse_def: "inverse f = (if f $ 0 = 0 then 0 else Abs_fps (natfun_inverse f))"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   693
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   694
definition
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   695
  fps_divide_def: "divide = (\<lambda>(f::'a fps) g. f * inverse g)"
36311
ed3a87a7f977 epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
haftmann
parents: 36309
diff changeset
   696
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   697
instance ..
36311
ed3a87a7f977 epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
haftmann
parents: 36309
diff changeset
   698
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   699
end
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   700
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   701
lemma fps_inverse_zero [simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   702
  "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
   703
  by (simp add: fps_ext fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   704
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   705
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
   706
  apply (auto simp add: expand_fps_eq fps_inverse_def)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   707
  apply (case_tac n)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   708
  apply auto
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   709
  done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   710
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   711
lemma inverse_mult_eq_1 [intro]:
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   712
  assumes f0: "f$0 \<noteq> (0::'a::field)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   713
  shows "inverse f * f = 1"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   714
proof -
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   715
  have c: "inverse f * f = f * inverse f" by (simp add: mult_commute)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   716
  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
   717
    by (simp add: fps_inverse_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   718
  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
   719
    by (simp add: fps_mult_nth fps_inverse_def)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   720
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   721
    fix n :: nat
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   722
    assume np: "n > 0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   723
    from np have eq: "{0..n} = {0} \<union> {1 .. n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   724
    have d: "{0} \<inter> {1 .. n} = {}" by auto
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   725
    from f0 np have th0: "- (inverse f $ n) =
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   726
      (setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}) / (f$0)"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   727
      by (cases n) (simp_all add: divide_inverse fps_inverse_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   728
    from th0[symmetric, unfolded nonzero_divide_eq_eq[OF f0]]
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   729
    have th1: "setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n} = - (f$0) * (inverse f)$n"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
   730
      by (simp add: field_simps)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   731
    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
   732
      unfolding fps_mult_nth ifn ..
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   733
    also have "\<dots> = f$0 * natfun_inverse f n + (\<Sum>i = 1..n. f$i * natfun_inverse f (n-i))"
46757
ad878aff9c15 removing finiteness goals
bulwahn
parents: 46131
diff changeset
   734
      by (simp add: eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   735
    also have "\<dots> = 0" unfolding th1 ifn by simp
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   736
    finally have "(inverse f * f)$n = 0" unfolding c .
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   737
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   738
  with th0 show ?thesis by (simp add: fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   739
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   740
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   741
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
   742
  by (simp add: fps_inverse_def nonzero_imp_inverse_nonzero)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   743
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   744
lemma fps_inverse_eq_0_iff[simp]: "inverse f = (0:: ('a::field) fps) \<longleftrightarrow> f $0 = 0"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   745
proof -
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   746
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   747
    assume "f$0 = 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   748
    then have "inverse f = 0" by (simp add: fps_inverse_def)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   749
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   750
  moreover
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   751
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   752
    assume h: "inverse f = 0" and c: "f $0 \<noteq> 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   753
    from inverse_mult_eq_1[OF c] h have False by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   754
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   755
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   756
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   757
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   758
lemma fps_inverse_idempotent[intro]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   759
  assumes f0: "f$0 \<noteq> (0::'a::field)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   760
  shows "inverse (inverse f) = f"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   761
proof -
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   762
  from f0 have if0: "inverse f $ 0 \<noteq> 0" by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   763
  from inverse_mult_eq_1[OF f0] inverse_mult_eq_1[OF if0]
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   764
  have "inverse f * f = inverse f * inverse (inverse f)"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   765
    by (simp add: mult_ac)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   766
  then show ?thesis using f0 unfolding mult_cancel_left by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   767
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   768
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   769
lemma fps_inverse_unique:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   770
  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
   771
  shows "inverse f = g"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   772
proof -
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   773
  from inverse_mult_eq_1[OF f0] fg
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   774
  have th0: "inverse f * f = g * f" by (simp add: mult_ac)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   775
  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
   776
    by (auto simp add: expand_fps_eq)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   777
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   778
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   779
lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field)))
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   780
  = 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
   781
  apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   782
  apply simp
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
   783
  apply (simp add: fps_eq_iff fps_mult_nth)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   784
proof clarsimp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   785
  fix n :: nat
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   786
  assume n: "n > 0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   787
  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
   788
  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
   789
  let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   790
  have th1: "setsum ?f {0..n} = setsum ?g {0..n}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   791
    by (rule setsum_cong2) auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   792
  have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   793
    using n apply - by (rule setsum_cong2) auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   794
  have eq: "{0 .. n} = {0.. n - 1} \<union> {n}" by auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   795
  from n have d: "{0.. n - 1} \<inter> {n} = {}" by auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   796
  have f: "finite {0.. n - 1}" "finite {n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   797
  show "setsum ?f {0..n} = 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   798
    unfolding th1
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   799
    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
   800
    unfolding th2
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   801
    apply (simp add: setsum_delta)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   802
    done
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   803
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   804
29912
f4ac160d2e77 fix spelling
huffman
parents: 29911
diff changeset
   805
subsection{* Formal Derivatives, and the MacLaurin theorem around 0*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   806
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   807
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
   808
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   809
lemma fps_deriv_nth[simp]: "fps_deriv f $ n = of_nat (n +1) * f $ (n+1)"
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   810
  by (simp add: fps_deriv_def)
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   811
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   812
lemma fps_deriv_linear[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   813
  "fps_deriv (fps_const (a::'a::comm_semiring_1) * f + fps_const b * g) =
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   814
    fps_const a * fps_deriv f + fps_const b * fps_deriv g"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
   815
  unfolding fps_eq_iff fps_add_nth  fps_const_mult_left fps_deriv_nth by (simp add: field_simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   816
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   817
lemma fps_deriv_mult[simp]:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   818
  fixes f :: "('a :: comm_ring_1) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   819
  shows "fps_deriv (f * g) = f * fps_deriv g + fps_deriv f * g"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   820
proof -
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   821
  let ?D = "fps_deriv"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   822
  { fix n::nat
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   823
    let ?Zn = "{0 ..n}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   824
    let ?Zn1 = "{0 .. n + 1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   825
    let ?f = "\<lambda>i. i + 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   826
    have fi: "inj_on ?f {0..n}" by (simp add: inj_on_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   827
    have eq: "{1.. n+1} = ?f ` {0..n}" by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   828
    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
   829
        of_nat (i+1)* f $ (i+1) * g $ (n - i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   830
    let ?h = "\<lambda>i. of_nat i * g $ i * f $ ((n+1) - i) +
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   831
        of_nat i* f $ i * g $ ((n + 1) - i)"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   832
    {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   833
      fix k
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   834
      assume k: "k \<in> {0..n}"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   835
      have "?h (k + 1) = ?g k" using k by auto
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   836
    }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   837
    note th0 = this
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   838
    have eq': "{0..n +1}- {1 .. n+1} = {0}" by auto
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   839
    have s0: "setsum (\<lambda>i. of_nat i * f $ i * g $ (n + 1 - i)) ?Zn1 =
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   840
      setsum (\<lambda>i. of_nat (n + 1 - i) * f $ (n + 1 - i) * g $ i) ?Zn1"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   841
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   842
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   843
      apply presburger
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   844
      apply (rule set_eqI)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   845
      apply (presburger add: image_iff)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   846
      apply simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   847
      done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   848
    have s1: "setsum (\<lambda>i. f $ i * g $ (n + 1 - i)) ?Zn1 =
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   849
      setsum (\<lambda>i. f $ (n + 1 - i) * g $ i) ?Zn1"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   850
      apply (rule setsum_reindex_cong[where f="\<lambda>i. n + 1 - i"])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   851
      apply (simp add: inj_on_def Ball_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   852
      apply presburger
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   853
      apply (rule set_eqI)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   854
      apply (presburger add: image_iff)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   855
      apply simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   856
      done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   857
    have "(f * ?D g + ?D f * g)$n = (?D g * f + ?D f * g)$n"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   858
      by (simp only: mult_commute)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   859
    also have "\<dots> = (\<Sum>i = 0..n. ?g i)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   860
      by (simp add: fps_mult_nth setsum_addf[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   861
    also have "\<dots> = setsum ?h {1..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   862
      using th0 setsum_reindex_cong[OF fi eq, of "?g" "?h"] by auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   863
    also have "\<dots> = setsum ?h {0..n+1}"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   864
      apply (rule setsum_mono_zero_left)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   865
      apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   866
      apply (simp add: subset_eq)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   867
      unfolding eq'
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   868
      apply simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   869
      done
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   870
    also have "\<dots> = (fps_deriv (f * g)) $ n"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   871
      apply (simp only: fps_deriv_nth fps_mult_nth setsum_addf)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   872
      unfolding s0 s1
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   873
      unfolding setsum_addf[symmetric] setsum_right_distrib
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   874
      apply (rule setsum_cong2)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   875
      apply (auto simp add: of_nat_diff field_simps)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   876
      done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   877
    finally have "(f * ?D g + ?D f * g) $ n = ?D (f*g) $ n" .
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   878
  }
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   879
  then show ?thesis unfolding fps_eq_iff by auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   880
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   881
31968
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   882
lemma fps_deriv_X[simp]: "fps_deriv X = 1"
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   883
  by (simp add: fps_deriv_def X_def fps_eq_iff)
0314441a53a6 FPS form a metric space, which justifies the infinte sum notation
chaieb
parents: 31790
diff changeset
   884
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   885
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
   886
  by (simp add: fps_eq_iff fps_deriv_def)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   887
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   888
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
   889
  using fps_deriv_linear[of 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   890
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   891
lemma 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
   892
  unfolding diff_minus by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   893
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   894
lemma 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
   895
  by (simp add: fps_ext fps_deriv_def fps_const_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   896
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   897
lemma fps_deriv_mult_const_left[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   898
    "fps_deriv (fps_const (c::'a::comm_ring_1) * f) = fps_const c * fps_deriv f"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   899
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   900
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   901
lemma fps_deriv_0[simp]: "fps_deriv 0 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   902
  by (simp add: fps_deriv_def fps_eq_iff)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   903
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   904
lemma fps_deriv_1[simp]: "fps_deriv 1 = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   905
  by (simp add: fps_deriv_def fps_eq_iff )
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   906
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   907
lemma fps_deriv_mult_const_right[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   908
    "fps_deriv (f * fps_const (c::'a::comm_ring_1)) = fps_deriv f * fps_const c"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   909
  by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   910
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   911
lemma fps_deriv_setsum:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   912
  "fps_deriv (setsum f S) = setsum (\<lambda>i. fps_deriv (f i :: ('a::comm_ring_1) fps)) S"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   913
proof-
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   914
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   915
    assume "\<not> finite S"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   916
    then have ?thesis by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   917
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   918
  moreover
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   919
  {
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   920
    assume fS: "finite S"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   921
    have ?thesis by (induct rule: finite_induct [OF fS]) simp_all
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   922
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   923
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   924
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   925
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   926
lemma fps_deriv_eq_0_iff[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   927
  "fps_deriv f = 0 \<longleftrightarrow> (f = fps_const (f$0 :: 'a::{idom,semiring_char_0}))"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   928
proof-
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   929
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   930
    assume "f = fps_const (f$0)"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   931
    then have "fps_deriv f = fps_deriv (fps_const (f$0))" by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   932
    then have "fps_deriv f = 0" by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   933
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   934
  moreover
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   935
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   936
    assume z: "fps_deriv f = 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   937
    then have "\<forall>n. (fps_deriv f)$n = 0" by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   938
    then have "\<forall>n. f$(n+1) = 0" by (simp del: of_nat_Suc of_nat_add One_nat_def)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   939
    then have "f = fps_const (f$0)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   940
      apply (clarsimp simp add: fps_eq_iff fps_const_def)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   941
      apply (erule_tac x="n - 1" in allE)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   942
      apply simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   943
      done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   944
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   945
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   946
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   947
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
   948
lemma fps_deriv_eq_iff:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   949
  fixes f:: "('a::{idom,semiring_char_0}) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   950
  shows "fps_deriv f = fps_deriv g \<longleftrightarrow> (f = fps_const(f$0 - g$0) + g)"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   951
proof -
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   952
  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
   953
  also have "\<dots> \<longleftrightarrow> f - g = fps_const ((f-g)$0)" unfolding fps_deriv_eq_0_iff ..
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
   954
  finally show ?thesis by (simp add: field_simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   955
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   956
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   957
lemma fps_deriv_eq_iff_ex:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   958
  "(fps_deriv f = fps_deriv g) \<longleftrightarrow> (\<exists>(c::'a::{idom,semiring_char_0}). f = fps_const c + g)"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   959
  apply auto
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
   960
  unfolding fps_deriv_eq_iff
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   961
  apply blast
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   962
  done
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   963
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   964
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   965
fun fps_nth_deriv :: "nat \<Rightarrow> ('a::semiring_1) fps \<Rightarrow> 'a fps"
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   966
where
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   967
  "fps_nth_deriv 0 f = f"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   968
| "fps_nth_deriv (Suc n) f = fps_nth_deriv n (fps_deriv f)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   969
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   970
lemma fps_nth_deriv_commute: "fps_nth_deriv (Suc n) f = fps_deriv (fps_nth_deriv n f)"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   971
  by (induct n arbitrary: f) auto
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   972
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   973
lemma fps_nth_deriv_linear[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   974
  "fps_nth_deriv n (fps_const (a::'a::comm_semiring_1) * f + fps_const b * g) =
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   975
    fps_const a * fps_nth_deriv n f + fps_const b * fps_nth_deriv n g"
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   976
  by (induct n arbitrary: f g) (auto simp add: fps_nth_deriv_commute)
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   977
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   978
lemma fps_nth_deriv_neg[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   979
  "fps_nth_deriv n (- (f:: ('a:: comm_ring_1) fps)) = - (fps_nth_deriv n f)"
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   980
  by (induct n arbitrary: f) simp_all
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   981
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   982
lemma fps_nth_deriv_add[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   983
  "fps_nth_deriv n ((f:: ('a::comm_ring_1) fps) + g) = fps_nth_deriv n f + fps_nth_deriv n g"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   984
  using fps_nth_deriv_linear[of n 1 f 1 g] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   985
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   986
lemma fps_nth_deriv_sub[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   987
  "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
   988
  unfolding diff_minus fps_nth_deriv_add by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   989
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   990
lemma fps_nth_deriv_0[simp]: "fps_nth_deriv n 0 = 0"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   991
  by (induct n) simp_all
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   992
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
   993
lemma fps_nth_deriv_1[simp]: "fps_nth_deriv n 1 = (if n = 0 then 1 else 0)"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   994
  by (induct n) simp_all
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   995
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   996
lemma fps_nth_deriv_const[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   997
  "fps_nth_deriv n (fps_const c) = (if n = 0 then fps_const c else 0)"
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   998
  by (cases n) simp_all
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
   999
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1000
lemma fps_nth_deriv_mult_const_left[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1001
  "fps_nth_deriv n (fps_const (c::'a::comm_ring_1) * f) = fps_const c * fps_nth_deriv n f"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1002
  using fps_nth_deriv_linear[of n "c" f 0 0 ] by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1003
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1004
lemma fps_nth_deriv_mult_const_right[simp]:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1005
  "fps_nth_deriv n (f * fps_const (c::'a::comm_ring_1)) = fps_nth_deriv n f * fps_const c"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1006
  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
  1007
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1008
lemma fps_nth_deriv_setsum:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1009
  "fps_nth_deriv n (setsum f S) = setsum (\<lambda>i. fps_nth_deriv n (f i :: ('a::comm_ring_1) fps)) S"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1010
proof -
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1011
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1012
    assume "\<not> finite S"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1013
    then have ?thesis by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1014
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1015
  moreover
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1016
  {
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1017
    assume fS: "finite S"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1018
    have ?thesis by (induct rule: finite_induct[OF fS]) simp_all
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1019
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1020
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1021
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1022
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1023
lemma fps_deriv_maclauren_0:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1024
  "(fps_nth_deriv k (f:: ('a::comm_semiring_1) fps)) $ 0 = of_nat (fact k) * f$(k)"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
  1025
  by (induct k arbitrary: f) (auto simp add: field_simps of_nat_mult)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1026
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1027
subsection {* Powers*}
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1028
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1029
lemma fps_power_zeroth_eq_one: "a$0 =1 \<Longrightarrow> a^n $ 0 = (1::'a::semiring_1)"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1030
  by (induct n) (auto simp add: expand_fps_eq fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1031
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1032
lemma fps_power_first_eq: "(a:: 'a::comm_ring_1 fps)$0 =1 \<Longrightarrow> a^n $ 1 = of_nat n * a$1"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1033
proof (induct n)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1034
  case 0
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1035
  then show ?case by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1036
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1037
  case (Suc n)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1038
  note h = Suc.hyps[OF `a$0 = 1`]
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1039
  show ?case unfolding power_Suc fps_mult_nth
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1040
    using h `a$0 = 1` fps_power_zeroth_eq_one[OF `a$0=1`]
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1041
    by (simp add: field_simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1042
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1043
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1044
lemma startsby_one_power:"a $ 0 = (1::'a::comm_ring_1) \<Longrightarrow> a^n $ 0 = 1"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1045
  by (induct n) (auto simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1046
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1047
lemma startsby_zero_power:"a $0 = (0::'a::comm_ring_1) \<Longrightarrow> n > 0 \<Longrightarrow> a^n $0 = 0"
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1048
  by (induct n) (auto simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1049
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1050
lemma startsby_power:"a $0 = (v::'a::{comm_ring_1}) \<Longrightarrow> a^n $0 = v^n"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1051
  by (induct n) (auto simp add: fps_mult_nth)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1052
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1053
lemma startsby_zero_power_iff[simp]: "a^n $0 = (0::'a::{idom}) \<longleftrightarrow> (n \<noteq> 0 \<and> a$0 = 0)"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1054
  apply (rule iffI)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1055
  apply (induct n)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1056
  apply (auto simp add: fps_mult_nth)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1057
  apply (rule startsby_zero_power, simp_all)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1058
  done
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1059
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1060
lemma startsby_zero_power_prefix:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1061
  assumes a0: "a $0 = (0::'a::idom)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1062
  shows "\<forall>n < k. a ^ k $ n = 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1063
  using a0
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1064
proof(induct k rule: nat_less_induct)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1065
  fix k
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1066
  assume H: "\<forall>m<k. a $0 =  0 \<longrightarrow> (\<forall>n<m. a ^ m $ n = 0)" and a0: "a $0 = (0\<Colon>'a)"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1067
  let ?ths = "\<forall>m<k. a ^ k $ m = 0"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1068
  { assume "k = 0" then have ?ths by simp }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1069
  moreover
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1070
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1071
    fix l
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1072
    assume k: "k = Suc l"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1073
    {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1074
      fix m
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1075
      assume mk: "m < k"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1076
      {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1077
        assume "m = 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1078
        then have "a^k $ m = 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1079
          using startsby_zero_power[of a k] k a0 by simp
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1080
      }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1081
      moreover
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1082
      {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1083
        assume m0: "m \<noteq> 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1084
        have "a ^k $ m = (a^l * a) $m" by (simp add: k mult_commute)
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  1085
        also have "\<dots> = (\<Sum>i = 0..m. a ^ l $ i * a $ (m - i))" by (simp add: fps_mult_nth)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1086
        also have "\<dots> = 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1087
          apply (rule setsum_0')
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  1088
          apply auto
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51107
diff changeset
  1089
          apply (case_tac "x = m")
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1090
          using a0 apply simp
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  1091
          apply (rule H[rule_format])
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1092
          using a0 k mk apply auto
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1093
          done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1094
        finally have "a^k $ m = 0" .
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1095
      }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1096
      ultimately have "a^k $ m = 0" by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1097
    }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1098
    then have ?ths by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1099
  }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1100
  ultimately show ?ths by (cases k) auto
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1101
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1102
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1103
lemma startsby_zero_setsum_depends:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1104
  assumes a0: "a $0 = (0::'a::idom)" and kn: "n \<ge> k"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1105
  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
  1106
  apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1107
  using kn apply auto
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1108
  apply (rule startsby_zero_power_prefix[rule_format, OF a0])
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1109
  apply arith
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1110
  done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1111
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1112
lemma startsby_zero_power_nth_same:
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1113
  assumes a0: "a$0 = (0::'a::{idom})"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1114
  shows "a^n $ n = (a$1) ^ n"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1115
proof (induct n)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1116
  case 0
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1117
  then show ?case by (simp add: power_0)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1118
next
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1119
  case (Suc n)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1120
  have "a ^ Suc n $ (Suc n) = (a^n * a)$(Suc n)" by (simp add: field_simps)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1121
  also have "\<dots> = setsum (\<lambda>i. a^n$i * a $ (Suc n - i)) {0.. Suc n}"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1122
    by (simp add: fps_mult_nth)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1123
  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
  1124
    apply (rule setsum_mono_zero_right)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1125
    apply simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1126
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1127
    apply clarsimp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1128
    apply (rule startsby_zero_power_prefix[rule_format, OF a0])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1129
    apply arith
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1130
    done
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1131
  also have "\<dots> = a^n $ n * a$1" using a0 by simp
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1132
  finally show ?case using Suc.hyps by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1133
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1134
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1135
lemma fps_inverse_power:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1136
  fixes a :: "('a::{field}) fps"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1137
  shows "inverse (a^n) = inverse a ^ n"
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1138
proof -
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1139
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1140
    assume a0: "a$0 = 0"
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1141
    then have eq: "inverse a = 0" by (simp add: fps_inverse_def)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1142
    { assume "n = 0" hence ?thesis by simp }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1143
    moreover
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1144
    {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1145
      assume n: "n > 0"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1146
      from startsby_zero_power[OF a0 n] eq a0 n have ?thesis
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1147
        by (simp add: fps_inverse_def)
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1148
    }
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1149
    ultimately have ?thesis by blast
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1150
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1151
  moreover
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1152
  {
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1153
    assume a0: "a$0 \<noteq> 0"
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1154
    have ?thesis
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1155
      apply (rule fps_inverse_unique)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1156
      apply (simp add: a0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1157
      unfolding power_mult_distrib[symmetric]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1158
      apply (rule ssubst[where t = "a * inverse a" and s= 1])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1159
      apply simp_all
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1160
      apply (subst mult_commute)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1161
      apply (rule inverse_mult_eq_1[OF a0])
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1162
      done
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1163
  }
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1164
  ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1165
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1166
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1167
lemma fps_deriv_power:
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1168
    "fps_deriv (a ^ n) = fps_const (of_nat n :: 'a:: comm_ring_1) * fps_deriv a * a ^ (n - 1)"
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1169
  apply (induct n)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1170
  apply (auto simp add: field_simps fps_const_add[symmetric] simp del: fps_const_add)
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1171
  apply (case_tac n)
52891
b8dede3a4f1d tuned proofs;
wenzelm
parents: 51542
diff changeset
  1172
  apply (auto simp add: field_simps)
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1173
  done
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1174
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1175
lemma fps_inverse_deriv:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1176
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1177
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1178
  shows "fps_deriv (inverse a) = - fps_deriv a * inverse a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1179
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1180
  from inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1181
  have "fps_deriv (inverse a * a) = 0" by simp
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1182
  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
  1183
  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
  1184
  with inverse_mult_eq_1[OF a0]
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1185
  have "inverse a ^ 2 * fps_deriv a + fps_deriv (inverse a) = 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1186
    unfolding power2_eq_square
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
  1187
    apply (simp add: field_simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1188
    by (simp add: mult_assoc[symmetric])
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1189
  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
  1190
    by simp
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
  1191
  then show "fps_deriv (inverse a) = - fps_deriv a * inverse a ^ 2" by (simp add: field_simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1192
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1193
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1194
lemma fps_inverse_mult:
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1195
  fixes a::"('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1196
  shows "inverse (a * b) = inverse a * inverse b"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1197
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1198
  {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
  1199
    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
  1200
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1201
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1202
  {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
  1203
    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
  1204
    have ?thesis unfolding th by simp}
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1205
  moreover
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1206
  {assume a0: "a$0 \<noteq> 0" and b0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1207
    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
  1208
    from inverse_mult_eq_1[OF ab0]
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1209
    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
  1210
    then have "inverse (a*b) * (inverse a * a) * (inverse b * b) = inverse a * inverse b"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
  1211
      by (simp add: field_simps)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1212
    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
  1213
ultimately show ?thesis by blast
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1214
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1215
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1216
lemma fps_inverse_deriv':
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1217
  fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1218
  assumes a0: "a$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1219
  shows "fps_deriv (inverse a) = - fps_deriv a / a ^ 2"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1220
  using fps_inverse_deriv[OF a0]
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1221
  unfolding power2_eq_square fps_divide_def fps_inverse_mult
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1222
  by simp
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1223
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1224
lemma inverse_mult_eq_1': assumes f0: "f$0 \<noteq> (0::'a::field)"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1225
  shows "f * inverse f= 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1226
  by (metis mult_commute inverse_mult_eq_1 f0)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1227
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1228
lemma fps_divide_deriv:   fixes a:: "('a :: field) fps"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1229
  assumes a0: "b$0 \<noteq> 0"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1230
  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
  1231
  using fps_inverse_deriv[OF a0]
48757
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1232
  by (simp add: fps_divide_def field_simps
1232760e208e tuned proofs;
wenzelm
parents: 47217
diff changeset
  1233
    power2_eq_square fps_inverse_mult inverse_mult_eq_1'[OF a0])
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1234
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1235
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1236
lemma fps_inverse_gp': "inverse (Abs_fps(\<lambda>n. (1::'a::field)))
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1237
  = 1 - X"
29911
c790a70a3d19 declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents: 29906
diff changeset
  1238
  by (simp add: fps_inverse_gp fps_eq_iff X_def)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1239
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1240
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
  1241
  by (cases "n", simp_all)
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1242
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1243
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1244
lemma fps_inverse_X_plus1:
31021
53642251a04f farewell to class recpower
haftmann
parents: 30994
diff changeset
  1245
  "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
  1246
proof-
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1247
  have eq: "(1 + X) * ?r = 1"
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1248
    unfolding minus_one_power_iff
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 36311
diff changeset
  1249
    by (auto simp add: field_simps fps_eq_iff)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46757
diff changeset
  1250
  show ?thesis by (auto simp add: eq intro: fps_inverse_unique simp del: minus_one)
29687
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1251
qed
4d934a895d11 A formalization of formal power series
chaieb
parents:
diff changeset
  1252
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30273
diff changeset
  1253
29906
80369da39838 section -> subsection
huffman
parents: 29692
diff changeset
  1254
subsection{* Integration *}
31273
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset
  1255
da95bc889ad2 use class field_char_0 for fps definitions
huffman
parents: 31199
diff changeset <