(12C) log1p function

01312019, 01:10 AM
(This post was last modified: 02012019 11:47 AM by Albert Chan.)
Post: #1




(12C) log1p function
This trick is from John D Cook's Tricks for computing log(1+X)
I picked the formula from the comment section instead. The result is slightly more accurate, and no worry about divide by zero. log1p(X) = ln(1 + X)  (X + 1  1  X) / (X + 1) Example: log1p(X = 1.23456789e6) 1.23456789 [EEX] 6 [CHS] [Enter] ; X value [Enter] 1 + 1  [X<>Y]  [CHS] ; epsilon => 4.3211e10 [LstX] 1 + ÷ ; correction to epsilon => 4.321094e10 [LstX] [LN] ; LN(1+X) => 1.234999237e6 + ; log1p(X) => 1.234567128e6 (all digits correct) 

01312019, 04:08 AM
Post: #2




RE: (12C) log1p function
From HP15C Advanced Functions Handbook
Level 1: Correctly Rounded, or Nearly So This trick is used e.g. in Accurate TVM for HP 35s and was adapted for the HP15C and the HP34C. Code: 01 ENTER Example: 1.23456789 EEX 6 CHS R/S 0.000001235 CLEAR PREFIX 1234567127 Cheers Thomas 

01312019, 05:48 AM
Post: #3




RE: (12C) log1p function
This is how the WP 34S does this computation. One of Kahan's clever algorithms I believe.
 Pauli 

01312019, 08:45 AM
(This post was last modified: 01312019 09:03 AM by Dieter.)
Post: #4




RE: (12C) log1p function
(01312019 01:10 AM)Albert Chan Wrote: This trick is from John D Cook's Tricks for computing log(1+X) What about this one: http://www.hpmuseum.org/forum/thread1072.html But the key sequence you posted is not correct. There must be a second [ENTER] at the beginning and the end it's [LSTx] [LN] (without the "1"). Dieter 

01312019, 09:42 AM
Post: #5




RE: (12C) log1p function
Hi, Dieter
Typo fixed. Thanks. A (quite) accurate ln1+x function, or "how close can you get" part II thread had the same formula. Was there a part I ? My rpn.exe confirmed +correction way much better, and avoided divideby0 test. Quote:>rpn 

01312019, 09:43 PM
(This post was last modified: 01312019 09:46 PM by Dieter.)
Post: #6




RE: (12C) log1p function
(01312019 09:42 AM)Albert Chan Wrote: Typo fixed. Thanks. The second "Enter" at the beginning is still missing. Without it the code will not work. (01312019 09:42 AM)Albert Chan Wrote: A (quite) accurate ln1+x function, or "how close can you get" part II thread had the same formula. Yes, but that was about Bernoulli numbers: http://www.hpmuseum.org/forum/thread870.html But I also posted a similar method for the e^x–1 function: http://www.hpmuseum.org/forum/thread5508.html (01312019 09:42 AM)Albert Chan Wrote: My rpn.exe confirmed +correction way much better, and avoided divideby0 test. Please excuse me, Albert, but this is one more case where I see a lot of numbers and cryptic code, but I don't understand anything. Who may understand the meaning of "r 1+ =10 s2 ? log s3 ? # 1+X, LN(1+X) value" ? Dieter 

01312019, 10:55 PM
(This post was last modified: 02012019 01:02 PM by Albert Chan.)
Post: #7




RE: (12C) log1p function
Hi, Dieter
2 Enters are there, but on 2 lines. First one after value entered. Regarding the cryptic commands, it was for my own toy rpn program. s for save memory, default to 0 r for recall memory, default to 0 = is round to digits, minus sign meant only for this number, otherwise globally # is starting comment, and ignored until endofline ? is display top of stack, default round to globally set digits (default 40) Code: RPN.EXE command HP12C keys (approx.) 

01312019, 11:13 PM
Post: #8




RE: (12C) log1p function
.
Hi, Dieter: (01312019 09:43 PM)Dieter Wrote: [...]I don't understand anything. Who may understand the meaning of "r 1+ =10 s2 ? log s3 ? # 1+X, LN(1+X) value" ? Probably the same people who understands "UNROT OVER SWAP * DUP OBJ\> DROP2 / 4. ROLL" ... (actual code, not made up) Regards. V. . Find All My HPrelated Materials here: Valentin Albillo's HP Collection 

02012019, 07:07 AM
Post: #9




RE: (12C) log1p function  
02012019, 12:30 PM
(This post was last modified: 02032019 02:28 AM by Albert Chan.)
Post: #10




RE: (12C) log1p function
Hi Werner
Typo fixed. Thanks Y = 1+X, approximately eps = (Y  1  X) Z = eps / Y ; correction to eps correction = LN(1+X, exactly)  LN(1+X, approximately) = LN(Y + eps)  LN(Y) = LN(1 + eps/Y) = LN(1 + Z) = Z  Z²/2 + Z³/3 ... > log1p(X) ~ LN(Y)  (Y1X)/Y 

02022019, 12:28 PM
Post: #11




RE: (12C) log1p function
(01312019 11:13 PM)Valentin Albillo Wrote: Probably the same people who understands "UNROT OVER SWAP * DUP OBJ\> DROP2 / 4. ROLL" ... (actual code, not made up) That's from DavidM's solution in your recent thread [VA] SRC#003 New Year 2019 Special: (01172019 06:04 PM)DavidM Wrote: A similar approach using Thomas' first optimization: As always the context makes it easier to understand what a program does. Using a local variable M for the constant matrix might help as well: Code: « → M But nah, I didn't understand Albert Chan's cryptic commands until he explained them. Cheers Thomas 

02102019, 09:08 AM
(This post was last modified: 06142019 12:14 PM by Albert Chan.)
Post: #12




RE: (12C) log1p function
Dieter's asinh formula look very nice: log1p(x) = asinh ( (x²+2x)/(2x+2) ) = asinh(x  x/(2+2/x))
We can create another version, using this nicely symmetrical relation: atanh(sin(z)) = asinh(tan(z)) log1p(x) = 2 atan( x/(x+2) ) = 2 asinh( x/ √((x+2)²  x²) ) log1p(x) = 2 asinh ( x/√(4x+4) ) 

02102019, 02:19 PM
(This post was last modified: 02112019 02:48 AM by Albert Chan.)
Post: #13




RE: (12C) log1p function
Using relation again: atanh(sin(z)) = asinh(tan(z))
Assume x positive, but close to 0 atanh( 1x ) = asinh( (1x) / √(2xx²) ) atanh( x1 ) = atanh( 1x ) Example, x = 1.2345678e9, using Casio FX115MS, showing internal digits: atanh( 1x ) = atanh(0.999999998766) = 10.6030760457 asinh( (1x) / √(2xx²) ) = asinh(20124.612604) = 10.6028460338 (all digits correct) Edit: another way, also very good: atanh( 1x ) = ½ ln(2/x  1) 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)