I think is is easier, both on the eye and for a beginner to understand: sage: x = polygen(ZZ) sage: f = 2*x**2 - x sage: f.factor() x * (2*x - 1)
The effect of the first line is that polynomials in x are elements of the polynomial ring with integer coefficients. Note the difference when we switch to rational coeffs: sage: x = polygen(QQ) sage: f = 2*x**2 - x sage: f.factor() (2) * (x - 1/2) * x Here 2 is the "unit factor" amd the other two are irreducible polynomials normalised to be monic, which makes sense over a field. John Cremona On Jun 17, 7:30 am, Robert Bradshaw <rober...@math.washington.edu> wrote: > On Jun 16, 2009, at 3:10 PM, Mikie wrote: > > > > > Yes, and as you can see it works great in sage command line. When I > > use it in a python script I get a syntax error for the period in > > R.<x>. > > Clearly you are not using the preparser. What you could do is > > x = QQ['x'].gen(0) > f = 2*x**2 - x > f.factor() > > You can also do > > sage: preparse("x = QQ['x'].0") > "x = QQ['x'].gen(0)" > > to see something that'll work in pure Python (assuming the needed > imports). > > - Robert > > > On Jun 16, 12:30 pm, David Joyner <wdjoy...@gmail.com> wrote: > >> Is this what you mean? > > >> sage: R.<x> = PolynomialRing(ZZ,"x") > >> sage: f = 2*x**2-x > >> sage: f.factor() > >> x * (2*x - 1) > > >> On Tue, Jun 16, 2009 at 11:12 AM, > >> Mikie<thephantom6...@hotmail.com> wrote: > > >>> When I use Sage to factor lets say 2*x**2-x it factors the 2 out > >>> and > >>> leaves a fraction in the expression. I would like to have it not > >>> factor the polynomial unless their is an integer factor. By the > >>> way I > >>> have created a Twisted API that works. > > >>> On Jun 15, 4:51 pm, William Stein <wst...@gmail.com> wrote: > >>>> On Mon, Jun 15, 2009 at 10:54 PM, > >>>> Mikie<thephantom6...@hotmail.com> wrote: > > >>>>> Is there anyway to get the factor function to factor an expression > >>>>> without using QQ['x'].0? I want just integer factors. > > >>>> I don't understand what you mean by "integer factors"? Can you > >>>> give an example? > > >>>>> I have created a Twisted server using Sage to do calculations > >>>>> from a > >>>>> form. > >>>>> When I put QQ['x'].0 into the sage script I get a systax on the > >>>>> period. It does work from the command line. > >>>>> Thanx > > >>>> -- > >>>> William Stein > >>>> Associate Professor of Mathematics > >>>> University of Washingtonhttp://wstein.org-Hide quoted text - > > >> - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---