Post Reply 
program gives different answer in Home and CAS
12-04-2021, 06:19 PM
Post: #1
program gives different answer in Home and CAS
With the Function App active, this program:

PHP Code:
EXPORT TANGENT()
BEGIN
 LOCAL f
sf;
 
"X^2-2*X+3"▶F1;
 
EXPR("F"+1)▶f;
 
diff(f,'X',1)▶sf;
 RETURN 
sf;
END

when run from Home returns the correct answer, 2*X-2. The same program when run from CAS returns 0. This is on the emulator running version 2.1.14592

Oddly enough on the handheld running version 2.1.14588 it works correctly in Home and CAS.

Can anyone tell me what is wrong?

-road
Find all posts by this user
Quote this message in a reply
12-05-2021, 02:02 AM
Post: #2
RE: program gives different answer in Home and CAS
(12-04-2021 06:19 PM)roadrunner Wrote:  With the Function App active, this program:

PHP Code:
EXPORT TANGENT()
BEGIN
 LOCAL f
sf;
 
"X^2-2*X+3"▶F1;
 
EXPR("F"+1)▶f;
 
diff(f,'X',1)▶sf;
 RETURN 
sf;
END

when run from Home returns the correct answer, 2*X-2. The same program when run from CAS returns 0. This is on the emulator running version 2.1.14592

Oddly enough on the handheld running version 2.1.14588 it works correctly in Home and CAS.

Can anyone tell me what is wrong?

-road

Expecting consistency from the Prime was the major error here...

Noted with sadness...

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
12-05-2021, 04:55 AM
Post: #3
RE: program gives different answer in Home and CAS
The line begins with "PHP Code:"?!

Is it supposed to be PPL, CAS, Python or what?

Home (ppl) usually defaults to UPPER CASE variable names
CAS usually defaults to lower case variable names.

A naive question here: does the HP Prime support PHP as well as
PPL, CAS, Python? If not why are poster using the phrase "PHP Code"?

Thanks.
Find all posts by this user
Quote this message in a reply
12-05-2021, 07:51 AM
Post: #4
RE: program gives different answer in Home and CAS
(12-05-2021 04:55 AM)Liamtoh Resu Wrote:  The line begins with "PHP Code:"?!
That is just the forum software. It adds PHP to the code block if you accidentally select the PHP BB code tag.

Code:
[php]example[/php]

PHP Code:
example 
Visit this user's website Find all posts by this user
Quote this message in a reply
12-05-2021, 10:27 AM (This post was last modified: 12-05-2021 11:14 AM by C.Ret.)
Post: #5
RE: program gives different answer in Home and CAS
(12-04-2021 06:19 PM)roadrunner Wrote:  Can anyone tell me what is wrong?

The main reason of the two different environnements on the HP Prime is due to the way that expression are interpreted and variable are evaluated.

Since the last fimware update, a subtile variation has appear on the way that global HOME variables are interpretated into the CAS mode. This subtitle varaition in the evaluation process made your code unappropriate for the rigourus CAS mode interpretaion. Especially, the way you define the intermédiate and local f function is valid on in HOME evaluation process since any reference to global X variable is consider (in differentiations by diff instruction only). In the CAS mode, a more rigourus interpratation is made, no special shortcut exist for a specific variable and the way you have define f, appears in CAS mode to be a constant function. Any differentiation of constant lead irremediately to zero.

Try this modifed version of your code:


EXPORT TANGENT()
BEGIN
"X^2-2*X+3"▶F1;
RETURN diff(F1(X),X,1);
END;


In this version, the argument to be use for the differentiation is explicit into the arguments of the diff instruction as exactly the same object is given in function definition and indication of the control variable.

In your version of the code, the control word indicated in the local 'f' variable unmatched the control variable.
Only the HOME mode interpretation hallow a vague reference to an X as the default variable for function evaluation, plotting, integrating or differentiating...

In CAS mode, ince the object you indicate doesn't appears in the function definition, it is assume that the function doesn't depend of this variable; differentiation over an independent variable is equivalent to differentiate a constant function.

That why this code will run as well :

EXPORT TANGENT()
BEGIN
"X^2-2*X+3"▶F1; // X is mandatory to insert the correct definition in the F1 slot of the graph Function Application
RETURN diff(F1(Y),Y,1); // Explicit indication of the control variable in function definition and arguments of the CAS.diff command. Exact match mandatory.
END;
Find all posts by this user
Quote this message in a reply
12-05-2021, 12:25 PM
Post: #6
RE: program gives different answer in Home and CAS
@ Liamtoh Resu:

It's PPL code, i just clicked the wrong button.

@ SammysHP

I always wondered why they don't have a PPL code tag.

@ rprosperi:

Yep, that was my mistake Sad

@ C.Ret:

I was aware of that fix, but integrating that into my programs will require a lot of extra typing and make the code substantially less elegant.

@ all responders:

Thanks for the help. This is the second time a recent software upgrade broke a program of mine. At least, now, I can have fun fixing them.

-road
Find all posts by this user
Quote this message in a reply
Post Reply 




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