What exactly is "exact" (was Clean Singleton Docstrings)

Chris Angelico rosuav at gmail.com
Mon Jul 18 01:48:50 EDT 2016


On Mon, Jul 18, 2016 at 3:37 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> On Monday, July 18, 2016 at 10:06:11 AM UTC+5:30, Chris Angelico wrote:
>> Why does that mean that 3.0 is inexact? In what way is 3.0 "inexact"?
>> It's an exact value representing the integer three.
>
> [Assuming you are asking in good faith and in the same vein I am answering
> without claiming to know all this with much certainty]

[Yes, I was]

> I believe we need to distinguish between the intention and its realization
> within the syntactic (in this case lexical) structures of the language.
>
> The INTENTION is that in addition to capturing the usual number tower
> ℕ ⊂ ℤ ⊂ ℝ (or parts therefore)
> scheme also captures ORTHOGONALLY (word in the docs) the (in)exactness attribute
>
> In the realization, the designers need to (over)load these different attributes
> onto numeric constants.
> So the ruse chosen is that fraction-constants by default are exact
> Decimal constants are inexact
> And one can override any of these by suitable a function
> [At least that's my understanding]

Ah. Okay. So in theory, you could have exact float literals and
inexact integer literals, if you tag them in some way:

300   ; Exactly 300
300!  ; Inexact - roughly 300
3.0  ; Exactly three
3.0!  ; Roughly three and zero tenths

This then eliminates the problem of representing exact non-integers
(for instance, IEEE floating point has no problem representing exactly
3.125, but if all floats are automatically "inexact", you lose that
facility), but it then pushes the question of "what does inexact
really MEAN" up to the programmer, at which point it really ends up in
the domain of error values rather than a simple flag "inexact". In
Python, this sort of thing would be perfect as a PyPI package -
"numbers with error values" - which could then define all arithmetic
operations and how they combine error values (with an implicit upcast
from any numeric type to "number with error value of +/- 0"). It
wouldn't need to be part of the core language.

ChrisA



More information about the Python-list mailing list