src/HOL/Decision_Procs/Polynomial_List.thy
author hoelzl
Mon, 14 Mar 2011 14:37:41 +0100
changeset 41975 d47eabd80e59
parent 39302 d7728f65b353
child 45605 a89b4bc311a5
permissions -rw-r--r--
simplified definition of open_extreal
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
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
     5
header {* Univariate Polynomials as Lists *}
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
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     8
imports Main
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
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    11
text{* Application of polynomial as a real function. *}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    12
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    13
primrec poly :: "'a list => 'a  => ('a::{comm_ring})" where
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    14
  poly_Nil:  "poly [] x = 0"
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    15
| poly_Cons: "poly (h#t) x = h + x * poly t x"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    16
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
subsection{*Arithmetic Operations on Polynomials*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    19
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    20
text{*addition*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    21
primrec padd :: "['a list, 'a list] => ('a::comm_ring_1) list"  (infixl "+++" 65) where
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    22
  padd_Nil:  "[] +++ l2 = l2"
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    23
| padd_Cons: "(h#t) +++ l2 = (if l2 = [] then h#t
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    24
                            else (h + hd l2)#(t +++ tl l2))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    25
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    26
text{*Multiplication by a constant*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    27
primrec cmult :: "['a :: comm_ring_1, 'a list] => 'a list"  (infixl "%*" 70) where
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    28
  cmult_Nil:  "c %* [] = []"
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    29
| cmult_Cons: "c %* (h#t) = (c * h)#(c %* t)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    30
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    31
text{*Multiplication by a polynomial*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    32
primrec pmult :: "['a list, 'a list] => ('a::comm_ring_1) list"  (infixl "***" 70) where
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    33
  pmult_Nil:  "[] *** l2 = []"
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    34
| pmult_Cons: "(h#t) *** l2 = (if t = [] then h %* l2
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    35
                              else (h %* l2) +++ ((0) # (t *** l2)))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    36
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    37
text{*Repeated multiplication by a polynomial*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    38
primrec mulexp :: "[nat, 'a list, 'a  list] => ('a ::comm_ring_1) list" where
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    39
  mulexp_zero:  "mulexp 0 p q = q"
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    40
| 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
    41
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    42
text{*Exponential*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    43
primrec pexp :: "['a list, nat] => ('a::comm_ring_1) list"  (infixl "%^" 80) where
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    44
  pexp_0:   "p %^ 0 = [1]"
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    45
| pexp_Suc: "p %^ (Suc n) = p *** (p %^ n)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    46
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    47
text{*Quotient related value of dividing a polynomial by x + a*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    48
(* Useful for divisor properties in inductive proofs *)
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    49
primrec pquot :: "['a list, 'a::field] => 'a list" where
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    50
  pquot_Nil:  "pquot [] a= []"
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    51
| pquot_Cons: "pquot (h#t) a = (if t = [] then [h]
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    52
                   else (inverse(a) * (h - hd( pquot t a)))#(pquot t a))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    53
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    54
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    55
text{*normalization of polynomials (remove extra 0 coeff)*}
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    56
primrec pnormalize :: "('a::comm_ring_1) list => 'a list" where
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    57
  pnormalize_Nil:  "pnormalize [] = []"
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    58
| pnormalize_Cons: "pnormalize (h#p) = (if ( (pnormalize p) = [])
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    59
                                     then (if (h = 0) then [] else [h])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    60
                                     else (h#(pnormalize p)))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    61
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    62
definition "pnormal p = ((pnormalize p = p) \<and> p \<noteq> [])"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    63
definition "nonconstant p = (pnormal p \<and> (\<forall>x. p \<noteq> [x]))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    64
text{*Other definitions*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    65
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    66
definition
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    67
  poly_minus :: "'a list => ('a :: comm_ring_1) list"      ("-- _" [80] 80) where
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    68
  "-- p = (- 1) %* p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    69
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    70
definition
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    71
  divides :: "[('a::comm_ring_1) list, 'a list] => bool"  (infixl "divides" 70) where
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    72
  "p1 divides p2 = (\<exists>q. poly p2 = poly(p1 *** q))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    73
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    74
definition
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    75
  order :: "('a::comm_ring_1) => 'a list => nat" where
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    76
    --{*order of a polynomial*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    77
  "order a p = (SOME n. ([-a, 1] %^ n) divides p &
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    78
                      ~ (([-a, 1] %^ (Suc n)) divides p))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    79
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    80
definition
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    81
  degree :: "('a::comm_ring_1) list => nat" where
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    82
     --{*degree of a polynomial*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    83
  "degree p = length (pnormalize p) - 1"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    84
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    85
definition
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    86
  rsquarefree :: "('a::comm_ring_1) list => bool" where
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    87
     --{*squarefree polynomials --- NB with respect to real roots only.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    88
  "rsquarefree p = (poly p \<noteq> poly [] &
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    89
                     (\<forall>a. (order a p = 0) | (order a p = 1)))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    90
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    91
lemma padd_Nil2: "p +++ [] = p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    92
by (induct p) auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    93
declare padd_Nil2 [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    94
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    95
lemma padd_Cons_Cons: "(h1 # p1) +++ (h2 # p2) = (h1 + h2) # (p1 +++ p2)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    96
by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    97
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    98
lemma pminus_Nil: "-- [] = []"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    99
by (simp add: poly_minus_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   100
declare pminus_Nil [simp]
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 pmult_singleton: "[h1] *** p1 = h1 %* p1"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   103
by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   104
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   105
lemma poly_ident_mult: "1 %* t = t"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   106
by (induct "t", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   107
declare poly_ident_mult [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   108
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   109
lemma poly_simple_add_Cons: "[a] +++ ((0)#t) = (a#t)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   110
by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   111
declare poly_simple_add_Cons [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   112
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   113
text{*Handy general properties*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   114
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   115
lemma padd_commut: "b +++ a = a +++ b"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   116
apply (subgoal_tac "\<forall>a. b +++ a = a +++ b")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   117
apply (induct_tac [2] "b", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   118
apply (rule padd_Cons [THEN ssubst])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   119
apply (case_tac "aa", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   120
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   121
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   122
lemma padd_assoc [rule_format]: "\<forall>b c. (a +++ b) +++ c = a +++ (b +++ c)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   123
apply (induct "a", simp, clarify)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   124
apply (case_tac b, simp_all)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   125
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   126
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   127
lemma poly_cmult_distr [rule_format]:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   128
     "\<forall>q. a %* ( p +++ q) = (a %* p +++ a %* q)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   129
apply (induct "p", simp, clarify) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   130
apply (case_tac "q")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   131
apply (simp_all add: right_distrib)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   132
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   133
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   134
lemma pmult_by_x[simp]: "[0, 1] *** t = ((0)#t)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   135
apply (induct "t", simp)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   136
by (auto simp add: mult_zero_left poly_ident_mult padd_commut)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   137
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   138
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   139
text{*properties of evaluation of polynomials.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   140
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   141
lemma poly_add: "poly (p1 +++ p2) x = poly p1 x + poly p2 x"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   142
apply (subgoal_tac "\<forall>p2. poly (p1 +++ p2) x = poly (p1) x + poly (p2) x")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   143
apply (induct_tac [2] "p1", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   144
apply (case_tac "p2")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   145
apply (auto simp add: right_distrib)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   146
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   147
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   148
lemma poly_cmult: "poly (c %* p) x = c * poly p x"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   149
apply (induct "p") 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   150
apply (case_tac [2] "x=0")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   151
apply (auto simp add: right_distrib mult_ac)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   152
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   154
lemma poly_minus: "poly (-- p) x = - (poly p x)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   155
apply (simp add: poly_minus_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   156
apply (auto simp add: poly_cmult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   157
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   158
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   159
lemma poly_mult: "poly (p1 *** p2) x = poly p1 x * poly p2 x"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   160
apply (subgoal_tac "\<forall>p2. poly (p1 *** p2) x = poly p1 x * poly p2 x")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   161
apply (simp (no_asm_simp))
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   162
apply (induct "p1")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   163
apply (auto simp add: poly_cmult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   164
apply (case_tac p1)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   165
apply (auto simp add: poly_cmult poly_add left_distrib right_distrib mult_ac)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   166
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   167
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   168
lemma poly_exp: "poly (p %^ n) (x::'a::comm_ring_1) = (poly p x) ^ n"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   169
apply (induct "n")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   170
apply (auto simp add: poly_cmult poly_mult power_Suc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   171
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   172
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   173
text{*More Polynomial Evaluation Lemmas*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   174
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   175
lemma poly_add_rzero: "poly (a +++ []) x = poly a x"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   176
by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   177
declare poly_add_rzero [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   178
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   179
lemma poly_mult_assoc: "poly ((a *** b) *** c) x = poly (a *** (b *** c)) x"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   180
  by (simp add: poly_mult mult_assoc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   181
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   182
lemma poly_mult_Nil2: "poly (p *** []) x = 0"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   183
by (induct "p", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   184
declare poly_mult_Nil2 [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   185
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   186
lemma poly_exp_add: "poly (p %^ (n + d)) x = poly( p %^ n *** p %^ d) x"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   187
apply (induct "n")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   188
apply (auto simp add: poly_mult mult_assoc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   189
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   190
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   191
subsection{*Key Property: if @{term "f(a) = 0"} then @{term "(x - a)"} divides
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   192
 @{term "p(x)"} *}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   193
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   194
lemma lemma_poly_linear_rem: "\<forall>h. \<exists>q r. h#t = [r] +++ [-a, 1] *** q"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   195
apply (induct "t", safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   196
apply (rule_tac x = "[]" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   197
apply (rule_tac x = h in exI, simp)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   198
apply (drule_tac x = aa in spec, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   199
apply (rule_tac x = "r#q" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   200
apply (rule_tac x = "a*r + h" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   201
apply (case_tac "q", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   202
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   203
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   204
lemma poly_linear_rem: "\<exists>q r. h#t = [r] +++ [-a, 1] *** q"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   205
by (cut_tac t = t and a = a in lemma_poly_linear_rem, auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   206
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   207
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   208
lemma poly_linear_divides: "(poly p a = 0) = ((p = []) | (\<exists>q. p = [-a, 1] *** q))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   209
apply (auto simp add: poly_add poly_cmult right_distrib)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   210
apply (case_tac "p", simp) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   211
apply (cut_tac h = aa and t = list and a = a in poly_linear_rem, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   212
apply (case_tac "q", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   213
apply (drule_tac x = "[]" in spec, simp)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   214
apply (auto simp add: poly_add poly_cmult add_assoc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   215
apply (drule_tac x = "aa#lista" in spec, auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   216
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   217
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   218
lemma lemma_poly_length_mult: "\<forall>h k a. length (k %* p +++  (h # (a %* p))) = Suc (length p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   219
by (induct "p", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   220
declare lemma_poly_length_mult [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   221
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   222
lemma lemma_poly_length_mult2: "\<forall>h k. length (k %* p +++  (h # p)) = Suc (length p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   223
by (induct "p", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   224
declare lemma_poly_length_mult2 [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   225
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   226
lemma poly_length_mult: "length([-a,1] *** q) = Suc (length q)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   227
by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   228
declare poly_length_mult [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   229
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   230
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   231
subsection{*Polynomial length*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   232
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   233
lemma poly_cmult_length: "length (a %* p) = length p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   234
by (induct "p", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   235
declare poly_cmult_length [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   236
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   237
lemma poly_add_length [rule_format]:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   238
     "\<forall>p2. length (p1 +++ p2) =
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   239
             (if (length p1 < length p2) then length p2 else length p1)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   240
apply (induct "p1", simp_all)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   241
apply arith
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   242
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   243
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   244
lemma poly_root_mult_length: "length([a,b] *** p) = Suc (length p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   245
by (simp add: poly_cmult_length poly_add_length)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   246
declare poly_root_mult_length [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   247
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   248
lemma poly_mult_not_eq_poly_Nil: "(poly (p *** q) x \<noteq> poly [] x) =
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   249
      (poly p x \<noteq> poly [] x & poly q x \<noteq> poly [] (x::'a::idom))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   250
apply (auto simp add: poly_mult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   251
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   252
declare poly_mult_not_eq_poly_Nil [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   253
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   254
lemma poly_mult_eq_zero_disj: "(poly (p *** q) (x::'a::idom) = 0) = (poly p x = 0 | poly q x = 0)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   255
by (auto simp add: poly_mult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   256
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   257
text{*Normalisation Properties*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   258
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   259
lemma poly_normalized_nil: "(pnormalize p = []) --> (poly p x = 0)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   260
by (induct "p", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   261
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   262
text{*A nontrivial polynomial of degree n has no more than n roots*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   263
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   264
lemma poly_roots_index_lemma0 [rule_format]:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   265
   "\<forall>p x. poly p x \<noteq> poly [] x & length p = n
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   266
    --> (\<exists>i. \<forall>x. (poly p x = (0::'a::idom)) --> (\<exists>m. (m \<le> n & x = i m)))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   267
apply (induct "n", safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   268
apply (rule ccontr)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   269
apply (subgoal_tac "\<exists>a. poly p a = 0", safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   270
apply (drule poly_linear_divides [THEN iffD1], safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   271
apply (drule_tac x = q in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   272
apply (drule_tac x = x in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   273
apply (simp del: poly_Nil pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   274
apply (erule exE)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   275
apply (drule_tac x = "%m. if m = Suc n then a else i m" in spec, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   276
apply (drule poly_mult_eq_zero_disj [THEN iffD1], safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   277
apply (drule_tac x = "Suc (length q)" in spec)
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35028
diff changeset
   278
apply (auto simp add: field_simps)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   279
apply (drule_tac x = xa in spec)
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35028
diff changeset
   280
apply (clarsimp simp add: field_simps)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   281
apply (drule_tac x = m in spec)
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35028
diff changeset
   282
apply (auto simp add:field_simps)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   283
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   284
lemmas poly_roots_index_lemma1 = conjI [THEN poly_roots_index_lemma0, standard]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   285
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   286
lemma poly_roots_index_length0: "poly p (x::'a::idom) \<noteq> poly [] x ==>
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   287
      \<exists>i. \<forall>x. (poly p x = 0) --> (\<exists>n. n \<le> length p & x = i n)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   288
by (blast intro: poly_roots_index_lemma1)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   289
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   290
lemma poly_roots_finite_lemma: "poly p (x::'a::idom) \<noteq> poly [] x ==>
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   291
      \<exists>N i. \<forall>x. (poly p x = 0) --> (\<exists>n. (n::nat) < N & x = i n)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   292
apply (drule poly_roots_index_length0, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   293
apply (rule_tac x = "Suc (length p)" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   294
apply (rule_tac x = i in exI) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   295
apply (simp add: less_Suc_eq_le)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   296
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   297
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   298
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   299
lemma real_finite_lemma:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   300
  assumes P: "\<forall>x. P x --> (\<exists>n. n < length j & x = j!n)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   301
  shows "finite {(x::'a::idom). P x}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   302
proof-
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   303
  let ?M = "{x. P x}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   304
  let ?N = "set j"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   305
  have "?M \<subseteq> ?N" using P by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   306
  thus ?thesis using finite_subset by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   307
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   308
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   309
lemma poly_roots_index_lemma [rule_format]:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   310
   "\<forall>p x. poly p x \<noteq> poly [] x & length p = n
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   311
    --> (\<exists>i. \<forall>x. (poly p x = (0::'a::{idom})) --> x \<in> set i)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   312
apply (induct "n", safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   313
apply (rule ccontr)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   314
apply (subgoal_tac "\<exists>a. poly p a = 0", safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   315
apply (drule poly_linear_divides [THEN iffD1], safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   316
apply (drule_tac x = q in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   317
apply (drule_tac x = x in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   318
apply (auto simp del: poly_Nil pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   319
apply (drule_tac x = "a#i" in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   320
apply (auto simp only: poly_mult List.list.size)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   321
apply (drule_tac x = xa in spec)
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35028
diff changeset
   322
apply (clarsimp simp add: field_simps)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   323
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   324
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   325
lemmas poly_roots_index_lemma2 = conjI [THEN poly_roots_index_lemma, standard]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   326
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   327
lemma poly_roots_index_length: "poly p (x::'a::idom) \<noteq> poly [] x ==>
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   328
      \<exists>i. \<forall>x. (poly p x = 0) --> x \<in> set i"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   329
by (blast intro: poly_roots_index_lemma2)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   330
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   331
lemma poly_roots_finite_lemma': "poly p (x::'a::idom) \<noteq> poly [] x ==>
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   332
      \<exists>i. \<forall>x. (poly p x = 0) --> x \<in> set i"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   333
by (drule poly_roots_index_length, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   334
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   335
lemma UNIV_nat_infinite: "\<not> finite (UNIV :: nat set)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   336
  unfolding finite_conv_nat_seg_image
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39246
diff changeset
   337
proof(auto simp add: set_eq_iff image_iff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   338
  fix n::nat and f:: "nat \<Rightarrow> nat"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   339
  let ?N = "{i. i < n}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   340
  let ?fN = "f ` ?N"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   341
  let ?y = "Max ?fN + 1"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   342
  from nat_seg_image_imp_finite[of "?fN" "f" n] 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   343
  have thfN: "finite ?fN" by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   344
  {assume "n =0" hence "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by auto}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   345
  moreover
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   346
  {assume nz: "n \<noteq> 0"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   347
    hence thne: "?fN \<noteq> {}" by (auto simp add: neq0_conv)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   348
    have "\<forall>x\<in> ?fN. Max ?fN \<ge> x" using nz Max_ge_iff[OF thfN thne] by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   349
    hence "\<forall>x\<in> ?fN. ?y > x" by (auto simp add: less_Suc_eq_le)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   350
    hence "?y \<notin> ?fN" by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   351
    hence "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by auto }
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   352
  ultimately show "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by blast
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   353
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   354
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   355
lemma UNIV_ring_char_0_infinte: "\<not> finite (UNIV:: ('a::ring_char_0) set)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   356
proof
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   357
  assume F: "finite (UNIV :: 'a set)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   358
  have th0: "of_nat ` UNIV \<subseteq> (UNIV:: 'a set)" by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   359
  from finite_subset[OF th0 F] have th: "finite (of_nat ` UNIV :: 'a set)" .
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   360
  have th': "inj_on (of_nat::nat \<Rightarrow> 'a) (UNIV)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   361
    unfolding inj_on_def by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   362
  from finite_imageD[OF th th'] UNIV_nat_infinite 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   363
  show False by blast
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   364
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   365
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   366
lemma poly_roots_finite: "(poly p \<noteq> poly []) = 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   367
  finite {x. poly p x = (0::'a::{idom, ring_char_0})}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   368
proof
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   369
  assume H: "poly p \<noteq> poly []"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   370
  show "finite {x. poly p x = (0::'a)}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   371
    using H
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   372
    apply -
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   373
    apply (erule contrapos_np, rule ext)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   374
    apply (rule ccontr)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   375
    apply (clarify dest!: poly_roots_finite_lemma')
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   376
    using finite_subset
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   377
  proof-
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   378
    fix x i
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   379
    assume F: "\<not> finite {x. poly p x = (0\<Colon>'a)}" 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   380
      and P: "\<forall>x. poly p x = (0\<Colon>'a) \<longrightarrow> x \<in> set i"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   381
    let ?M= "{x. poly p x = (0\<Colon>'a)}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   382
    from P have "?M \<subseteq> set i" by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   383
    with finite_subset F show False by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   384
  qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   385
next
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   386
  assume F: "finite {x. poly p x = (0\<Colon>'a)}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   387
  show "poly p \<noteq> poly []" using F UNIV_ring_char_0_infinte by auto  
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   388
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   389
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   390
text{*Entirety and Cancellation for polynomials*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   391
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   392
lemma poly_entire_lemma: "[| poly (p:: ('a::{idom,ring_char_0}) list) \<noteq> poly [] ; poly q \<noteq> poly [] |]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   393
      ==>  poly (p *** q) \<noteq> poly []"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   394
by (auto simp add: poly_roots_finite poly_mult Collect_disj_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   395
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   396
lemma poly_entire: "(poly (p *** q) = poly ([]::('a::{idom,ring_char_0}) list)) = ((poly p = poly []) | (poly q = poly []))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   397
apply (auto intro: ext dest: fun_cong simp add: poly_entire_lemma poly_mult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   398
apply (blast intro: ccontr dest: poly_entire_lemma poly_mult [THEN subst])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   399
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   400
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   401
lemma poly_entire_neg: "(poly (p *** q) \<noteq> poly ([]::('a::{idom,ring_char_0}) list)) = ((poly p \<noteq> poly []) & (poly q \<noteq> poly []))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   402
by (simp add: poly_entire)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   403
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   404
lemma fun_eq: " (f = g) = (\<forall>x. f x = g x)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   405
by (auto intro!: ext)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   406
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   407
lemma poly_add_minus_zero_iff: "(poly (p +++ -- q) = poly []) = (poly p = poly q)"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35028
diff changeset
   408
by (auto simp add: field_simps poly_add poly_minus_def fun_eq poly_cmult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   409
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   410
lemma poly_add_minus_mult_eq: "poly (p *** q +++ --(p *** r)) = poly (p *** (q +++ -- r))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   411
by (auto simp add: poly_add poly_minus_def fun_eq poly_mult poly_cmult right_distrib)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   412
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   413
lemma poly_mult_left_cancel: "(poly (p *** q) = poly (p *** r)) = (poly p = poly ([]::('a::{idom, ring_char_0}) list) | poly q = poly r)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   414
apply (rule_tac p1 = "p *** q" in poly_add_minus_zero_iff [THEN subst])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   415
apply (auto intro: ext simp add: poly_add_minus_mult_eq poly_entire poly_add_minus_zero_iff)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   416
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   417
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   418
lemma poly_exp_eq_zero:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   419
     "(poly (p %^ n) = poly ([]::('a::idom) list)) = (poly p = poly [] & n \<noteq> 0)"
37598
893dcabf0c04 explicit is better than implicit
haftmann
parents: 36350
diff changeset
   420
apply (simp only: fun_eq add: HOL.all_simps [symmetric]) 
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   421
apply (rule arg_cong [where f = All]) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   422
apply (rule ext)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   423
apply (induct_tac "n")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   424
apply (auto simp add: poly_mult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   425
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   426
declare poly_exp_eq_zero [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   427
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   428
lemma poly_prime_eq_zero: "poly [a,(1::'a::comm_ring_1)] \<noteq> poly []"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   429
apply (simp add: fun_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   430
apply (rule_tac x = "1 - a" in exI, simp)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   431
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   432
declare poly_prime_eq_zero [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   433
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   434
lemma poly_exp_prime_eq_zero: "(poly ([a, (1::'a::idom)] %^ n) \<noteq> poly [])"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   435
by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   436
declare poly_exp_prime_eq_zero [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   437
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   438
text{*A more constructive notion of polynomials being trivial*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   439
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   440
lemma poly_zero_lemma': "poly (h # t) = poly [] ==> h = (0::'a::{idom,ring_char_0}) & poly t = poly []"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   441
apply(simp add: fun_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   442
apply (case_tac "h = 0")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   443
apply (drule_tac [2] x = 0 in spec, auto) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   444
apply (case_tac "poly t = poly []", simp) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   445
proof-
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   446
  fix x
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   447
  assume H: "\<forall>x. x = (0\<Colon>'a) \<or> poly t x = (0\<Colon>'a)"  and pnz: "poly t \<noteq> poly []"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   448
  let ?S = "{x. poly t x = 0}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   449
  from H have "\<forall>x. x \<noteq>0 \<longrightarrow> poly t x = 0" by blast
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   450
  hence th: "?S \<supseteq> UNIV - {0}" by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   451
  from poly_roots_finite pnz have th': "finite ?S" by blast
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   452
  from finite_subset[OF th th'] UNIV_ring_char_0_infinte[where ?'a = 'a]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   453
  show "poly t x = (0\<Colon>'a)" by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   454
  qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   455
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   456
lemma poly_zero: "(poly p = poly []) = list_all (%c. c = (0::'a::{idom,ring_char_0})) p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   457
apply (induct "p", simp)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   458
apply (rule iffI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   459
apply (drule poly_zero_lemma', auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   460
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   461
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   462
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   463
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   464
text{*Basics of divisibility.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   465
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   466
lemma poly_primes: "([a, (1::'a::idom)] divides (p *** q)) = ([a, 1] divides p | [a, 1] divides q)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   467
apply (auto simp add: divides_def fun_eq poly_mult poly_add poly_cmult left_distrib [symmetric])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   468
apply (drule_tac x = "-a" in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   469
apply (auto simp add: poly_linear_divides poly_add poly_cmult left_distrib [symmetric])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   470
apply (rule_tac x = "qa *** q" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   471
apply (rule_tac [2] x = "p *** qa" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   472
apply (auto simp add: poly_add poly_mult poly_cmult mult_ac)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   473
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   474
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   475
lemma poly_divides_refl: "p divides p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   476
apply (simp add: divides_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   477
apply (rule_tac x = "[1]" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   478
apply (auto simp add: poly_mult fun_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   479
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   480
declare poly_divides_refl [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   481
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   482
lemma poly_divides_trans: "[| p divides q; q divides r |] ==> p divides r"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   483
apply (simp add: divides_def, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   484
apply (rule_tac x = "qa *** qaa" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   485
apply (auto simp add: poly_mult fun_eq mult_assoc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   486
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   487
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   488
lemma poly_divides_exp: "m \<le> n ==> (p %^ m) divides (p %^ n)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   489
apply (auto simp add: le_iff_add)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   490
apply (induct_tac k)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   491
apply (rule_tac [2] poly_divides_trans)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   492
apply (auto simp add: divides_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   493
apply (rule_tac x = p in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   494
apply (auto simp add: poly_mult fun_eq mult_ac)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   495
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   496
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   497
lemma poly_exp_divides: "[| (p %^ n) divides q;  m\<le>n |] ==> (p %^ m) divides q"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   498
by (blast intro: poly_divides_exp poly_divides_trans)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   499
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   500
lemma poly_divides_add:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   501
   "[| p divides q; p divides r |] ==> p divides (q +++ r)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   502
apply (simp add: divides_def, auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   503
apply (rule_tac x = "qa +++ qaa" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   504
apply (auto simp add: poly_add fun_eq poly_mult right_distrib)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   505
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   506
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   507
lemma poly_divides_diff:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   508
   "[| p divides q; p divides (q +++ r) |] ==> p divides r"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   509
apply (simp add: divides_def, auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   510
apply (rule_tac x = "qaa +++ -- qa" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   511
apply (auto simp add: poly_add fun_eq poly_mult poly_minus right_diff_distrib algebra_simps)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   512
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   513
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   514
lemma poly_divides_diff2: "[| p divides r; p divides (q +++ r) |] ==> p divides q"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   515
apply (erule poly_divides_diff)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   516
apply (auto simp add: poly_add fun_eq poly_mult divides_def add_ac)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   517
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   518
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   519
lemma poly_divides_zero: "poly p = poly [] ==> q divides p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   520
apply (simp add: divides_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   521
apply (rule exI[where x="[]"])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   522
apply (auto simp add: fun_eq poly_mult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   523
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   524
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   525
lemma poly_divides_zero2: "q divides []"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   526
apply (simp add: divides_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   527
apply (rule_tac x = "[]" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   528
apply (auto simp add: fun_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   529
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   530
declare poly_divides_zero2 [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   531
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   532
text{*At last, we can consider the order of a root.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   533
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   534
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   535
lemma poly_order_exists_lemma [rule_format]:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   536
     "\<forall>p. length p = d --> poly p \<noteq> poly [] 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   537
             --> (\<exists>n q. p = mulexp n [-a, (1::'a::{idom,ring_char_0})] q & poly q a \<noteq> 0)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   538
apply (induct "d")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   539
apply (simp add: fun_eq, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   540
apply (case_tac "poly p a = 0")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   541
apply (drule_tac poly_linear_divides [THEN iffD1], safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   542
apply (drule_tac x = q in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   543
apply (drule_tac poly_entire_neg [THEN iffD1], safe, force) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   544
apply (rule_tac x = "Suc n" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   545
apply (rule_tac x = qa in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   546
apply (simp del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   547
apply (rule_tac x = 0 in exI, force) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   548
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   549
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   550
(* FIXME: Tidy up *)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   551
lemma poly_order_exists:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   552
     "[| length p = d; poly p \<noteq> poly [] |]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   553
      ==> \<exists>n. ([-a, 1] %^ n) divides p &
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   554
                ~(([-a, (1::'a::{idom,ring_char_0})] %^ (Suc n)) divides p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   555
apply (drule poly_order_exists_lemma [where a=a], assumption, clarify)  
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   556
apply (rule_tac x = n in exI, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   557
apply (unfold divides_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   558
apply (rule_tac x = q in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   559
apply (induct_tac "n", simp)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   560
apply (simp (no_asm_simp) add: poly_add poly_cmult poly_mult right_distrib mult_ac)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   561
apply safe
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   562
apply (subgoal_tac "poly (mulexp n [- a, 1] q) \<noteq> poly ([- a, 1] %^ Suc n *** qa)") 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   563
apply simp 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   564
apply (induct_tac "n")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   565
apply (simp del: pmult_Cons pexp_Suc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   566
apply (erule_tac Q = "poly q a = 0" in contrapos_np)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   567
apply (simp add: poly_add poly_cmult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   568
apply (rule pexp_Suc [THEN ssubst])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   569
apply (rule ccontr)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   570
apply (simp add: poly_mult_left_cancel poly_mult_assoc del: pmult_Cons pexp_Suc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   571
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   572
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   573
lemma poly_one_divides: "[1] divides p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   574
by (simp add: divides_def, auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   575
declare poly_one_divides [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   576
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   577
lemma poly_order: "poly p \<noteq> poly []
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   578
      ==> EX! n. ([-a, (1::'a::{idom,ring_char_0})] %^ n) divides p &
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   579
                 ~(([-a, 1] %^ (Suc n)) divides p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   580
apply (auto intro: poly_order_exists simp add: less_linear simp del: pmult_Cons pexp_Suc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   581
apply (cut_tac x = y and y = n in less_linear)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   582
apply (drule_tac m = n in poly_exp_divides)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   583
apply (auto dest: Suc_le_eq [THEN iffD2, THEN [2] poly_exp_divides]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   584
            simp del: pmult_Cons pexp_Suc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   585
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   586
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   587
text{*Order*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   588
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   589
lemma some1_equalityD: "[| n = (@n. P n); EX! n. P n |] ==> P n"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   590
by (blast intro: someI2)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   591
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   592
lemma order:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   593
      "(([-a, (1::'a::{idom,ring_char_0})] %^ n) divides p &
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   594
        ~(([-a, 1] %^ (Suc n)) divides p)) =
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   595
        ((n = order a p) & ~(poly p = poly []))"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   596
apply (unfold order_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   597
apply (rule iffI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   598
apply (blast dest: poly_divides_zero intro!: some1_equality [symmetric] poly_order)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   599
apply (blast intro!: poly_order [THEN [2] some1_equalityD])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   600
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   601
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   602
lemma order2: "[| poly p \<noteq> poly [] |]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   603
      ==> ([-a, (1::'a::{idom,ring_char_0})] %^ (order a p)) divides p &
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   604
              ~(([-a, 1] %^ (Suc(order a p))) divides p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   605
by (simp add: order del: pexp_Suc)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   606
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   607
lemma order_unique: "[| poly p \<noteq> poly []; ([-a, 1] %^ n) divides p;
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   608
         ~(([-a, (1::'a::{idom,ring_char_0})] %^ (Suc n)) divides p)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   609
      |] ==> (n = order a p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   610
by (insert order [of a n p], auto) 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   611
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   612
lemma order_unique_lemma: "(poly p \<noteq> poly [] & ([-a, 1] %^ n) divides p &
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   613
         ~(([-a, (1::'a::{idom,ring_char_0})] %^ (Suc n)) divides p))
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   614
      ==> (n = order a p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   615
by (blast intro: order_unique)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   616
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   617
lemma order_poly: "poly p = poly q ==> order a p = order a q"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   618
by (auto simp add: fun_eq divides_def poly_mult order_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   619
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   620
lemma pexp_one: "p %^ (Suc 0) = p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   621
apply (induct "p")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   622
apply (auto simp add: numeral_1_eq_1)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   623
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   624
declare pexp_one [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   625
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   626
lemma lemma_order_root [rule_format]:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   627
     "\<forall>p a. 0 < n & [- a, 1] %^ n divides p & ~ [- a, 1] %^ (Suc n) divides p
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   628
             --> poly p a = 0"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   629
apply (induct "n", blast)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   630
apply (auto simp add: divides_def poly_mult simp del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   631
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   632
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   633
lemma order_root: "(poly p a = (0::'a::{idom,ring_char_0})) = ((poly p = poly []) | order a p \<noteq> 0)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   634
apply (case_tac "poly p = poly []", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   635
apply (simp add: poly_linear_divides del: pmult_Cons, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   636
apply (drule_tac [!] a = a in order2)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   637
apply (rule ccontr)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   638
apply (simp add: divides_def poly_mult fun_eq del: pmult_Cons, blast)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   639
using neq0_conv
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   640
apply (blast intro: lemma_order_root)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   641
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   642
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   643
lemma order_divides: "(([-a, 1::'a::{idom,ring_char_0}] %^ n) divides p) = ((poly p = poly []) | n \<le> order a p)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   644
apply (case_tac "poly p = poly []", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   645
apply (simp add: divides_def fun_eq poly_mult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   646
apply (rule_tac x = "[]" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   647
apply (auto dest!: order2 [where a=a]
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
   648
            intro: poly_exp_divides simp del: pexp_Suc)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   649
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   650
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   651
lemma order_decomp:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   652
     "poly p \<noteq> poly []
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   653
      ==> \<exists>q. (poly p = poly (([-a, 1] %^ (order a p)) *** q)) &
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   654
                ~([-a, 1::'a::{idom,ring_char_0}] divides q)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   655
apply (unfold divides_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   656
apply (drule order2 [where a = a])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   657
apply (simp add: divides_def del: pexp_Suc pmult_Cons, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   658
apply (rule_tac x = q in exI, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   659
apply (drule_tac x = qa in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   660
apply (auto simp add: poly_mult fun_eq poly_exp mult_ac simp del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   661
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   662
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   663
text{*Important composition properties of orders.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   664
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   665
lemma order_mult: "poly (p *** q) \<noteq> poly []
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   666
      ==> order a (p *** q) = order a p + order (a::'a::{idom,ring_char_0}) q"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   667
apply (cut_tac a = a and p = "p***q" and n = "order a p + order a q" in order)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   668
apply (auto simp add: poly_entire simp del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   669
apply (drule_tac a = a in order2)+
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   670
apply safe
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   671
apply (simp add: divides_def fun_eq poly_exp_add poly_mult del: pmult_Cons, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   672
apply (rule_tac x = "qa *** qaa" in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   673
apply (simp add: poly_mult mult_ac del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   674
apply (drule_tac a = a in order_decomp)+
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   675
apply safe
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   676
apply (subgoal_tac "[-a,1] divides (qa *** qaa) ")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   677
apply (simp add: poly_primes del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   678
apply (auto simp add: divides_def simp del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   679
apply (rule_tac x = qb in exI)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   680
apply (subgoal_tac "poly ([-a, 1] %^ (order a p) *** (qa *** qaa)) = poly ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   681
apply (drule poly_mult_left_cancel [THEN iffD1], force)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   682
apply (subgoal_tac "poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** (qa *** qaa))) = poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))) ")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   683
apply (drule poly_mult_left_cancel [THEN iffD1], force)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   684
apply (simp add: fun_eq poly_exp_add poly_mult mult_ac del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   685
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   686
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   687
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   688
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   689
lemma order_root2: "poly p \<noteq> poly [] ==> (poly p a = 0) = (order (a::'a::{idom,ring_char_0}) p \<noteq> 0)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   690
by (rule order_root [THEN ssubst], auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   691
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   692
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   693
lemma pmult_one: "[1] *** p = p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   694
by auto
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   695
declare pmult_one [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   696
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   697
lemma poly_Nil_zero: "poly [] = poly [0]"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   698
by (simp add: fun_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   699
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   700
lemma rsquarefree_decomp:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   701
     "[| rsquarefree p; poly p a = (0::'a::{idom,ring_char_0}) |]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   702
      ==> \<exists>q. (poly p = poly ([-a, 1] *** q)) & poly q a \<noteq> 0"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   703
apply (simp add: rsquarefree_def, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   704
apply (frule_tac a = a in order_decomp)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   705
apply (drule_tac x = a in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   706
apply (drule_tac a = a in order_root2 [symmetric])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   707
apply (auto simp del: pmult_Cons)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   708
apply (rule_tac x = q in exI, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   709
apply (simp add: poly_mult fun_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   710
apply (drule_tac p1 = q in poly_linear_divides [THEN iffD1])
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   711
apply (simp add: divides_def del: pmult_Cons, safe)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   712
apply (drule_tac x = "[]" in spec)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   713
apply (auto simp add: fun_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   714
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   715
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   716
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   717
text{*Normalization of a polynomial.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   718
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   719
lemma poly_normalize: "poly (pnormalize p) = poly p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   720
apply (induct "p")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   721
apply (auto simp add: fun_eq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   722
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   723
declare poly_normalize [simp]
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   724
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   725
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   726
text{*The degree of a polynomial.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   727
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   728
lemma lemma_degree_zero:
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   729
     "list_all (%c. c = 0) p \<longleftrightarrow>  pnormalize p = []"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   730
by (induct "p", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   731
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   732
lemma degree_zero: "(poly p = poly ([]:: (('a::{idom,ring_char_0}) list))) \<Longrightarrow> (degree p = 0)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   733
apply (simp add: degree_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   734
apply (case_tac "pnormalize p = []")
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   735
apply (auto simp add: poly_zero lemma_degree_zero )
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   736
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   737
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   738
lemma pnormalize_sing: "(pnormalize [x] = [x]) \<longleftrightarrow> x \<noteq> 0" by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   739
lemma pnormalize_pair: "y \<noteq> 0 \<longleftrightarrow> (pnormalize [x, y] = [x, y])" by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   740
lemma pnormal_cons: "pnormal p \<Longrightarrow> pnormal (c#p)" 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   741
  unfolding pnormal_def by simp
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   742
lemma pnormal_tail: "p\<noteq>[] \<Longrightarrow> pnormal (c#p) \<Longrightarrow> pnormal p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   743
  unfolding pnormal_def 
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   744
  apply (cases "pnormalize p = []", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   745
  by (cases "c = 0", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   746
lemma pnormal_last_nonzero: "pnormal p ==> last p \<noteq> 0"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   747
  apply (induct p, auto simp add: pnormal_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   748
  apply (case_tac "pnormalize p = []", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   749
  by (case_tac "a=0", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   750
lemma  pnormal_length: "pnormal p \<Longrightarrow> 0 < length p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   751
  unfolding pnormal_def length_greater_0_conv by blast
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   752
lemma pnormal_last_length: "\<lbrakk>0 < length p ; last p \<noteq> 0\<rbrakk> \<Longrightarrow> pnormal p"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   753
  apply (induct p, auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   754
  apply (case_tac "p = []", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   755
  apply (simp add: pnormal_def)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   756
  by (rule pnormal_cons, auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   757
lemma pnormal_id: "pnormal p \<longleftrightarrow> (0 < length p \<and> last p \<noteq> 0)"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   758
  using pnormal_last_length pnormal_length pnormal_last_nonzero by blast
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   759
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   760
text{*Tidier versions of finiteness of roots.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   761
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   762
lemma poly_roots_finite_set: "poly p \<noteq> poly [] ==> finite {x::'a::{idom,ring_char_0}. poly p x = 0}"
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   763
unfolding poly_roots_finite .
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   764
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   765
text{*bound for polynomial.*}
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   766
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33268
diff changeset
   767
lemma poly_mono: "abs(x) \<le> k ==> abs(poly p (x::'a::{linordered_idom})) \<le> poly (map abs p) k"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   768
apply (induct "p", auto)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   769
apply (rule_tac y = "abs a + abs (x * poly p x)" in order_trans)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   770
apply (rule abs_triangle_ineq)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   771
apply (auto intro!: mult_mono simp add: abs_mult)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   772
done
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   773
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   774
lemma poly_Sing: "poly [c] x = c" by simp
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
   775
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   776
end