# Singular

 Note: If not registered, provide any username. For more comfort, register here.
Subject:
Message body:
Enter your message here, it may contain no more than 60000 characters.

 Smilies
 Font size: Tiny Small Normal Large Huge Font colour [quote="jcapco"]So far I am using this procedure. It could exist in some library already? [code] //rational roots of a rational polynomial proc Qroots(poly f) { ideal l = factorize(f,1); list ret; for (int i=1;i<=size(l);i++) { if (deg(l[i])==1) { //roots are rational if (size(l[i])==1) { ret=ret+list(0);} else { ret = ret + list(-leadcoef(l[i][2])/leadcoef(l[i][1])); } } } return(ret); } [/code][/quote]
Options:
 BBCode is ON [img] is ON [flash] is OFF [url] is ON Smilies are ON
 Disable BBCode Disable smilies Do not automatically parse URLs
Confirmation of post
To prevent automated posts the board requires you to enter a confirmation code. The code is displayed in the image you should see below. If you are visually impaired or cannot otherwise read this code please contact the %sBoard Administrator%s.
Confirmation code:
Enter the code exactly as it appears. All letters are case insensitive, there is no zero.

Topic review - Roots of rational polynomials
Author Message
 jcapco
 Post subject: Re: Roots of rational polynomials
 So far I am using this procedure. It could exist in some library already?Code://rational roots of a rational polynomialproc Qroots(poly f) {  ideal l = factorize(f,1);  list ret;  for (int i=1;i<=size(l);i++)   {    if (deg(l[i])==1)    { //roots are rational      if (size(l[i])==1) { ret=ret+list(0);}      else { ret = ret + list(-leadcoef(l[i][2])/leadcoef(l[i][1])); }    }  } return(ret);} So far I am using this procedure. It could exist in some library already?[code]//rational roots of a rational polynomialproc Qroots(poly f) { ideal l = factorize(f,1); list ret; for (int i=1;i<=size(l);i++) { if (deg(l[i])==1) { //roots are rational if (size(l[i])==1) { ret=ret+list(0);} else { ret = ret + list(-leadcoef(l[i][2])/leadcoef(l[i][1])); } } } return(ret);}[/code]
 Posted: Mon Apr 24, 2017 9:36 am
 jcapco
 Post subject: Roots of rational polynomials
 Consider this code:Code:ring A=0,x,lp;poly f=(x-3/17)*(x+2/3);I don't see a straightforward way to find the exact (as rational numbers) roots of f. I looked a bit at the documentation and if I use the command laguerre(f,5,1), I obtain roots up to 5 digits (decimal) precision and not really the rational roots 3/17 and -2/3. Of course I can use factorize(f) and write a code that extracts the rational roots, but I am sure (I hope) there is a cleaner way to do this. Any hints would be much appreciated. Thanks! Consider this code:[code]ring A=0,x,lp;poly f=(x-3/17)*(x+2/3);[/code]I don't see a straightforward way to find the exact (as rational numbers) roots of f. I looked a bit at the documentation and if I use the command [i][color=#626567]laguerre(f,5,1)[/color][/i], I obtain roots up to 5 digits (decimal) precision and not really the rational roots 3/17 and -2/3. Of course I can use [i][color=#626567]factorize(f)[/color][/i] and write a code that extracts the rational roots, but I am sure (I hope) there is a cleaner way to do this. Any hints would be much appreciated. Thanks!
 Posted: Mon Apr 24, 2017 8:49 am

 It is currently Sun Sep 23, 2018 2:21 pm