Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substitution fails in the fraction field of an InfinitePolynomialRing #36576

Closed
2 tasks done
mantepse opened this issue Oct 29, 2023 · 2 comments
Closed
2 tasks done

substitution fails in the fraction field of an InfinitePolynomialRing #36576

mantepse opened this issue Oct 29, 2023 · 2 comments

Comments

@mantepse
Copy link
Contributor

Steps To Reproduce

sage: P.<a> = InfinitePolynomialRing(QQ)
sage: c = a[0]/(a[0] + 1)
sage: c
a_0/(a_0 + 1)
sage: c.subs({a[0]: 1})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [90], line 1
----> 1 c.subs({a[Integer(0)]: Integer(1)})

File ~/sage-trac/src/sage/structure/element.pyx:822, in sage.structure.element.Element.subs()
    820 for i in range(ngens):
    821     gen = parent.gen(i)
--> 822     if str(gen) in kwds:
    823         variables.append(kwds[str(gen)])
    824     elif in_dict and gen in in_dict:

File ~/sage-trac/src/sage/structure/sage_object.pyx:221, in sage.structure.sage_object.SageObject.__repr__()
    219     except AttributeError:
    220         return super().__repr__()
--> 221     return reprfunc()
    222 
    223 def _ascii_art_(self):

File ~/sage-trac/src/sage/rings/fraction_field_element.pyx:478, in sage.rings.fraction_field_element.FractionFieldElement._repr_()
    476     '1/x'
    477 """
--> 478 if self.is_zero():
    479     return "0"
    480 s = "%s" % self._numerator

File ~/sage-trac/src/sage/rings/fraction_field_element.pyx:1017, in sage.rings.fraction_field_element.FractionFieldElement.is_zero()
   1015         True
   1016     """
-> 1017     return self._numerator.is_zero()
   1018 
   1019 def is_one(self):

AttributeError: 'InfinitePolynomialGen' object has no attribute 'is_zero'

Expected Behavior

It should return the result of the substitution.

Actual Behavior

A cryptic error is raised.

Additional Information

The problem is that the fraction field inherits subs from Element. This tries to access the i-th generator of the ring. However, in the InfinitePolynomialRing, the i-the generator actually corresponds to the i-th family of generators. For example:

sage: P.gen(0)
a_*

Note that, for example, symmetric functions do not have gens at all, so Element.subs does nothing and this bug does not surface there.

Environment

irrelevant.

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@maxale
Copy link
Contributor

maxale commented Nov 5, 2023

While the issue is not fixed, a possible workaround is to make substitution separately in the numerator and in the denominator of c:

c.numerator().subs({a[0]: 1}) / c.denominator().subs({a[0]: 1})

@mantepse
Copy link
Contributor Author

mantepse commented Apr 2, 2024

Fixed by #37143.

@mantepse mantepse closed this as completed Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants