Singular https://www.singular.uni-kl.de/forum/ |
|
Square Roots and Perfect Squares https://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=1403 |
Page 1 of 1 |
Author: | Luis Menasche Schechter [ Thu Aug 11, 2005 5:32 pm ] |
Post subject: | Square Roots and Perfect Squares |
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: luisms@uol.com.br Posted in old Singular Forum on: 2004-08-28 01:34:46+02 |
Author: | Jose Ignacio Farran [ Thu Sep 08, 2005 12:12 pm ] |
Post subject: | |
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.es Posted in old Singular Forum on: 2004-08-30 12:01:09+02 |
Page 1 of 1 | All times are UTC + 1 hour [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |