Project

General

Profile

Feature #896

myIsEqual, myCmp: direct comparisons between RingElem and MachineInt, BigInt and BigRat?

Added by John Abbott almost 8 years ago. Updated almost 6 years ago.

Status:
In Progress
Priority:
Normal
Assignee:
-
Category:
Improving
Target version:
Start date:
25 Jun 2016
Due date:
% Done:

10%

Estimated time:
Spent time:

Description

Currently all comparisons between a RingElem and a MachineInt (or BigInt or BigRat) entails first converting the numerical value into a RingElem and then calling the ring's myCmp function.

Might it be worth allowing direct comparisons without necessarily creating a temporary ring-elem?


Related issues

Related to CoCoALib - Design #859: Twin-float: comparisons and equality testClosed2016-03-28

History

#1 Updated by John Abbott almost 8 years ago

  • Related to Design #859: Twin-float: comparisons and equality test added

#2 Updated by John Abbott almost 8 years ago

Here are some pros and cons:
  • (+) avoid making temporary ring-elem values (wasteful new-delete cycle);
  • (+) should fix issue #859 if done correctly;
  • (-) many new member fns for (esp. ordered) rings;
  • (-) (mild) there is overlap between the fns, so compatibility must be guaranteed (manually!).

#3 Updated by John Abbott almost 8 years ago

Here are the new mem fns which every ring would have to offer:
  • myIsEqual(RingElem, MachineInt)
  • myIsEqual(RingElem, BigInt)
  • myIsEqual(RingElem, BigRat)
  • myIsEqual(MachineInt, RingElem)
  • myIsEqual(BigInt, RingElem)
  • myIsEqual(BigRat, RingElem)

In fact, we could also put default impls in RingBase which simply convert the args to RingElem and then call the extant, generic myCmp for comparison of ring-elems.

Here are the new mem fns which every ORDERED ring would have to offer:
  • myCmp(RingElem, MachineInt)
  • myCmp(RingElem, BigInt)
  • myCmp(RingElem, BigRat)
  • myCmp(MachineInt, RingElem)
  • myCmp(BigInt, RingElem)
  • myCmp(BigRat, RingElem)

#4 Updated by John Abbott almost 8 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10

I note there could be a "mild inconsistency" in the RingTwinFloat implementation: let N be a BigInt and x a twin-float then it is possible that cmp(N,x) and cmp(RingElem(RR,N),x) might give different results (i.e. the second may throw while the first does not).

The difference derives from the fact that an integer N is an exact value, whereas converting it to a twin-float makes it approximate (with corresponding inner and outer intervals); if the exact integer N lies just outside the outer interval of x, while x lies inside the outer interval of the twin-float conversion of N then InsuffPrec could result. This does require x to have an unusually narrow outer interval (compared to a freshly created twin-float with practically the same central value).

#5 Updated by John Abbott over 6 years ago

  • Target version changed from CoCoALib-0.99560 to CoCoALib-0.99600

#6 Updated by John Abbott almost 6 years ago

  • Target version changed from CoCoALib-0.99600 to CoCoALib-1.0

Also available in: Atom PDF