[sage-support] Re: is_prime for polynomials over ZZ
Apparently I was incorrectly defining x as an integer, however, I did not get an error the first I tried. incorrect way: x = PolynomialRing(ZZ) correct way: g. = PolynomialRing(ZZ) The len method works now. Thanks. On 3/26/07, Justin C. Walker <[EMAIL PROTECTED]> wrote: > > > On Mar 26, 2007, at 12:24 , Timothy Clemans wrote: > > > > > I just want to tell the user of my factoring apps when the quadratic > > that they submit is prime. I've tried is_prime, and > > len(factor(x^2+B*x+C)) (thinking an answer of one would mean its > > prime, but it does not mean that). What is the best way in SAGE right > > now to test a polynomial over ZZ to tell if it is irreducible over ZZ? > > I think is_prime() is just for integers. > > You should be able to infer that a polynomial is irreducible if factor > () returns a value with length 1. Why don't you think that will work? > > There may be a few kinks in the strategy, depending on the kind of > polynomial the user hands you, though. > > You can always verify that a quadratic polynomial over ZZ is > irreducible over ZZ by doing it the hard way: compute the roots; if > they are both integers, the polynomial is reducible over ZZ; else > not :-}. > > Justin > > -- > Justin C. Walker, Curmudgeon at Large > Institute for the Absorption of Federal Funds > --- > My wife 'n kids 'n dogs are gone, > I can't get Jesus on the phone, > But Ol' Milwaukee's Best is my best friend. > --- > > > > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---
[sage-support] Re: is_prime for polynomials over ZZ
On Mar 26, 2007, at 13:02 , David Harvey wrote: > > > On Mar 26, 2007, at 3:57 PM, Timothy Clemans wrote: > >> >> Apparently I was incorrectly defining x as an integer, however, I did >> not get an error the first I tried. >> >> incorrect way: x = PolynomialRing(ZZ) >> correct way: g. = PolynomialRing(ZZ) >> >> The len method works now. Thanks. > > Be careful though: > > sage: R. = PolynomialRing(ZZ) > > sage: f = 2*x^2 + 4*x + 8 > > sage: f.factor() > 2 * (x^2 + 2*x + 4) > > sage: len(f.factor()) > 2 Just to make matters worse: sage: f=2*x^2+4*x+8 sage: F=factor(f) sage: len(F) 1 sage: len(f.factor()) 1 sage: F (2) * (x^2 + 2*x + 4) In my case, I did not predefined the polynomial ring. Hmmmthis probably means that in my case, the '2' is viewed as a unit, not a factor, and 'f' is a rational polynomial, not an integer one. In fact, type()' gives in your case, and in mine. Timothy, this illustrates an issue in developing software: you have to know what your inputs are. Here's a case where it's unlikely that the average student, with little sophistication in the use of CAS's, will know (he can create what appears to be f\in ZZ[x], but in fact, it's in QQ[x]; and the reason it's important is kind of subtle). Justin -- Justin C. Walker, Curmudgeon-At-Large Director Institute for the Enhancement of the Director's Income "Weaseling out of things is what separates us from the animals. Well, except the weasel." - Homer J Simpson --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---
[sage-support] Re: is_prime for polynomials over ZZ
On Monday 26 March 2007 1:02 pm, David Harvey wrote: > On Mar 26, 2007, at 3:57 PM, Timothy Clemans wrote: > > Apparently I was incorrectly defining x as an integer, however, I did > > not get an error the first I tried. > > > > incorrect way: x = PolynomialRing(ZZ) > > correct way: g. = PolynomialRing(ZZ) > > > > The len method works now. Thanks. > > Be careful though: > > sage: R. = PolynomialRing(ZZ) > > sage: f = 2*x^2 + 4*x + 8 > > sage: f.factor() > 2 * (x^2 + 2*x + 4) > > sage: len(f.factor()) > 2 Which might actually be what one wants, since indeed your poly f is not "prime" as an element of ZZ[x], since (2) is a prime ideal and (x^2+2*x+4) is divisible by other prime ideals. Note that there is an is_irreducible() method for polynomials, which correctly deals with the case of a multiple factor: sage: f = (x-1)^2 sage: f.is_irreducible() False sage: len(f.factor()) 1 -- william --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---
[sage-support] Re: is_prime for polynomials over ZZ
On Mar 26, 2007, at 3:57 PM, Timothy Clemans wrote: > > Apparently I was incorrectly defining x as an integer, however, I did > not get an error the first I tried. > > incorrect way: x = PolynomialRing(ZZ) > correct way: g. = PolynomialRing(ZZ) > > The len method works now. Thanks. Be careful though: sage: R. = PolynomialRing(ZZ) sage: f = 2*x^2 + 4*x + 8 sage: f.factor() 2 * (x^2 + 2*x + 4) sage: len(f.factor()) 2 David --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---
[sage-support] Re: is_prime for polynomials over ZZ
On Mar 26, 2007, at 12:24 , Timothy Clemans wrote: > > I just want to tell the user of my factoring apps when the quadratic > that they submit is prime. I've tried is_prime, and > len(factor(x^2+B*x+C)) (thinking an answer of one would mean its > prime, but it does not mean that). What is the best way in SAGE right > now to test a polynomial over ZZ to tell if it is irreducible over ZZ? I think is_prime() is just for integers. You should be able to infer that a polynomial is irreducible if factor () returns a value with length 1. Why don't you think that will work? There may be a few kinks in the strategy, depending on the kind of polynomial the user hands you, though. You can always verify that a quadratic polynomial over ZZ is irreducible over ZZ by doing it the hard way: compute the roots; if they are both integers, the polynomial is reducible over ZZ; else not :-}. Justin -- Justin C. Walker, Curmudgeon at Large Institute for the Absorption of Federal Funds --- My wife 'n kids 'n dogs are gone, I can't get Jesus on the phone, But Ol' Milwaukee's Best is my best friend. --- --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~--~~~~--~~--~--~---