Dear All,
for some project I have been working on for some time I found myself interested
in comparing elements of two different LaurentPolynomialRing. Unfortunately,
at the moment this is somewhat broken. The current behaviour is this:


sage: L1 = LaurentPolynomialRing(ZZ, 'x0,x1,x2,y0,y1,y2')
sage: L2 = LaurentPolynomialRing(ZZ, 'y0,y1,y2')
sage: L2.gen(0) in L1
False
sage: L1(L2.gen(0))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
...
TypeError: tuple key must have same length as ngens


On the other hand PolynomialRing behave differently:

sage: P1 = PolynomialRing(ZZ, 'x0,x1,x2,y0,y1,y2')
sage: P2 = PolynomialRing(ZZ, 'y0,y1,y2')
sage: P2.gen(0) in P1
True
sage: P1(P2.gen(0))
y0


I made a ticket to address this issue #19538 and in the discussion there many
more inconsistencies popped out. This e-mail is to ask the community which 
should
be the desired behavior of both PolynomialRing and LaurentPolynomialRing and how
to get them to agree.

I will use this function to prettyprint

sage: def printmap(target, source):
    print(str(source) + " --> " + str(map(target,source)))


* PolynomialRing

  sage: P1 = PolynomialRing(ZZ, 'x,y')
  sage: P2 = PolynomialRing(ZZ, 'x,t')
  sage: P3 = PolynomialRing(ZZ, 't,x')
  sage: P4 = PolynomialRing(ZZ, 'x,t,y')
  ##### these behave somewhat predictably
  sage: printmap(P4, P1.gens())
  (x, y) --> [x, y]
  sage: printmap(P4, P3.gens())
  (t, x) --> [t, x]
  y
  sage: P1(P4('t'))
  Traceback (most recent call last):
  ...
  TypeError: Could not find a mapping of the passed element to this ring.
  #### these instead are not really behaving in the same way
  sage: printmap(P1, P3.gens()) # this maps the i-th generator to the i-th 
generator irregardless of their names (t to x and x to y)
  (t, x) --> [x, y]
  sage: printmap(P3, P2.gens()) # this instead maps x to x and t to t 
  (x, t) --> [x, t]

* LaurentPolynomialRing

  sage: L1 = LaurentPolynomialRing(ZZ, 'x,y')
  sage: L2 = LaurentPolynomialRing(ZZ, 'x,t')
  sage: L3 = LaurentPolynomialRing(ZZ, 't,x')
  sage: L4 = LaurentPolynomialRing(ZZ, 'x,t,y')
  sage: printmap(L4, L1.gens())
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  ...
  TypeError: tuple key must have same length as ngens
  sage: printmap(L4, L3.gens())
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  ...
  TypeError: tuple key must have same length as ngens
  sage: L1(L4('t'))
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  ...
  TypeError: tuple key must have same length as ngens
  sage: sage: printmap(L1, L3.gens())
  (t, x) --> [x, y]
  sage: sage: printmap(L3, L2.gens())
  (x, t) --> [t, x]

As you can see for LaurentPolynomialRing the maps currently work only if source
and target have the same number of variables. Moreover, whenever they do, the
behaviour is different from the one of PolynomialRing: in any case the map sends
the i-th generator to the i-th generator (arguably this could e seen as more 
consistent).

After the patch I wrote the situation is the following:

* patched LaurentPolynomialRing

  sage: R1 = LaurentPolynomialRing(ZZ, 'x,y')
  sage: R2 = LaurentPolynomialRing(ZZ, 'x,t')
  sage: R3 = LaurentPolynomialRing(ZZ, 't,x')
  sage: R4 = LaurentPolynomialRing(ZZ, 'x,t,y')
  sage: printmap(R4, R1.gens())
  (x, y) --> [x, y]
  sage: printmap(R4, R3.gens())
  (t, x) --> [t, x]
  sage: R1(R4('t'))
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  ...
  ValueError: tuple.index(x): x not in tuple
  sage: sage: printmap(R1, R3.gens())
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  ValueError: tuple.index(x): x not in tuple
  sage: sage: printmap(R3, R2.gens())
  (x, t) --> [x, t]

The patch maps a generator to the generator having the same name, if any (which
explain the failures). The error code should probably be improved.  Note that 

sage: R1(R3.gen(1))
x
 
works as expected. This patch, though, while making LaurentPolynomialRing behave
like PolynomialRing in most cases, makes the behaviour inconsistent in the
previous to last case.

A note on speed: I expect the patched code to be slower than the original one. I
did not make any test to gauge how much.


In view of the above examples, which do you think should be the behaviour of 
both
LaurentpolynomialRing and PolynomialRing? This is quite a central piece of code
in sage and it would be better if the decision about how to proceed is not taken
in some obscure ticket.

Best
S.



-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to