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