Hello:
I guess you mean to check if an "integer" number is a
perfect square. Otherwise, every non-negative real number
is a perfect square (or even every real number over the
complex numbers).
Since there is no "sqrt" function in Singular, you can
check it in an indirect way: you define the quadratic
polynomial whose root is the searched square root, and
then you factorize over the rational numbers. If the
integer is a perfect square it will factorize into two
linear factors, and otherwise the quadratic polynomial
is irreducible. For example:
> ring r=0,x,dp;
> poly f=x2-25;
> factorize(f,1);
_[1]=x-5
_[2]=x+5
> poly g=x2-24;
> factorize(g,1);
_[1]=x2-24
You can easily write a procedure like this:
proc perfectSquare (int n)
{
int answer;
if (n==0)
{
answer=1;
}
else
{
def R=basering;
ring r=0,x,dp;
poly f=x2-n;
ideal I=factorize(f,1);
answer=size(I)-1;
setring R;
}
return(answer);
}
> Hi,
>
> I am an undergraduate student. I am using Singular to implement the algorithms developed in my Dissertation. In one of this algorithms, I need to check if a real number is a perfect square. So, I would like to know how can I calculate a square root in Singular or how can I directly determine if a number is a perfect square in Singular.
>
> Thank you all very much.
>
> Luis
email:
ignfar@eis.uva.esPosted in old Singular Forum on: 2004-08-30 12:01:09+02