HP Forums
Prime and Saturn calculators - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: Prime and Saturn calculators (/thread-21995.html)



Prime and Saturn calculators - dm319 - 07-05-2024 06:37 PM

One of things I found from my dive into TVM solvers was that the Saturn-based calculators I looked at returned almost identical 12 digit results. These had a distinctive profile of results (which was different to the HP-12c platinum).

What surprised me was that the HP Prime also returned (pretty much) identical results, which implies to me that it may emulate the same 15/12 digit architecture as well as the same TVM algorithms.

But this doesn't marry up with the HP-prime apparently not emulating the Saturn machines.

Does anyone know if the HP-Prime does emulate some aspects of the Saturn calculators?


RE: Prime and Saturn calculators - Steve Simpkin - 07-05-2024 06:56 PM

I recall Cyrille De Brébisson mentioning that they had recreated the Saturn math library in C for use in their more modern calculators that did not use Saturn emulation like the HP 39gII and the HP Prime. I believe that Home mode on the HP Prime utilizes this library which is why it has the same forensic results as Saturn-based models.

Edit: Here is a reference from Cyrille mentioning the recreating of the math library.
https://www.hpmuseum.org/forum/thread-14061-post-124770.html#pid124770


RE: Prime and Saturn calculators - Didier Lachieze - 07-05-2024 07:05 PM

(07-05-2024 06:56 PM)Steve Simpkin Wrote:  I recall Cyrille De Brébisson mentioning that they had recreated the Saturn math library in C (or C++)

Yes, this was done for the HP 20b/30b and then reused in the Prime as explained by Cyrille here.

Another nice quote from Cyrille:
Quote: Apart from the 38/48 series calculators, none of the ACO and later calculators are RPL based (starting with the newer 10BII, 17Bs, 32SII, 35...)
They are all developed in C, using a math library which is a "copy" in C of the math library used in the 95LX, which is itself a copy in Intel ASM of the saturn one...
Unfortunately, it is a a rather simplistic implementation, based, somewhat on a virtual implementation of the Saturn CPU. So it is slow as hell...
In 2004 or so, when it became clear that we would be working more and more with ARM chips for low end calcs, I recreated the whole math library in C, but as a recreation based on the code rather than a copy. This library is what is used in Prime and a couple of other calcs...



RE: Prime and Saturn calculators - dm319 - 07-05-2024 07:57 PM

That's very interesting! I wonder how deep the emulation goes - I would have thought it would need to emulate the 15 digit BCD to give the pretty much identical results, but I could be wrong about that.

So when the most recent Prime was introduced in 2018, it was using 31 year old code, now 37 years.

I see further down that second thread that someone mentions the HP-12c source code went missing. I wonder if that was before or after the HP-12c platinum, which shares some similarities to the original HP-12c, but seems to work on a 12 digit platform.


RE: Prime and Saturn calculators - Steve Simpkin - 07-05-2024 10:13 PM

(07-05-2024 07:57 PM)dm319 Wrote:  That's very interesting! I wonder how deep the emulation goes - I would have thought it would need to emulate the 15 digit BCD to give the pretty much identical results, but I could be wrong about that.

So when the most recent Prime was introduced in 2018, it was using 31 year old code, now 37 years.

I see further down that second thread that someone mentions the HP-12c source code went missing. I wonder if that was before or after the HP-12c platinum, which shares some similarities to the original HP-12c, but seems to work on a 12 digit platform.

I don't believe any of the math code used in the HP Prime is that old. My understanding it that it was entirely new code written to mimic the behavior of the original Saturn math libraries.

"In 2004 or so, when it became clear that we would be working more and more with ARM chips for low end calcs, I recreated the whole math library in C, but as a recreation based on the code rather than a copy. This library is what is used in Prime and a couple of other calcs..."

The math library and algorithms used in the HP-12C Platinum was not written by HP at all. HP provided a detailed set of specifications for the functionality of the HP-12C Platinum and its form factor to an outside contractor (perhaps Kinpo Electronics). That company then designed the calculator circuitry, hardware, wrote the software and manufactured the calculator for HP. The HP 33s and HP 35s went through a similar process. They are all using a variations of a Sunplus CPU which has a core based on the 6502 microprocessor.
https://en.wikipedia.org/wiki/HP-12C#HP_12c_Platinum_/_Prestige
https://en.wikipedia.org/wiki/HP_33s
https://en.wikipedia.org/wiki/HP_35s


RE: Prime and Saturn calculators - dm319 - 07-06-2024 12:03 AM

Ok, maybe not exactly that code, but a faithful recreation of it!

I've heard that about the 12-c platinum and Kinpo, but I find it hard to believe. If you look at the result for puzzle 4, it reflects exactly the result from the other Saturn models. It fails on 5 and 6, but then on puzzle 7 it returns a result similarly impressively to the regular HP-12c. It looks like it has the underlying calculating architecture of the Saturns and a similar solve-for-i as the Saturns or HP-12c.


RE: Prime and Saturn calculators - dm319 - 07-06-2024 08:27 AM

(07-06-2024 12:03 AM)dm319 Wrote:  I've heard that about the 12-c platinum and Kinpo, but I find it hard to believe.

Been thinking about this more. Puzzle 4 is N = 480, I%YR = 0, PV = 100'000, FV = 0, solve for PMT. Then take result, put back into PMT, and attempt to calculate Interest rate, which should be 0.

These the results for puzzle 4:

Code:
| calculator                  | 4                                       |
|-----------------------------|-----------------------------------------|
| HP-80                       | ERR                                     |
| HP-70                       | -1.03950104e-9                          |
| HP-27                       | -1.039501039e-9                         |
| HP-22                       | -1.03950104e-9                          |
| HP-41CX Financial Decisions | 0                                       |
| HP-92                       | 0                                       |
| HP-37E                      | -1e-9                                   |
| HP-38E                      | -1e-9                                   |
| HP-12c                      | -7.983367984e-10                        |
| HP-12cp                     | -7.98336798336e-12                      |
| HP-12c comma                | ERR                                     |
| HP-10bII+                   | -7.98336798336e-12                      |
| HP-17B                      | -7.98336798336e-12                      |
| HP-17BII                    | -7.98336798336e-12                      |
| HP-17BII+ mk1               | -7.98336798336e-12                      |
| HP-17BII+ mk2               | -7.98336798336e-12                      |
| HP-19BII                    | -7.98336798336e-12                      |
| HP-20b                      | -7.98336798336e-12                      |
| HP-30b                      | -7.98336798336e-12                      |
| HP-50G                      | -7.98336798336e-12                      |
| HP Prime 2.1.14730          | -7.98336798336e-12                      |
| Casio FC-200                | -8.316008316e-13                        |
| Sharp EL-735                | 0                                       |
| Sharp PC-1403H HPF 188177   | 0                                       |
| Sharp PC-1421               | ERR                                     |
| Victor V12                  | ERR                                     |
| BWK Business                | -0.000019581                            |
| RPN83P v0.9.0               | 0                                       |
| RPN83P v0.12.0 RC2          | 0                                       |
| RPN83P v0.12.0              | 0                                       |
| TI-83 Plus                  | 0                                       |
| TI BA II Plus Professional  | -6.652807e-14                           |
| NSTK TVM V5                 | 4.584636057662297410319999999999998e-10 |
| NSTK TVM V6                 | 0                                       |
| Plus42 1.1.9                | 0                                       |
| C47 1531f1cb2               | ERR                                     |
| C47 eadc4507f               | -3.75935122288958926199999999999999e-19 |
| NSTK TVM V8                 | 0                                       |
| R Rmpfr                     |                                         |
| Ref                         | 0                                       |
| WP43 0.25.2                 | ERR                                     |
| Casio FC-100V               | ERR                                     |
| Casio FC-200V               | ERR                                     |

The Saturns all get the same result, which to me suggests the same algorithm, same starting values and stopping criteria, and same rounding behaviour in each iteration. The HP-12c is very similar which suggests to me it uses the same algorithm with less internal precision.

So if Kinpo were only given specifications for the solver, it must have been very specific! Or they weren't officially given the code, but somehow got hold of it? The HP-12c platinum is not exactly the same as the Saturns though - like the HP-12c it returns the ceiling of N rather than a fraction, and for problem 7 returns a very similar result to the HP-12c.


RE: Prime and Saturn calculators - Steve Simpkin - 07-06-2024 12:33 PM

A bit of a clue regarding the HP-12C Platinum coding from Cyrille De Brébisson.

">7 12C Platinum ... Sunplus SPLB20D2 (6502) ... Emulation?
Nope, the sunplus are a "brand new implementation" copying the original 12C UI. It is all C based. I do not remember if they use the math code that was developped for the 10BII or not."

https://www.hpmuseum.org/forum/thread-5180-post-99434.html#pid99434

Some more clues about the Platinum:

https://en.wikipedia.org/wiki/HP-12C#HP_12c_Platinum_/_Prestige

https://www.hpcc.org/datafile/V22N3/platinum.pdf


RE: Prime and Saturn calculators - dm319 - 07-06-2024 02:29 PM

It's odd I guess. I suppose Cyrille leaves open the possibility of code use from another machine.

The article on the HP-12c platinum is fairly negative. At least on my TVM tests, the HP-12c platinum roundly surpasses the accuracy of the HP-12c on every test. One criticism I have of the platinum is that it replicated the solve-for-N behaviour of HP-12c. For whatever reason the solve-for-i for tiny i is better on the HP-12c platinum (and hp-12c) than the Saturns.

Despite losing out on the Saturn machines due to the solve-for-N behaviour, the platinum more than makes up it by doing a bit better on solve-for-i, which means (as tested) it is the most accurate financial calculator HP has made.


RE: Prime and Saturn calculators - Albert Chan - 07-06-2024 04:57 PM

(07-06-2024 08:27 AM)dm319 Wrote:  The Saturns all get the same result, which to me suggests the same algorithm, same starting values and stopping criteria, and same rounding behaviour in each iteration. The HP-12c is very similar which suggests to me it uses the same algorithm with less internal precision.

No, results are close because they are essentially correct.
You can only get algorithm "signature" if results are not correct.

Problem 4, starting with 0% rate, get payment M

>N=480 @ P=1E5 @ M=P/-N
>M
-208.333333333

M has error of -1/3 ULP, where ULP = 1E-9, back solve for rate will not get back 0%

error = exact - approx
approx = exact - error

C = n*pmt/-pv = n*(pv/-n - (ulp error)) / -pv = 1 - n*(ulp error) / -pv
C-1 = n*(ulp error) / pv

>C1 = N * 1E-9/-3 / P
>C1 ! tiny compounding effect
-1.6E-12

With tiny compounding effect, we can approximate C as linear.

C = i*n/(1-(1+i)^-n) = 1 + (n+1)/2*i + (n^2-1)/12*i^2 - (n^2-1)/24*i^3 + ...
C-1 ≈ (n+1)/2 * i

>I = C1 / ((n+1)/2)
>I * 1200 ! APR %
-7.98336798337E-12

Or, add quadratic effect, but without solving quadratics

C-1 ≈ (n+1)/2*i / (1 - (n-1)/6*i

>I = C1 / ((n+1)/2 + C1*(n-1)/6)
>I * 1200
-7.98336798337E-12

HP12C, 10 digits instead of 12, ULP size is 100 times bigger --> rate also 100 times bigger.


RE: Prime and Saturn calculators - dm319 - 07-06-2024 05:31 PM

Oh good point Albert!

What about problem 7? Any ideas why the HP-12c gets closer to the result but the Saturns don't?


RE: Prime and Saturn calculators - dm319 - 07-06-2024 06:22 PM

Sorry forgot to include problem 7 (which is your one!).
N = 10, PV = -100, PMT = 10, FV = 1.e-10, P/YR = 12, solve for i.

Code:
| calculator                  | 7                                        |
|-----------------------------|------------------------------------------|
| HP-80                       | ERR                                      |
| HP-70                       | ERR                                      |
| HP-27                       | ERR                                      |
| HP-22                       | ERR                                      |
| HP-41CX Financial Decisions | 0                                        |
| HP-92                       | 0                                        |
| HP-37E                      | 0                                        |
| HP-38E                      | 0                                        |
| HP-12c                      | 2.181818182e-10                          |
| HP-12cp                     | 2.18181818182e-10                        |
| HP-12c comma                | ERR                                      |
| HP-10bII+                   | 2.16e-10                                 |
| HP-17B                      | 2.16987100416e-10                        |
| HP-17BII                    | 2.16e-10                                 |
| HP-17BII+ mk1               | 2.16e-10                                 |
| HP-17BII+ mk2               | 2.16e-10                                 |
| HP-19BII                    | 2.16e-10                                 |
| HP-20b                      | 2.16e-10                                 |
| HP-30b                      | 2.16e-10                                 |
| HP-50G                      | 2.16278831114e-10                        |
| HP Prime 2.1.14730          | 2.16e-10                                 |
| Casio FC-200                | 2.181818182e-10                          |
| Sharp EL-735                | 0                                        |
| Sharp PC-1403H HPF 188177   | 0                                        |
| Sharp PC-1421               | 0                                        |
| Victor V12                  | ERR                                      |
| BWK Business                | 0                                        |
| RPN83P v0.9.0               | 2.2191952055123e-10                      |
| RPN83P v0.12.0 RC2          | 2.1818181818159e-10                      |
| RPN83P v0.12.0              | 2.1818181818159e-10                      |
| TI-83 Plus                  | 2.181818181858e-10                       |
| TI BA II Plus Professional  | 2.181818e-10                             |
| NSTK TVM V5                 | 2.181818181976061618063772094675914e-10  |
| NSTK TVM V6                 | 2.181818181815801652892599238858506e-10  |
| Plus42 1.1.9                | 2.181818181815801652892155741905381e-10  |
| C47 1531f1cb2               | 2.181818181815806921160850718651876e-10  |
| C47 eadc4507f               | 2.18181818181580062818816748324244e-10   |
| NSTK TVM V8                 | 2.181818181815801652892599238858506e-10  |
| R Rmpfr                     | 2.1818181818158016528925658782870022e-10 |
| Ref                         | 2.1818181818158016528925658782870022e-10 |
| WP43 0.25.2                 | 2.181818181815806921160850718651876e-10  |
| Casio FC-100V               | ERR                                      |
| Casio FC-200V               | ERR                                      |



RE: Prime and Saturn calculators - Albert Chan - 07-06-2024 10:44 PM

(07-06-2024 05:31 PM)dm319 Wrote:  What about problem 7? Any ideas why the HP-12c gets closer to the result but the Saturns don't?

I think it is just luck, perhaps 0 was stored in I as guess, before solving rate.

HP12C: N=10, PV=-100, PMT=10, FV=1E-10

1E-4 [I] [I] -->  5.322034956E-11, [12x] -->  6.386441947E-10
1E-8 [I] [I] --> -1.400000000E-18, [12x] --> -1.680000000E-17
0      [I] [I] -->  1.818181818E-11, [12x] -->  2.181818182E-10

HP-12c internals is still a mystery ... Why would it overshoot to negative rate?

With little compounding effect, curve is practically a straight line (col 3 = npmt slope)
Also, there is very little difference among curves NPV, NPMT, NFV. (they overlap when plotted!)

Code:
lua> n,pv,pmt,fv = 10, -100e10, 10e10, 1 -- scaled so fv=1
lua> tvm(n,0,pv,pmt,fv, true)
0                       0.1                     -550000000000.45
1.8181818181803308e-13  -2.7269853042355408e-14 -550000000000.75
1.818181818179835e-13   0                       -550000000000.75
1.818181818179835e-13
lua> _ * 1200
2.181818181815802e-10



RE: Prime and Saturn calculators - dm319 - 07-07-2024 10:11 AM

That's very interesting. For testing the machines (if able to) I reset the registers, so yes it would have been 0. I was going to say that the HP-12c does seem to accept a guess and the HP-12c platinum doesn't, but going back to my HP-12c platinum, it does seem to take a guess also. However, it does get the correct result with 1E-8 unlike the 12c.

The Saturns and Prime seem to return 2.16e-10 - which gives more weight to the Prime operating similarly to the Saturns. I don't think the Saturns take a guess.

However, the HP-12c platinum, even if you can't exactly treat problem 4 as a forensic result, does seem to operate very very similarly to the HP-12c with two extra digits. They are lined up very closely on that heatmap for what that's worth, and certainly closer in behaviour than other calculators imitating the 12c - like the Victor V12 and the HP-12c 'comma' (whether official or not).


RE: Prime and Saturn calculators - Albert Chan - 07-07-2024 01:37 PM

(07-06-2024 10:44 PM)Albert Chan Wrote:  HP-12c internals is still a mystery ... Why would it overshoot to negative rate?

Here is plot of {NPV, NPMT, NFV}, rate = ± 10%
Curves practically overlap when rate are tiny.

plot {
  ((1e-10-10/x)*((1+x)^-10-1)+(-100+1e-10)),
  (((-100+1e-10)/((1+x)^10-1)-100)*x+10)*10,
  ((-100+10/x)*((1+x)^10-1) + (-100+1e-10))
}, x = -0.1 .. 0.1


Unlike NPMT or NFV, NPV is concaved up.
Rate guess from the right, NPV=0 with Newton's method may overshoot, even to negative rate.
But, overshoot should occur only once, which means we won't notice.

We see the issue with NPV zoom-in (±1e-6%). Line look like a smudge.
This explained why we observed multiple overshoots, even to final iteration.

plot {((1e-10-10/x)*((1+x)^-10-1)+(-100+1e-10))}, x = -1e-8 .. 1e-8

With good expm1/log1p, fuzziness will be lessened, but still a smudge.
If rate=0, formula resulted in nan. This is why small rate branch is needed.


RE: Prime and Saturn calculators - dm319 - 07-07-2024 08:24 PM

So I think you've deduced the HP-12c uses the NPV formula?

I can't prod the HP-12c platinum into getting a negative result, but the result does vary depending on what was input into i to begin with. Maybe they extended the stopping criteria as they had more performance to work with?


RE: Prime and Saturn calculators - Albert Chan - 07-09-2024 12:26 PM

(07-07-2024 08:24 PM)dm319 Wrote:  So I think you've deduced the HP-12c uses the NPV formula?

NPV=0 is in HP-12c manual, Appendix D, formulas used.

Quote:I can't prod the HP-12c platinum into getting a negative result, but the result does vary depending on what was input into i to begin with. Maybe they extended the stopping criteria as they had more performance to work with?

HP-12cp has internal 15 digits, whereas HP-12c has 13.
This may be a case of solving problem by throwing precisions to it.

(07-07-2024 01:37 PM)Albert Chan Wrote:  With good expm1/log1p, fuzziness will be lessened, but still a smudge.
If rate=0, formula resulted in nan. This is why small rate branch is needed.

Let EFF(i,n) = (1+i)^n - 1, but accurately evaluated using expm1/log1p

Effect is gradual, but this will still get in trouble with small rate.
If EFF(i,n) ≈ i*n, formulas (NPV,NPMT,NFV} totally breaks down.

f = NPMT/n = ((pv+fv)/EFF(i,n) + pv)*i + pmt ≈ (pv+fv+n*pmt)/n + pv*i

Without solving for f=0, formula cannot be correct.
Time reversed expression give different slope (+pi --> -fv), which make no sense.
BTW, these slopes are from i=∞ and -1, completely opposite of small rate!

With small rate formula, {n,pv,fv} ↔ {-n,-fv,-pv} time reversal make no difference.

f = (pv+fv+n*pmt)/n + ((pv+fv)/n+(pv-fv))/2*i + (pv+fv)/n*(n²-1)/12*i^2 + ...