Skip to content

Convert factorization to symbolic expression #17624

Closed
@gagern

Description

@gagern
mannequin

Dealing with polynomial rings is nice, but the fact that they always present their content in fully expanded form can make it hard to read results. For a single polynomial, computing its factorization can help. But for e.g. a vector or matrix composed of factorizations, this is not possible.

sage: R.<a,b> = QQ[]
sage: m = matrix([[a^2-b^2, a^3-a*b^2], [a*b + b^2, -77*a+77*b]])
sage: factor(m[0,0])
(a - b) * (a + b)
sage: m.apply_map(factor)
TypeError: x must be a list
sage: SR(factor(m[0,0]))
TypeError: 
sage: m.apply_map(lambda x: SR(str(factor(x))))
[  (a + b)*(a - b) (a + b)*(a - b)*a]
[        (a + b)*b      -77*a + 77*b]
sage: m[1,1].factor()
(-77) * (a - b)

It would be nice if the apply_map(factor) call would simply work, returning a matrix of symbolic expressions to help reading that matrix. The detour via str is a very hackish workaround, in my opinion.

Note that SR will automatically expand some things, as evidenced by the coeffcicient 77 in the example above. I guess that could only be avoided if we could have matrices of factorizations. That would be a viable alternative, and might be worth its own ticket, but I think coercion to SR might have other benefits as well, so this ticket here is about that coercion.

Component: symbolics

Author: Ralf Stephan

Branch/Commit: 9c461e3

Reviewer: Jeroen Demeyer

Issue created by migration from https://trac.sagemath.org/ticket/17624

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions