hp15c
this model was one pioneering the implementation of solve and integrate numerically, i think the first was the hp34. the implementations used several tricks to make these operations stable. for example, using a modified romberg method for quadrature in order to track the error and avoid sampling the function at its endpoints. error tracking meant that the machine knew if its answer was on track or just garbage. its biggest drawback was performance. programs ran too slow. this hampered the integrate and solve features because 30 seconds might only allow something like 15 samples which makes quadrature accuracy tricky. despite this, a lot could be achieved. the manual and the advanced functions handbook (well worth a read) showed how the user could manually rearrange harder problems so that the machine could get a quicker answer. for example by splitting up the range of definite integration or by variable substitution. later, brute force took over and a simple implementation of simpson's rule can often suffice (see fx-3900pv and the torture test). even some later hp models take this route (eg hp20s). example programhere is an example program for the 15c. routine `A' tries to determine if the currently displayed number (ie in X) is prime. it returns 1 if prime, 0 if composite. lblA fix0 sto1 2 x>y? gto3 x=y? gto4 0 sto6 sto8 rcl1 1 - sto7 lbl5 rcl7 rcl7 2 / int sto9 2 * x<>y? gto6 1 sto+6 rcl9 sto7 gto5 lbl6 rcl6 x=0? gto3 1 sto-6 lbl7 2 sto+8 rcl8 7 x=y? gto4 3 - x=y? dse8 rcl8 sto2 rcl1 x=y? gto4 1 sto3 rcl7 sto9 lbl8 rcl9 rcl9 2 / int sto9 2 * x<>y? gsbB rcl9 x=0? gto.0 rcl3 sto0 rcl2 sto3 gsbB sto2 rcl0 sto3 gto8 lbl.0 rcl3 1 x=y? gto7 chs rcl1 + x=y? gto7 rcl6 sto9 lbl.1 rcl9 x=0? gto3 rcl3 sto2 gsbB rcl1 1 - x=y? gto7 1 sto-9 gto.1 lbl4 1 rtn lbl3 0 rtn lblB rcl2 rcl3 * rcl1 / frac rcl1 * rnd sto3 rtn this is an attempt to implement the rabin-miller strong pseudoprime test. using bases 2, 3 and 5. the first strong pseudoprime concurrent to all three bases is 25,326,001. the program should be modified to reject this special case. however subroutine `B' limits the possible input range to x < 10^6 because it requires computing x*y (mod m) and so the given exception is out of range. unfortunately x*y (mod m) is a tricky problem when x, y & m can be your machine precision. see the secret life of the mod function. it is possible, however, by writing your own multiply, thus, lblB rcl2 sto5 0 sto4 lbl1 rcl3 rcl3 2 / int sto3 2 * x==y? gto.3 rcl5 sto+4 rcl4 rcl1 x<y? sto-4 lbl.3 rcl3 x==0? gto2 2 sto*5 rcl5 rcl1 x<y? sto-5 gto1 lbl2 rcl4 sto3 rtn this has the same effect as the original lblB routine above, but the multiply is written out so as to affect the modulo as it goes and thus prevent overflow. the bad news. its too slow for the 15c. in theory it should cope with larger numbers, the practice is that it gets too slow to be useful as the numbers increase in magnitude. |