Macaulay2 / Workshop-2023-Minneapolis

Collaboration area for the Macaulay2 workshop in Minneapolis, 2023
https://macaulay2.github.io/Workshop-2023-Minneapolis/
8 stars 2 forks source link

Better way to get index of the generator of a ring #17

Closed TheGrateSalmon closed 1 year ago

TheGrateSalmon commented 1 year ago

TL,DR Implement a way to get the index of an IndexedVariable or generator of a polynomial ring.

Examples

i1 : R = QQ[x_1..x_5,y_1..y_4];
i2 : indexOfVariable x_1
o2 = 1
i3 : indexOfVariable y_3
o3 = 3
i1 : R = QQ[x_(1,1)..x_(4,4)];
i2 : indexOfVariable x_(2,3)
o2 = (2, 3)
o2 : Sequence
i1 : R = QQ[x_{1,1}..x_{4,4}];
i2 : indexOfVariable x_{2,3}
o2 = {2, 3}
o2 : List

Currently, via the method variableIndex in MatrixSchubert.m2, a variable is type-cast to a string, parsed with regex, and the index is type-cast back to some M2 type through value.

variableIndex RingElement := Sequence => (elem) -> (
    --convert to string, parse, and select index, convert back
    value replace(".*_+", "", toString elem)
)

This is bad. After some discussion, the following will accomplish the same task, but in a better way:

indexOfVariable = v -> ( i := index v; last toList (ring v).generatorSymbols#i )

However, this requires debug Core to be executed so that generatorSymbols can be used. Is there a way to do this without using debug Core? If not, how to do this in the setting of a package?

TheGrateSalmon commented 1 year ago

An alternative provided by Ayah: (expression(x_1))#1

mahrud commented 1 year ago

Try this:

last baseName x_(1,2)
TheGrateSalmon commented 1 year ago

I think @mahrud's suggestion is the most foolproof versatile version, so I am closing this issue.