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