Macaulay2 / M2

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

Promotion issues #3184

Open pzinn opened 6 months ago

pzinn commented 6 months ago

3177 let M2 create fraction fields of iterated rings. Even though this works now, there is an issue which is not easily fixed: promotion. For example:

i1 : R=QQ[x]

o1 = R

o1 : PolynomialRing

i2 : S=R[y]

o2 = S

o2 : PolynomialRing

i3 : 1/x+1/y
stdio:3:3:(3): error: expected pair to have a method for '+'

i4 : 1/x

     1
o4 = -
     x

o4 : frac R

i5 : 1/y

     1
o5 = -
     y

o5 : frac S

Easy, add promotion from frac R to frac S? but that's not currently possible because one can only promote from one ring to another if the former is in the base rings of the latter, and it's not the case here:

i7 : (frac S).baseRings

o7 = {ZZ, QQ, R, S}

Basically, the current system is based on a "linear chain" of promotion whereas in the situation above we have a graph of the form Screenshot from 2024-04-16 22-18-11 One possibility would be to replace the current test of "promotability" which is pretty much what I wrote above with a more flexible

isPromotable = (R,S) -> S#?(promote,R,S);

This would have other advantages, like define "natural" maps between rings say A and B which should be applied automatically when multiplying an element of A and an element of B. (typical situation is when A is a subring of B, since M2 doesn't have a concept of subring). It wouldn't solve every problem (what if one tries to add an element of S and an element of frac R in the situation above?) but it would be a start.

pzinn commented 1 month ago

I'm working on this. Here's another example that fails and should work:

i1 : R=QQ[x,y]

o1 = R

o1 : PolynomialRing

i2 : S=QQ[z]

o2 = S

o2 : PolynomialRing

i3 : T=R**S

o3 = T

o3 : PolynomialRing

i4 : R_0*T_2
stdio:4:3:(3): error: expected pair to have a method for '*'
pzinn commented 1 month ago

also, some of these remarks also apply to lift. incidentally, shouldn't liftable be renamed isLiftable?

mahrud commented 1 month ago

incidentally, shouldn't liftable be renamed isLiftable?

This was brought up before too, I think. I think it would be good to deprecate liftable in favor of isLiftable.

pzinn commented 1 week ago

Keeping open, we're not quite there yet:

i1 : R=QQ[x]

o1 = R

o1 : PolynomialRing

i2 : S=R[y]

o2 = S

o2 : PolynomialRing

i3 : 1/y+1/x
stdio:3:3:(3): error: expected pair to have a method for '+'