[BACK]Return to generic_polynomials.ads CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Polynomials

Annotation of OpenXM_contrib/PHC/Ada/Math_Lib/Polynomials/generic_polynomials.ads, Revision 1.1.1.1

1.1       maekawa     1: with Abstract_Ring;
                      2: with Standard_Natural_Vectors;
                      3:
                      4: generic
                      5:
                      6:   with package Ring is new Abstract_Ring(<>);
                      7:
                      8: package Generic_Polynomials is
                      9:
                     10: -- DESCRIPTION :
                     11: --   This package represents polynomials in several variables with
                     12: --   coefficients over any ring, to be specified by instantiation.
                     13:
                     14:   use Ring;
                     15:
                     16: -- DATA STRUCTURES :
                     17:
                     18:   type Degrees is new Standard_Natural_Vectors.Link_to_Vector;
                     19:
                     20:   type Term is record
                     21:     cf : number;     -- coefficient of the term
                     22:     dg : Degrees;    -- the degrees of the term
                     23:   end record;
                     24:
                     25:   type Poly is private;
                     26:
                     27:   Null_Poly : constant Poly;    -- represents zero in the polynomial ring
                     28:   One_Poly : constant Poly;     -- represents one in the polynomial ring
                     29:
                     30: -- CONSTRUCTORS :
                     31:
                     32:   function Create ( n : natural ) return Poly;
                     33:   function Create ( n : number ) return Poly;
                     34:
                     35:   function Create ( t : Term ) return Poly;
                     36:
                     37:   procedure Copy ( t1 : in Term; t2 : in out Term );    -- makes a deep copy
                     38:   procedure Copy ( p: in Poly; q : in out Poly );
                     39:
                     40: -- SELECTORS :
                     41:
                     42:   function Equal ( t1,t2 : Term )  return boolean;
                     43:   function Equal ( p,q : Poly )  return boolean;
                     44:
                     45:   function Number_of_Unknowns ( p : Poly ) return natural;
                     46:   function Number_of_Terms    ( p : Poly ) return natural;
                     47:
                     48:   function Degree ( p : Poly ) return integer;              -- return deg(p);
                     49:   function Degree ( p : Poly; i : integer ) return integer; -- return deg(p,xi);
                     50:
                     51:   function "<" ( d1,d2 : Degrees ) return boolean;          -- return d1 < d2
                     52:   function ">" ( d1,d2 : Degrees ) return boolean;          -- return d1 > d2
                     53:
                     54:   function Coeff ( p : Poly; d : Degrees ) return number;
                     55:    -- Ex.: Coeff(c1*x^2+c2*x*y^3,(1 2))=c2;  Coeff(c1*x^2+c2,(1 0))=zero;
                     56:
                     57: -- ARITHMETICAL OPERATIONS :
                     58:
                     59:   function "+" ( p : Poly; t : Term ) return Poly;      -- return p+t;
                     60:   function "+" ( t : Term; p : Poly ) return Poly;      -- return t+p;
                     61:   function "+" ( p : Poly ) return Poly;                -- returns copy of p;
                     62:   function "+" ( p,q : Poly ) return Poly;              -- return p+q;
                     63:   function "-" ( p : Poly; t : Term ) return Poly;      -- return p-t;
                     64:   function "-" ( t : Term; p : Poly ) return Poly;      -- return t-p;
                     65:   function "-" ( p : Poly ) return Poly;                -- return -p;
                     66:   function "-" ( p,q : Poly ) return Poly;              -- return p-q;
                     67:   function "*" ( p : Poly; a : number ) return Poly;    -- return a*p;
                     68:   function "*" ( a : number; p : Poly ) return Poly;    -- return p*a;
                     69:   function "*" ( p : Poly; t : Term ) return Poly;      -- return p*t;
                     70:   function "*" ( t : Term; p : Poly ) return Poly;      -- return t*p;
                     71:   function "*" ( p,q : Poly ) return Poly;              -- return p*q;
                     72:
                     73:   procedure Add ( p : in out Poly; t : in Term );       -- p := p + t;
                     74:   procedure Add ( p : in out Poly; q : in Poly );       -- p := p + q;
                     75:   procedure Sub ( p : in out Poly; t : in Term );       -- p := p - t;
                     76:   procedure Min ( p : in out Poly );                    -- p := -p;
                     77:   procedure Sub ( p : in out Poly; q : in Poly );       -- p := p - q;
                     78:   procedure Mul ( p : in out Poly; a : in number );     -- p := p * a;
                     79:   procedure Mul ( p : in out Poly; t : in Term );       -- p := p * t;
                     80:   procedure Mul ( p : in out Poly; q : in Poly );       -- p := p * q;
                     81:
                     82:   function  Diff ( p : Poly; i : integer ) return Poly;
                     83:   procedure Diff ( p : in out Poly; i : in integer );
                     84:     -- symbolic differentiation w.r.t. the i-th unknown of p
                     85:
                     86: -- ITERATORS : run through all terms of p and apply the generic procedure.
                     87:
                     88:   generic
                     89:     with procedure process ( t : in out Term; continue : out boolean );
                     90:   procedure Changing_Iterator ( p : in out Poly );  -- t can be changed
                     91:   generic
                     92:     with procedure process ( t : in Term; continue : out boolean );
                     93:   procedure Visiting_Iterator ( p : in Poly );      -- t can only be read
                     94:
                     95: -- DESTRUCTORS : deallocate memory.
                     96:
                     97:   procedure Clear ( d : in out Degrees );
                     98:   procedure Clear ( t : in out Term );
                     99:   procedure Clear ( p : in out Poly );
                    100:
                    101: private
                    102:
                    103:   type Poly_Rep;
                    104:   type Poly is access Poly_Rep;
                    105:
                    106:   Null_Poly : constant Poly := null;
                    107:
                    108:   One_Term : constant Term := (one,null);
                    109:   One_Poly : constant Poly := Create(One_Term);
                    110:
                    111: end Generic_Polynomials;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>