Post Reply 
Functions Created in CAS - My Insights
02-15-2014, 06:47 AM
Post: #1
Functions Created in CAS - My Insights
First, let's create two functions in the CAS with two different methods:
Code:

f1(x):=x^2-5
f2:=x->x^3+6

Both functions are now listed under
[Shift] -> [Toolbox|Mem] -> CAS Vars
Code:

f1 (Function)
f2 (Function)

First insight for me: You can define functions in the CAS with either mothods shown above and you get the same result. This is not a surprise but good to know.

When you want to use these functions in your calculations you can choose them from
[Vars] -> CAS -> Program

This was my first confusion as a beginner with the HP Prime: You are entering a function and it is stored as such in the memory but when you want to choose it from [Vars] you have to know that a CAS function is a (CAS) program. This was my second insight.

Now let us switch to Program:
[Shift] -> Program

Both functions created above appear in this list:
Code:

f1 (CAS)
f2 (CAS)

There is a hint (CAS) that f1 and f2 are belonging to the CAS. It is great that you can edit and extend them in the program editor.

The summary of my insights:
A function created in the CAS is a CAS function which is a CAS program and it is stored in CAS variable.

If you know that this is due to functional programming then this is logical. But I didn't know that the CAS allows functional programming and was lost in the beginning. I therefore suggest to to add a seperate functional programming chapter to the HP Prime User Guide.

Are my reflections and insights correct?

Many thanks for reading this and your feedbacks.

Best,
Dominik
Find all posts by this user
Quote this message in a reply
02-15-2014, 04:58 PM
Post: #2
RE: Functions Created in CAS - My Insights
Wow, I didn't know that. Thanks!
Find all posts by this user
Quote this message in a reply
02-16-2014, 02:21 AM
Post: #3
RE: Functions Created in CAS - My Insights
(02-15-2014 06:47 AM)Dominik Holenstein Wrote:  Are my reflections and insights correct?

Yes, with only one tiny clarification: When you press Vars CAS, your CAS programs appear in BOTH lists, "All" and "Program". The latter list is just a subset of the former, containing only user-defined CAS functions, for your convenience.

For two examples of CAS programming, doing stuff that's only possible in CAS, see my D2F and PDQ programs in the HP Prime Software Library.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
02-16-2014, 06:30 AM
Post: #4
RE: Functions Created in CAS - My Insights
@Stefan
You are welcome!

@Joe
Many thanks for you feedback, clarification and the hint to your D2F and PQF programs. The CAS programming is very interesting.

Best,
Dominik
Find all posts by this user
Quote this message in a reply
02-16-2014, 01:25 PM
Post: #5
RE: Functions Created in CAS - My Insights
(02-16-2014 02:21 AM)Joe Horn Wrote:  ...
For two examples of CAS programming, doing stuff that's only possible in CAS, see my D2F and PDQ programs in the HP Prime Software Library.

@Joe:
Maybe it could be helpful to add some more words about entering a CAS program, since I didn't find hints about creating a CAS program in the manual(s).
My way:
First in CAS mode I created an empty program like
Code:
d2f:=(x)->x
then I could edit this by [Shift]+1 (Program), and enter your code. Works fine, besides a small typo ('END;;').

Are there other steps to create/enter a CAS program?
Where did you find the operators like '/=' and '+=' ?
Again the manuals are unhelpful ;-)

Many thanks, Thomas
Find all posts by this user
Quote this message in a reply
02-16-2014, 04:29 PM
Post: #6
RE: Functions Created in CAS - My Insights
I think the quick way that Joe showed us was:

f(x):=expression using x ENTER like

f(x):=x^2-5 ENTER

But Joe and others are experts.
Find all posts by this user
Quote this message in a reply
02-16-2014, 05:02 PM
Post: #7
RE: Functions Created in CAS - My Insights
Thanks! Another question:
I couldn't find where to transfer the CAS programs from the virtual calc to the real calc. (No 'send' button for CAS programs in Virtual Calc, CAS programms are not shown in Connectivity kit). My fault?
Do you have any suggestions?

Thanks in advance, Thomas
Find all posts by this user
Quote this message in a reply
02-16-2014, 05:45 PM
Post: #8
RE: Functions Created in CAS - My Insights
Quote:(No 'send' button for CAS programs in Virtual Calc, CAS programms are not shown in Connectivity kit). My fault?
Nope, not your fault.
Find all posts by this user
Quote this message in a reply
02-16-2014, 05:59 PM
Post: #9
RE: Functions Created in CAS - My Insights
found a possible work-around ;-)
- copy CAS program text to notes ([Shift] 0) (files named like programs),
- transfer notes / or send it in virtual calc
- now in real calc you may edit and copy the Notes,
- and paste it within program editor.
Works!
Find all posts by this user
Quote this message in a reply
02-16-2014, 11:06 PM
Post: #10
RE: Functions Created in CAS - My Insights
Thomas_Sch: CR Haeger is right; the easiest way to create a CAS program (in the current version of Prime) is to do function_name(x):=anything in CAS, then edit it in the program editor. It's silly but it works. The number of arguments and their names can be changed in the editor, and the name of the program itself can be changed in the Program Catalog.

Quote:[D2F/PDQ] Works fine, besides a small typo ('END;;').

Strange to tell, that's not a typo. If the unnecessary ";" is removed, Prime puts it back in. I don't know why.

Quote:Where did you find the operators like '/=' and '+=' ?

C++. PPL has lots of little goodies like that hidden in it; maybe somebody will write a “Secrets of the HP Prime” book some day. Not me... I'm having too much fun playing with it.

debrouxl is right: There is currently no one-step way to send a single CAS program to a Prime. I have always used Thomas_Sch's four-step method: paste it into a Note, send the Note to the Prime, copy the Note on the Prime, then paste it into the program editor.

FWIW, all the CAS variables in the emulator (including your CAS programs) are stored in a single file on your PC, called "cas.settings" in the HP_Prime folder. If you save a copy of that file elsewhere, then you can restore all your CAS programs in one fell swoop by replacing the current cas.settings file with the one you saved. The drawback is that it's like a Restore; it wipes out any existing CAS programs.

I hope HP introduces serious support for CAS programming in a future upgrade.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
02-17-2014, 10:39 AM (This post was last modified: 02-17-2014 03:32 PM by CR Haeger.)
Post: #11
RE: Functions Created in CAS - a few financial formulas and applications
Perhaps there should be a new thread for CAS programs?

After Joe showed us how to quickly create/save CAS programs, I spent some time seeing where they can/may not be used on the Prime. Here are some financial formulas I transcribed from an Engineering Econ chapter:

F_A(rate,per):=((1+rate)^per-1)/rate;

F_P(rate,per):=(rate+1)^per;

P_A(rate,per):=((1+rate)^per-1)/(rate*(1+rate)^per);

P_G(rate,per):=((rate+1)^per-1)/(rate^2*(rate+1)^per)-per/(rate*(rate+1)^per)


As others have noted, at this point it may be best for you to copy/paste the above into the CK in a new note, say "CAS Formulas". From there, if you send to the emulator or your handheld, they can be copy/pasted into a CAS command line then ENTER to save the CAS variable (program).

So far, it seems to me that these CAS variable (programs) can be used for;
1. Calculating a value based on numerical variable inputs (from Home or CAS): F_A(0.1,10)=15.94
2. Showing expression variable(s) while in CAS: F_A(rate,10) shows F_A in terms of rate with periods set to 10.
3. Expression arithmetic while in CAS: F_P(rate,per) * P_G(rate,per) yields an expression for F_G(rate, per) in this case.
4. Can use many CAS Toolbox commands, like solve(), diff(), zeros(): solve(F_A(0.1,per)=20,per) {11.52} or ~11.5 periods at 10% interest will yield a future 20x the investment per period.
5. Can be used/referred to in a Spreadsheet APP: =F_A(cellref1, cellref2) will calculate F_A for the rate, per you enter in cellrefs 1,2.
6. Can be transferred to Function APP to graph versus rate or per: f(x):= F_A(.1,x) then Function.F1:=f stores F_A(0.1,X) in F1 for plotting*.
7. You can transfer to Solver APP using say E1:=F_A(rate,per). From there though, its a little tricky in the Solver App. Create user vars, change expression to an equation, solve, delete user vars.... May not be worth the effort.

* This stores F_A(0.1,X) in F1. Excecute F_A(0.1,x) first in CAS if you want the expression saved.
** I have not yet tried calling these from a program I think it would be powerful if this works.

I look forward to seeing what others have done with CAS variables (programs). Maybe this is/was common with the HP50G but for me, coming from the 15C this seems pretty powerful.

Best,
Carl
Find all posts by this user
Quote this message in a reply
02-17-2014, 07:48 PM
Post: #12
RE: Functions Created in CAS - My Insights
(02-17-2014 10:39 AM)CR Haeger Wrote:  I have not yet tried calling these from a program I think it would be powerful if this works.

They should work. Any program (CAS or not) becomes part of the command set once compiled.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-28-2017, 06:06 PM
Post: #13
RE: Functions Created in CAS - My Insights
(02-17-2014 07:48 PM)Han Wrote:  
(02-17-2014 10:39 AM)CR Haeger Wrote:  I have not yet tried calling these from a program I think it would be powerful if this works.

They should work. Any program (CAS or not) becomes part of the command set once compiled.

How do you compile a program in the Prime?
Find all posts by this user
Quote this message in a reply
03-28-2017, 06:47 PM
Post: #14
RE: Functions Created in CAS - My Insights
A program is compiled when its source file is exited. Just to "re-compile" a program, just open its source, and then close it.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 




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