Author robert_smallshire
Recipients Austin Bingham, christian.heimes, facundobatista, mark.dickinson, rhettinger, robert_smallshire, serhiy.storchaka, skrah, tim.peters
Date 2016-04-05.13:10:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1459861825.86.0.60666600361.issue26680@psf.upfronthosting.co.za>
In-reply-to
Content
Java makes no claim to have a numeric tower.  Amongst the dynamic languages I surveyed Matlab (isinteger), Javascript ES6 (isInteger), PHP (is_integer), R (is.integer), TCL (is entier), and as we have seen Scheme (integer?) all have methods for testing for integer values. Python has a numeric tower modelled on Scheme. In the Scheme documentation we find this:

"...the integer 5 may have several representations. Scheme's numerical operations treat number objects as abstract data, as independent of their representation as possible. Although an implementation of Scheme may use many different representations for numbers, this should not be apparent to a casual programmer writing simple programs."

This is what I'm advocating.

There isn't a single mathematical (as opposed to representational) method on int that isn't 'inherited' from the numeric tower.  There are exactly two methods on float which aren't inherited from the tower: is_integer and as_integer_ratio.  So I think it's would be a stretch to claim that "Most of the [numerical] ABCs have only a subset of the [numerical] methods in the [numerical] concrete types."

Rather than looking at the numeric tower as a construct which forces proliferation of methods, it would be better to look on it as a device to prevent bloat. I risk straying off topic here, but I want to give an example of why the numeric tower is important:

Were float to inherit from Rational, rather than Real (all finite floats are rationals with a power-of-two denominator, all Decimals are rationals with a power-of-ten denominator, so this is reasonable) then the as_integer_ratio method which was added to float and latterly Decimal (http://bugs.python.org/issue25928), arguably cluttering their interfaces, may have been deemed unnecessary. The numerator and denominator attributes present in Rational could have been used instead.  I think this is an example of lack of adherence to the numeric tower (at least in spirit in the case of Decimal) resulting in interface clutter or bloat.

The consequent control-flow complexity required handle numeric objects as 'abstract data' is surprising: statistics._exact_ratio is a good example of this. I count five API tests just to be able to treat numbers as, well, just numbers.
History
Date User Action Args
2016-04-05 13:10:25robert_smallshiresetrecipients: + robert_smallshire, tim.peters, rhettinger, facundobatista, mark.dickinson, christian.heimes, skrah, serhiy.storchaka, Austin Bingham
2016-04-05 13:10:25robert_smallshiresetmessageid: <1459861825.86.0.60666600361.issue26680@psf.upfronthosting.co.za>
2016-04-05 13:10:25robert_smallshirelinkissue26680 messages
2016-04-05 13:10:24robert_smallshirecreate