# Factorizing matrix entries that are polynomials

Suppose i have a polynomial matrix like:

var('x')
g=graph.CompleteGraph(4)
h=g.am()
t=h-x*identity_matrix(4)
t1


Then, how do i get t1 in the factorized/simplified form. Specifically, I see that there are exactly two distinct entries in t1, and each of them can be factorized into two distinct monomial powers. But, how do I get this directly, without having to factorize each element separately. Any hints? Thanks beforehand.

edit retag close merge delete

Sort by ยป oldest newest most voted

Thanks to @MaxAlexseyev, to get what I wanted, which is the adjugate matrix having all its individual entries factored, I used the command t1.apply_map(lambda z:factor(z)), which does the work.

more

You do not need to wrap factor in a lambda expression ; this wrapping is useful to wrap a method?

( 2023-08-22 22:30:35 +0100 )edit

I'm not sure if I got your question correct, but if you want to find a common factor of the matrix elements, you can do so by computing gcd:

c = gcd(t1.list())


Then you can divide your matrix by this common factor and simplify the rest:

print( (t1 / c).apply_map(lambda z: z.full_simplify()) )


which gives

[-x + 2     -1     -1     -1]
[    -1 -x + 2     -1     -1]
[    -1     -1 -x + 2     -1]
[    -1     -1     -1 -x + 2]


Btw, if you know upfront that you'll deal with polynomial entries, it's better to define a polynomial ring in variable x, which eliminates the need in calling .full_simplify():

R.<x> = QQ[]
g=graphs.CompleteGraph(4)
h=g.am()
t=h-x*identity_matrix(4)
c = gcd(t1.list())
print( t1 / c )

more

Thanks! I actually wanted to factorize each of the individual matrix entries. On writing factor(t1.list()), I get error saying it cannot factor the list. Any workaround?

( 2023-08-22 17:37:08 +0100 )edit

Got it! I used t1.apply_map(lambda z:factor(z))to get what I wanted.

( 2023-08-22 17:44:20 +0100 )edit

Then you can simply use t1.apply_map(factor).

( 2023-08-25 04:00:13 +0100 )edit