Two tiny, simple, yet useful functions that I miss on the 34s  Printable Version + HP Forums (https://archived.hpcalc.org/museumforum) + Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum1.html) + Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum2.html) + Thread: Two tiny, simple, yet useful functions that I miss on the 34s (/thread228160.html) 
Two tiny, simple, yet useful functions that I miss on the 34s  Dieter  08012012 It looks like the 34s project sooner or later will come to an end, so I would like to suggest a simple extension of its function set that I consider useful. If I'm not too late, that is. We all know the INC and DEC commands that increment resp. decrement any register by one without disturbing the stack. The is no doubt these are two extremely handy commands that can be found in many user programs. I would suggest two similiar commands that multiply resp. divide a register with/by 2. The are countless applications where this would be useful. Sure, doubling X can be done by STO+X or RCL+X, but there is no shortcut for other registers. Even more important, there is no way to provide X/2 (or Y/2, R01/2, ...) without disturbing the stack, and a sequence like 2 STO/ 01 DROP even takes three steps and loses T. All you can do is prestore 0.5 in a data register and then use RCLx nn. That's why I would like to suggest these two commands. These and maybe one tiny little additional value in the constants catalogue: 1/2 or 0.5. Thank you. :)
Dieter
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Walter B  08012012 Assume yo're aware of ASR, SR, and SL, but want something alike in real mode?
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Dieter  08012012 Well, yes, since I do virtually all my calculations with reals, this is what I am looking for. I also like SDL and SDR very much  two nice and handy functions that do something similar (but limited to X) with powers of ten. Together with the integer constants #000...#255 they are also useful for generating short reals  a feature that I use quite often. The two new functions should behave just as INC and DEC, so that any register can be altered without disturbing the stack. Including X, of course. 8)
Example: assuming the command is named HALF, here's how to get the Normal integral from 0 to x with best accuracy, using the regularized incomplete Gamma function. Please also note the constant #0.5... ;) X^2
Dieter
It may be late in the 34S dev cycle...  Gene Wright  08012012 but I really like this idea myself.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08012012 I did contemplate commands to add, subtract, multiply or divide X by a small integer constant. A half and double command would be easy enough to add of course. The constant 0.5 is in the image already but not exposed to the user. We'll discuss I suspect.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08012012 INC and DEC are there because they are essentially free since they can share code with ISZ and DSZ  just no skip on zero.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08012012 Quote: Using existing commands:
x^2 So one extra step. If the half constant were available, the lengths would be the same.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  fhub  08012012 Quote:What about MUL2 and DIV2 ?
BTW, some time ago I wondered if there's really no integer division command (e.g. DIV or QUOT or \ ) in the WP34s.
Franz
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Dieter  08012012 Ok, ok  in this case it can be done with existing commands as well. Yet not quite as elegant. ;) This example was taken from my current implementation of the Normal quantile (oops, there it is again ;)). Here the constant 0.5 is required so often that I even sacrificed an extra register just for this value. BTW... this solution seems to return 33 or 34 valid digits, it has no problems with p close to 0.5 and requires just two iterations (or even less). The current version (including two additional tests for even faster execution) requires 100 steps of user code, including the code for the initial estimate. Would you be interested, maybe to use this for an XROM routine?
Dieter
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08012012 Yes, I'd be interested. The current in rom normal should be nice and fast and accurate but at quite some space cost.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Dieter  08022012 Yes, I know the 34s is a "moving target" (and it's moving fast), but I have to admit I'm a bit confused now. I thought the Normal quantile had moved to XROM?! So it is back to ROM now? Coded in C with 39digit precision? Great to hear this. In this case it just requires a few minor improvements. I currently use version 3.1 3208 with the emulator. There are some issues if you leave SP mode and switch to DP. Here, accuracy may drop down to 18 digits and calculating the quantile for p close to (but less than) 0.5 may take very long. On the other hand, p > 0.5 seems to work fine. I suspect the distribution's symmetry is not used, which would also explain why, for example, p = 1E20 and 1  1E20 do not return the same result (except the sign). Anyway  I will post my current solution in 34s user code. Maybe you can make use of the one or other idea in it. Especially this symmetry thing. ;)
Dieter
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08022012 I put back the cdf_helper code and went back to the older xrom code in revision 3210. The QF is still xrom, but it is using a faster converging method but the pdf and cdf are (almost) internal precision again. The down side is this cost half a kilobyte of flash.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Dieter  08022012 Fine. As long as the two IGamma functions can be used, the two cdf helper functions are obsolete. Well, almost. But with user code / keystroke programming in DP mode it will not get better than 3334 digits anyway. If you once choose to implement the posted solution in a regular internal function (using 39 digit precision) you may include another (fourth) term in the correction so that a result close to full precision will be possible (I guess something like 37 digits  with sufficient working precision 3940 digits would be possible). You say you have put back the cdf helper functions, so I guess this also applies to the series resp. continued fraction expansion. In the latter case the number of required CF loops can be evaluated quite exactly in advance. For 34+ digit precision, please use n = ceiling(1700/z^2) + 20 loops. In this case the max. error is approx. 1 unit in the 35th digit. For an internal function use 2100/z^2 + 21 loops. In both cases z >= 2. However, if 33 digits are fine, the proposed method can be an option. Use the same algorithm with 39 digit precision, and you should get all 34 DP digits right.
Dieter
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Walter B  08032012 IDIV is in now. MUL2 and DIV2 won't come.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  fhub  08032012 Quote:Well, these functions were not my idea (I just made a suggestion for possible names), so I don't really miss them. ;)
Franz
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Damir  08032012 Oh happines Franz is your name :)))
Damir
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08032012 The reason these two aren't in is purely space. INC and DEC were freebies to implement. MUL2 and DIV2 aren't.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  fhub  08032012 Quote:LOL, I'm indeed quite happy with the current WP34s status. But what would make me absolutely happy would be longer names for selfdefined functions. With only 3 characters you just can't find any meaningful abbreviation for any function or program you write. Is there really no way to allow at least 6 (or even 8) characters?
Franz
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Walter B  08032012 I'm afraid I can't imagine you'll ever get more than 6 characters for that since the limit for internal function names is 6 characters as well. And now you want to have 6 character labels, don't you? That sounds like blowing our function code space [:( but Pauli shall know exactly. Edited: 3 Aug 2012, 8:48 a.m.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  fhub  08032012 Quote:Well, 6 would be ok and definitely much better than the current 3. I know lots of mathematical functions with combined names and with 2x3 characters you could give them useful names (e.g. INVMOD, EXTGCD, LINPRO, TRIGON, MODSYS etc. just to name a few). And then think about writing a package for a special purpose  e.g. I've started with a polynomial package: now if you would want names like P.xxx (as M.xxx for matrix functions), then you've just left one single character after 'P.' which doesn't allow any useful names. With 6 letters everything would just be much easier and better to understand, and I won't care at all if such a 6letter label would need 4 (or even more) bytes instead of 2. Franz
Edited: 3 Aug 2012, 9:56 a.m.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Dieter  08032012 Hmmm... I just had an idea where I don't know whether it's simply brilliant or plain stupid. #)
Do you think there is a way to use RCLarithmetics with the builtin constants? A wellknown equation might then look liks this: before afterAnd now imagine what you could do with RCL+ #002, RCL #005, RCLx #pi etc. Would you consider this useful  and possible to implement without too much effort? Or does this require as much space as a special x2 resp. /2 command? Dieter
Edited: 3 Aug 2012, 6:51 p.m.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Dieter  08032012 I agree that a command for integer division is useful. But there is an even more useful way to provide such a function. Have you ever done some programming in x86 assembler? The standard division command returns both the integer part of the quotient and the remainder. I always considered this a nice and handy feature since often both values are required. So this would be a kind of DIVMOD command that returns both y DIV x and y MOD x. Just an idea. :)
Dieter
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08032012 The three character limit is due to the way we store opcodes for commands.
 Pauli
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08032012 At one stage, I did propose four operations that added, subtracted, multiplied and divided X by a constant argument. This suggestion didn't make it. I doubt the same thing using the built in constants would either. Space wise, I don't think they would be much difference between this and the multiply and divide by two commands.
 Pauli
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Walter B  08042012 That sounds like viable at little cost. Pauli?
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08042012 DIV and MOD or DIV and RMDR? Integer, real and complex?
This operation makes most sense in integer mode to my mind at least.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08042012 In integer mode, what should carry and overflow be set to?
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Walter B  08042012 DIV and RMDR in real to serve customer request :) Would be fine in integer as well but wasn't requested AFAIK. Who needs complex? ;)
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Paul Dale  08042012 The DIVMOD instruction in question is for integers only I thought. It doesn't make as much sense for reals. We support almost every function over the reals, integers and complex domains so yes, complex support isn't insignificant.
Re: Two tiny, simple, yet useful functions that I miss on the 34s  Walter B  08042012 Wrapping it up: Quote:That's for real, since for integers this is covered by /. He continued later: Quote:So that's meant for real as well. Then Pauli responded: Quote:So let us have DIVRMD in real and integer modes at least. We could drop IDIV then. Just my 20m€  YMMV. Re: Two tiny, simple, yet useful functions that I miss on the 34s  Dieter  08042012 Sorry if I my intention was not clear. The assembler command I originally referred to is the DIV command for integers, returning both the quotient and the remainder. But of course I would like to see such a command included for both integers and reals (which is the data type most of us will use 99% of the time). Complex for me is nice, but optional. ;)
Dieter
