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

File: [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Polynomials / generic_polynomials.ads (download)

Revision 1.1.1.1 (vendor branch), Sun Oct 29 17:45:26 2000 UTC (23 years, 7 months ago) by maekawa
Branch: PHC, MAIN
CVS Tags: v2, maekawa-ipv6, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, HEAD
Changes since 1.1: +0 -0 lines

Import the second public release of PHCpack.

OKed by Jan Verschelde.

with Abstract_Ring;
with Standard_Natural_Vectors;

generic

  with package Ring is new Abstract_Ring(<>);

package Generic_Polynomials is

-- DESCRIPTION :
--   This package represents polynomials in several variables with
--   coefficients over any ring, to be specified by instantiation.

  use Ring;

-- DATA STRUCTURES :

  type Degrees is new Standard_Natural_Vectors.Link_to_Vector;

  type Term is record
    cf : number;     -- coefficient of the term
    dg : Degrees;    -- the degrees of the term
  end record;

  type Poly is private;

  Null_Poly : constant Poly;    -- represents zero in the polynomial ring
  One_Poly : constant Poly;     -- represents one in the polynomial ring

-- CONSTRUCTORS :

  function Create ( n : natural ) return Poly;
  function Create ( n : number ) return Poly;

  function Create ( t : Term ) return Poly;

  procedure Copy ( t1 : in Term; t2 : in out Term );    -- makes a deep copy
  procedure Copy ( p: in Poly; q : in out Poly );

-- SELECTORS :

  function Equal ( t1,t2 : Term )  return boolean;
  function Equal ( p,q : Poly )  return boolean;

  function Number_of_Unknowns ( p : Poly ) return natural;
  function Number_of_Terms    ( p : Poly ) return natural;

  function Degree ( p : Poly ) return integer;              -- return deg(p);
  function Degree ( p : Poly; i : integer ) return integer; -- return deg(p,xi);

  function "<" ( d1,d2 : Degrees ) return boolean;          -- return d1 < d2
  function ">" ( d1,d2 : Degrees ) return boolean;          -- return d1 > d2

  function Coeff ( p : Poly; d : Degrees ) return number;
   -- Ex.: Coeff(c1*x^2+c2*x*y^3,(1 2))=c2;  Coeff(c1*x^2+c2,(1 0))=zero;

-- ARITHMETICAL OPERATIONS :

  function "+" ( p : Poly; t : Term ) return Poly;      -- return p+t;
  function "+" ( t : Term; p : Poly ) return Poly;      -- return t+p;
  function "+" ( p : Poly ) return Poly;                -- returns copy of p;
  function "+" ( p,q : Poly ) return Poly;              -- return p+q;
  function "-" ( p : Poly; t : Term ) return Poly;      -- return p-t;
  function "-" ( t : Term; p : Poly ) return Poly;      -- return t-p;
  function "-" ( p : Poly ) return Poly;                -- return -p;
  function "-" ( p,q : Poly ) return Poly;              -- return p-q;
  function "*" ( p : Poly; a : number ) return Poly;    -- return a*p;
  function "*" ( a : number; p : Poly ) return Poly;    -- return p*a;
  function "*" ( p : Poly; t : Term ) return Poly;      -- return p*t;
  function "*" ( t : Term; p : Poly ) return Poly;      -- return t*p;
  function "*" ( p,q : Poly ) return Poly;              -- return p*q;

  procedure Add ( p : in out Poly; t : in Term );       -- p := p + t;
  procedure Add ( p : in out Poly; q : in Poly );       -- p := p + q;
  procedure Sub ( p : in out Poly; t : in Term );       -- p := p - t;
  procedure Min ( p : in out Poly );                    -- p := -p;
  procedure Sub ( p : in out Poly; q : in Poly );       -- p := p - q;
  procedure Mul ( p : in out Poly; a : in number );     -- p := p * a;
  procedure Mul ( p : in out Poly; t : in Term );       -- p := p * t;
  procedure Mul ( p : in out Poly; q : in Poly );       -- p := p * q;

  function  Diff ( p : Poly; i : integer ) return Poly; 
  procedure Diff ( p : in out Poly; i : in integer );
    -- symbolic differentiation w.r.t. the i-th unknown of p

-- ITERATORS : run through all terms of p and apply the generic procedure.

  generic
    with procedure process ( t : in out Term; continue : out boolean );
  procedure Changing_Iterator ( p : in out Poly );  -- t can be changed
  generic
    with procedure process ( t : in Term; continue : out boolean );
  procedure Visiting_Iterator ( p : in Poly );      -- t can only be read

-- DESTRUCTORS : deallocate memory.

  procedure Clear ( d : in out Degrees );
  procedure Clear ( t : in out Term );
  procedure Clear ( p : in out Poly );

private

  type Poly_Rep;
  type Poly is access Poly_Rep;

  Null_Poly : constant Poly := null;

  One_Term : constant Term := (one,null);
  One_Poly : constant Poly := Create(One_Term);

end Generic_Polynomials;