--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Tue Aug 24 10:36:51 1993
--* Received: from yktvmv2.watson.ibm.com by radical.watson.ibm.com (AIX 3.2/UCB 5.64/900524)
--*           id AA19479; Tue, 24 Aug 1993 10:36:51 -0400
--* X-External-Networks: yes
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 6347; Tue, 24 Aug 93 10:40:44 EDT
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.GIANNI.NOTE.VAGENT2.0559.Aug.24.10:40:43.-0400>
--*           for asbugs@watson; Tue, 24 Aug 93 10:40:44 -0400
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id 0553; Tue, 24 Aug 1993 10:40:42 EDT
--* Received: from matthew.watson.ibm.com by yktvmv.watson.ibm.com
--*    (IBM VM SMTP V2R3) with TCP; Tue, 24 Aug 93 10:40:41 EDT
--* Received: by matthew.watson.ibm.com (AIX 3.2/UCB 5.64/4.03)
--*           id AA19244; Tue, 24 Aug 1993 10:41:54 -0400
--* Date: Tue, 24 Aug 1993 10:41:54 -0400
--* From: gianni@matthew.watson.ibm.com
--* Message-Id: <9308241441.AA19244@matthew.watson.ibm.com>
--* To: asbugs@watson.ibm.com
--* Subject: compiles in v30.0 not in current [factored.as][current (v30.0)]

--@ Fixed  by: JMS Thu Oct 07 12:06:16 1993
--@ Tested by: intfact.as
--@ Summary:   Outport -> OutPort, Bit -> Boolean


#include "aslib.as"

#library DemoLib       "asdem"

import DemoLib

macro
  Boolean == Bit
  B == Bit
  N == Integer
  I == Integer
  min(aa,bb) == if aa < bb then aa else bb
  one? aa == aa = 1


facFlags ==> 'nil, sqfr, irred, prime'

FFE(S:BasicType): BasicType with
   bracket: (facFlags, S, Integer) -> %
   apply: (%, 'xpnt') -> Integer
   apply: (%, 'fctr') -> S
   apply: (%, 'flg') -> facFlags
   set!: (%, 'xpnt', Integer) -> Integer
 == add
   Rep ==> Record(flg:facFlags, fctr:S, xpnt:Integer)
   import Rep
   import S
   import Integer
   (f:%) = (g:%):Bit ==  rep(f).fctr = rep(g).fctr and rep(f).xpnt = rep(g).xpnt
   (f:%) ~= (g:%):Bit == not(f=g)
   apply(f:%, tag:'xpnt'):Integer == rep(f).xpnt
   apply(f:%, tag:'fctr'):S == rep(f).fctr
   apply(f:%, tag:'flg'):facFlags == rep(f).flg
   set!(f:%, tag:'xpnt', e:Integer):Integer == set!(rep(f),xpnt,e)
   set!(f:%, tag:'fctr', s:S):S == set!(rep(f),fctr,s)
   set!(f:%, tag:'flg', flag:facFlags):facFlags == set!(rep(f),flg,flag)
   [flag:facFlags, s:S, e:Integer]:% == per [flag,s,e]
   apply(p: Outport, l: %): Outport ==
         import String
         import S
         import Integer
         p("ffe(fctr: ")(rep(l).fctr)(" xpnt: ")(rep(l).xpnt)(")")

Factored(S: BasicType with
           1:%
        ) : with
   makeFR: (S, List FFE(S)) -> %
   factorList: % -> List FFE(S)
   unit: % -> S
   apply: (Outport, %) -> Outport
 == add
   Rep ==> Record(unit:S, faclist:List FFE(S))
   import Rep
   makeFR(u:S, lffe:List FFE(S)):% == per [u, lffe]
   factorList(x:%):List FFE(S) == apply(rep(x),faclist)
   unit(x:%):S == apply(rep(x),unit)
   apply(p:Outport, f:%): Outport ==
      import String
      import S
      import List FFE(S)
      import FFE(S)
      import 'xpnt'
      import 'fctr'
      import I
      if unit(f) ~= 1 then p:=p(unit f)
      for fac in factorList f repeat
        p:=p(" ")((fac.fctr)@S)
        if fac.xpnt ~= 1@I then p:=p("^")((fac.xpnt)@I)
      p
 
