Project

General

Profile

Design #1689

Automatic mapping of RHS in += etc

Added by John Abbott about 2 years ago. Updated 13 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Tidying
Target version:
Start date:
15 Jun 2022
Due date:
% Done:

100%

Estimated time:
0.88 h
Spent time:

Description

Currently CoCoALib does not permit automatic promotion with operators like +=.

This means that one cannot do, for instance, f /= content(f);
even though f = f/content(f); works just fine. This feel inconsistent!

There is the question about whether to permit the LHS to be promoted automatically.
At the moment I cannot think of a situation where this would be convenient/useful
[but that alone is not sufficient to exclude the possibility]. If we do forbid it,
then again we have a situation where a = a+b; has (slightly) different behaviour
from a +=b;


Related issues

Related to CoCoALib - Feature #645: Automatic mapping of RingElem: user selectable at run-time (GlobalManager?)Rejected2014-11-04

Related to CoCoA-5 - Feature #1461: Automatic mapping for multiplication?Closed2020-06-10

History

#1 Updated by John Abbott about 2 years ago

I have made a first update (not checked in) which allows the RHS to be promoted, but not the LHS.
Somehow it "feels funny" to allow the LHS to be promoted automatically... but that is not really
a good reason to forbid it.

What do you think?

#2 Updated by John Abbott over 1 year ago

  • Status changed from New to In Progress
  • Assignee set to John Abbott
  • % Done changed from 0 to 80

The current impl gives an error if the LHS would be promoted.
I am inclined to accept this impl, and close this issue.
If people object, it should be easy to change the code to allow the LHS to be promoted too.

What do you think?

#3 Updated by John Abbott over 1 year ago

  • Status changed from In Progress to Closed
  • % Done changed from 80 to 100
  • Estimated time set to 0.88 h

#4 Updated by Anna Maria Bigatti 5 months ago

  • Related to Feature #645: Automatic mapping of RingElem: user selectable at run-time (GlobalManager?) added

#5 Updated by Anna Maria Bigatti 5 months ago

  • Subject changed from Automatic promotion of RHS in += etc to Automatic mapping of RHS in += etc

#6 Updated by Anna Maria Bigatti about 1 month ago

Is this valid now? something along this lines is valid.

#7 Updated by Anna Maria Bigatti about 1 month ago

  • Related to Feature #1461: Automatic mapping for multiplication? added

#8 Updated by Anna Maria Bigatti about 1 month ago

When we multiply or divide a polynomial by a coefficient, we can use myMulByCoeff/myDivByCoeff.
This is actually checked in the multiply divide functions, but it maps the coefficient up, then checks if it's a coefficient, then myMulByCoeff/myDivByCoeff.

Is it worth the trouble to call myMulByCoeff/myDivByCoeff directly before mapping?

#9 Updated by John Abbott 13 days ago

I have implemented the short-cuts for op*= and op/=. All tests pass.

One minus point... here is the (simpler) code for op*=

      if (IsPolyRing(Rx) && CoeffRing(Rx) == Ry)  { PolyRing(Rx)->myMulByCoeff(raw(x),raw(y)); return x; }

It is a shame that Rx is dynamically cast 3 times in this implementation; bear in mind that dynamic casting is costly.
Is there a neat way to do better?

Also available in: Atom PDF