> < ^ Date: Sun, 17 Sep 1995 14:38:00 -0700
> < ^ From: Jacob Hirbawi <hirbawi@commquest.com >
< ^ Subject: Re: Reducing rationals to finite field elements

Geoffrey Mess <geoff@math.ucla.edu> writes :

a)It should only be defined for prime values of the second variable.
b) Reduce( n, p) yields n*Z(p)^0, if n is an integer.
c) Reduce(a/b, p) yields a * ( b*Z(p)^0 )^(-1), if b is coprime to p.
d) Reduce should also apply to vectors and matrices with rational
entries, to functions that return vectors and matrices with rational
entries, and so on.

I haven't had the need to use such a function, but it is fairly straight
forward to implement one. Here's a quick attempt at it, you might want to
clean it up a little, especially the error handling part :

```################################################################################
Reduce:=function(n,p) local a,b;
# handle a non-prime second argument
if not(IsPrime(p)) then
Print("ERROR : p is not a prime \n");
return;
fi;
# case when n is an integer
if IsInt(n) then
return n*Z(p)^0;
fi;
# case when n is rational
if IsRat(n) then
a:=Numerator(n);
b:=Denominator(n);
if Gcd(b,p)<>1 then
Print("ERROR : b not coprime to p \n");
return;
fi;
return a*(b*Z(p)^0 )^(-1);
fi;
# case when n is a vector
if IsVector(n) then
return List(n,x->Reduce(x,p));
fi;
# case when n is a matrix
if IsMat(n) then
return List(n,x->Reduce(x,p));
fi;
return;
end;
################################################################################

for example :
gap> tw3;
[ [ 1, 0, 0, 0 ], [ 1, 1, -1, 0 ], [ 0, 0, 1, 0 ], [ -1, 0, 1, 1 ] ]

gap> Reduce(tw3,2);
[ [ Z(2)^0, 0*Z(2), 0*Z(2), 0*Z(2) ], [ Z(2)^0, Z(2)^0, Z(2)^0, 0*Z(2) ],
[ 0*Z(2), 0*Z(2), Z(2)^0, 0*Z(2) ], [ Z(2)^0, 0*Z(2), Z(2)^0, Z(2)^0 ] ]

gap> Reduce(tw3/3,5);
[ [ Z(5), 0*Z(5), 0*Z(5), 0*Z(5) ], [ Z(5), Z(5), Z(5)^3, 0*Z(5) ],
[ 0*Z(5), 0*Z(5), Z(5), 0*Z(5) ], [ Z(5)^3, 0*Z(5), Z(5), Z(5) ] ]

gap> Reduce(tw3[2],2);
[ Z(2)^0, Z(2)^0, Z(2)^0, 0*Z(2) ]
```

Good luck,

Jacob.

> < [top]