Post Reply 
What comes next?
10-19-2024, 12:03 AM
Post: #41
RE: What comes next?
Yes, I think so.
At least the following works with the HP-48:
Code:
DIR
  LST
    \<< DUP SIZE GET
    \>>
  NEXT?
    \<< DUP LST SWAP \GDLIST DUP SIZE 1 >
      \<< NEXT?
      \>> IFT ADD
    \>>
END
Find all posts by this user
Quote this message in a reply
10-19-2024, 12:03 AM (This post was last modified: 10-19-2024 12:10 AM by FLISZT.)
Post: #42
RE: What comes next?
(10-18-2024 10:49 PM)Gil Wrote:  Is really the above code complete as lastly written by Gilles?

Yes, it does (tested with the list given above).
As I don't have newRPL, I simply replaced RHEAD with Last from the GoferList library.

Edit: I replaced + by ADD too.

Several answers at the same time! Smile

Bruno
Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G
Find all posts by this user
Quote this message in a reply
10-19-2024, 12:17 AM
Post: #43
RE: What comes next?
Also the following works:
Code:
\<< DUP LST SWAP \GDLIST DUP SIZE 1 > :: NEXT? IFT ADD
\>>
Find all posts by this user
Quote this message in a reply
10-19-2024, 01:00 AM
Post: #44
RE: What comes next?
I changed the + sign at the end with ADD and it works perfectly now.


Thanks
Find all posts by this user
Quote this message in a reply
10-19-2024, 01:29 AM
Post: #45
RE: What comes next?
(10-15-2024 01:34 PM)Gil Wrote:  what is the code algorithm you used in your first post to get the binomial coefficient ?

We don't need binomial coefficients for next number.

Operator E, Ek f = f(x+k)
Operator ∇, ∇ f = f(x) - f(x-1) = (1 - E-1) f

∇ = 1 - E-1
E = 1/(1-∇) = 1 + ∇ + ∇² + ∇³ + ...

If we do polynomial fit, next number is simply sum of all the backward differences.
This is why sum of below red numbers gives next number.

(10-08-2024 02:31 PM)Thomas Klemm Wrote:  Instead of the red numbers of Post #7 the following red numbers are stored:

\(
\begin{matrix}
U &: & 0 & & 1 & & 4 & & 10 & & {\color{Red} {20}} & & 35 & & 56 & & \cdots \\
\Delta U &: & & 1 & & 3 & & 6 & & {\color{Red} {10}} & & 15 & & 21 & & \cdots & \\
\Delta^2 U &: & & & 2 & & 3 & & {\color{Red} {4}} & & 5 & & 6 & & \cdots & & \\
\Delta^3 U &: & & & & 1 & & {\color{Red} {1}} & & 1 & & 1 & & \cdots & & & \\
\Delta^4 U &: & & & & & {\color{Red} {0}} & & 0 & & 0 & & \cdots & & & & \\
\cdots &: & & & & & & & \cdots
\end{matrix}
\)

Only if we want a general formula, binomial coefficients is needed.

E^n = (1-∇)^-n = 1 + comb(n,1) ∇ + comb(n+1,2) ∇² + comb(n+2,3) ∇³ + ...

Example, from red numbers, to get next of next number --> n=2

20 + comb(2,1)*10 + comb(3,2)*4 + comb(4,3)*1 = 20 + 2*10 + 3*4 + 4*1 = 56
Find all posts by this user
Quote this message in a reply
10-19-2024, 08:12 AM
Post: #46
RE: What comes next?
Now this is a bit off topic, but the same method can be used to calculate square roots.
To calculate \(\sqrt{a}\), we use NEXT to calculate consecutive values of \(f(x)=x^2-a\).
Once we overshoot, we go BACK one step, ZOOM in and rinse and repeat.
This is the digit by digit method being used in most HP calculators.

This program is for the HP-42S:
Code:
00 { 129-Byte Prgm }
01▸LBL "ROOT"
02 XEQ "INIT"
03 12
04 STO 00
05▸LBL 00
06 XEQ "NEXT"
07 X≤0?
08 GTO 00
09 XEQ "BACK"
10 XEQ "ZOOM"
11 DSE 00
12 GTO 00
13 RCL 02
14 RCL 01
15 +
16 RTN
17▸LBL "INIT"
18 -2
19 ÷
20 STO 03
21 -0.5
22 STO 02
23 1
24 STO 01
25 RTN
26▸LBL "NEXT"
27 RCL 01
28 RCL+ 02
29 STO 02
30 RCL+ 03
31 STO 03
32 RTN
33▸LBL "BACK"
34 RCL 02
35 STO- 03
36 RCL 01
37 STO- 02
38 RCL 03
39 RTN
40▸LBL "ZOOM"
41 10
42 STO× 03
43 STO÷ 01
44 4.5
45 RCL× 01
46 STO+ 02
47 END

Example

41 XEQ "ROOT"
6.40312423743(05)


But this can also be done manually:

41 XEQ "INIT"

XEQ "NEXT"
-20

XEQ "NEXT"
-18.5

XEQ "NEXT"
-16

XEQ "NEXT"
-12.5

XEQ "NEXT"
-8

XEQ "NEXT"
-2.5

XEQ "NEXT"
4

XEQ "BACK"
-2.5

XEQ "ZOOM"

(…)
Find all posts by this user
Quote this message in a reply
10-19-2024, 06:08 PM (This post was last modified: 10-19-2024 06:10 PM by Gil.)
Post: #47
RE: What comes next?
Binomial Coefficient in x
Nice to get the next number and, as does my program, an underlying polynomial as shown in post 20.
Find all posts by this user
Quote this message in a reply
10-19-2024, 09:09 PM
Post: #48
RE: What comes next?
(10-19-2024 08:12 AM)Thomas Klemm Wrote:  Now this is a bit off topic, but the same method can be used to calculate square roots.
To calculate \(\sqrt{a}\), we use NEXT to calculate consecutive values of \(f(x)=x^2-a\).

Just to clear up confusion, f(x) = k*(x^2-a), where k start at 0.5, scale-up by 10 for each correct x digit.

Initially, f = 0.5*(x^2-a), ∇f = x-0.5, ∇²f = 1

This is the reason for INIT setup, at x=0:
M03 = f = -0.5*a
M02 = ∇f = -0.5
M01 = ∇²f = 1

Example, if we do √41 manually, digit by digit, we have:

f(x=6) = 0.5*(6^2 - 41) = -0.5*41 + 0.5 + 1.5 + 2.5 + 3.5 + 4.5 + 5.5 = -2.5
f(x=6.4) = 5*(6.4^2 - 41) = -25 + 6.05 + 6.15 + 6.25 + 6.35 = -0.2
f(x=6.40) = 50*(6.40^2 - 41) = -2
f(x=6.403) = 500*(6.403^2 - 41) = -20 + 6.4005 + 6.4015 + 6.4025 = -0.7955
...

This is similar to HP calculator, but not quite.
Calculator sqrt algorithm scale F by 100 for each correct digit, to keep ∇²F = 1, all the time.

F(X=6) = -2.5
F(X=64) = -250 + 60.5 + 61.5 + 62.5 + 63.5 = -2
F(X=640) = -200
F(X=6403) = -20000 + 6400.5 + 6401.5 + 6402.5 = -795.5
...

https://www.hpmuseum.org/forum/thread-17...#pid152220
Find all posts by this user
Quote this message in a reply
10-19-2024, 11:25 PM
Post: #49
RE: What comes next?
A few links related to calculating the square root in HP calculators:
I find it interesting that with the correct setup the main loop is just these instructions:
Code:
 501   L01250:  .1111...1.                      sqt15:  c + 1 -> c[p]
 502   L01251:  11.1..111.                      sqt16:  a - c -> a[w]
 503   L01252:  1.1.1...11  -> L01250                   if no carry go to sqt15
Find all posts by this user
Quote this message in a reply
10-20-2024, 08:44 PM
Post: #50
RE: What comes next?
(10-19-2024 09:09 PM)Albert Chan Wrote:  Calculator sqrt algorithm scale F by 100 for each correct digit, to keep ∇²F = 1, all the time.

F(X=6) = -2.5
F(X=64) = -250 + 60.5 + 61.5 + 62.5 + 63.5 = -2
F(X=640) = -200
F(X=6403) = -20000 + 6400.5 + 6401.5 + 6402.5 = -795.5
...

https://www.hpmuseum.org/forum/thread-17...#pid152220

For each digit, we can stop if (F + ∇F + ∇²F) > 0, eliminate routine BACK

Stack Y = (-F) = -K*(x^2 - a)
Stack X = (∇F + ∇²F) = K*((2x-1) + 2) = K*(2x+1) = ΔF

Stop routine NEXT if stack X > Y
Initial setup, K=0.5, x=0 --> Stack Y, X = a/2, 1/2

Code:
00 { 100-Byte Prgm }
01▸LBL "ROOT"
02 12       
03 STO 00
04 10↑X     
05 STO 01
06 X<>Y
07 XEQ "INIT"
08▸LBL 00
09 XEQ "NEXT"
10 XEQ "ZOOM"
11 DSE 00
12 GTO 00
13 IP
14 RCL÷ 01
15 RTN

16▸LBL "INIT"
17 0.5
18 ×
19 LASTX
20 RTN

21▸LBL "NEXT"
22 X>Y?
23 RTN
24 -
25 LASTX
26 1
27 +
28 GTO "NEXT"

29▸LBL "ZOOM"
30 10
31 STO× ST Z
32 STO× ST Z
33 ×
34 4.5
35 -
36 END

41 XEQ "ROOT"      → 6.40312423743

Here, we do √41 manually, digit by digit.

Code:
41
XEQ "INIT"      --> Y=20.5  , X=0.5
XEQ "NEXT"      --> Y=2.5   , X=6.5
XEQ "ZOOM"      --> Y=250   , X=60.5
XEQ "NEXT"      --> Y=2     , X=64.5
XEQ "ZOOM"      --> Y=200   , X=640.5
XEQ "NEXT"      --> Y=200   , X=640.5
XEQ "ZOOM"      --> Y=20000 , X=6400.5
XEQ "NEXT"      --> Y=795.5 , X=6403.5
...
Find all posts by this user
Quote this message in a reply
10-20-2024, 09:39 PM (This post was last modified: 10-20-2024 09:43 PM by Thomas Klemm.)
Post: #51
RE: What comes next?
(10-19-2024 11:25 PM)Thomas Klemm Wrote:  
Code:
 501   L01250:  .1111...1.                      sqt15:  c + 1 -> c[p]
 502   L01251:  11.1..111.                      sqt16:  a - c -> a[w]
 503   L01252:  1.1.1...11  -> L01250                   if no carry go to sqt15

Compare this to the corresponding code of the TI-57:
Code:
0x0655: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF 
0x0656: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF 
0x0657: 0x0308  LOAD    A,A+B,000F FFFF FFFF FFFF 
0x0658: 0x0385  LOAD    NUL,C-A,000F FFFF FFFF FFFF 
0x0659: 0x1a55  BRNC    0x0655

Two subtractions instead of one and then another one to check the carry.
Find all posts by this user
Quote this message in a reply
Post Reply 




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