Opened 2 years ago

Last modified 4 weeks ago

#29771 new enhancement

Unify factor and factor_list behaviour on SR, numbers and polynomials

Reported by: gh-petRUShka Owned by:
Priority: major Milestone: sage-9.8
Component: symbolics Keywords: factor, factor_list, symbolic ring
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

It is pretty annoying to have different styles of usage of factor\factor_list methods in case of different but usually interchangeable base rings.

My proposal is to unify approach. All the more factor(list(element)) in one case is essentially the same as element.factor_list() in another.

Lets have more details and consider SymbolicRing case:

var(t)
f = t^5 + 3*t^4 + t^3 - 15/2*t^2 - 11*t - 9/2

factor(f)
# => 1/2*(2*t^3 + 2*t^2 - 4*t - 9)*(t + 1)^2
f.factor()
# => 1/2*(2*t^3 + 2*t^2 - 4*t - 9)*(t + 1)^2
f.factor_list()
# => [(2*t^3 + 2*t^2 - 4*t - 9, 1), (t + 1, 2), (1/2, 1)]
list(factor(f))
# ---------------------------------------------------------------------------
# TypeError                                 Traceback (most recent call last)
# <ipython-input-23-fdf89aa78828> in <module>
# ----> 1 list(factor(f))
# 
# TypeError: 'sage.symbolic.expression.Expression' object is not iterable

Next, consider Univariate Polynomial Ring over Rational Field

P.<t> = QQ[]
f = t^5 + 3*t^4 + t^3 - 15/2*t^2 - 11*t - 9/2

f.factor()
# => (t + 1)^2 * (t^3 + t^2 - 2*t - 9/2)
f.factor_list()
# ---------------------------------------------------------------------------
# AttributeError                            Traceback (most recent call last)
# <ipython-input-32-1c648293eb79> in <module>
# ----> 1 f.factor_list()
# 
# /usr/lib/python3.8/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4651)(
# )
#     485             AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'
#     486         """
# --> 487         return self.getattr_from_category(name)
#     488
#     489     cdef getattr_from_category(self, name):
# 
# /usr/lib/python3.8/site-packages/sage/structure/element.pyx in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/elemen
# t.c:4763)()
#     498         else:
#     499             cls = P._abstract_element_class
# --> 500         return getattr_from_other_class(self, cls, name)
#     501
#     502     def __dir__(self):
# 
# /usr/lib/python3.8/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2633)()
#     392         dummy_error_message.cls = type(self)
#     393         dummy_error_message.name = name
# --> 394         raise AttributeError(dummy_error_message)
#     395     attribute = <object>attr
#     396     # Check for a descriptor (__get__ in Python)
# 
# AttributeError: 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint' object has no attribute 'factor_list'

list(factor(f))
# => [(t + 1, 2), (t^3 + t^2 - 2*t - 9/2, 1)]

Number case and case of FractionField where f = 100 is similar to polynomial case: AttributeError: 'sage.rings.integer.Integer' object has no attribute 'factor_list'.

Change History (7)

comment:1 Changed 2 years ago by Matthias Köppe

Milestone: sage-9.3sage-9.2

comment:2 Changed 2 years ago by Matthias Köppe

Milestone: sage-9.2sage-9.3

comment:3 Changed 18 months ago by Matthias Köppe

Milestone: sage-9.3sage-9.4

Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review.

comment:4 Changed 14 months ago by Matthias Köppe

Milestone: sage-9.4sage-9.5

comment:5 Changed 9 months ago by Matthias Köppe

Milestone: sage-9.5sage-9.6

comment:6 Changed 6 months ago by Matthias Köppe

Milestone: sage-9.6sage-9.7

comment:7 Changed 4 weeks ago by Matthias Köppe

Milestone: sage-9.7sage-9.8
Note: See TracTickets for help on using tickets.