12224
|
1 |
(* Title: Poly.thy
|
|
2 |
Author: Jacques D. Fleuriot
|
|
3 |
Copyright: 2000 University of Edinburgh
|
|
4 |
Description: Properties of univariate real polynomials (cf. Harrison)
|
|
5 |
*)
|
|
6 |
|
|
7 |
Poly = Transcendental +
|
|
8 |
|
|
9 |
(* ------------------------------------------------------------------------- *)
|
|
10 |
(* Application of polynomial as a real function. *)
|
|
11 |
(* ------------------------------------------------------------------------- *)
|
|
12 |
|
|
13 |
consts poly :: real list => real => real
|
|
14 |
primrec
|
|
15 |
poly_Nil "poly [] x = 0"
|
|
16 |
poly_Cons "poly (h#t) x = h + x * poly t x"
|
|
17 |
|
|
18 |
|
|
19 |
(* ------------------------------------------------------------------------- *)
|
|
20 |
(* Arithmetic operations on polynomials. *)
|
|
21 |
(* ------------------------------------------------------------------------- *)
|
|
22 |
|
|
23 |
(* addition *)
|
|
24 |
consts "+++" :: [real list, real list] => real list (infixl 65)
|
|
25 |
primrec
|
|
26 |
padd_Nil "[] +++ l2 = l2"
|
|
27 |
padd_Cons "(h#t) +++ l2 = (if l2 = [] then h#t
|
|
28 |
else (h + hd l2)#(t +++ tl l2))"
|
|
29 |
|
|
30 |
(* Multiplication by a constant *)
|
|
31 |
consts "%*" :: [real, real list] => real list (infixl 70)
|
|
32 |
primrec
|
|
33 |
cmult_Nil "c %* [] = []"
|
|
34 |
cmult_Cons "c %* (h#t) = (c * h)#(c %* t)"
|
|
35 |
|
|
36 |
(* Multiplication by a polynomial *)
|
|
37 |
consts "***" :: [real list, real list] => real list (infixl 70)
|
|
38 |
primrec
|
|
39 |
pmult_Nil "[] *** l2 = []"
|
|
40 |
pmult_Cons "(h#t) *** l2 = (if t = [] then h %* l2
|
|
41 |
else (h %* l2) +++ ((0) # (t *** l2)))"
|
|
42 |
|
|
43 |
(* Repeated multiplication by a polynomial *)
|
|
44 |
consts mulexp :: [nat, real list, real list] => real list
|
|
45 |
primrec
|
|
46 |
mulexp_zero "mulexp 0 p q = q"
|
|
47 |
mulexp_Suc "mulexp (Suc n) p q = p *** mulexp n p q"
|
|
48 |
|
|
49 |
|
|
50 |
(* Exponential *)
|
|
51 |
consts "%^" :: [real list, nat] => real list (infixl 80)
|
|
52 |
primrec
|
|
53 |
pexp_0 "p %^ 0 = [1]"
|
|
54 |
pexp_Suc "p %^ (Suc n) = p *** (p %^ n)"
|
|
55 |
|
|
56 |
(* Quotient related value of dividing a polynomial by x + a *)
|
|
57 |
(* Useful for divisor properties in inductive proofs *)
|
|
58 |
consts "pquot" :: [real list, real] => real list
|
|
59 |
primrec
|
|
60 |
pquot_Nil "pquot [] a= []"
|
|
61 |
pquot_Cons "pquot (h#t) a = (if t = [] then [h]
|
|
62 |
else (inverse(a) * (h - hd( pquot t a)))#(pquot t a))"
|
|
63 |
|
|
64 |
(* ------------------------------------------------------------------------- *)
|
|
65 |
(* Differentiation of polynomials (needs an auxiliary function). *)
|
|
66 |
(* ------------------------------------------------------------------------- *)
|
|
67 |
consts pderiv_aux :: nat => real list => real list
|
|
68 |
primrec
|
|
69 |
pderiv_aux_Nil "pderiv_aux n [] = []"
|
|
70 |
pderiv_aux_Cons "pderiv_aux n (h#t) =
|
|
71 |
(real n * h)#(pderiv_aux (Suc n) t)"
|
|
72 |
|
|
73 |
(* ------------------------------------------------------------------------- *)
|
|
74 |
(* normalization of polynomials (remove extra 0 coeff) *)
|
|
75 |
(* ------------------------------------------------------------------------- *)
|
|
76 |
consts pnormalize :: real list => real list
|
|
77 |
primrec
|
|
78 |
pnormalize_Nil "pnormalize [] = []"
|
|
79 |
pnormalize_Cons "pnormalize (h#p) = (if ( (pnormalize p) = [])
|
|
80 |
then (if (h = 0) then [] else [h])
|
|
81 |
else (h#(pnormalize p)))"
|
|
82 |
|
|
83 |
|
|
84 |
(* ------------------------------------------------------------------------- *)
|
|
85 |
(* Other definitions *)
|
|
86 |
(* ------------------------------------------------------------------------- *)
|
|
87 |
|
|
88 |
constdefs
|
|
89 |
poly_minus :: real list => real list ("-- _" [80] 80)
|
|
90 |
"-- p == (- 1) %* p"
|
|
91 |
|
|
92 |
pderiv :: real list => real list
|
|
93 |
"pderiv p == if p = [] then [] else pderiv_aux 1 (tl p)"
|
|
94 |
|
|
95 |
divides :: [real list,real list] => bool (infixl 70)
|
|
96 |
"p1 divides p2 == EX q. poly p2 = poly(p1 *** q)"
|
|
97 |
|
|
98 |
(* ------------------------------------------------------------------------- *)
|
|
99 |
(* Definition of order. *)
|
|
100 |
(* ------------------------------------------------------------------------- *)
|
|
101 |
|
|
102 |
order :: real => real list => nat
|
|
103 |
"order a p == (@n. ([-a, 1] %^ n) divides p &
|
|
104 |
~ (([-a, 1] %^ (Suc n)) divides p))"
|
|
105 |
|
|
106 |
(* ------------------------------------------------------------------------- *)
|
|
107 |
(* Definition of degree. *)
|
|
108 |
(* ------------------------------------------------------------------------- *)
|
|
109 |
|
|
110 |
degree :: real list => nat
|
|
111 |
"degree p == length (pnormalize p)"
|
|
112 |
|
|
113 |
(* ------------------------------------------------------------------------- *)
|
|
114 |
(* Define being "squarefree" --- NB with respect to real roots only. *)
|
|
115 |
(* ------------------------------------------------------------------------- *)
|
|
116 |
|
|
117 |
rsquarefree :: real list => bool
|
|
118 |
"rsquarefree p == poly p ~= poly [] &
|
|
119 |
(ALL a. (order a p = 0) | (order a p = 1))"
|
|
120 |
|
|
121 |
end
|