Post Reply 
Prime User Function Catalog, Pressing "Run"
08-23-2022, 04:24 PM
Post: #1
Prime User Function Catalog, Pressing "Run"
User's don't only create programs.

Sometimes, we create math functions. It is useful to give descriptive names to such functions. For example, see the attached user function. Put it into your HP Prime.

Now, list your available user "Programs" in the catalog. Scroll down to that descriptively named user function. It is the one named "Lambert_Omega_Householder."

Press "Run."

As Henry Gibson said, "Very interesting, but stupid."

Instead of transferring the name of the function to the command line, the present machine's firmware flashes an exclamation point at the user, and ignores what the user obviously needs done.

Why? Well, because the user tried to "run" a "function" instead of a program. If run this way, a function can have no input.

It really looks as if every single time a user intends to get the name of a function from the catalog, and place it into the command line, the user is forced to type the function name over again, manually. Using a simulator this is easy. Use the PC's keyboard, but what if the person is using an actual physical calculator?

It feels like an infinite number of twiddly shifts and alpha button presses.

Every time.

This can make people hate the physical calculator's actual buttons.

If a user highlights the name of a user function in the program list, and hits "Run" the machine should transfer a copy of the long descriptive function name into the command line, and supply a set of open and close parenthesis.

Every time.

Lots of people know more than I know about how to get around this type of "feature."

I hope.

Otherwise, we should ask HP to update the firmware. Please add this astonishingly simple behavior in the user interface. It would conflict with nothing else.

Bill Triplett
20220823

PS: In case you only have a physical calculator, and have not yet set up a simulator or the connectivity kit, I will also post code for the example program here:

Code:

#CAS
//Lambert_Omega_Householder
//Principal branch of the Lambert W function using the Householder method.
//Rev.1.46 (Nov. 28, 2020) (c) Takayuki HOSODA (aka Lyuka)
//Acknowledgments: Thanks to Albert Chan for his informative suggestions.
Lambert_Omega_Householder(x):=
BEGIN
  LOCAL y, p, s, t, u, v;
  LOCAL q, r;
  HComplex := 1; // Enable complex result from a real input.
  r := sqrt(MAXREAL) / 1e4; // Limit x range
  IF abs(RE(x)) > r OR abs(IM(x)) > r THEN return "LW0H: x out of range"; END;
  r := 1.0 / e;
  s := x + r;
  IF s == 0 THEN return -1; END;
  q := e - sqrt(2.0) - 1.0;
  y := 1.0 * ln(r + sqrt(2.0 * r * s) + q * s); // approximation near x=-1/e
  r := MAXREAL;
  REPEAT
    q := r;
    p := y;
    s := exp(y);
    t := s + x;
    u := y * s;
    v := u - x;
    v := (6.0 * ((y + 1.0) * u * x + t * (t + u)) + v * (3.0 * (u + x) + y * v));
    IF (0 == v) THEN break; END;
    t := 3.0 * (u - x) * ((u + x) * (y + 2.0) + 2.0 * s);
    y := y - t * inv(v); // Householder's method of order 4
    r := abs(y - p); // correction radius;
  UNTIL 0 == r OR q <= r; // convergence check
  return p;
END;
#END

This code does some heavy lifting. In optics, we sometimes need to use this function when nothing else will do. The author is amazing. His code handles imaginary inputs and outputs quite nicely.


Attached File(s)
.hpprgm  Lambert_Omega_Householder.hpprgm (Size: 3.34 KB / Downloads: 3)
Find all posts by this user
Quote this message in a reply
08-23-2022, 05:34 PM
Post: #2
RE: Prime User Function Catalog, Pressing "Run"
This behaviour only seems to be true for user defined CAS functions. For "non-CAS" functions, if you hit "run" in the program list, the first function followed by an "EXPORT" command in the code is run via the RUN button in the program list, and then the Prime asks for values for the parameters to be entered in a form. If a program exports multiple functions, then there is a select menu appearing on top of "run" that lets you choose the function you want to execute. From the Home screen, you can find these functions via the "Toolbox" key, then in the "User" menu. Selecting one from there will put the function name and parentheses onto the command line for further editing and execution.

It seems to work differently for CAS functions, probably because they are handled differently internally, but you can actually find the functionality you are looking for elsewhere:

In the Home screen (no matter if CAS or Home mode), hit the "Vars" button, then select "CAS", then "Program". The list should contain your function name and when you select it, it is put into the command line like you were asking. You have to add the parentheses and parameter and can execute with the ENTER key.

As a side note, at first glance I don't see a reason why your function needs to be a CAS function. It should work with the same code (maybe some uppercase required) when you define it as "non-CAS" function in your program. Then you will find it in the "Toolbox" key's "User" menu, via the name of your program.

Hope this helps.
Find all posts by this user
Quote this message in a reply
08-23-2022, 09:16 PM (This post was last modified: 08-23-2022 09:42 PM by Bill Triplett.)
Post: #3
RE: Prime User Function Catalog, Pressing "Run"
goetz,

That does help. Thank you for patiently investigating options, and explaining.

This option you found is good, but it doesn't eliminate the odd problem where in the Shift>Program list of CAS programs, if one of the items listed is a function, a user would not be looking at that list, and pressing "Run" unless a user wanted to fetch that function's name.

If simply pressing "Run" at that point, the user would wish to have that long detailed function name instantly echoed into the command input line. This would be the Home command input area or the CAS command input area, depending on where the user had been working immediately before viewing the catalog. Or, the firmware could be adjusted to allow highlighting the catalog item name, and then copying the name into the copy/paste buffer. Then, a user could decide where to paste it. Example: The user could wish to past the name into code for another program. Functions are often useful that way.

The alternative you found with Vars>CAS>Program is a workable way to get the function name into the command area. However, both methods should work. If specifically shopping the Shift>Program catalog, not only should the user defined function name be available for extraction, when copied and pasted, or echoed, a set of parenthesis should also appear. If the function takes two arguments, then the parenthesis should appear with a comma inside, and with the cursor placed inside between the left parenthesis and the comma. This would remind the user that two arguments are needed.

Hey, I noticed an odd thing. If you have only one user function stored in the calculator, and change its name, the old name stays on that Vars>CAS>Program list you mentioned, along with the new name. Even stranger, if you use the old name, it still works. Stranger still, if you then delete all user programs from the machine, the deleted function still works when given an argument. I suppose this is because the CAS function is still available stored in a CAS variable with the function name. This part probably won't be confusing to me after I get used to the idea that a CAS function or a CAS program are separate creatures. They seem to exist/persist somewhat independently from the catalog list of user defined programs and functions.

Methinks that if a user renames the one and only user defined function in the catalog, then the old function name should automatically vanish from that Vars>CAS>Program name list.

As for why the Omega function was done in CAS, the author wrote a truly astonishing explanation here:

http://www.finetune.jp/~lyuka/technote/l...w-hpp.html

We don't usually see user-defined function authors ... functioning ... at this level.

Bill Triplett
Find all posts by this user
Quote this message in a reply
08-24-2022, 06:14 AM
Post: #4
RE: Prime User Function Catalog, Pressing "Run"
From what I have seen for CAS user functions so far, the programs in the program editor are only used to store a program into a CAS program variable. You can indeed remove the program from the editor/list and the user defined CAS function remains in the CAS variable (under Vars->CAS->Program).

To update, you can edit the existing program in the program editor and hit the "Check" button. This should then update the CAS program variable. If you rename the function in the program editor, you should get a new copy in the new CAS variable.

This is based only on my observations. For the question why it was decided to be designed and implemented that way and for more details, I would have to refer to the HP prime developer team.
Find all posts by this user
Quote this message in a reply
08-24-2022, 01:04 PM
Post: #5
RE: Prime User Function Catalog, Pressing "Run"
I understand. At one point I deleted everything except one CAS variable which had been created by the original program. That CAS variable contained a copy of the program code from BEGIN to END.

I managed to get back the code into an editable form by echoing the contents of the CAS variable to the command line. Then, highlight copy and paste into a new program.

It isn't terribly confusing once we get used to the idea that a CAS variable can contain a copy of the bulk of a program. Weirdly, this prevents such a program from appearing in the catalog of user-defined programs/functions.

Thanks again.
Find all posts by this user
Quote this message in a reply
Post Reply 




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