3
$\begingroup$

The code below is given in Eric Weisstein's Math World article: Matrix Minimal Polynomial.

MatrixMinimalPolynomial[a_List?MatrixQ,x_]:=Module[
    {
      i,
      n=1,
      qu={},
      mnm={Flatten[IdentityMatrix[Length[a]]]}
    },
    While[Length[qu]==0,
      AppendTo[mnm,Flatten[MatrixPower[a,n]]];
      qu=NullSpace[Transpose[mnm]];
      n++
    ];
    First[qu].Table[x^i,{i,0,n-1}]
  ]

Is it possible to adapt the code to give the minimal polynomial of a matrix over a finite field of prime order $p$. Perhaps by adding Modulus -> p in the argument for NullSpace.

$\endgroup$
2
  • 1
    $\begingroup$ Yes, it seems to work fine with adding a Modulus argument to NullSpace. What is your question? $\endgroup$
    – Roman
    Commented Nov 19, 2022 at 16:07
  • $\begingroup$ Hi Roman. Thanks. The reason I am asking is that I am not clear on what the code is actually doing and consequently I am not sure if just adding a Modulus argument will work. $\endgroup$
    – geoffrey
    Commented Nov 19, 2022 at 16:34

1 Answer 1

5
$\begingroup$

This can be done in such a way:

ResourceFunction["MatrixMinimalPolynomial"][{{22,-16},{25,-18}}, x,Extension->alg,Modulus->5]

1 + 4*x + 4*x^2

Of course, the above matrix is treated by mod 5. The theory is stated here.

$\endgroup$
5
  • 1
    $\begingroup$ This is fine (as in +1). Just wanted to add that the Extension option can be omitted if there is no algebraic extension under consideration. $\endgroup$ Commented Nov 19, 2022 at 17:32
  • $\begingroup$ @DanielLichtblau: No, in 13.1 on Windows 10 ResourceFunction["MatrixMinimalPolynomial"][{{22, -16}, {25, -18}}, x, Modulus -> 5] produces Last[{}] . {1} and the error "Last::nolast: {} has zero length and no last element". The documentation on this option is unclear. $\endgroup$
    – user64494
    Commented Nov 19, 2022 at 18:11
  • $\begingroup$ Hi user64494. Thanks. I accepted your answer already but I think there is a problem. For example: Let the matrix over $\mathbb{F}_2$ be {{0,1,0,0},{1,1,0,0},{0,0,0,1},{0,0,1,1}}. The minimal polynomial should be $x^2 + x + 1$. But using your code I get $x^3 + 1. $\endgroup$
    – geoffrey
    Commented Nov 19, 2022 at 20:03
  • $\begingroup$ Thanks both of you for pointing out those bugs. I'll look into them. $\endgroup$ Commented Nov 20, 2022 at 21:41
  • $\begingroup$ I updated` ResourceFunction["MatrixMinimalPolynomial"]` to fix the two issues noted here. I hope there are no further issues (but of course will look into any that get noted). $\endgroup$ Commented Nov 23, 2022 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.