Programming Exercise (HP-15C, 15C LE - and others)
|
03-22-2014, 09:47 PM
Post: #21
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
42S:
Code: 00 { 20-Byte Prgm } Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
03-22-2014, 10:19 PM
(This post was last modified: 03-22-2014 10:20 PM by Dave Britten.)
Post: #22
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
Got a TI-95 in the mail today, and (naturally) had a go at this with the "new" machine:
Code: LBL 00 This ran in just a hair under 13 minutes. (Make sure you ASM it.) Some observations: The TI-95 sort of reminds me of an algebraic HP-41C. The ASM instruction is interesting in that it translates all label branches (GTL, SBL) into absolute addresses (GTO, SBR) in order to improve speed in programs that do a lot of tight looping and branching. You can reverse the process with INV ASM to make editing easier. The STO/RCL operations are one byte smaller when using the alpha-named registers, as opposed to their numeric names, but there doesn't seem to be any meaningful difference in execution speed. |
|||
03-23-2014, 12:36 AM
(This post was last modified: 04-01-2014 02:48 AM by Gerson W. Barbosa.)
Post: #23
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-22-2014 09:47 PM)Werner Wrote: 42S: 14 minutes 59 seconds on my HP-42S! The faster running time on the HP-20S can be explained by the higher perfomance index of the latter, according to this benchmark. The WP 34S version is about only 200 milliseconds slower than the fastest one so far: Code:
Cheers, Gerson. Edited to correct an error: 14 minutes 59 seconds, not 14.59 seconds. |
|||
03-23-2014, 01:31 AM
(This post was last modified: 03-23-2014 04:31 AM by Gerson W. Barbosa.)
Post: #24
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-22-2014 10:19 PM)Dave Britten Wrote: Got a TI-95 in the mail today, and (naturally) had a go at this with the "new" machine: This runs on the TI-57 with only minor modifications: Code:
Alas, no ASM instruction. 100 SBR 0 takes exactly 100 seconds and returns 0.6881722 (0.6881721794), or about 2 hours and 46 minutes for 10000 iterations. Regards, Gerson. ---------------------- 0.6930972 (0.6930971831), after 2 hours and 51 minutes. |
|||
03-23-2014, 08:54 AM
(This post was last modified: 03-23-2014 08:58 AM by RMollov.)
Post: #25
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-22-2014 12:47 PM)Gerson W. Barbosa Wrote: - it takes too long: 4 min 6 sec. Looks great, but the WP34s struggles. Mine turned itself off several times until eventually got to the end. I have Bit's Y register showing version on and wonder if that causes problems. It also shows result as 0.69309718306 but takes forever. iPhone emulator solves it in 11 secs. Interesting, after turning off I turn it on and R/S keeps it going. There is something dodgy with estimating batteries charge IMO. |
|||
03-23-2014, 08:59 AM
Post: #26
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-22-2014 03:02 AM)Gerson W. Barbosa Wrote: But we can easily break the 20-second barrier on the WP 34S Yet another idea is to combine two terms: \(\frac{1}{n}-\frac{1}{n+1}=\frac{1}{n(n+1)}\) Code: LBL A XEQ A Code: LBL B \(\sum\) B We don't have to deal with the alternating sign and it should be both faster and more accurate. Cheers Thomas |
|||
03-23-2014, 11:26 AM
Post: #27
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-23-2014 08:54 AM)RMollov Wrote: Looks great, but the WP34s struggles. ...There is something dodgy with estimating batteries charge IMO. Maybe the internal resistance of the batteries is a bit high so that the voltage drops under load to a point where the calculator shuts down. Try again with fresh batteries or switch the calculator to SLOW mode which limits the clock frequency to about half the maximum. This should remove some strain from the batteries. Marcus von Cube Wehrheim, Germany http://www.mvcsys.de http://wp34s.sf.net http://mvcsys.de/doc/basic-compare.html |
|||
03-23-2014, 01:49 PM
(This post was last modified: 03-23-2014 05:59 PM by Gerson W. Barbosa.)
Post: #28
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-23-2014 08:59 AM)Thomas Klemm Wrote:You've moved the time barrier to the 10-second line! 10.8 seconds, perhaps a few milliseconds less. The summation now takes about half the previous time, but still disappointly long: 2 min 5 sec.(03-22-2014 03:02 AM)Gerson W. Barbosa Wrote: But we can easily break the 20-second barrier on the WP 34S Cheers, Gerson. P.S.: Well, not item (b) of the exercise anymore, but if all we want is just computing the sum of the first ten thousand terms of the series then we can do it in one tenth of a second (one TICK) and eleven steps at most (LBL and END included), using information available in this thread. The result will be accurate to 20 digits in double precision mode. |
|||
03-25-2014, 11:27 AM
Post: #29
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
I ran this through my Casio fx9860G Slim:
Code:
This prints 0.6930971831 in just under a minute. It's definitely one of the faster models available. Too bad the interface design is so heavily modal - it's much too cumbersome for day-to-day use. I don't know why Casio has clung to that paradigm for so long. |
|||
03-25-2014, 03:50 PM
Post: #30
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
HP-4C, two terms per loop, but preserving the original fractions: Code:
0.6930971830, 32 min 9 sec. |
|||
03-25-2014, 09:11 PM
Post: #31
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-23-2014 01:49 PM)Gerson W. Barbosa Wrote: P.S.: Well, not item (b) of the exercise anymore, but if all we want is just computing the sum of the first ten thousand terms of the series then we can do it in one tenth of a second (one TICK) and eleven steps at most (LBL and END included), using information available in this thread. The result will be accurate to 20 digits in double precision mode. A proof can be found here: Pi, Euler Numbers, and Asymptotic Expansions Author(s): J. M. Borwein, P. B. Borwein, K. Dilcher Cheers Thomas |
|||
03-25-2014, 09:27 PM
Post: #32
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others) | |||
03-25-2014, 11:45 PM
(This post was last modified: 03-26-2014 02:47 AM by Gerson W. Barbosa.)
Post: #33
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-25-2014 09:27 PM)Thomas Klemm Wrote:I don't think so. I haven't tested it on the HP-41C, but this is faster on the WP 34S. BTW, shouldn't it be \[\frac{1}{n-1}-\frac{1}{n}=\frac{1}{n^{2}-n}\]?(03-25-2014 03:50 PM)Gerson W. Barbosa Wrote: 0.6930971830, 32 min 9 sec.Is that faster than combining the two terms: \(\frac{1}{n}-\frac{1}{n+1}=\frac{1}{n(n+1)}\) ? I just prefer the left side of the expression because it preserves the original terms: \[1-\frac{1}{2}+\frac{1}{3}-\frac{1}{4}+ \cdots +\frac{1}{9999}-\frac{1}{10000}\] If n = 4, for instance, then \[\frac{1}{3}-\frac{1}{4}\neq \frac{1}{12}\] on a 10-digit calculator ( 3 1/x 4 1/x 12 1/x - --> -3e-11 ). Cheers, Gerson. -------------- P.S.: HP-41C Code:
0.6930971831 (28 min 28 sec) |
|||
03-25-2014, 11:46 PM
Post: #34
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
on my HP50 with UBasic this take 5.5 Sec
Code:
result: UBasic v 0.2b (C) Suma =0.693097183 ready! press << ON >> |
|||
03-26-2014, 12:00 AM
Post: #35
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-25-2014 11:46 PM)churichuro Wrote: on my HP50 with UBasic this take 5.5 Sec Would you try Thomas Klemm's idea, that is, evaluating two terms per loop? Thanks! Code:
|
|||
03-26-2014, 02:22 AM
Post: #36
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-26-2014 12:00 AM)Gerson W. Barbosa Wrote: Would you try Thomas Klemm's idea, that is, evaluating two terms per loop? Thanks! Do this change: for no get error "Divide by zero" (well, this error but in spanish) for n=5000 to 2 step -1 get suma= 0.999800000 in about 3 sec if change to for n=10000 to 2 step -1 get suma= 0.999900000 in 5.5 sec |
|||
03-26-2014, 02:42 AM
Post: #37
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-26-2014 02:22 AM)churichuro Wrote:(03-26-2014 12:00 AM)Gerson W. Barbosa Wrote: Would you try Thomas Klemm's idea, that is, evaluating two terms per loop? Thanks! Oops! this should have been ... for n=10000 to 2 step -2 ... Sorry! |
|||
03-26-2014, 03:59 AM
Post: #38
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-25-2014 11:45 PM)Gerson W. Barbosa Wrote: If n = 4, for instance, then Since \(\frac{1}{n}\) and \(\frac{1}{n+1}\) are close we experience extinction when calculating the difference. Thus using \(\frac{1}{n(n+1)}\) is more accurate. Cheers Thomas |
|||
03-26-2014, 02:04 PM
Post: #39
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
Alright, I've managed to implement this on what may be the weakest possible machine that can still handle the algorithm: the Sinclair Cambridge Programmable. The manual is available on Katie's site, but allow me to summarize the notable points for this barely-programmable calculator:
1. Precision is awful. Trig functions are often only accurate to 2 or 3 figures. 2. There's no built-in PI constant, but you can get about 5 digits from 2 * arccos 0 (all trig functions operate in radians). Or just key it in manually for better accuracy. 3. There's no y^x operator. You have to do e^(y * ln x), and like trig, it isn't particularly accurate. 4. You only get 36 completely unmerged program steps to work with. About half the available operations require two steps because of the down-shift key. Constant entry requires an additional 'escape' key. 5. There's only a single storage register. Thankfully, there's an operator to exchange the display with the register, otherwise I don't think this would have been possible. 6. Branching is all absolute, and requires FOUR steps (shift, go to/go if neg, two-digit step number). 7. 'go if neg' is the only conditional test available. If the display is negative, it acts like go to, otherwise skips the next two steps (the line number). To use, enter the desired number of iterations (e.g. 10000) in the display, and press RUN. Code: 00 sto 100 iterations (50 actual passes through the loop) takes 18.5 seconds. A full run of 10000 iterations would clock in at about 30 minutes. |
|||
03-26-2014, 06:20 PM
Post: #40
|
|||
|
|||
RE: Programming Exercise (HP-15C, 15C LE - and others)
version for HP PRIME:
Code:
result in about 1 sec ! Suma=.693097183059 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)