Skip to content

Some mutableMatrix updates - #4666

Open
d-torrance wants to merge 8 commits into
Macaulay2:developmentfrom
d-torrance:rank-error
Open

Some mutableMatrix updates#4666
d-torrance wants to merge 8 commits into
Macaulay2:developmentfrom
d-torrance:rank-error

Conversation

@d-torrance

Copy link
Copy Markdown
Member

A few semi-related things that all grew out of fixing the first thing:

Rank errors

According to mutable-matrix.h:

/**
   returns the rank of the matrix M.  If 'rank' is not defined on this type of
   matrix, then returns -1 (and an error message is given).
 */
long rawLinAlgRank(MutableMatrix *M);

However, no such error message is given, and we just get -1!

i1 : rank mutableMatrix(ZZ/101, {{1}}, Dense => false)

o1 = -1

So I added a little check in the interpreter -- if we get -1, return the last engine error instead, so now we have:

i1 : rank mutableMatrix(ZZ/101, {{1}}, Dense => false)
stdio:1:4:(3):[1]: error: 'rank' not implemented for this kind of matrix over this ring

Constructor methods

While testing the above, I was sad that I had to type {{ and }}' when constructing a $1\times 1$ mutable matrix and wanted the Number/RingElement constructors we have for immutable matrices. So I'm proposing 6 new methods:

i1 : mutableMatrix 2 -- mutableMatrix(Number)

o1 = | 2 |

o1 : MutableMatrix

i2 : mutableMatrix(QQ, 2) -- mutableMatrix(Ring, Number)

o2 = | 2 |

o2 : MutableMatrix

i3 : mutableMatrix(RR, 2) -- mutableMatrix(RingFamily, Number)

o3 = | 2 |

o3 : MutableMatrix

i4 : R = QQ[x]; mutableMatrix x -- mutableMatrix(RingElement)

o5 = | x |

o5 : MutableMatrix

i6 : mutableMatrix(R[y], x) -- mutableMatrix(Ring, RingElement)

o6 = | x |

o6 : MutableMatrix

There's also mutableMatrix(RingFamily, RingElement), which won't do anything now except raise errors about promoting. But it might work in the future (e.g., after adding $p$-adics to the engine).

Documentation updates

When I went to document the new constructor methods, I saw that a bunch of the mutable matrix docs were in the old format and in the poorly named doc3.m2 file. So I moved them and had Claude update them to SimpleDoc format.

AfterPrint method

While writing this pull request description, I realized that mutable matrices don't tell us the size or what ring we're working over like we get for immutable matrices. That's a great use for AfterPrint methods so we just use the Matrix one:

i1 : mutableMatrix(QQ[x,y,z,w], 6, 7)

o1 = 0

                                6                  7
o1 : MutableMatrix (QQ[x..z, w])  <-- (QQ[x..z, w])

🤖 AI Disclosure 🤖

I wrote the actual d and m2 code, but got lazy and had Claude do the boring stuff (documentation and tests) lol.

d-torrance and others added 8 commits August 25, 2026 12:08
We return -1 when rank fails but never checked for it.
Prose, examples, keys, SeeAlso lists, and Subnodes lists are carried over
verbatim; rewrapped line breaks are the only change to running text.

A few slots that the old "document {...}" calls left empty are filled in,
since the SimpleDoc item syntax asks for a type: the Dense option is
documented as a Boolean, the ring and size arguments of the mutableMatrix
and mutableIdentity constructors get their types, the output of
mutableMatrix is typed MutableMatrix, and the unnamed permutation
argument of rowPermute and columnPermute (formerly "Nothing => ...") is
typed List.

In the MutableMatrix node, the row and column operations list is now a
SimpleDoc Tree, the idiomatic way to write a menu of links: its entries
carry headlines, and they remain plain TOH links rather than subnode
registrations, so they don't collide with the Subnodes list of the "row
and column operations" node.  SimpleDoc renders a Tree heading as a
HEADER4, so the "matrix arithmetic" subheading was demoted from HEADER3
to HEADER4 to keep the node's two subheadings at the same level.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The six methods added in 94920c9 are documented by adding their keys
to the existing mutableMatrix node, together with examples of the two
forms: the ring inferred from the number or ring element, and the ring
given explicitly.  The list of classes accepted for the argument is
extended to match the new keys.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Covers the methods added in 94920c9, except for
(mutableMatrix, RingFamily, RingElement), which has no reachable
arguments at present, as the elements of every ring family (RR, CC, RRi,
CCi) are numbers rather than ring elements.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The engine has no rank routine for these, and before f3e5f9b the -1
it returned was passed along as the rank.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@d-torrance d-torrance added Engine Macaulay2/e Core Issues involving the Core scripts. Interpreter AI-generated This PR contains AI-generated code labels Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-generated This PR contains AI-generated code Core Issues involving the Core scripts. Engine Macaulay2/e Interpreter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant