src/HOL/Decision_Procs/Polynomial_List.thy
author wenzelm
Sat, 22 Oct 2016 21:10:02 +0200
changeset 64350 3af8566788e7
parent 62390 842917225d56
child 67399 eab6ce8368fa
permissions -rw-r--r--
remote_builds has PAR-SEQ semantics of old isatest-makedist; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
     1
(*  Title:      HOL/Decision_Procs/Polynomial_List.thy
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
     2
    Author:     Amine Chaieb
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     3
*)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     4
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 59807
diff changeset
     5
section \<open>Univariate Polynomials as lists\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     6
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     7
theory Polynomial_List
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
     8
imports Complex_Main
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     9
begin
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    10
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    11
text \<open>Application of polynomial as a function.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    12
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    13
primrec (in semiring_0) poly :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    14
where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    15
  poly_Nil: "poly [] x = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    16
| poly_Cons: "poly (h # t) x = h + x * poly t x"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    17
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    18
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    19
subsection \<open>Arithmetic Operations on Polynomials\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    20
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    21
text \<open>Addition\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    22
primrec (in semiring_0) padd :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"  (infixl "+++" 65)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    23
where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    24
  padd_Nil: "[] +++ l2 = l2"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    25
| padd_Cons: "(h # t) +++ l2 = (if l2 = [] then h # t else (h + hd l2) # (t +++ tl l2))"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    26
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    27
text \<open>Multiplication by a constant\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    28
primrec (in semiring_0) cmult :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list"  (infixl "%*" 70) where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    29
  cmult_Nil: "c %* [] = []"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    30
| cmult_Cons: "c %* (h#t) = (c * h)#(c %* t)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    31
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    32
text \<open>Multiplication by a polynomial\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    33
primrec (in semiring_0) pmult :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"  (infixl "***" 70)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    34
where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    35
  pmult_Nil: "[] *** l2 = []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    36
| pmult_Cons: "(h # t) *** l2 = (if t = [] then h %* l2 else (h %* l2) +++ (0 # (t *** l2)))"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    37
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    38
text \<open>Repeated multiplication by a polynomial\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    39
primrec (in semiring_0) mulexp :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a  list \<Rightarrow> 'a list"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    40
where
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    41
  mulexp_zero: "mulexp 0 p q = q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    42
| mulexp_Suc: "mulexp (Suc n) p q = p *** mulexp n p q"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    43
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    44
text \<open>Exponential\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    45
primrec (in semiring_1) pexp :: "'a list \<Rightarrow> nat \<Rightarrow> 'a list"  (infixl "%^" 80)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    46
where
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    47
  pexp_0: "p %^ 0 = [1]"
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    48
| pexp_Suc: "p %^ (Suc n) = p *** (p %^ n)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    49
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    50
text \<open>Quotient related value of dividing a polynomial by x + a.
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    51
  Useful for divisor properties in inductive proofs.\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    52
primrec (in field) "pquot" :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    53
where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    54
  pquot_Nil: "pquot [] a = []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    55
| pquot_Cons: "pquot (h # t) a =
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    56
    (if t = [] then [h] else (inverse a * (h - hd( pquot t a))) # pquot t a)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    57
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    58
text \<open>Normalization of polynomials (remove extra 0 coeff).\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    59
primrec (in semiring_0) pnormalize :: "'a list \<Rightarrow> 'a list"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    60
where
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    61
  pnormalize_Nil: "pnormalize [] = []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    62
| pnormalize_Cons: "pnormalize (h # p) =
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    63
    (if pnormalize p = [] then (if h = 0 then [] else [h]) else h # pnormalize p)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    64
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    65
definition (in semiring_0) "pnormal p \<longleftrightarrow> pnormalize p = p \<and> p \<noteq> []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    66
definition (in semiring_0) "nonconstant p \<longleftrightarrow> pnormal p \<and> (\<forall>x. p \<noteq> [x])"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    67
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    68
text \<open>Other definitions.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    69
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    70
definition (in ring_1) poly_minus :: "'a list \<Rightarrow> 'a list" ("-- _" [80] 80)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    71
  where "-- p = (- 1) %* p"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    72
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    73
definition (in semiring_0) divides :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"  (infixl "divides" 70)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    74
  where "p1 divides p2 \<longleftrightarrow> (\<exists>q. poly p2 = poly(p1 *** q))"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    75
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    76
lemma (in semiring_0) dividesI: "poly p2 = poly (p1 *** q) \<Longrightarrow> p1 divides p2"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    77
  by (auto simp add: divides_def)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    78
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    79
lemma (in semiring_0) dividesE:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    80
  assumes "p1 divides p2"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    81
  obtains q where "poly p2 = poly (p1 *** q)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    82
  using assms by (auto simp add: divides_def)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    83
61586
5197a2ecb658 isabelle update_cartouches -c -t;
wenzelm
parents: 60698
diff changeset
    84
\<comment> \<open>order of a polynomial\<close>
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    85
definition (in ring_1) order :: "'a \<Rightarrow> 'a list \<Rightarrow> nat"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    86
  where "order a p = (SOME n. ([-a, 1] %^ n) divides p \<and> \<not> (([-a, 1] %^ (Suc n)) divides p))"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    87
61586
5197a2ecb658 isabelle update_cartouches -c -t;
wenzelm
parents: 60698
diff changeset
    88
\<comment> \<open>degree of a polynomial\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    89
definition (in semiring_0) degree :: "'a list \<Rightarrow> nat"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    90
  where "degree p = length (pnormalize p) - 1"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    91
61586
5197a2ecb658 isabelle update_cartouches -c -t;
wenzelm
parents: 60698
diff changeset
    92
\<comment> \<open>squarefree polynomials --- NB with respect to real roots only\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    93
definition (in ring_1) rsquarefree :: "'a list \<Rightarrow> bool"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    94
  where "rsquarefree p \<longleftrightarrow> poly p \<noteq> poly [] \<and> (\<forall>a. order a p = 0 \<or> order a p = 1)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    95
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    96
context semiring_0
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    97
begin
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    98
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    99
lemma padd_Nil2[simp]: "p +++ [] = p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   100
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   101
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   102
lemma padd_Cons_Cons: "(h1 # p1) +++ (h2 # p2) = (h1 + h2) # (p1 +++ p2)"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   103
  by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   104
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   105
lemma pminus_Nil: "-- [] = []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   106
  by (simp add: poly_minus_def)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   107
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   108
lemma pmult_singleton: "[h1] *** p1 = h1 %* p1" by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   109
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   110
end
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   111
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   112
lemma (in semiring_1) poly_ident_mult[simp]: "1 %* t = t"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   113
  by (induct t) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   114
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   115
lemma (in semiring_0) poly_simple_add_Cons[simp]: "[a] +++ (0 # t) = a # t"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   116
  by simp
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   117
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   118
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   119
text \<open>Handy general properties.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   120
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   121
lemma (in comm_semiring_0) padd_commut: "b +++ a = a +++ b"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   122
proof (induct b arbitrary: a)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   123
  case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   124
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   125
    by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   126
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   127
  case (Cons b bs a)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   128
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   129
    by (cases a) (simp_all add: add.commute)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   130
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   131
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   132
lemma (in comm_semiring_0) padd_assoc: "(a +++ b) +++ c = a +++ (b +++ c)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   133
proof (induct a arbitrary: b c)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   134
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   135
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   136
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   137
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   138
  case Cons
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   139
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   140
    by (cases b) (simp_all add: ac_simps)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   141
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   142
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   143
lemma (in semiring_0) poly_cmult_distr: "a %* (p +++ q) = a %* p +++ a %* q"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   144
proof (induct p arbitrary: q)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   145
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   146
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   147
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   148
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   149
  case Cons
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   150
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   151
    by (cases q) (simp_all add: distrib_left)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   152
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   153
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   154
lemma (in ring_1) pmult_by_x[simp]: "[0, 1] *** t = 0 # t"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   155
proof (induct t)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   156
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   157
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   158
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   159
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   160
  case (Cons a t)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   161
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   162
    by (cases t) (auto simp add: padd_commut)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   163
qed
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   164
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   165
text \<open>Properties of evaluation of polynomials.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   166
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   167
lemma (in semiring_0) poly_add: "poly (p1 +++ p2) x = poly p1 x + poly p2 x"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   168
proof (induct p1 arbitrary: p2)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   169
  case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   170
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   171
    by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   172
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   173
  case (Cons a as p2)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   174
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   175
    by (cases p2) (simp_all add: ac_simps distrib_left)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   176
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   177
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   178
lemma (in comm_semiring_0) poly_cmult: "poly (c %* p) x = c * poly p x"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   179
proof (induct p)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   180
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   181
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   182
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   183
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   184
  case Cons
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   185
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   186
    by (cases "x = zero") (auto simp add: distrib_left ac_simps)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   187
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   188
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   189
lemma (in comm_semiring_0) poly_cmult_map: "poly (map (op * c) p) x = c * poly p x"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   190
  by (induct p) (auto simp add: distrib_left ac_simps)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   191
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   192
lemma (in comm_ring_1) poly_minus: "poly (-- p) x = - (poly p x)"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   193
  by (simp add: poly_minus_def) (auto simp add: poly_cmult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   194
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   195
lemma (in comm_semiring_0) poly_mult: "poly (p1 *** p2) x = poly p1 x * poly p2 x"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   196
proof (induct p1 arbitrary: p2)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   197
  case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   198
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   199
    by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   200
next
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   201
  case (Cons a as)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   202
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   203
    by (cases as) (simp_all add: poly_cmult poly_add distrib_right distrib_left ac_simps)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   204
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   205
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   206
class idom_char_0 = idom + ring_char_0
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   207
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   208
subclass (in field_char_0) idom_char_0 ..
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   209
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   210
lemma (in comm_ring_1) poly_exp: "poly (p %^ n) x = (poly p x) ^ n"
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   211
  by (induct n) (auto simp add: poly_cmult poly_mult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   212
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   213
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   214
text \<open>More Polynomial Evaluation lemmas.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   215
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   216
lemma (in semiring_0) poly_add_rzero[simp]: "poly (a +++ []) x = poly a x"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   217
  by simp
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   218
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   219
lemma (in comm_semiring_0) poly_mult_assoc: "poly ((a *** b) *** c) x = poly (a *** (b *** c)) x"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55417
diff changeset
   220
  by (simp add: poly_mult mult.assoc)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   221
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   222
lemma (in semiring_0) poly_mult_Nil2[simp]: "poly (p *** []) x = 0"
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   223
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   224
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   225
lemma (in comm_semiring_1) poly_exp_add: "poly (p %^ (n + d)) x = poly (p %^ n *** p %^ d) x"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55417
diff changeset
   226
  by (induct n) (auto simp add: poly_mult mult.assoc)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   227
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   228
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   229
subsection \<open>Key Property: if @{term "f a = 0"} then @{term "(x - a)"} divides @{term "p(x)"}.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   230
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   231
lemma (in comm_ring_1) lemma_poly_linear_rem: "\<exists>q r. h#t = [r] +++ [-a, 1] *** q"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   232
proof (induct t arbitrary: h)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   233
  case Nil
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   234
  have "[h] = [h] +++ [- a, 1] *** []" by simp
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   235
  then show ?case by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   236
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   237
  case (Cons  x xs)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   238
  have "\<exists>q r. h # x # xs = [r] +++ [-a, 1] *** q"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   239
  proof -
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   240
    from Cons obtain q r where qr: "x # xs = [r] +++ [- a, 1] *** q"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   241
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   242
    have "h # x # xs = [a * r + h] +++ [-a, 1] *** (r # q)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   243
      using qr by (cases q) (simp_all add: algebra_simps)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   244
    then show ?thesis by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   245
  qed
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   246
  then show ?case by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   247
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   248
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   249
lemma (in comm_ring_1) poly_linear_rem: "\<exists>q r. h#t = [r] +++ [-a, 1] *** q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   250
  using lemma_poly_linear_rem [where t = t and a = a] by auto
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   251
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   252
lemma (in comm_ring_1) poly_linear_divides: "poly p a = 0 \<longleftrightarrow> p = [] \<or> (\<exists>q. p = [-a, 1] *** q)"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   253
proof (cases p)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   254
  case Nil
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   255
  then show ?thesis by simp
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   256
next
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   257
  case (Cons x xs)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   258
  have "poly p a = 0" if "p = [-a, 1] *** q" for q
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   259
    using that by (simp add: poly_add poly_cmult)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   260
  moreover
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   261
  have "\<exists>q. p = [- a, 1] *** q" if p0: "poly p a = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   262
  proof -
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   263
    from poly_linear_rem[of x xs a] obtain q r where qr: "x#xs = [r] +++ [- a, 1] *** q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   264
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   265
    have "r = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   266
      using p0 by (simp only: Cons qr poly_mult poly_add) simp
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   267
    with Cons qr show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   268
      apply -
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   269
      apply (rule exI[where x = q])
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   270
      apply auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   271
      apply (cases q)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   272
      apply auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   273
      done
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   274
  qed
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   275
  ultimately show ?thesis using Cons by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   276
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   277
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   278
lemma (in semiring_0) lemma_poly_length_mult[simp]:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   279
  "length (k %* p +++  (h # (a %* p))) = Suc (length p)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   280
  by (induct p arbitrary: h k a) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   281
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   282
lemma (in semiring_0) lemma_poly_length_mult2[simp]:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   283
  "length (k %* p +++  (h # p)) = Suc (length p)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   284
  by (induct p arbitrary: h k) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   285
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   286
lemma (in ring_1) poly_length_mult[simp]: "length([-a,1] *** q) = Suc (length q)"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   287
  by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   288
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   289
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   290
subsection \<open>Polynomial length\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   291
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   292
lemma (in semiring_0) poly_cmult_length[simp]: "length (a %* p) = length p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   293
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   294
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   295
lemma (in semiring_0) poly_add_length: "length (p1 +++ p2) = max (length p1) (length p2)"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   296
  by (induct p1 arbitrary: p2) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   297
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   298
lemma (in semiring_0) poly_root_mult_length[simp]: "length ([a, b] *** p) = Suc (length p)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   299
  by (simp add: poly_add_length)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   300
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   301
lemma (in idom) poly_mult_not_eq_poly_Nil[simp]:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   302
  "poly (p *** q) x \<noteq> poly [] x \<longleftrightarrow> poly p x \<noteq> poly [] x \<and> poly q x \<noteq> poly [] x"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   303
  by (auto simp add: poly_mult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   304
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   305
lemma (in idom) poly_mult_eq_zero_disj: "poly (p *** q) x = 0 \<longleftrightarrow> poly p x = 0 \<or> poly q x = 0"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   306
  by (auto simp add: poly_mult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   307
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   308
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   309
text \<open>Normalisation Properties.\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   310
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   311
lemma (in semiring_0) poly_normalized_nil: "pnormalize p = [] \<longrightarrow> poly p x = 0"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   312
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   313
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   314
text \<open>A nontrivial polynomial of degree n has no more than n roots.\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   315
lemma (in idom) poly_roots_index_lemma:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   316
  assumes "poly p x \<noteq> poly [] x"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   317
    and "length p = n"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   318
  shows "\<exists>i. \<forall>x. poly p x = 0 \<longrightarrow> (\<exists>m\<le>n. x = i m)"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   319
  using assms
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   320
proof (induct n arbitrary: p x)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   321
  case 0
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   322
  then show ?case by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   323
next
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   324
  case (Suc n)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   325
  have False if C: "\<And>i. \<exists>x. poly p x = 0 \<and> (\<forall>m\<le>Suc n. x \<noteq> i m)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   326
  proof -
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   327
    from Suc.prems have p0: "poly p x \<noteq> 0" "p \<noteq> []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   328
      by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   329
    from p0(1)[unfolded poly_linear_divides[of p x]]
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   330
    have "\<forall>q. p \<noteq> [- x, 1] *** q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   331
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   332
    from C obtain a where a: "poly p a = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   333
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   334
    from a[unfolded poly_linear_divides[of p a]] p0(2) obtain q where q: "p = [-a, 1] *** q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   335
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   336
    have lg: "length q = n"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   337
      using q Suc.prems(2) by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   338
    from q p0 have qx: "poly q x \<noteq> poly [] x"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   339
      by (auto simp add: poly_mult poly_add poly_cmult)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   340
    from Suc.hyps[OF qx lg] obtain i where i: "\<And>x. poly q x = 0 \<longrightarrow> (\<exists>m\<le>n. x = i m)"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   341
      by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   342
    let ?i = "\<lambda>m. if m = Suc n then a else i m"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   343
    from C[of ?i] obtain y where y: "poly p y = 0" "\<forall>m\<le> Suc n. y \<noteq> ?i m"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   344
      by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   345
    from y have "y = a \<or> poly q y = 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   346
      by (simp only: q poly_mult_eq_zero_disj poly_add) (simp add: algebra_simps)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   347
    with i[of y] y(1) y(2) show ?thesis
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   348
      apply auto
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   349
      apply (erule_tac x = "m" in allE)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   350
      apply auto
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   351
      done
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   352
  qed
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   353
  then show ?case by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   354
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   355
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   356
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   357
lemma (in idom) poly_roots_index_length:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   358
  "poly p x \<noteq> poly [] x \<Longrightarrow> \<exists>i. \<forall>x. poly p x = 0 \<longrightarrow> (\<exists>n. n \<le> length p \<and> x = i n)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   359
  by (blast intro: poly_roots_index_lemma)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   360
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   361
lemma (in idom) poly_roots_finite_lemma1:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   362
  "poly p x \<noteq> poly [] x \<Longrightarrow> \<exists>N i. \<forall>x. poly p x = 0 \<longrightarrow> (\<exists>n::nat. n < N \<and> x = i n)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   363
  apply (drule poly_roots_index_length)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   364
  apply safe
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   365
  apply (rule_tac x = "Suc (length p)" in exI)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   366
  apply (rule_tac x = i in exI)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   367
  apply (simp add: less_Suc_eq_le)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   368
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   369
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   370
lemma (in idom) idom_finite_lemma:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   371
  assumes "\<forall>x. P x \<longrightarrow> (\<exists>n. n < length j \<and> x = j!n)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   372
  shows "finite {x. P x}"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   373
proof -
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   374
  from assms have "{x. P x} \<subseteq> set j"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   375
    by auto
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   376
  then show ?thesis
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   377
    using finite_subset by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   378
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   379
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   380
lemma (in idom) poly_roots_finite_lemma2:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   381
  "poly p x \<noteq> poly [] x \<Longrightarrow> \<exists>i. \<forall>x. poly p x = 0 \<longrightarrow> x \<in> set i"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   382
  apply (drule poly_roots_index_length)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   383
  apply safe
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   384
  apply (rule_tac x = "map (\<lambda>n. i n) [0 ..< Suc (length p)]" in exI)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   385
  apply (auto simp add: image_iff)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   386
  apply (erule_tac x="x" in allE)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   387
  apply clarsimp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   388
  apply (case_tac "n = length p")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   389
  apply (auto simp add: order_le_less)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   390
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   391
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   392
lemma (in ring_char_0) UNIV_ring_char_0_infinte: "\<not> finite (UNIV :: 'a set)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   393
proof
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   394
  assume F: "finite (UNIV :: 'a set)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   395
  have "finite (UNIV :: nat set)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   396
  proof (rule finite_imageD)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   397
    have "of_nat ` UNIV \<subseteq> UNIV"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   398
      by simp
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   399
    then show "finite (of_nat ` UNIV :: 'a set)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   400
      using F by (rule finite_subset)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   401
    show "inj (of_nat :: nat \<Rightarrow> 'a)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   402
      by (simp add: inj_on_def)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   403
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   404
  with infinite_UNIV_nat show False ..
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   405
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   406
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   407
lemma (in idom_char_0) poly_roots_finite: "poly p \<noteq> poly [] \<longleftrightarrow> finite {x. poly p x = 0}"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   408
  (is "?lhs \<longleftrightarrow> ?rhs")
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   409
proof
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   410
  show ?rhs if ?lhs
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   411
    using that
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   412
    apply -
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   413
    apply (erule contrapos_np)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   414
    apply (rule ext)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   415
    apply (rule ccontr)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   416
    apply (clarify dest!: poly_roots_finite_lemma2)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   417
    using finite_subset
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   418
  proof -
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   419
    fix x i
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   420
    assume F: "\<not> finite {x. poly p x = 0}"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   421
      and P: "\<forall>x. poly p x = 0 \<longrightarrow> x \<in> set i"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   422
    from P have "{x. poly p x = 0} \<subseteq> set i"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   423
      by auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   424
    with finite_subset F show False
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   425
      by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   426
  qed
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   427
  show ?lhs if ?rhs
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   428
    using UNIV_ring_char_0_infinte that by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   429
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   430
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   431
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   432
text \<open>Entirety and Cancellation for polynomials\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   433
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   434
lemma (in idom_char_0) poly_entire_lemma2:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   435
  assumes p0: "poly p \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   436
    and q0: "poly q \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   437
  shows "poly (p***q) \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   438
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   439
  let ?S = "\<lambda>p. {x. poly p x = 0}"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   440
  have "?S (p *** q) = ?S p \<union> ?S q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   441
    by (auto simp add: poly_mult)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   442
  with p0 q0 show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   443
    unfolding poly_roots_finite by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   444
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   445
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   446
lemma (in idom_char_0) poly_entire:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   447
  "poly (p *** q) = poly [] \<longleftrightarrow> poly p = poly [] \<or> poly q = poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   448
  using poly_entire_lemma2[of p q]
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   449
  by (auto simp add: fun_eq_iff poly_mult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   450
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   451
lemma (in idom_char_0) poly_entire_neg:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   452
  "poly (p *** q) \<noteq> poly [] \<longleftrightarrow> poly p \<noteq> poly [] \<and> poly q \<noteq> poly []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   453
  by (simp add: poly_entire)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   454
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   455
lemma (in comm_ring_1) poly_add_minus_zero_iff:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   456
  "poly (p +++ -- q) = poly [] \<longleftrightarrow> poly p = poly q"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   457
  by (auto simp add: algebra_simps poly_add poly_minus_def fun_eq_iff poly_cmult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   458
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   459
lemma (in comm_ring_1) poly_add_minus_mult_eq:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   460
  "poly (p *** q +++ --(p *** r)) = poly (p *** (q +++ -- r))"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   461
  by (auto simp add: poly_add poly_minus_def fun_eq_iff poly_mult poly_cmult algebra_simps)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   462
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   463
subclass (in idom_char_0) comm_ring_1 ..
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   464
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   465
lemma (in idom_char_0) poly_mult_left_cancel:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   466
  "poly (p *** q) = poly (p *** r) \<longleftrightarrow> poly p = poly [] \<or> poly q = poly r"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   467
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   468
  have "poly (p *** q) = poly (p *** r) \<longleftrightarrow> poly (p *** q +++ -- (p *** r)) = poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   469
    by (simp only: poly_add_minus_zero_iff)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   470
  also have "\<dots> \<longleftrightarrow> poly p = poly [] \<or> poly q = poly r"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   471
    by (auto intro: simp add: poly_add_minus_mult_eq poly_entire poly_add_minus_zero_iff)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   472
  finally show ?thesis .
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   473
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   474
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   475
lemma (in idom) poly_exp_eq_zero[simp]: "poly (p %^ n) = poly [] \<longleftrightarrow> poly p = poly [] \<and> n \<noteq> 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   476
  apply (simp only: fun_eq_iff add: HOL.all_simps [symmetric])
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   477
  apply (rule arg_cong [where f = All])
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   478
  apply (rule ext)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   479
  apply (induct n)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   480
  apply (auto simp add: poly_exp poly_mult)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   481
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   482
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   483
lemma (in comm_ring_1) poly_prime_eq_zero[simp]: "poly [a, 1] \<noteq> poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   484
  apply (simp add: fun_eq_iff)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   485
  apply (rule_tac x = "minus one a" in exI)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55417
diff changeset
   486
  apply (simp add: add.commute [of a])
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   487
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   488
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   489
lemma (in idom) poly_exp_prime_eq_zero: "poly ([a, 1] %^ n) \<noteq> poly []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   490
  by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   491
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   492
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   493
text \<open>A more constructive notion of polynomials being trivial.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   494
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   495
lemma (in idom_char_0) poly_zero_lemma': "poly (h # t) = poly [] \<Longrightarrow> h = 0 \<and> poly t = poly []"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   496
  apply (simp add: fun_eq_iff)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   497
  apply (case_tac "h = zero")
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   498
  apply (drule_tac [2] x = zero in spec)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   499
  apply auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   500
  apply (cases "poly t = poly []")
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   501
  apply simp
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   502
proof -
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   503
  fix x
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   504
  assume H: "\<forall>x. x = 0 \<or> poly t x = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   505
  assume pnz: "poly t \<noteq> poly []"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   506
  let ?S = "{x. poly t x = 0}"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   507
  from H have "\<forall>x. x \<noteq> 0 \<longrightarrow> poly t x = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   508
    by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   509
  then have th: "?S \<supseteq> UNIV - {0}"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   510
    by auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   511
  from poly_roots_finite pnz have th': "finite ?S"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   512
    by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   513
  from finite_subset[OF th th'] UNIV_ring_char_0_infinte show "poly t x = 0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   514
    by simp
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   515
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   516
60537
5398aa5a4df9 eliminated list_all;
wenzelm
parents: 60536
diff changeset
   517
lemma (in idom_char_0) poly_zero: "poly p = poly [] \<longleftrightarrow> (\<forall>c \<in> set p. c = 0)"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   518
proof (induct p)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   519
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   520
  then show ?case by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   521
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   522
  case Cons
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   523
  show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   524
    apply (rule iffI)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   525
    apply (drule poly_zero_lemma')
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   526
    using Cons
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   527
    apply auto
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   528
    done
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   529
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   530
60537
5398aa5a4df9 eliminated list_all;
wenzelm
parents: 60536
diff changeset
   531
lemma (in idom_char_0) poly_0: "\<forall>c \<in> set p. c = 0 \<Longrightarrow> poly p x = 0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   532
  unfolding poly_zero[symmetric] by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   533
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   534
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   535
text \<open>Basics of divisibility.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   536
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   537
lemma (in idom) poly_primes: "[a, 1] divides (p *** q) \<longleftrightarrow> [a, 1] divides p \<or> [a, 1] divides q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   538
  apply (auto simp add: divides_def fun_eq_iff poly_mult poly_add poly_cmult distrib_right [symmetric])
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   539
  apply (drule_tac x = "uminus a" in spec)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   540
  apply (simp add: poly_linear_divides poly_add poly_cmult distrib_right [symmetric])
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   541
  apply (cases "p = []")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   542
  apply (rule exI[where x="[]"])
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   543
  apply simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   544
  apply (cases "q = []")
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   545
  apply (erule allE[where x="[]"])
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   546
  apply simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   547
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   548
  apply clarsimp
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   549
  apply (cases "\<exists>q. p = a %* q +++ (0 # q)")
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   550
  apply (clarsimp simp add: poly_add poly_cmult)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   551
  apply (rule_tac x = qa in exI)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   552
  apply (simp add: distrib_right [symmetric])
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   553
  apply clarsimp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   554
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   555
  apply (auto simp add: poly_linear_divides poly_add poly_cmult distrib_right [symmetric])
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   556
  apply (rule_tac x = "pmult qa q" in exI)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   557
  apply (rule_tac [2] x = "pmult p qa" in exI)
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   558
  apply (auto simp add: poly_add poly_mult poly_cmult ac_simps)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   559
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   560
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   561
lemma (in comm_semiring_1) poly_divides_refl[simp]: "p divides p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   562
  apply (simp add: divides_def)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   563
  apply (rule_tac x = "[one]" in exI)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   564
  apply (auto simp add: poly_mult fun_eq_iff)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   565
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   566
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   567
lemma (in comm_semiring_1) poly_divides_trans: "p divides q \<Longrightarrow> q divides r \<Longrightarrow> p divides r"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   568
  apply (simp add: divides_def)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   569
  apply safe
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   570
  apply (rule_tac x = "pmult qa qaa" in exI)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   571
  apply (auto simp add: poly_mult fun_eq_iff mult.assoc)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   572
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   573
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   574
lemma (in comm_semiring_1) poly_divides_exp: "m \<le> n \<Longrightarrow> (p %^ m) divides (p %^ n)"
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 61945
diff changeset
   575
  by (auto simp: le_iff_add divides_def poly_exp_add fun_eq_iff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   576
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   577
lemma (in comm_semiring_1) poly_exp_divides: "(p %^ n) divides q \<Longrightarrow> m \<le> n \<Longrightarrow> (p %^ m) divides q"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   578
  by (blast intro: poly_divides_exp poly_divides_trans)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   579
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   580
lemma (in comm_semiring_0) poly_divides_add: "p divides q \<Longrightarrow> p divides r \<Longrightarrow> p divides (q +++ r)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   581
  apply (auto simp add: divides_def)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   582
  apply (rule_tac x = "padd qa qaa" in exI)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   583
  apply (auto simp add: poly_add fun_eq_iff poly_mult distrib_left)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   584
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   585
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   586
lemma (in comm_ring_1) poly_divides_diff: "p divides q \<Longrightarrow> p divides (q +++ r) \<Longrightarrow> p divides r"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   587
  apply (auto simp add: divides_def)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   588
  apply (rule_tac x = "padd qaa (poly_minus qa)" in exI)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   589
  apply (auto simp add: poly_add fun_eq_iff poly_mult poly_minus algebra_simps)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   590
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   591
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   592
lemma (in comm_ring_1) poly_divides_diff2: "p divides r \<Longrightarrow> p divides (q +++ r) \<Longrightarrow> p divides q"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   593
  apply (erule poly_divides_diff)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   594
  apply (auto simp add: poly_add fun_eq_iff poly_mult divides_def ac_simps)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   595
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   596
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   597
lemma (in semiring_0) poly_divides_zero: "poly p = poly [] \<Longrightarrow> q divides p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   598
  apply (simp add: divides_def)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   599
  apply (rule exI[where x = "[]"])
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   600
  apply (auto simp add: fun_eq_iff poly_mult)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   601
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   602
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   603
lemma (in semiring_0) poly_divides_zero2 [simp]: "q divides []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   604
  apply (simp add: divides_def)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   605
  apply (rule_tac x = "[]" in exI)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   606
  apply (auto simp add: fun_eq_iff)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   607
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   608
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   609
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   610
text \<open>At last, we can consider the order of a root.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   611
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   612
lemma (in idom_char_0) poly_order_exists_lemma:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   613
  assumes "length p = d"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   614
    and "poly p \<noteq> poly []"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   615
  shows "\<exists>n q. p = mulexp n [-a, 1] q \<and> poly q a \<noteq> 0"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   616
  using assms
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   617
proof (induct d arbitrary: p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   618
  case 0
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   619
  then show ?case by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   620
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   621
  case (Suc n p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   622
  show ?case
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   623
  proof (cases "poly p a = 0")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   624
    case True
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   625
    from Suc.prems have h: "length p = Suc n" "poly p \<noteq> poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   626
      by auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   627
    then have pN: "p \<noteq> []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   628
      by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   629
    from True[unfolded poly_linear_divides] pN obtain q where q: "p = [-a, 1] *** q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   630
      by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   631
    from q h True have qh: "length q = n" "poly q \<noteq> poly []"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   632
      apply simp_all
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   633
      apply (simp only: fun_eq_iff)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   634
      apply (rule ccontr)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   635
      apply (simp add: fun_eq_iff poly_add poly_cmult)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   636
      done
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   637
    from Suc.hyps[OF qh] obtain m r where mr: "q = mulexp m [-a,1] r" "poly r a \<noteq> 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   638
      by blast
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   639
    from mr q have "p = mulexp (Suc m) [-a,1] r \<and> poly r a \<noteq> 0"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   640
      by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   641
    then show ?thesis by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   642
  next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   643
    case False
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   644
    then show ?thesis
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   645
      using Suc.prems
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   646
      apply simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   647
      apply (rule exI[where x="0::nat"])
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   648
      apply simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   649
      done
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   650
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   651
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   652
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   653
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   654
lemma (in comm_semiring_1) poly_mulexp: "poly (mulexp n p q) x = (poly p x) ^ n * poly q x"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   655
  by (induct n) (auto simp add: poly_mult ac_simps)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   656
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   657
lemma (in comm_semiring_1) divides_left_mult:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   658
  assumes "(p *** q) divides r"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   659
  shows "p divides r \<and> q divides r"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   660
proof-
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   661
  from assms obtain t where "poly r = poly (p *** q *** t)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   662
    unfolding divides_def by blast
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   663
  then have "poly r = poly (p *** (q *** t))" and "poly r = poly (q *** (p *** t))"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   664
    by (auto simp add: fun_eq_iff poly_mult ac_simps)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   665
  then show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   666
    unfolding divides_def by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   667
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   668
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   669
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   670
(* FIXME: Tidy up *)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   671
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   672
lemma (in semiring_1) zero_power_iff: "0 ^ n = (if n = 0 then 1 else 0)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   673
  by (induct n) simp_all
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   674
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   675
lemma (in idom_char_0) poly_order_exists:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   676
  assumes "length p = d"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   677
    and "poly p \<noteq> poly []"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   678
  shows "\<exists>n. [- a, 1] %^ n divides p \<and> \<not> [- a, 1] %^ Suc n divides p"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   679
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   680
  from assms have "\<exists>n q. p = mulexp n [- a, 1] q \<and> poly q a \<noteq> 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   681
    by (rule poly_order_exists_lemma)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   682
  then obtain n q where p: "p = mulexp n [- a, 1] q" and "poly q a \<noteq> 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   683
    by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   684
  have "[- a, 1] %^ n divides mulexp n [- a, 1] q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   685
  proof (rule dividesI)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   686
    show "poly (mulexp n [- a, 1] q) = poly ([- a, 1] %^ n *** q)"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 54219
diff changeset
   687
      by (induct n) (simp_all add: poly_add poly_cmult poly_mult algebra_simps)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   688
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   689
  moreover have "\<not> [- a, 1] %^ Suc n divides mulexp n [- a, 1] q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   690
  proof
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   691
    assume "[- a, 1] %^ Suc n divides mulexp n [- a, 1] q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   692
    then obtain m where "poly (mulexp n [- a, 1] q) = poly ([- a, 1] %^ Suc n *** m)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   693
      by (rule dividesE)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   694
    moreover have "poly (mulexp n [- a, 1] q) \<noteq> poly ([- a, 1] %^ Suc n *** m)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   695
    proof (induct n)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   696
      case 0
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   697
      show ?case
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   698
      proof (rule ccontr)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   699
        assume "\<not> ?thesis"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   700
        then have "poly q a = 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   701
          by (simp add: poly_add poly_cmult)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   702
        with \<open>poly q a \<noteq> 0\<close> show False
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   703
          by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   704
      qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   705
    next
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   706
      case (Suc n)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   707
      show ?case
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   708
        by (rule pexp_Suc [THEN ssubst])
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   709
          (simp add: poly_mult_left_cancel poly_mult_assoc Suc del: pmult_Cons pexp_Suc)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   710
    qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   711
    ultimately show False by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   712
  qed
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   713
  ultimately show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   714
    by (auto simp add: p)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   715
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   716
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   717
lemma (in semiring_1) poly_one_divides[simp]: "[1] divides p"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   718
  by (auto simp add: divides_def)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   719
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   720
lemma (in idom_char_0) poly_order:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   721
  "poly p \<noteq> poly [] \<Longrightarrow> \<exists>!n. ([-a, 1] %^ n) divides p \<and> \<not> (([-a, 1] %^ Suc n) divides p)"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   722
  apply (auto intro: poly_order_exists simp add: less_linear simp del: pmult_Cons pexp_Suc)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   723
  apply (cut_tac x = y and y = n in less_linear)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   724
  apply (drule_tac m = n in poly_exp_divides)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   725
  apply (auto dest: Suc_le_eq [THEN iffD2, THEN [2] poly_exp_divides]
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   726
    simp del: pmult_Cons pexp_Suc)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   727
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   728
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   729
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   730
text \<open>Order\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   731
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   732
lemma some1_equalityD: "n = (SOME n. P n) \<Longrightarrow> \<exists>!n. P n \<Longrightarrow> P n"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   733
  by (blast intro: someI2)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   734
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   735
lemma (in idom_char_0) order:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   736
  "([-a, 1] %^ n) divides p \<and> \<not> (([-a, 1] %^ Suc n) divides p) \<longleftrightarrow>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   737
    n = order a p \<and> poly p \<noteq> poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   738
  unfolding order_def
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   739
  apply (rule iffI)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   740
  apply (blast dest: poly_divides_zero intro!: some1_equality [symmetric] poly_order)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   741
  apply (blast intro!: poly_order [THEN [2] some1_equalityD])
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   742
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   743
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   744
lemma (in idom_char_0) order2:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   745
  "poly p \<noteq> poly [] \<Longrightarrow>
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   746
    ([-a, 1] %^ (order a p)) divides p \<and> \<not> ([-a, 1] %^ Suc (order a p)) divides p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   747
  by (simp add: order del: pexp_Suc)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   748
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   749
lemma (in idom_char_0) order_unique:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   750
  "poly p \<noteq> poly [] \<Longrightarrow> ([-a, 1] %^ n) divides p \<Longrightarrow> \<not> ([-a, 1] %^ (Suc n)) divides p \<Longrightarrow>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   751
    n = order a p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   752
  using order [of a n p] by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   753
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   754
lemma (in idom_char_0) order_unique_lemma:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   755
  "poly p \<noteq> poly [] \<and> ([-a, 1] %^ n) divides p \<and> \<not> ([-a, 1] %^ (Suc n)) divides p \<Longrightarrow>
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   756
    n = order a p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   757
  by (blast intro: order_unique)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   758
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   759
lemma (in ring_1) order_poly: "poly p = poly q \<Longrightarrow> order a p = order a q"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   760
  by (auto simp add: fun_eq_iff divides_def poly_mult order_def)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   761
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   762
lemma (in semiring_1) pexp_one[simp]: "p %^ (Suc 0) = p"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   763
  by (induct p) auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   764
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   765
lemma (in comm_ring_1) lemma_order_root:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   766
  "0 < n \<and> [- a, 1] %^ n divides p \<and> \<not> [- a, 1] %^ (Suc n) divides p \<Longrightarrow> poly p a = 0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   767
  by (induct n arbitrary: a p) (auto simp add: divides_def poly_mult simp del: pmult_Cons)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   768
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   769
lemma (in idom_char_0) order_root: "poly p a = 0 \<longleftrightarrow> poly p = poly [] \<or> order a p \<noteq> 0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   770
  apply (cases "poly p = poly []")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   771
  apply auto
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   772
  apply (simp add: poly_linear_divides del: pmult_Cons)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   773
  apply safe
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   774
  apply (drule_tac [!] a = a in order2)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   775
  apply (rule ccontr)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   776
  apply (simp add: divides_def poly_mult fun_eq_iff del: pmult_Cons)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   777
  apply blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   778
  using neq0_conv apply (blast intro: lemma_order_root)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   779
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   780
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   781
lemma (in idom_char_0) order_divides:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   782
  "([-a, 1] %^ n) divides p \<longleftrightarrow> poly p = poly [] \<or> n \<le> order a p"
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   783
  apply (cases "poly p = poly []")
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   784
  apply auto
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   785
  apply (simp add: divides_def fun_eq_iff poly_mult)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   786
  apply (rule_tac x = "[]" in exI)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   787
  apply (auto dest!: order2 [where a=a] intro: poly_exp_divides simp del: pexp_Suc)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   788
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   789
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   790
lemma (in idom_char_0) order_decomp:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   791
  "poly p \<noteq> poly [] \<Longrightarrow> \<exists>q. poly p = poly (([-a, 1] %^ order a p) *** q) \<and> \<not> [-a, 1] divides q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   792
  unfolding divides_def
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   793
  apply (drule order2 [where a = a])
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   794
  apply (simp add: divides_def del: pexp_Suc pmult_Cons)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   795
  apply safe
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   796
  apply (rule_tac x = q in exI)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   797
  apply safe
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   798
  apply (drule_tac x = qa in spec)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   799
  apply (auto simp add: poly_mult fun_eq_iff poly_exp ac_simps simp del: pmult_Cons)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   800
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   801
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   802
text \<open>Important composition properties of orders.\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   803
lemma order_mult:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   804
  fixes a :: "'a::idom_char_0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   805
  shows "poly (p *** q) \<noteq> poly [] \<Longrightarrow> order a (p *** q) = order a p + order a q"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   806
  apply (cut_tac a = a and p = "p *** q" and n = "order a p + order a q" in order)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   807
  apply (auto simp add: poly_entire simp del: pmult_Cons)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   808
  apply (drule_tac a = a in order2)+
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   809
  apply safe
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   810
  apply (simp add: divides_def fun_eq_iff poly_exp_add poly_mult del: pmult_Cons, safe)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   811
  apply (rule_tac x = "qa *** qaa" in exI)
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   812
  apply (simp add: poly_mult ac_simps del: pmult_Cons)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   813
  apply (drule_tac a = a in order_decomp)+
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   814
  apply safe
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   815
  apply (subgoal_tac "[-a, 1] divides (qa *** qaa) ")
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   816
  apply (simp add: poly_primes del: pmult_Cons)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   817
  apply (auto simp add: divides_def simp del: pmult_Cons)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   818
  apply (rule_tac x = qb in exI)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   819
  apply (subgoal_tac "poly ([-a, 1] %^ (order a p) *** (qa *** qaa)) =
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   820
    poly ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))")
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   821
  apply (drule poly_mult_left_cancel [THEN iffD1])
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   822
  apply force
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   823
  apply (subgoal_tac "poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** (qa *** qaa))) =
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   824
    poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))) ")
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   825
  apply (drule poly_mult_left_cancel [THEN iffD1])
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   826
  apply force
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   827
  apply (simp add: fun_eq_iff poly_exp_add poly_mult ac_simps del: pmult_Cons)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   828
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   829
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   830
lemma (in idom_char_0) order_mult:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   831
  assumes "poly (p *** q) \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   832
  shows "order a (p *** q) = order a p + order a q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   833
  using assms
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   834
  apply (cut_tac a = a and p = "pmult p q" and n = "order a p + order a q" in order)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   835
  apply (auto simp add: poly_entire simp del: pmult_Cons)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   836
  apply (drule_tac a = a in order2)+
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   837
  apply safe
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   838
  apply (simp add: divides_def fun_eq_iff poly_exp_add poly_mult del: pmult_Cons)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   839
  apply safe
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   840
  apply (rule_tac x = "pmult qa qaa" in exI)
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   841
  apply (simp add: poly_mult ac_simps del: pmult_Cons)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   842
  apply (drule_tac a = a in order_decomp)+
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   843
  apply safe
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   844
  apply (subgoal_tac "[uminus a, one] divides pmult qa qaa")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   845
  apply (simp add: poly_primes del: pmult_Cons)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   846
  apply (auto simp add: divides_def simp del: pmult_Cons)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   847
  apply (rule_tac x = qb in exI)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   848
  apply (subgoal_tac "poly (pmult (pexp [uminus a, one] (order a p)) (pmult qa qaa)) =
59807
22bc39064290 prefer local fixes;
wenzelm
parents: 58889
diff changeset
   849
    poly (pmult (pexp [uminus a, one] (order a p)) (pmult [uminus a, one] qb))")
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   850
  apply (drule poly_mult_left_cancel [THEN iffD1], force)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   851
  apply (subgoal_tac "poly (pmult (pexp [uminus a, one] (order a q))
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   852
      (pmult (pexp [uminus a, one] (order a p)) (pmult qa qaa))) =
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   853
    poly (pmult (pexp [uminus a, one] (order a q))
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   854
      (pmult (pexp [uminus a, one] (order a p)) (pmult [uminus a, one] qb)))")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   855
  apply (drule poly_mult_left_cancel [THEN iffD1], force)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   856
  apply (simp add: fun_eq_iff poly_exp_add poly_mult ac_simps del: pmult_Cons)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   857
  done
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   858
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   859
lemma (in idom_char_0) order_root2: "poly p \<noteq> poly [] \<Longrightarrow> poly p a = 0 \<longleftrightarrow> order a p \<noteq> 0"
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   860
  by (rule order_root [THEN ssubst]) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   861
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   862
lemma (in semiring_1) pmult_one[simp]: "[1] *** p = p"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   863
  by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   864
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   865
lemma (in semiring_0) poly_Nil_zero: "poly [] = poly [0]"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   866
  by (simp add: fun_eq_iff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   867
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   868
lemma (in idom_char_0) rsquarefree_decomp:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   869
  "rsquarefree p \<Longrightarrow> poly p a = 0 \<Longrightarrow> \<exists>q. poly p = poly ([-a, 1] *** q) \<and> poly q a \<noteq> 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   870
  apply (simp add: rsquarefree_def)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   871
  apply safe
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   872
  apply (frule_tac a = a in order_decomp)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   873
  apply (drule_tac x = a in spec)
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   874
  apply (drule_tac a = a in order_root2 [symmetric])
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   875
  apply (auto simp del: pmult_Cons)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   876
  apply (rule_tac x = q in exI, safe)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   877
  apply (simp add: poly_mult fun_eq_iff)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   878
  apply (drule_tac p1 = q in poly_linear_divides [THEN iffD1])
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   879
  apply (simp add: divides_def del: pmult_Cons, safe)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   880
  apply (drule_tac x = "[]" in spec)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   881
  apply (auto simp add: fun_eq_iff)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   882
  done
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   883
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   884
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   885
text \<open>Normalization of a polynomial.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   886
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   887
lemma (in semiring_0) poly_normalize[simp]: "poly (pnormalize p) = poly p"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   888
  by (induct p) (auto simp add: fun_eq_iff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   889
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   890
text \<open>The degree of a polynomial.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   891
60537
5398aa5a4df9 eliminated list_all;
wenzelm
parents: 60536
diff changeset
   892
lemma (in semiring_0) lemma_degree_zero: "(\<forall>c \<in> set p. c = 0) \<longleftrightarrow> pnormalize p = []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   893
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   894
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   895
lemma (in idom_char_0) degree_zero:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   896
  assumes "poly p = poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   897
  shows "degree p = 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   898
  using assms
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   899
  by (cases "pnormalize p = []") (auto simp add: degree_def poly_zero lemma_degree_zero)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   900
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   901
lemma (in semiring_0) pnormalize_sing: "pnormalize [x] = [x] \<longleftrightarrow> x \<noteq> 0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   902
  by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   903
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   904
lemma (in semiring_0) pnormalize_pair: "y \<noteq> 0 \<longleftrightarrow> pnormalize [x, y] = [x, y]"
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   905
  by simp
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   906
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   907
lemma (in semiring_0) pnormal_cons: "pnormal p \<Longrightarrow> pnormal (c # p)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   908
  unfolding pnormal_def by simp
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   909
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   910
lemma (in semiring_0) pnormal_tail: "p \<noteq> [] \<Longrightarrow> pnormal (c # p) \<Longrightarrow> pnormal p"
62390
842917225d56 more canonical names
nipkow
parents: 62378
diff changeset
   911
  unfolding pnormal_def by (auto split: if_split_asm)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   912
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   913
lemma (in semiring_0) pnormal_last_nonzero: "pnormal p \<Longrightarrow> last p \<noteq> 0"
62390
842917225d56 more canonical names
nipkow
parents: 62378
diff changeset
   914
  by (induct p) (simp_all add: pnormal_def split: if_split_asm)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   915
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   916
lemma (in semiring_0) pnormal_length: "pnormal p \<Longrightarrow> 0 < length p"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   917
  unfolding pnormal_def length_greater_0_conv by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   918
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   919
lemma (in semiring_0) pnormal_last_length: "0 < length p \<Longrightarrow> last p \<noteq> 0 \<Longrightarrow> pnormal p"
62390
842917225d56 more canonical names
nipkow
parents: 62378
diff changeset
   920
  by (induct p) (auto simp: pnormal_def  split: if_split_asm)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   921
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   922
lemma (in semiring_0) pnormal_id: "pnormal p \<longleftrightarrow> 0 < length p \<and> last p \<noteq> 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   923
  using pnormal_last_length pnormal_length pnormal_last_nonzero by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   924
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   925
lemma (in idom_char_0) poly_Cons_eq: "poly (c # cs) = poly (d # ds) \<longleftrightarrow> c = d \<and> poly cs = poly ds"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   926
  (is "?lhs \<longleftrightarrow> ?rhs")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   927
proof
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   928
  show ?rhs if ?lhs
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   929
  proof -
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   930
    from that have "poly ((c # cs) +++ -- (d # ds)) x = 0" for x
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   931
      by (simp only: poly_minus poly_add algebra_simps) (simp add: algebra_simps)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   932
    then have "poly ((c # cs) +++ -- (d # ds)) = poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   933
      by (simp add: fun_eq_iff)
60537
5398aa5a4df9 eliminated list_all;
wenzelm
parents: 60536
diff changeset
   934
    then have "c = d" and "\<forall>x \<in> set (cs +++ -- ds). x = 0"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   935
      unfolding poly_zero by (simp_all add: poly_minus_def algebra_simps)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   936
    from this(2) have "poly (cs +++ -- ds) x = 0" for x
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   937
      unfolding poly_zero[symmetric] by simp
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   938
    with \<open>c = d\<close> show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   939
      by (simp add: poly_minus poly_add algebra_simps fun_eq_iff)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   940
  qed
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   941
  show ?lhs if ?rhs
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   942
    using that by (simp add:fun_eq_iff)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   943
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   944
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   945
lemma (in idom_char_0) pnormalize_unique: "poly p = poly q \<Longrightarrow> pnormalize p = pnormalize q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   946
proof (induct q arbitrary: p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   947
  case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   948
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   949
    by (simp only: poly_zero lemma_degree_zero) simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   950
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   951
  case (Cons c cs p)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   952
  then show ?case
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   953
  proof (induct p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   954
    case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   955
    then have "poly [] = poly (c # cs)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   956
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   957
    then have "poly (c#cs) = poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   958
      by simp
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   959
    then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   960
      by (simp only: poly_zero lemma_degree_zero) simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   961
  next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   962
    case (Cons d ds)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   963
    then have eq: "poly (d # ds) = poly (c # cs)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   964
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   965
    then have eq': "\<And>x. poly (d # ds) x = poly (c # cs) x"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   966
      by simp
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   967
    then have "poly (d # ds) 0 = poly (c # cs) 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   968
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   969
    then have dc: "d = c"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   970
      by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   971
    with eq have "poly ds = poly cs"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   972
      unfolding  poly_Cons_eq by simp
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   973
    with Cons.prems have "pnormalize ds = pnormalize cs"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   974
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   975
    with dc show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   976
      by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   977
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   978
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   979
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   980
lemma (in idom_char_0) degree_unique:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   981
  assumes pq: "poly p = poly q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   982
  shows "degree p = degree q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   983
  using pnormalize_unique[OF pq] unfolding degree_def by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   984
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   985
lemma (in semiring_0) pnormalize_length: "length (pnormalize p) \<le> length p"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   986
  by (induct p) auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   987
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   988
lemma (in semiring_0) last_linear_mul_lemma:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   989
  "last ((a %* p) +++ (x # (b %* p))) = (if p = [] then x else b * last p)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   990
  apply (induct p arbitrary: a x b)
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   991
  apply auto
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   992
  subgoal for a p c x b
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   993
    apply (subgoal_tac "padd (cmult c p) (times b a # cmult b p) \<noteq> []")
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   994
    apply simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   995
    apply (induct p)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   996
    apply auto
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   997
    done
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   998
  done
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   999
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1000
lemma (in semiring_1) last_linear_mul:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1001
  assumes p: "p \<noteq> []"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1002
  shows "last ([a, 1] *** p) = last p"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1003
proof -
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1004
  from p obtain c cs where cs: "p = c # cs"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1005
    by (cases p) auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1006
  from cs have eq: "[a, 1] *** p = (a %* (c # cs)) +++ (0 # (1 %* (c # cs)))"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1007
    by (simp add: poly_cmult_distr)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1008
  show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1009
    using cs unfolding eq last_linear_mul_lemma by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1010
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1011
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1012
lemma (in semiring_0) pnormalize_eq: "last p \<noteq> 0 \<Longrightarrow> pnormalize p = p"
62390
842917225d56 more canonical names
nipkow
parents: 62378
diff changeset
  1013
  by (induct p) (auto split: if_split_asm)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1014
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1015
lemma (in semiring_0) last_pnormalize: "pnormalize p \<noteq> [] \<Longrightarrow> last (pnormalize p) \<noteq> 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1016
  by (induct p) auto
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1017
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1018
lemma (in semiring_0) pnormal_degree: "last p \<noteq> 0 \<Longrightarrow> degree p = length p - 1"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1019
  using pnormalize_eq[of p] unfolding degree_def by simp
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
  1020
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1021
lemma (in semiring_0) poly_Nil_ext: "poly [] = (\<lambda>x. 0)"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1022
  by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1023
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1024
lemma (in idom_char_0) linear_mul_degree:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1025
  assumes p: "poly p \<noteq> poly []"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1026
  shows "degree ([a, 1] *** p) = degree p + 1"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1027
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1028
  from p have pnz: "pnormalize p \<noteq> []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1029
    unfolding poly_zero lemma_degree_zero .
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1030
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1031
  from last_linear_mul[OF pnz, of a] last_pnormalize[OF pnz]
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1032
  have l0: "last ([a, 1] *** pnormalize p) \<noteq> 0" by simp
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1033
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1034
  from last_pnormalize[OF pnz] last_linear_mul[OF pnz, of a]
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1035
    pnormal_degree[OF l0] pnormal_degree[OF last_pnormalize[OF pnz]] pnz
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1036
  have th: "degree ([a,1] *** pnormalize p) = degree (pnormalize p) + 1"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1037
    by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1038
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1039
  have eqs: "poly ([a,1] *** pnormalize p) = poly ([a,1] *** p)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1040
    by (rule ext) (simp add: poly_mult poly_add poly_cmult)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1041
  from degree_unique[OF eqs] th show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1042
    by (simp add: degree_unique[OF poly_normalize])
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1043
qed
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
  1044
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1045
lemma (in idom_char_0) linear_pow_mul_degree:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1046
  "degree([a,1] %^n *** p) = (if poly p = poly [] then 0 else degree p + n)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1047
proof (induct n arbitrary: a p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1048
  case (0 a p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1049
  show ?case
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1050
  proof (cases "poly p = poly []")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1051
    case True
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1052
    then show ?thesis
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1053
      using degree_unique[OF True] by (simp add: degree_def)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1054
  next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1055
    case False
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1056
    then show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1057
      by (auto simp add: poly_Nil_ext)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1058
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1059
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1060
  case (Suc n a p)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1061
  have eq: "poly ([a, 1] %^(Suc n) *** p) = poly ([a, 1] %^ n *** ([a, 1] *** p))"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1062
    apply (rule ext)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1063
    apply (simp add: poly_mult poly_add poly_cmult)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1064
    apply (simp add: ac_simps distrib_left)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1065
    done
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1066
  note deq = degree_unique[OF eq]
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1067
  show ?case
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1068
  proof (cases "poly p = poly []")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1069
    case True
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1070
    with eq have eq': "poly ([a, 1] %^(Suc n) *** p) = poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1071
      by (auto simp add: poly_mult poly_cmult poly_add)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1072
    from degree_unique[OF eq'] True show ?thesis
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1073
      by (simp add: degree_def)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1074
  next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1075
    case False
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1076
    then have ap: "poly ([a,1] *** p) \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1077
      using poly_mult_not_eq_poly_Nil unfolding poly_entire by auto
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1078
    have eq: "poly ([a, 1] %^(Suc n) *** p) = poly ([a, 1]%^n *** ([a, 1] *** p))"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1079
      by (auto simp add: poly_mult poly_add poly_exp poly_cmult algebra_simps)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1080
    from ap have ap': "poly ([a, 1] *** p) = poly [] \<longleftrightarrow> False"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1081
      by blast
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1082
    have th0: "degree ([a, 1]%^n *** ([a, 1] *** p)) = degree ([a, 1] *** p) + n"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1083
      apply (simp only: Suc.hyps[of a "pmult [a,one] p"] ap')
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1084
      apply simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1085
      done
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1086
    from degree_unique[OF eq] ap False th0 linear_mul_degree[OF False, of a]
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1087
    show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1088
      by (auto simp del: poly.simps)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1089
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1090
qed
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
  1091
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1092
lemma (in idom_char_0) order_degree:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1093
  assumes p0: "poly p \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1094
  shows "order a p \<le> degree p"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1095
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1096
  from order2[OF p0, unfolded divides_def]
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1097
  obtain q where q: "poly p = poly ([- a, 1]%^ (order a p) *** q)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1098
    by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1099
  with q p0 have "poly q \<noteq> poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1100
    by (simp add: poly_mult poly_entire)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1101
  with degree_unique[OF q, unfolded linear_pow_mul_degree] show ?thesis
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1102
    by auto
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1103
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1104
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1105
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1106
text \<open>Tidier versions of finiteness of roots.\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1107
lemma (in idom_char_0) poly_roots_finite_set:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1108
  "poly p \<noteq> poly [] \<Longrightarrow> finite {x. poly p x = 0}"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
  1109
  unfolding poly_roots_finite .
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1110
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1111
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1112
text \<open>Bound for polynomial.\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1113
lemma poly_mono:
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1114
  fixes x :: "'a::linordered_idom"
61945
1135b8de26c3 more symbols;
wenzelm
parents: 61586
diff changeset
  1115
  shows "\<bar>x\<bar> \<le> k \<Longrightarrow> \<bar>poly p x\<bar> \<le> poly (map abs p) k"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1116
proof (induct p)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1117
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1118
  then show ?case by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1119
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1120
  case (Cons a p)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1121
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1122
    apply auto
61945
1135b8de26c3 more symbols;
wenzelm
parents: 61586
diff changeset
  1123
    apply (rule_tac y = "\<bar>a\<bar> + \<bar>x * poly p x\<bar>" in order_trans)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1124
    apply (rule abs_triangle_ineq)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1125
    apply (auto intro!: mult_mono simp add: abs_mult)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1126
    done
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1127
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1128
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1129
lemma (in semiring_0) poly_Sing: "poly [c] x = c"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1130
  by simp
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
  1131
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1132
end