--* From BMT%WATSON.vnet.ibm.com@yktvmh.watson.ibm.com  Fri Dec  3 10:43:29 1993
--* Received: from yktvmh.watson.ibm.com by leonardo.watson.ibm.com (AIX 3.2/UCB 5.64/4.03)
--*           id AA27022; Fri, 3 Dec 1993 10:43:29 -0500
--* Received: from watson.vnet.ibm.com by yktvmh.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 1432; Fri, 03 Dec 93 10:49:45 EST
--* Received: from YKTVMH by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.BMT.NOTE.VAGENT2.6342.Dec.03.10:49:44.-0500>
--*           for asbugs@watson; Fri, 03 Dec 93 10:49:45 -0500
--* Received: from YKTVMH by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id 6340; Fri, 3 Dec 1993 10:49:43 EST
--* Received: from cyst.watson.ibm.com by yktvmh.watson.ibm.com (IBM VM SMTP V2R3)
--*    with TCP; Fri, 03 Dec 93 10:49:43 EST
--* Received: from spadserv.watson.ibm.com by cyst.watson.ibm.com (AIX 3.2/UCB 5.64/900528)
--*   id AA50780; Fri, 3 Dec 1993 10:49:13 -0500
--* Received: by spadserv.watson.ibm.com (AIX 3.2/UCB 5.64/900524)
--*           id AA26867; Fri, 3 Dec 1993 10:50:52 -0500
--* Date: Fri, 3 Dec 1993 10:50:52 -0500
--* From: bmt@spadserv.watson.ibm.com
--* X-External-Networks: yes
--* Message-Id: <9312031550.AA26867@spadserv.watson.ibm.com>
--* To: asbugs@watson.ibm.com
--* Subject: [5] error messages about the type problem on line 5 are multiple and unintelligible [/u/bmt/as/sqfr.as][33.0]

--@ Fixed  by:  PI   Thu Mar 17 22:19:08 EST 1994 
--@ Tested by:  none 
--@ Summary:    no more a bug. The version on the server compiles without error msgs. 


#include "aslib.as"
#library demolib "asdem"
import from demolib

SqfrMultDeriv(K:Field, derivs:List (K -> K),UPOLY:PolynomialCategory(K,NonNegativeInteger)):with
   squareFree: UPOLY -> List UPOLY
 == add
   characteristic:Integer := 0

   deriv(p:UPOLY):UPOLY ==
      import from NonNegativeInteger


      import from Integer
      (d:=(degree(p)::Integer)) = 0 => 0
      monomial(d * leadingCoefficient p, retract(d-1)) + deriv reductum p

   enlarge(d:K -> K):(UPOLY -> UPOLY) == (p:UPOLY):UPOLY +-> apply(d,p)
   apply(d: K -> K, p:UPOLY):UPOLY ==
      p = 0 => p
      monomial(d leadingCoefficient p, degree p) + apply(d, reductum p)

   gcd(p:UPOLY, q:UPOLY):UPOLY == p

   squareFree(p:UPOLY):List UPOLY ==
      import from NonNegativeInteger
      c1:=gcd(p, deriv p)
      import from List (K -> K)
      for dd in derivs while c1 ~=1 repeat
          c1 := gcd(c1, apply(dd, p))
      b1 := exquo(p,c1)
      result : List UPOLY := nil
      import from SingleInteger
      for i in 1.. while b1 ~= 1 repeat
          d1 := gcd(c1, b1)
          c1 := exquo(c1, d1)
          result := cons(exquo(b1, d1), result)
          b1 := d1
      result := reverse result
      degree(c1)=0 => result
      h := charthRoot(c1)
      presult := squareFree h
      result := pmerge(result, presult)

   pmerge(l1:List UPOLY, lp:List UPOLY):List UPOLY ==
      import from Integer
      import from Segment Integer
      ans : List UPOLY := nil
      for pp in lp repeat
         for i in 1..characteristic-1 repeat
            ans :=
              empty? l1 => cons(1, ans)
              p:UPOLY := first l1
              l1 := rest l1
              cons(p, ans)
         ans :=
            empty? l1 => cons(pp, ans)
            p:UPOLY := first l1
            l1 := rest l1
            cons(pp * p, ans)
      concat( reverse ans, l1)

   charthRoot(q:UPOLY):UPOLY == q
   exquo(p:UPOLY, q:UPOLY):UPOLY == p
   (n:Integer) * (k:K):K ==
      n < 0 => (-n) * (-k)
      n = 0 => 0
      sum : K := 0
      import from Segment Integer
      for i in 1..n repeat
         sum := sum + k
      sum
 
