0
$\begingroup$

I have a problem trying to create a function in a programming language that does not support any functions other than that of basic arithmetic (addition, subtraction, exponentiation, division...). This function should replicate that of the natural logarithm, or $\ln(x)$ function. Currently, I have $e=\sqrt[y]{x}$ (from $e^y=x$). As of now, I have not found any way to isolate $y$ in that equation without also using the $\log()$ function. Is this possible to do without using said function? Once I have the $\ln(x)$ function, I can construct the $\log_{base}(x)$ function as $$\log_{base}(x)=\dfrac{\ln(x)}{\ln(base)}.$$ And, with the Taylor series, I can create dynamic functions for $\sin,\cos,$ and $\tan$ as well as there inverses. From there, I've got a more or less functional programming space.

$\endgroup$
  • 1
    $\begingroup$ I think that this question is somewhat misguided: there is no way to "isolate y" without $y = \log x$; this is the definition of the logarithm. There is a Taylor Series for $\log (1+x)$ where $|x| \le 1$, and you can use this to calculate $\log$ for all numbers. $\endgroup$ – George V. Williams Nov 29 '14 at 2:19
  • $\begingroup$ @GeorgeV.Williams The question is asking whether there is a way to compute $\log$ in terms of other functions. Just because that is the definition does not mean I cannot express it in simpler terms. A sufficient answer to the question would involve the claim that $\log$ cannot be expressed in terms of the other allowed operations. $\endgroup$ – 6005 Nov 29 '14 at 6:39
1
$\begingroup$

Obviously, since $y=\ln(x)$ is the solution, this is equivalent to writing $\log$ in terms of "elementary" functions. This can't be done - a simple argument to this fact would be that there is no way to, in terms of the map $x\mapsto e^x$ and rational functions, create a function tending to infinity, but having vanishing derivative. (A more sophisticated argument could proceed by noting that $\ln(x)$ is as "well-defined" as the other operations, since $\ln(1)$ could be argued to be $2\pi i$ since $e^{2\pi i}=1$ - then tossing the word "holomorphic" around a few times, we'd get a result).

However, if you're okay with Taylor series, then the following may be useful: $$\ln(x+1)=x-\frac{x^2}2+\frac{x^3}3-\frac{x^4}4+\frac{x^5}5+\ldots$$ and, if you want to limit the number of terms you must compute, you could compute, for instance, $\alpha=\sqrt{e}$ (or a higher root; you just need to be able to precompute $\ln(\alpha)$ and, before computing $\ln(x)$ multiply by $\alpha^n$ for an integer $n$ such that $x$ is in $[\alpha^{-\frac{1}2},\sqrt{\alpha})$ - that is, let $x=y\alpha^n$ where $y$ is in that interval, then $\ln(x)=\ln(y\alpha^n)=\ln(y)+n\ln(\alpha)$ and if you use the Taylor series for $\ln(y)$ near $y=1$, you should be able to get reasonable accuracy on any input, since you're only using the Taylor series in a relatively small interval.

Another method would be to abuse the identity $\ln(x^a)=a\ln(x)$ and to use a linear approximation of $\ln$ In particular, if you chose some large integer $n$, then you could compute $$\ln(x)=n\ln(\sqrt[n]x)\approx n(\sqrt[n]x-1).$$

You could also use Newton's method or something similar to numerically solve the equation - you could use one of the above methods to approximate a good place to start, and then iterate Newton's method until you reach acceptable accuracy.

$\endgroup$
  • $\begingroup$ Your idea of 'abusing' $\ln$'s identity method works perfectly for what I'm doing. $\endgroup$ – Conor O'Brien Nov 29 '14 at 2:25
0
$\begingroup$

In almost the same spirit as Meelo's answer, since you need to sompute $y=\log(x)$, start defining the smallest integer $n$ such that $x=10^n a$ with $a<1$. So $$y=\log(10^n a)=n\log(10) +\log(a)$$ but now define $b$ such that $a=\frac{1+b}{1-b}$ that is to say $b=\frac{a-1}{a+1}$ and now use the very fast converging and not alternating Taylor series $$\log(a)=\log\Big(\frac{1+b}{1-b}\Big)=2\Big(b+\frac{b^3}{3}+\frac{b^5}{5}+\frac{b^7}{7}+\cdots\Big)$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.