HP Forums
MOD, ODD() in Program - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: MOD, ODD() in Program (/thread-978.html)



MOD, ODD() in Program - Angus - 03-25-2014 02:21 PM

hi!

I'm struggling with a program and need help from the forum. Current Problem is a piece of code like that:

Code:

EXPORT FILT(N,L)
BEGIN
  IF (N MOD 2) = 1 THEN 
    MSGBOX("Odd Core Length required.");
    RETURN "";
  END;
  (...)

My Questions are:
- how would I check Integer Operations like ODD(), MOD,.. for an Input Variable? I get an "Error:Bad Argument Value". Maybe a real to integer cast would do the job. Is that possible?
- Is Typing of Input Variables and local Variables free to choose or do I have to stick to some nomenclature like with home/cas Variables and Command Variants? That is a big issue which still confuses me. Must admit that.
- When I start a program via Shift+Program instead of Toolbox/User I get a dialog with the program's Parameters. Is that totally equal to the toolbox launch? I mean there are no data left in any Variable after the program finishes independent of how I started the program?

Thanks


RE: MOD, ODD() in Program - Han - 03-25-2014 03:37 PM

Use == for boolean equality. And in general, when you run into an issue in a program:

1) Press the "Info" menu option at the error message screen to find the approximate location in the source
2) You can trace the variables by using the debug feature. Insert the debug() command in your source to have the debugger start at the instance debug() appears in the source. You can optionally debug your program from the very start using the "Debug" menu option from the program catalog.


RE: MOD, ODD() in Program - cyrille de brébisson - 03-26-2014 06:20 AM

Hello,

== is equality test, not = which is more for equations.

type allows you to check variable types.

if FP != 0 then bla bla bla end;
will allow you to test if something has a fractional part or not

user variable names are free for you to name as you want. there is no need for you to respect any nomenclature.

Quote:When I start a program via Shift+Program instead of Toolbox/User I get a dialog with the program's Parameters. Is that totally equal to the toolbox launch?
yes, exactly the same.

Cyrille


RE: MOD, ODD() in Program - Angus - 03-26-2014 10:33 AM

Thanks for the info so far.
I think I did try == for equality first, that would be natural since I use c for at least 90% of my work... Well maybe I was blind. I will try that later on tthe day.

Do I understand you correctly that I should do like?

IF FP(N/2) != 0 THEN //test for odd N

...which I suppose does not work.


RE: MOD, ODD() in Program - Han - 03-26-2014 03:55 PM

(03-26-2014 10:33 AM)Angus Wrote:  Thanks for the info so far.
I think I did try == for equality first, that would be natural since I use c for at least 90% of my work... Well maybe I was blind. I will try that later on tthe day.

Do I understand you correctly that I should do like?

IF FP(N/2) != 0 THEN //test for odd N

...which I suppose does not work.

For non-equality, consider using <> (or you can use the \( \not = \) symbol. The != syntax is valid in the CAS view; however programs are considered "Home view" operations.


RE: MOD, ODD() in Program - Angus - 03-26-2014 04:02 PM

Thank you, Han. That is it.


edit: if programs are homeview operations how come I can do a program like:

EXPORT tst()
BEGIN
LOCAL eq:="x^2+1";
LOCAL ret:=int(eq);
RETURN ret;
END;

and do not need a CAS.int() command. Plus the result is X*(x^2+1) no matter if in cas or home. 'X' and 'x' are mixed.
Now that I started to think about all that it confuses me more and more.....

Plus I did not notice anything about cas and Home in the help System or in the manual. Is there a reference anywhere? Where do I get such important facts from? Of course there will be similar problems in the future if I keep working with the prime which I would like to deal with alone.


RE: MOD, ODD() in Program - Han - 03-27-2014 01:10 AM

(03-26-2014 04:02 PM)Angus Wrote:  Thank you, Han. That is it.


edit: if programs are homeview operations how come I can do a program like:

EXPORT tst()
BEGIN
LOCAL eq:="x^2+1";
LOCAL ret:=int(eq);
RETURN ret;
END;

and do not need a CAS.int() command. Plus the result is X*(x^2+1) no matter if in cas or home. 'X' and 'x' are mixed.
Now that I started to think about all that it confuses me more and more.....

Plus I did not notice anything about cas and Home in the help System or in the manual. Is there a reference anywhere? Where do I get such important facts from? Of course there will be similar problems in the future if I keep working with the prime which I would like to deal with alone.

When you intentionally leave off the second parameter for the int() command (i.e. the variable of integration), the command will assume that you are integrating with respect to \( X \) (capital letter). Since lowercase \( x \) is not the same as capital \( X \), then the integrand \( x^2+1 \) is considered to be a constant, so that the integral (principal result) is simply the constant multiplied by the variable of integration: \( (x^2+1) \cdot X \)


RE: MOD, ODD() in Program - Angus - 03-27-2014 08:21 AM

That makes sense. I just wonder if I should or could have known that before. I have searched the command list and the handbook again and I must state I still don't get a better understanding. I even did not find e.g operator/command limitations mentioned anywhere.
So to sum it up: a program is interpreted as if the calculator is in home mode? Why does a program compile the int() command at all if not coded as CAS.int() ?

I somehow do expect HP to rework the typing and all the differences between home and cas so this effect. Might not be in the next update but in one to come.
Anyhow a reworked documentation and reference is needed, soon. Adaquate documentation is part of a technical device and a student needs to understand what is going on. Would you be willing to confront your students with such miracles?

Sometimes I wonder if my intellectional abilities are the cause for my prime confusion or if I question everything too much....


RE: MOD, ODD() in Program - Han - 03-27-2014 03:24 PM

(03-27-2014 08:21 AM)Angus Wrote:  That makes sense. I just wonder if I should or could have known that before. I have searched the command list and the handbook again and I must state I still don't get a better understanding. I even did not find e.g operator/command limitations mentioned anywhere.
So to sum it up: a program is interpreted as if the calculator is in home mode? Why does a program compile the int() command at all if not coded as CAS.int() ?

Knowledge of this behavior depends on whether you are familiar with the HP39GII and/or xcas/giac. At any rate, you can always get useful information about command syntax via Help. Press the toolbox button, select the catalog of commands, and find your command int among the list (you can just tap [TAN] [()] [/] really quickly to get there) and press the help button. Maybe a future firmware update will allow the [Help] button to pull up the help info by simply placing the cursor in the command line on the command of interest. Keep your fingers crossed.


RE: MOD, ODD() in Program - Angus - 03-27-2014 05:02 PM

Help provides information, however it does not explain why I cannot change the program into
Code:

EXPORT tst()
BEGIN
LOCAL eq:="x^2+1";
LOCAL ret:=int(eq,x);
RETURN ret;
END;

Using 'X' is bad argument value...

My complain is that the given device is not easy understandable and not at all usable without even looking at a manual as stated elsewhere.
How would the help system help to gain an understanding of how to code/solve certain problems.

Maybe people who already are familiar with the prime should start a well organized wiki here to have standard problems explained?


RE: MOD, ODD() in Program - Han - 03-27-2014 05:13 PM

(03-27-2014 05:02 PM)Angus Wrote:  Help provides information, however it does not explain why I cannot change the program into
Code:

EXPORT tst()
BEGIN
LOCAL eq:="x^2+1";
LOCAL ret:=int(eq,x);
RETURN ret;
END;

Using 'X' is bad argument value...

My complain is that the given device is not easy understandable and not at all usable without even looking at a manual as stated elsewhere.
How would the help system help to gain an understanding of how to code/solve certain problems.

Maybe people who already are familiar with the prime should start a well organized wiki here to have standard problems explained?

You are ignoring the fact that x, X, and "x", and "X" are literally all different. You should have: int(eq, "x") if you plan to only use lower-case x as your variable. On the other hand, you can create a variable named x whose contents is a string consisting of a single letter representing the variable of integration.