--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Mon Aug  1 18:56:48 1994
--* Received: from yktvmv-ob.watson.ibm.com by asharp.watson.ibm.com (AIX 3.2/UCB 5.64/930311)
--*           id AA20417; Mon, 1 Aug 1994 18:56:48 -0400
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 7535; Mon, 01 Aug 94 18:56:52 EDT
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.LAL.NOTE.YKTVMV.2355.Aug.01.18:56:52.-0400>
--*           for asbugs@watson; Mon, 01 Aug 94 18:56:52 -0400
--* Received: from nag.com by watson.ibm.com (IBM VM SMTP V2R3) with TCP;
--*    Mon, 01 Aug 94 18:56:50 EDT
--* Received: by nag.com (/\==/\ Smail3.1.28.1 #28.1)
--* 	id <m0qV6Im-0001XtC@nag.com>; Mon, 1 Aug 94 17:57 CDT
--* Message-Id: <m0qV6Im-0001XtC@nag.com>
--* Date: Mon, 1 Aug 94 17:57 CDT
--* From: lal@nag.com (Larry A. Lambe)
--* To: asbugs@watson.ibm.com, lal@nag.com
--* Subject: [2] ex18.as (part 2) [myEx18-2.as][36.1 (suncc)]

--@ Fixed  by:  SSD   Tue Aug 2 09:04:32 EDT 1994 
--@ Tested by:  none 
--@ Summary:    ex18.as updated to correspond to v36. 

--+ I should get stomped for writing
--+
--+ e ^$ degree
--+
--+ since degree can be an integer, but R : EuclidianDomain, right?  Instead,
--+ it compiles and runs (I do not test the offending line).
--+ =================================================
--+
--+ fruit% myEx18-2
--+ X^2 + 1
--+ 5
--+
-- Example 18.  Polynomial Evaluation

#include "aslib";

-- SEE
#library PolyCat "polycat.aso";
import from PolyCat;
#library Poly "poly.aso";
import from Poly;
-- SEE

Applicable(R: BasicType): Category == with { apply: (%, R) -> R };

-- SEE
--SimplePoly(R: GcdDomain):
-- SEE
SimplePoly(R: EuclideanDomain):
        Join(PolynomialCategory(R, Integer), Applicable R)
== Polynomial(R, Integer) add {
        import from R;
        import from Integer;
        import from Polynomial(R, Integer);

-- SEE
-- The following should not have EVER worked should it have??
-- I.e., what's the deal if n < 0?  Can you trace what x^(-2)
-- means?
--
-- The four lines commented out were in the original file.
-- SEE

--      (x: R) ^ (n: Integer): R == {
--              n = 0  => 1;
--              odd? n => x * (x ^ (n-1));
--              (x * x) ^ (n quo 2)
        (x: R) ^ (n: Integer): R == {
-- SEE
-- so we write bogus stuff
-- SEE
                n >= 0 => 1@R;
                0@R;
        }
apply(p: %, e: R) : R == {
                poly := p;
                val : R := 0;
                while (degree poly > 0) repeat {
--
-- SEE
-- The following line was commented out since the compiler complains
-- about having two choices.  Can you explain the proper way to call
-- the local function?  I tried e ^$% degree, but it bombed.  Now I
-- replace it with the IMPROPER line using ^$R and the compiler does
-- not seem to mind!  Since degree can be any integer, there is no such
-- function in R.  Right?
-- SEE
--                      mon := leadingCoefficient(p)*(e^degree poly);
                        mon := leadingCoefficient(p)*(e ^$R degree poly);
                        val := val + mon;
                        poly := reductum poly;
                }
                val + leadingCoefficient poly;
        }
}


T1(): () == {
        import from SimplePoly(Integer), Integer;

        x: SimplePoly Integer := monomial(1,1);

        x2p1: SimplePoly Integer := (x*x) + 1;

        print << x2p1 << newline;
-- SEE
-- well, ok, I like newlines ...
--      print << (x2p1 2);
        print << (x2p1 2) << newline;
-- SEE
}

T1();


 
