Project

General

Profile

Design #549

Automatic conversion from RINGELEM to INT or RAT

Added by John Abbott almost 10 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Incomplete function
Target version:
Start date:
07 May 2014
Due date:
% Done:

100%

Estimated time:
5.00 h
Spent time:

Description

It could be helpful sometimes to allow "automatic" conversion from RINGELEM to INT or RAT. I discovered this when an expression like FloatStr(eval(f,alpha))
which caused FloatStr to complain that it wanted a RAT but found a RINGELEM.


Related issues

Related to CoCoA-5 - Feature #453: Automatic conversion from INT (or RAT) to RINGELEMIn Progress2014-03-03

Related to CoCoA-5 - Feature #1313: Automatic conversion from RINGELEM to INTNew2019-09-11

History

#1 Updated by John Abbott almost 10 years ago

I'm not sure how widespread this should be.

Perhaps the best approach would be to implement separately for a few functions, and then decide whether we want to (and can) automate the "coercion" from RINGELEM to INT or RAT.

I do have some doubts (=gut feeling) about automatic conversion for some "number theory" functions.
NOTE for instance gcd

#2 Updated by John Abbott almost 10 years ago

I note that FloatStr used to be implemented in approx.cpkg5 and would accept a RINGELEM argument (which was presumably converted by AsRAT).

The problem arose when I tried running last year's examples for system solving...

#3 Updated by John Abbott almost 10 years ago

  • Status changed from New to In Progress
  • Assignee set to John Abbott
  • % Done changed from 0 to 20
  • Estimated time set to 5.00 h

I now think that it is appropriate for FloatStr, DecimalStr and ScientificStr to accept RINGELEM and auto convert the value to RAT (or error if not possible). I do not see how it could be harmful, and it is definitely helpful in some likely/natural contexts.

I have implemented and documented the above decision

Which other RAT fns should behave similarly?
  • MantissaAndExponent10, MantissaAndExponent2 - done
  • FloatApprox - done

#4 Updated by John Abbott over 9 years ago

  • % Done changed from 20 to 30

#5 Updated by John Abbott over 9 years ago

Here are the fns which can be applied to RAT according to the C5 online help system:

? abs -- absolute value of a number
? AsINT -- convert into an INT
? AsRAT -- convert into a RAT
? ceil -- round rational up to integer
? CFApprox -- continued fraction approximation
? CFApproximants -- continued fraction approximants
? ContFrac -- continued fraction quotients
? floor -- round rational down to integer
? FloorLog2, FloorLogBase -- integer part of the logarithm
? IsZero -- test whether an object is zero
? max -- a maximum element of a sequence or list
? min -- a minimum element of a sequence or list
? num -- numerator
? product -- the product of the elements of a list
? round -- round to integer
? SimplestRatBetween -- find simplest rational in a closed interval
? sum -- the sum of the elements of a list
? TimeFrom -- time elapsed since a given moment

I think that abs, max, min, floor, ceil should not do auto conversion to RAT because they are operations defined on elements of ordered rings -- if the ring is not ordered, they should fail.

Similarly num and den should not do auto conversion because they are defined for elements of fraction fields.

sum and product would convert from INT|RAT to RINGELEM, and not the other way.

The only doubtful cases are: CFApprox, CFApproximants, ContFrac, ILogBase, round, SimplestRatBetween. At the moment I prefer not to have automatic conversion from RINGELEM to RAT for these functions.

#6 Updated by John Abbott over 9 years ago

  • % Done changed from 30 to 40
Here are what I think are the potentially doubtful cases for INT:
  • binomial, BinomialRepr, BinomialReprShift
  • factorial, FloorRoot, FloorSqrt, valuation
  • IsEven, IsOdd
  • RatReconstructByContFrac, RatReconstructByLattice

In all cases, I prefer at the moment not to have automatic conversion.

#7 Updated by John Abbott over 9 years ago

  • Subject changed from Automatic conversion from RINGELEM to INTor RAT to Automatic conversion from RINGELEM to INT or RAT
  • Status changed from In Progress to Closed
  • % Done changed from 40 to 100

Since the current code has been running without problems for 4+ months, I'm closing. If further closely related issues arise, the notes here should help.

#8 Updated by John Abbott over 4 years ago

  • Related to Feature #1313: Automatic conversion from RINGELEM to INT added

Also available in: Atom PDF