(* Copyright (C) 1999-2000 Samuel Thibault This program is free software : you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation ; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the program ; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. This License should be available in the same directory as this program, in a file called COPYING. If not, you may ask the webmaster or ftpmaster *) let rec somme_poly_pleins p1 p2 = let n1=vect_length p1 and n2=vect_length p2 in if n1>n2 then somme_poly_pleins p2 p1 else let res=make_vect n2 0 in for i=0 to n1-1 do res.(i)<-p1.(i)+p2.(i) done; for i=n1 to n2-1 do res.(i)<-p2.(i) done; res;; let rˇduit_poly_plein p = let i=ref (vect_length p - 1) in while !i>=0 & p.(!i)=0 do decr i done; let res=make_vect (!i+1) 0 in for j=0 to !i do res.(j)<-p.(j) done; res;; let produit_poly_pleins p1 p2= let n1=vect_length p1 and n2=vect_length p2 in let res=make_vect (n1+n2-1) 0 in for i=0 to n1-1 do for j=0 to n2-1 do res.(i+j)<-res.(i+j)+p1.(i)*p2.(j) done done; rˇduit_poly_plein res;; let puissance_poly_plein p n = let i=ref 1 and res=ref (rˇduit_poly_plein p) in while !i 0 do res:=produit_poly_pleins !res p; incr i done; !res;; let rec somme_poly_creux p1 p2 = match p1,p2 with [],_ ->p2 | _,[]->p1 |(a,i)::r1,(b,j)::r2 -> if i=j then if a+b <> 0 then (a+b,i)::(somme_poly_creux r1 r2) else somme_poly_creux r1 r2 else if i[] |(b,j)::r-> (a*b,j+i)::(produit_par_mon™me r (a,i));; let rec produit_poly_creux p1 p2 = match p1 with []->[] |m::r->somme_poly_creux (produit_par_mon™me p2 m) (produit_poly_creux r p2);; let poly_plein_vers_creux p = let n=vect_length p in let rec poly_creux i = if i=n then [] else let recur=poly_creux (i+1) in if p.(i)<>0 then (p.(i),i)::recur else recur in poly_creux 0;; let rec dernier_ˇlˇment l= match l with []->failwith "Liste vide !" |[a]->a |_->dernier_ˇlˇment (tl l);; let poly_creux_vers_plein p = let res=make_vect (snd(dernier_ˇlˇment p) + 1) 0 in let rec poly_plein l = match l with []->() |(a,i)::r->res.(i)<-a ; poly_plein r in poly_plein p; res;; type polyn™me= Plein of int vect |Creux of (int*int) list;; let somme_poly = fun (Plein p1) (Plein p2) -> Plein (somme_poly_pleins p1 p2) |(Plein p1) (Creux p2) -> Creux (somme_poly_creux (poly_plein_vers_creux p1) p2) |(Creux p1) (Plein p2) -> Creux (somme_poly_creux p1 (poly_plein_vers_creux p2)) |(Creux p1) (Creux p2) -> Creux (somme_poly_creux p1 p2);; let produit_poly = fun (Plein p1) (Plein p2) -> Plein (produit_poly_pleins p1 p2) |(Plein p1) (Creux p2) -> Creux (produit_poly_creux (poly_plein_vers_creux p1) p2) |(Creux p1) (Plein p2) -> Creux (produit_poly_creux p1 (poly_plein_vers_creux p2)) |(Creux p1) (Creux p2) -> Creux (produit_poly_creux p1 p2);;