Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Square Roots and Perfect Squares
PostPosted: Thu Aug 11, 2005 5:32 pm 
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: [email protected]
Posted in old Singular Forum on: 2004-08-28 01:34:46+02


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 08, 2005 12:12 pm 
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: [email protected]
Posted in old Singular Forum on: 2004-08-30 12:01:09+02


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

It is currently Fri May 13, 2022 10:57 am
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group