0

I want to compute the function $f(x) = -x \log x$. AFAIK, if we postulate the extension $f(0) = 0$, then $f(x)$ is a monotonically increasing function on the interval $x \in [0, e^{-1}]$. What is the correct approach to numerically calculate $f(\epsilon)$ where $\epsilon$ is a small number? It seems that series expansion of $f(x)$ around $x=0$ does not behave well...

  • What difficulties do you expect from the usual floating point operations? $\ln(2^{-k}(1+m))=-k\ln 2+\ln(1+m)$ will be evaluated without (unusual) loss of precision, and the multiplication with $x$ is likewise unproblematic. – Lutz Lehmann Dec 06 '19 at 11:41
  • The "series expansion" of $f$ around $x=0$ is $\log(x)\sum a_kx^k=-\log(x)x$. You will not get better. – Lutz Lehmann Dec 06 '19 at 11:58
  • @Dr.LutzLehmann 1) Forgot minus sign, corrected 2) That's a cool transformation you suggest, I have not seen it before, and would not call it usual. – Aleksejs Fomins Dec 06 '19 at 11:59
  • I meant "unusual" in relation to "loss of precision", that is, not having the 1/2 or 1 ulp loss of precision of the elementary floating point operations and functions. Such as in catastrophic cancellation, for instance in computing $\log(1+x)$ for $x\approx 0$. – Lutz Lehmann Dec 06 '19 at 12:02
  • Ah, I see. I guess it works. So I have to express $x = 2^{-k}(1+m)$? But then I need a formal way to convert 1 variable into two. – Aleksejs Fomins Dec 06 '19 at 12:05
  • The question is, what is your aim here. Are you concerned about floating point errors, then there is no problem (and these two numbers are components of the floating point format). Or do you want some kind of uniform polynomial approximation over that interval for some theoretical purposes, then the task becomes more difficult because of the singularity at $x=0$, just compute the derivative of $f$ to see singular behavior. – Lutz Lehmann Dec 06 '19 at 12:14
  • Wait, I am still confused. Let's say that my number x is very small, and I can represent it as $x=e^{-k}$. When I substitute it into $f(x)$ I get $f(k) = k \exp(-k)$, which is still a multiplication of a large number by a small number. – Aleksejs Fomins Dec 06 '19 at 12:24
  • Ok, I think I do finally get it. The problem does not actually exist. As long as it is possible to accurately compute both multipliers, there is not problem computing their product. So the problem reduces to computing the logarithm of a small number, which can be re-expressed as computing the logarithm of a very large number and solved as noted in suggested answer – Aleksejs Fomins Dec 06 '19 at 12:37
  • 1
    "small" and "large" do not play the same important role in multiplication as they do in addition and subtraction. The only related floating point situations are overflow and underflow, which will not happen in the addition of a positive and negative floating point exponent. – Lutz Lehmann Dec 06 '19 at 12:44

1 Answers1

0

Hint:

  • We have the indeterminate form $0 \cdot \infty$
  • Let $t = \dfrac{1}{x}$ and now change the limit to use $t \rightarrow \infty$.

What do you get and what can you use?

  • L'hopital? So I expanded f(t) at $t\rightarrow \infty$, first term tends to zero, second is -t^{-3}. A bit strange, I was expecting a positive number, unless I made a typo somewhere – Aleksejs Fomins Dec 06 '19 at 12:08