#15364: Introduce factor_or_zero into global namespace
-------------------------------------+-------------------------------------
       Reporter:  zabrocki           |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  minor              |    Milestone:  sage-5.13
      Component:  factorization      |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Mike Zabrocki      |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  public/ticket/15364-factor_or_zero |  16e72e7244e735bcbfc3cc4bf8effb2ea7fae330
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by darij):

 Nice, but incomplete, since it only works with integers:
 {{{
 sage: P = PolynomialRing(QQ, 'x')
 sage: P.inject_variables()
 Defining x
 sage: factor(P.zero())
 ---------------------------------------------------------------------------
 ValueError                                Traceback (most recent call
 last)
 <ipython-input-3-81007cf0bccf> in <module>()
 ----> 1 factor(P.zero())

 /home/darij/gitsage/sage-5.13.beta1/local/lib/python2.7/site-
 packages/sage/rings/arith.pyc in factor(n, proof, int_, algorithm,
 verbose, **kwds)
    2470         # e.g. n = x**2 + y**2 + 2*x*y
    2471         try:
 -> 2472             return n.factor(proof=proof, **kwds)
    2473         except AttributeError:
    2474             raise TypeError, "unable to factor n"

 /home/darij/gitsage/sage-5.13.beta1/local/lib/python2.7/site-
 packages/sage/rings/polynomial/polynomial_element.so in
 sage.rings.polynomial.polynomial_element.Polynomial.factor
 (sage/rings/polynomial/polynomial_element.c:24652)()

 ValueError: factorization of 0 not defined.  See factor_or_zero to return
 0.
 }}}

 Also, please be aware that `Factorization` objects (which is what `factor`
 normally returns) have some methods which should probably be imitated by
 the `0` object, or else the can is merely being kicked down the road. For
 instance, the `value` method of a factorization multiplies it back
 together, and it is way more useful than it looks from that description:

 {{{
 sage: Q = FractionField(P)
 sage: Q(14*x) / Q(28*(x+1))
 14*x/(28*x + 28)
 sage: factor(_).value()
 1/2*x/(x + 1)
 }}}

 0, of course, doesn't have that attribute:
 {{{
 sage: 0.value()
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)
 <ipython-input-4-65708360c0e8> in <module>()
 ----> 1 Integer(0).value()

 /home/darij/gitsage/sage-5.13.beta1/local/lib/python2.7/site-
 packages/sage/structure/element.so in
 sage.structure.element.Element.__getattr__
 (sage/structure/element.c:3873)()

 /home/darij/gitsage/sage-5.13.beta1/local/lib/python2.7/site-
 packages/sage/structure/misc.so in
 sage.structure.misc.getattr_from_other_class
 (sage/structure/misc.c:1696)()

 AttributeError: 'sage.rings.integer.Integer' object has no attribute
 'value'
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/15364#comment:7>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

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

Reply via email to