Proposal: Add log1p and expm1 to GHC.Float.Floating
Henning Thielemann
schlepptop at henning-thielemann.de
Thu Apr 24 09:41:50 UTC 2014
Am 21.04.2014 10:34, schrieb Daniel Trstenjak:
>
> On Sun, Apr 20, 2014 at 11:25:36PM -0400, Edward Kmett wrote:
>> I use log1p as a better log (1 + x).
>>
>> It lets me pick up a few decimal places worth of accuracy opportunistically.
>
> But isn't it a bit unfortunate to take a function name that is known and
> used in numercial circles to get a higher accuracy and in the Haskell
> world it only might give you a higher accuracy?
I guess in other languages expm1 and log1p are fixed to Double and
Float. If you stay with Double or Float in Haskell then you will get the
higher precision, otherwise the precision might be better, but never worse.
> I'm not that much into numerics, but are you really using log1p without
> also really needing it?
> If you're using log1p to possibly get a higher accuracy but don't
> really need it, why you're using it in the first place?
So far I have not needed log1p and expm1, at all, although I use log and
exp regularly. I guess every programmer can mechanically replace
log(1+x) and (exp x - 1) by (log1p x) and (expm1 x), respectively, and
never makes things worse.
> Is it completely out of question to have another type class for these
> higher accuracy functions?
I am uncertain. Since other fused functions were mentioned, a new Fused
or HighPrecision class might be sensible.
> Sure, if you're having some code that's generic on Floating, which
> should just work with and without these higher accuracy funtions, then
> this is out of question.
>
> But then at least IMHO the function names should somehow indicate that
> you can't be sure that they return a higher accuracy.
This seems to lead to a solution were log1p and expm1 are added to
Floating with default implementations and a new Fused class containing
the methods Fused.log1p and Fused.expm1 with no default implementations.
log1p and expm1 can be used if you like to benefit from higher precision
but do not rely on it, and Fused.log1p and Fused.expm1 if you need the
higher precision.
More information about the Libraries
mailing list