# HP Forums

Full Version: Programming with CAS commands (e.g., arcLen)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

arcLen() works fine in CAS view, but in home view there are problems.

For example, arcLen(x^3,0,2) in CAS gives the correct answer approx. 8.63...

In home view, arcLen(X^3,0,2) returns 2 ???

Other CAS commands work correctly in home view, e.g., diff(X^2,X) returns 2*X.

This also presents a challenge for programming.

This simple program

EXPORT TPP()
BEGIN
LOCAL QQ,RR,SS;
INPUT({QQ,RR,SS});
arcLen(QQ,RR,SS);
END;

gives the wrong answer if entering X^3 into QQ.

But I can't enter lower case x^3 into QQ. Why? Syntax error. I tried quotes around the symbolic expression, but to no avail. Any ideas?

The home parser requires all objects exist on parse time. Mixing CAS stuff with HOME stuff is not a great thing to do at this moment as there are just so many cases that will misbehave.

TW

Quote:
arcLen() works fine in CAS view, but in home view there are problems.

For example, arcLen(x^3,0,2) in CAS gives the correct answer approx. 8.63...

In home view, arcLen(X^3,0,2) returns 2 ???

Other CAS commands work correctly in home view, e.g., diff(X^2,X) returns 2*X.

This also presents a challenge for programming.

This simple program

```EXPORT TPP()
BEGIN
LOCAL QQ,RR,SS;
INPUT({QQ,RR,SS});
arcLen(QQ,RR,SS);
END;
```
gives the wrong answer if entering X^3 into QQ.

But I can't enter lower case x^3 into QQ. Why? Syntax error. I tried quotes around the symbolic expression, but to no avail. Any ideas?

When you enter X^3, are you entering that as just X^3, 'X^3', or "X^3" as all three are handled differently. X^3 converts into a number first, so the arclength is just SS-RR. I am still trying to figure out when the second and third cases are treated the same and when they are not... :-(

OK, so how do I, on the Prime, write a program where the user can enter a function, start and end values, and run something like arcLen? (This is just an example).

Sorry for the bad formatting in the post before; hopefully, this reads better.

```EXPORT TPP()
BEGIN
LOCAL QQ,RR,SS;
INPUT({QQ,RR,SS});
arcLen(QQ,RR,SS);
END;
```

Is it not possible to do this at all? Not even workarounds?

I tried everything I could think of.

Ideally you should be able to enter lower case "X", i.e., x^3, into the variable on the INPUT screen, but at runtime the parser doesn't let you.

Quote:
I tried everything I could think of.

Ideally you should be able to enter lower case "X", i.e., x^3, into the variable on the INPUT screen, but at runtime the parser doesn't let you.

I have found that pretty much anytime I need to do anything with symbolic expressions, I end up have to use expr(" blah "); And even this can break the calculator. For example,

F0:=expr("'X-F1(X)/(" + diff(F1(X),X) + "')");

works fine within a program. However,

```BEGIN EXAMPLE()
LOCAL QQ, RR, SS;
QQ:="";  // this will enable you to enter a string, now
INPUT({QQ,RR,SS});
CAS.arcLen(EXPR("'"+QQ+"'"),RR,SS); // warmstarts even without RR,SS at end
END;
```

causes a warmstart on my actual calculator. I can type: X^2-5 for QQ and it shows up properly during the input screen. But it seems to fail once inputs are entered. In sum, working with built-in variables _usually_ works. Most of the time, anything with CAS seems broken. Then again, I have yet to consult the manual regarding CAS operations (assuming I can find it in there).

Edited: 1 Oct 2013, 2:47 p.m.

Thanks so much for looking at this problem as well!

All this (storing and evaluating symbolic expressions with the CAS) works fine on the 50G, so when I tried this out on my Prime, I first thought I was going crazy!

As for a Prime CAS reference, maybe this XCAS manual will be of help:

http://www-fourier.ujf-grenoble.fr/~parisse/giac/cascmd_en.pdf

Covers the HP Prime CAS commands (and then some). I don't know if there is a newer edition.

I guess for now we'll just have to be content using the CAS commands and functions in CAS view, and in interactive mode only.

```EXPORT AL()
BEGIN
LOCAL RR,SS;
INPUT({F1,RR,SS}); // changing F1 to CAS.F1 causes warmstart.
CAS.arcLen(CAS.F1,RR,SS);
END;
```

Allows you to enter in a function, and at least does not crash. Heading out a.t.m. so didn't test if it correctly returns the result we want.

Edited: 1 Oct 2013, 3:53 p.m.

For arcLen(x^3,0,2), that returns 2*sqrt(2), so it is not correct (sigh).

Running CAS.arcLen(F1, RR, SS) gives an error message "expecting an expression, not a function."