Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
343 stars 230 forks source link

Substituting matrices in polynomials #2882

Open mahrud opened 1 year ago

mahrud commented 1 year ago

This issue is inspired by this Stack Exchange question that I randomly ran into.

Would be great if the following worked:

S = QQ[t]
m = random(ZZ^2, ZZ^2)
f = det(m - t*m^0) -- characteristic polynomial
-- By Cayley-Hamilton theorem we should have:
0 == f[m] -- error: expected a matrix with 1 row
0 == sub(f, t => m) -- error: expected substitution values to be ring elements or numbers

The easiest workaround I can think of is still too complicated:

0 == sum(pairs reverse flatten entries last coefficients(f, Variables => t), (i, c) -> m^i * c)

But more generally, if I have a polynomial in some number of variables, it shouldn't be too difficult to substitute matrices (or even ring maps) for the variables or return an error if the matrices are not compatible in some way.

Related: #2863, #2792

pzinn commented 1 year ago

with univariate polynomials, I think this is a good idea and should be implemented. not sure about multivariate polynomials, since the matrices you feed may not commute and then it's ambiguous how to take products.

mahrud commented 1 year ago

I main had linear combinations of variables in mind, but you could use a multivariate free algebra instead.