2013/10/7 Jori Mantysalo <jori.mantys...@uta.fi>

> On Mon, 7 Oct 2013, John Cremona wrote:
>
>  sage: R.<x,y> = ZZ[]; print (4*x^2-1).factor()
>> ------------------------------**------------------------------**
>> ---------------
>> NotImplementedError                       Traceback (most recent call
>> last)
>>
>
> But that is just what I would like to "implement", i.e. make few lines of
> code that converts polynomial to QQ, factors it and then convert back to ZZ.
>
>
Great, when you do, make sure to mention the ticket number on this thread.


> (But my first suggestion lacks .unit(), which need to be added.)


It's not just a matter of units. In polynomial rings over QQ, all non-zero
constants are units. In polynomial rings over ZZ, only +/- 1 are units,
prime numbers are primes, and composite numbers are neither units nor
primes (hence need to be factored). This is correctly implemented for
ZZ[x], QQ[x] and QQ[x,y]:

sage: P.<x> = ZZ[]
sage: p = -15*(3*x+2)*(7*x-5)
sage: f = p.factor()
sage: f.unit()
-1
sage: list(f)
[(3, 1), (5, 1), (3*x + 2, 1), (7*x - 5, 1)]

sage: P.<x> = QQ[]
sage: p = -15*(3*x+2)*(7*x-5)
sage: f = p.factor()
sage: f.unit()
-315
sage: list(f)
[(x - 5/7, 1), (x + 2/3, 1)]

sage: P.<x,y> = QQ[]
sage: p = -15*(3*x+2)*(7*x-5)
sage: f = p.factor()
sage: f.unit()
-15
sage: list(f)
[(3*x + 2, 1), (7*x - 5, 1)]




>
>
> --
> Jori Mäntysalo
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to 
> sage-devel+unsubscribe@**googlegroups.com<sage-devel%2bunsubscr...@googlegroups.com>
> .
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at 
> http://groups.google.com/**group/sage-devel<http://groups.google.com/group/sage-devel>
> .
> For more options, visit 
> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to