GENERIC INTERFACE VectorInt (VRep); (* Integer Linear algebra operations over vector of N dimension. Created 95-07-19 by M. V. Andrade based on Vector.ig by J. Stolfi. Last edited 96-09-04 by M. V. A. Andrade. *) IMPORT Random, Thread, Wr, Rd, Lex; CONST N = VRep.N; TYPE ElemT = VRep.ElemT; T = VRep.T; IntegerT = VRep.IntegerT; LongRealT = VRep.LongRealT; CartesianT = ARRAY[0..N-2] OF LONGREAL; Sign = [-1..+1]; PROCEDURE All(x: ElemT): T; (* A vector with all coordinates equal to "x". *) PROCEDURE IsAllZero(READONLY a: T): BOOLEAN; (* Returns TRUE if "a=[0,0,...,0]". *) PROCEDURE Axis(i: [0..N-1]): T; (* The "i"th element of the canonical basis: all coordinates are zero, except coordinate "i" which is one. *) PROCEDURE Get(READONLY a: T; i: [0..N-1]): ElemT; (* Extracts coordinate "i" of "a", converting it to VRep.ElemT. *) PROCEDURE Set(VAR a: T; i: [0..N-1]; x: ElemT); (* Sets coordinate "i" of "a" to "x". *) PROCEDURE Copy(READONLY a: T): T; (* Returns a copy of "a". *) PROCEDURE Add(READONLY a, b: T): T; (* Returns "a + b". *) PROCEDURE Sub(READONLY a, b: T): T; (* Returns "a - b". *) PROCEDURE Neg(READONLY a: T): T; (* Returns "-a". *) PROCEDURE Mult(s: ElemT; READONLY a: T): T; (* Returns "s * a". *) PROCEDURE Div(READONLY a: T; s: ElemT): T; (* Returns "a DIV s". *) PROCEDURE Mod(READONLY a: T; s: ElemT): T; (* Returns "a MOD s". *) PROCEDURE Dot(READONLY a, b: T): ElemT; (* Returns the dot product of vectors "a" and "b". *) PROCEDURE Norm(READONLY a: T): LONGREAL; (* Returns the Euclidean norm (length) of vector "a". *) PROCEDURE Dist(READONLY a,b : LongRealT) : LONGREAL; (* Returns the distance between the points a,b *) PROCEDURE Reduce(READONLY p : T) : T; (* Returns the coordinates of the point p divided by the GCD(p0,...,pn-1), that is, reduces the coordinates of p to the "simplest" coordinates. *) PROCEDURE Equal(READONLY p,q : T) : Sign; (* Returns +1 if "p=q"; -1 if "p = -q" and 0 otherwise. *) PROCEDURE InsideSphere(READONLY p : T) : Sign; (* Returns the relative position between the point $p$ and the Nd-sphere. Returns, -1 if the point is inside the Nd-sphere, 0 if the point belongs to the Nd-sphere e +1 if the point is outside. *) PROCEDURE ToInteger(READONLY a: T): IntegerT; (* Convert from "VRep.T" to plain array of "INTEGER". *) PROCEDURE FromInteger(READONLY c: IntegerT): T; (* Convert from plain array of "INTEGER" to "VRep.T". *) PROCEDURE ToLongReal(a : T) : LongRealT; (* Convert from plain array of MPInt to "VRep.Longreal". *) PROCEDURE FromLongReal(READONLY a: LongRealT; eps : LONGREAL): T; (* Returns a point p with integer coordinates that is an approximation to a, i.e., |p - a| < eps. *) PROCEDURE ToCartesian(READONLY p: T) : CartesianT; (* Returns the cartesian coordinates of the point p. *) PROCEDURE URandom(rnd: Random.T; min, max: INTEGER): T; (* A vector whose coordinates are independent random numbers, uniformly distributed in "[min __ max)". *) PROCEDURE NRandom(rnd: Random.T; avg, dev: INTEGER): T; (* A vector whose coordinates are independent Gaussian random numbers with mean "avg" and standard deviation "dev". *) PROCEDURE Read( rd : Rd.T; lp := ""; rp := ""; ) : T RAISES {Rd.Failure, Thread.Alerted, Lex.Error}; (* Reads a vector of integer on the given reader. The strings "lp", "sep", and "rp" are read (and discarded) respectively before, between, and after the coordinates of "a". *) PROCEDURE Print( wr: Wr.T; READONLY a: T; base : [1..16]; lp := "("; sep := " "; rp := ")"; ) RAISES {Wr.Failure, Thread.Alerted}; (* Prints "a" on the given writer. The strings "lp", "sep", and "rp" are printed respectively before, between, and after the coordinates of "a". *) END VectorInt.