1. RE: logs and antilogs
- Posted by rudy toews <rltoews at ilos.net> Oct 26, 2002
- 515 views
Kat wrote: > I have been looking all over the net for a formula to calculate logs and > > antilogs for any given number, but turned up zip. Can anyone suggest a > formula? > > Kat > > i did a search for "log anti-log" and got hits for faqs on using a TI calculator. then searched for 'graphing calculator' and got hits for a couple of programs. also a search for 'math equations' got lots of hits but i have not gone through them. i can forward my search results, if you want to search them. rltoews ilos net rudy lotterywars
2. RE: logs and antilogs
- Posted by Andy Serpa <ac at onehorseshy.com> Oct 26, 2002
- 482 views
Kat wrote: > I have been looking all over the net for a formula to calculate logs and > > antilogs for any given number, but turned up zip. Can anyone suggest a > formula? > > Kat > > Found this on web, and translated to Euphoria: -- natural logarithm function ln(atom x) atom precision,l,m,n,k,val if x <= 0.0 then -- ERROR: can't take a log of zero or negative -- return some appropriate error here (like a sequence) -- or kill program end if precision = 1e-15 m = 1.0 n = 0.0 while (x/m >= 10.0) do m *= 10.0 n += 1.0 end while if x < 1.0 then n = 0.0 while (x/m <= 0.1) do m *= 0.1 n -= 1.0 end while end if x /= m x = (x-1)/(x+1) l = x val = x k = 3.0 l *= x*x m = l/k val += m if m < 0.0 then m = -m end if while (m >= precision) do k += 2.0 l *= x*x m = l/k val += m if m < 0.0 then m = -m end if end while val = (val * 2) + (n*2.30258509298749) return val -- / 2.30258509298749 (uncomment to get log10) end function -- returns base-based logarithm of x function logbase(atom x, atom base) return ln(x)/ln(base) end function
3. RE: logs and antilogs
- Posted by Andy Serpa <ac at onehorseshy.com> Oct 26, 2002
- 479 views
I forgot antilogs. Antilogs are just the inverse of log. The standard exp() function is the same as the natural antilog. More generally, the antilog is the base raised to the power of the logarithm. The base of natural logs is Euler's number, which is: E = 2.718281828459045235 ... Andy Serpa wrote: > > Kat wrote: > > I have been looking all over the net for a formula to calculate logs and > > > > > > antilogs for any given number, but turned up zip. Can anyone suggest a > > formula? > > > > Kat > > > > > Found this on web, and translated to Euphoria: > > -- natural logarithm > function ln(atom x) > atom precision,l,m,n,k,val > > if x <= 0.0 then > -- ERROR: can't take a log of zero or negative > -- return some appropriate error here (like a sequence) > -- or kill program > end if > > precision = 1e-15 > > m = 1.0 > > n = 0.0 > while (x/m >= 10.0) do > m *= 10.0 > n += 1.0 > end while > > if x < 1.0 then > n = 0.0 > while (x/m <= 0.1) do > m *= 0.1 > n -= 1.0 > end while > end if > > x /= m > x = (x-1)/(x+1) > l = x > val = x > > > k = 3.0 > > l *= x*x > m = l/k > val += m > > if m < 0.0 then > m = -m > end if > > while (m >= precision) do > k += 2.0 > l *= x*x > m = l/k > val += m > > if m < 0.0 then > m = -m > end if > end while > > val = (val * 2) + (n*2.30258509298749) > > return val -- / 2.30258509298749 (uncomment to get log10) > > end function > > > -- returns base-based logarithm of x > function logbase(atom x, atom base) > return ln(x)/ln(base) > end function > >
4. RE: logs and antilogs
- Posted by rforno at tutopia.com Oct 26, 2002
- 494 views
Kat: I assume you want to compute logs and antilogs for big numbers, at a large precision. If not, the best bet is to use Euphoria functions log() and power(), which I think, are the same as the ones used by C/C++. They use very fast algorithms. Please bear in mind that log(x) is base e log, and power(b,x) is "antilog" of x base b. If you don't want to use these functions because you need to make large precision calculations, a good formula to compute log(x) base e = 2.718281828459045... is: make y = x - 1 then: log(x) = y - y^2 / 2 + y^3 / 3 - y^4 / 4 + y^5 / 5 + ... where y^n = power(y,n) that should be computed as y*y*y*y... n times (instead of using power(), since you will be dealing with large precision numbers). This formula should be used for 0 < x < 2. If x >= 2, divide it by e = 2.7182... as many times as needed, and add the number of divisions to the log() of the result. This will also help to speed up the calculation when x is near 2. The antilogarithm, or e^x, can be computed as: e^x = 1 + x + x^2 / 2! + x^3 / 3! + x^4 / 4! + ... where n! = 1*2*3*...*n This converges rapidly for small values of x, but for big values it doesn't. A way to overcome this difficulty is to compute z = x - floor(x), then pre-compute e^1 by the above formula, compute e^floor(x) by repeated multiplication, obtain e^z by the above formula, and finally e^x = e^z * e^floor(x). Regarding repeated multiplication, there is a recursive method to diminish the number of operations, such that for example e^9 = ((e^2) * (e^2)) *((e^2) * (e^2)) * (e^1), using 4 multiplications instead of the apparently necessary 8. This is very important while operating with large precision numbers. These are the simplest methods I know of. I know there are faster ones. I will search the literature to find them in case you want. Regards. ----- Original Message ----- From: Kat <kat at kogeijin.com> To: EUforum <EUforum at topica.com> Sent: Saturday, October 26, 2002 11:06 PM Subject: Re: logs and antilogs > > On 27 Oct 2002, at 1:59, Juergen Luethje wrote: > > > > > Kat wrote: > > > > > I have been looking all over the net for a formula to calculate logs and > > > antilogs for any given number, but turned up zip. Can anyone suggest a > > > formula? > > > > I'm not sure if it got you right, maybe this is what you are looking > > for: > > > > > > type positive_not_1 (object x) > > if atom(x) and x > 0 then > > return x != 1 > > end if > > return 0 > > end type > > > > > > global function log_any (positive_not_1 b, object x) > > -- general log() function > > -- logarithm for base b and number (or sequence) x > > -- in : b: real number > 0 and != 1 > > -- x: real number > 0 (or sequence of such numbers) > > -- out: real number > > > > return log(x)/log(b) > > Ok, what code is behind that line? What does log() do? I know what > logarithms are, and how to use them, i was using them back in 1969. But > they were in a table in a book. The ones i use now are in my calculators. I > opened the calculator, but couldn't find them.> > Kat > > > >
5. RE: logs and antilogs
- Posted by Christian.CUVIER at agriculture.gouv.fr Oct 30, 2002
- 501 views
> Date: Tue, 29 Oct 2002 16:21:53 -0600 > From: Kat <kat at kogeijin.com> > Subject: RE: logs and antilogs (to Kat) > > ..... Besides, i hate to ask the > > computer for a math answer, and get something like 2.99999999 when i > > know the answer is 3. > > > > Kat If you don't give a clue to computer about the kind of result you need, is it expected to guess? I think that's definitely a good AI problem, isn't it? BTW: did any CPU manufacturer fully implement MMIX specs yet? The #E (epsilon) special register could be of some use in reducing these annoying meanless decimals. MMX2's DAZ flag doesn't solve it all, far from that.. Good math software attempt to implement some form of cleverness, but far from perfect, and they are so expensive... Regards CChris
6. RE: logs and antilogs
- Posted by rforno at tutopia.com Oct 30, 2002
- 507 views
Have you tried ABC language from the Netherlands? It features exact arithmetic even beyound the decimals that are shown. For example: 1 / 3 = 0.3333333333333333333333333333333... When you multiply it back by 3, you get 1. It seems that it never loses precision. I do not know how they do that: perhaps maintaining the numbers as rational fractions. Regards. ----- Original Message ----- From: <Christian.CUVIER at agriculture.gouv.fr> Subject: RE: logs and antilogs > > > > Date: Tue, 29 Oct 2002 16:21:53 -0600 > > From: Kat <kat at kogeijin.com> > > Subject: RE: logs and antilogs (to Kat) > > > > ..... Besides, i hate to ask the > > > computer for a math answer, and get something like 2.99999999 when i > > > know the answer is 3. > > > > > > Kat > > If you don't give a clue to computer about the kind of result you need, > is it expected to guess? I think that's definitely a good AI problem, > isn't it? > BTW: did any CPU manufacturer fully implement MMIX specs yet? The #E > (epsilon) special register could be of some use in reducing these > annoying meanless decimals. MMX2's DAZ flag doesn't solve it all, far > from that.. > Good math software attempt to implement some form of cleverness, but > far from perfect, and they are so expensive... > > Regards > > CChris > > > >
7. RE: logs and antilogs
- Posted by rforno at tutopia.com Oct 30, 2002
- 529 views
Have you tried ABC language from the Netherlands? It features exact arithmetic even beyond the decimals that are shown. For example: 1 / 3 = 0.3333333333333333333333333333333... When you multiply it back by 3, you get 1. It seems that it never loses precision. I do not know how they do that: perhaps maintaining the numbers as rational fractions. Regards. ----- Original Message ----- From: <Christian.CUVIER at agriculture.gouv.fr> Subject: RE: logs and antilogs > > > > Date: Tue, 29 Oct 2002 16:21:53 -0600 > > From: Kat <kat at kogeijin.com> > > Subject: RE: logs and antilogs (to Kat) > > > > ..... Besides, i hate to ask the > > > computer for a math answer, and get something like 2.99999999 when i > > > know the answer is 3. > > > > > > Kat > > If you don't give a clue to computer about the kind of result you need, > is it expected to guess? I think that's definitely a good AI problem, > isn't it? > BTW: did any CPU manufacturer fully implement MMIX specs yet? The #E > (epsilon) special register could be of some use in reducing these > annoying meanless decimals. MMX2's DAZ flag doesn't solve it all, far > from that.. > Good math software attempt to implement some form of cleverness, but > far from perfect, and they are so expensive... > > Regards > > CChris > > > >
8. RE: logs and antilogs
- Posted by Kat <kat at kogeijin.com> Oct 30, 2002
- 479 views
On 30 Oct 2002, at 14:38, Christian.CUVIER at agriculture.gouv.fr wrote: > > > > Date: Tue, 29 Oct 2002 16:21:53 -0600 > > From: Kat <kat at kogeijin.com> > > Subject: RE: logs and antilogs (to Kat) > > > > ..... Besides, i hate to ask the > > > computer for a math answer, and get something like 2.99999999 when i > > > know the answer is 3. > > > > > > Kat > > If you don't give a clue to computer about the kind of result you need, > is it expected to guess? I think that's definitely a good AI problem, > isn't it? Well, not really. An Ai would tend to be fuzzy about the decision point, unreliable in the repeatabilty of the answer,, not good. > BTW: did any CPU manufacturer fully implement MMIX specs yet? The #E > (epsilon) special register could be of some use in reducing these > annoying meanless decimals. MMX2's DAZ flag doesn't solve it all, far > from that.. I have no clue. > Good math software attempt to implement some form of cleverness, but > far from perfect, and they are so expensive... I am guessing some rounding is going on somewhere. Kat