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

Evaluation of polynomial coefficient rings in free algebras #38801

Open
2 tasks done
stumpc5 opened this issue Oct 11, 2024 · 2 comments
Open
2 tasks done

Evaluation of polynomial coefficient rings in free algebras #38801

stumpc5 opened this issue Oct 11, 2024 · 2 comments

Comments

@stumpc5
Copy link
Contributor

stumpc5 commented Oct 11, 2024

Steps To Reproduce

sage: version()
'SageMath version 10.5.beta5, Release Date: 2024-09-22'
sage: Pyab.<a,b> = FreeAlgebra(QQ,2)
sage: f = 2*a - 2*b + a*b - b*a
sage: f
2*a - 2*b + a*b - b*a
sage: for mon,coeff in f:
....:     print(coeff, coeff.parent(), mon, coeff*mon)
2 Rational Field a None
-2 Rational Field b None
1 Rational Field a*b a*b
-1 Rational Field b*a None

sage: for mon,coeff in f:
....:     print(coeff,coeff.parent(),mon, Pyab(coeff) * mon)
....: 
2 Rational Field a 2*a
-2 Rational Field b -2*b
1 Rational Field a*b a*b
-1 Rational Field b*a -b*a

Expected Behavior

Multiplying coefficients with monomials correctly

Actual Behavior

Does it correctly, in the example, only for the coefficient 1, not for \pm 2, -1.

Additional Information

No response

Environment

  • OS: Ubuntu 24.04
  • Sage Version: 10.5.beta5

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
@stumpc5 stumpc5 added the t: bug label Oct 11, 2024
@mantepse
Copy link
Collaborator

mantepse commented Oct 11, 2024

This is only very surprising behaviour, not a bug:

sage: for mon, coeff in f:
....:     print(mon.parent(), coeff.parent())
....:     
Free monoid on 2 generators (a, b) Rational Field
Free monoid on 2 generators (a, b) Rational Field
Free monoid on 2 generators (a, b) Rational Field
Free monoid on 2 generators (a, b) Rational Field

What you want is

sage: [c * Pyab(m) for m, c in f]
[2*a, -2*b, a*b, -b*a]

@mantepse
Copy link
Collaborator

As an aside, I cannot reproduce the report, which is a bit odd. With the same sage version, I get

sage: for mon,coeff in f:
....:     print(coeff, coeff.parent(), mon, coeff*mon)
....:     
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 2
      1 for mon,coeff in f:
----> 2     print(coeff, coeff.parent(), mon, coeff*mon)

File ~/sage-trac/src/sage/rings/rational.pyx:2443, in sage.rings.rational.Rational.__mul__()
   2441         return x
   2442 
-> 2443     return coercion_model.bin_op(left, right, operator.mul)
   2444 
   2445 cpdef _mul_(self, right):

File ~/sage-trac/src/sage/structure/coerce.pyx:1282, in sage.structure.coerce.CoercionModel.bin_op()
   1280     # We should really include the underlying error.
   1281     # This causes so much headache.
-> 1282     raise bin_op_exception(op, x, y)
   1283 
   1284 cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for *: 'Rational Field' and 'Free monoid on 2 generators (a, b)'

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

3 participants