HP Prime: CAS Commands in Home Mode - 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: HP Prime: CAS Commands in Home Mode (/thread-146.html) HP Prime: CAS Commands in Home Mode - Eddie W. Shore - 12-18-2013 04:21 AM http://edspi31415.blogspot.com/2013/12/hp-prime-cas-commands-in-home-mode.html RE: HP Prime: CAS Commands in Home Mode - Michael de Estrada - 12-18-2013 04:54 AM Hi Eddie, There's an alternate approach that I prefer that preserves the CAS format and avoids all the quoting or changing from lower case to upper case. For example: zeros(r^3-6,r) in CAS view becomes CAS("zeros(r^3-6,r)") in Home view. This also works well when using CAS commands in programs. RE: HP Prime: CAS Commands in Home Mode - Helge Gabert - 12-18-2013 09:48 PM A question: Why exactly are the quotes (" ") needed? Thanks! RE: HP Prime: CAS Commands in Home Mode - Han - 12-18-2013 09:53 PM (12-18-2013 09:48 PM)Helge Gabert Wrote:  A question: Why exactly are the quotes (" ") needed? Thanks! Arguments inside ( ) are handled as if from the Home view. So without it, the parser tries to evaluate the arguments and will error out as it is unable to evaluate undefined variables. By passing a string, the single argument then gets parsed by the CAS parser. (Yes, there are two separate parsers at the moment.) RE: HP Prime: CAS Commands in Home Mode - Helge Gabert - 12-19-2013 12:17 AM Thanks so much! And what would be the best way to pass a function or symbolic expression to a PPL program from the home view command line? I know that defining a function in CAS view first, say a(x):=x^2+2, works - - which then can be called by the CAS(" . . . a(x) ") construct in the PPL program. Alternatively, defining F0, . . . , F9 beforehand also works with CAS("solve(F1(x),x") etc. But can I call the PPL program like TEST(X^2+2)? And have the PPL program TEST(k) . . . do something here with k, recognizing k is a function? END; That doesn't seem to work. RE: HP Prime: CAS Commands in Home Mode - Han - 12-19-2013 12:57 AM Sure -- all you have to remember is that an unevaluated expression needs single-quoting. So you can pass an expression via: TEST('X^2+2*X') and the program Code: ```TEST(k) BEGIN   // blah blah END;``` will store the symbolic expression X^2+2*X into k. RE: HP Prime: CAS Commands in Home Mode - John Colvin - 12-19-2013 01:06 AM I prefer using RPN mode in Home View, but I keep getting a syntax error when I attempt to use CAS. For example, if I enter the following expression: CAS("zeros(X^3-4)"), I get the Error: syntax error message. What am I doing wrong or does RPN mode not support CAS operations? RE: HP Prime: CAS Commands in Home Mode - Han - 12-19-2013 01:11 AM Type: "zeros(x^3-4)" ENTER CAS(1) In RPN mode, commands have an "argument" specifying how many stack arguments to use. Hence the CAS(1). Also, remember that when using CAS, global variables like X get replaced with their actual values. Thus, X^3-4 will result in an empty vector (no solution) since you would be equivalently solving for the zeros of a constant function. So do note the lower case x in the commands above. RE: HP Prime: CAS Commands in Home Mode - John Colvin - 12-19-2013 01:15 AM (12-19-2013 01:11 AM)Han Wrote:  Type: "zeros(x^3-4)" ENTER CAS(1) In RPN mode, commands have an "argument" specifying how many stack arguments to use. Hence the CAS(1). Also, remember that when using CAS, global variables like X get replaced with their actual values. Thus, X^3-4 will result in an empty vector (no solution) since you would be equivalently solving for the zeros of a constant function. So do note the lower case x in the commands above. Thanks Han, I didn't know that. RE: HP Prime: CAS Commands in Home Mode - Helge Gabert - 12-19-2013 03:24 AM (12-19-2013 12:57 AM)Han Wrote:  Sure -- all you have to remember is that an unevaluated expression needs single-quoting. So you can pass an expression via: TEST('X^2+2*X') and the program Code: ```TEST(k) BEGIN   // blah blah END;``` will store the symbolic expression X^2+2*X into k. Yes, of course, single quotes are fine with upper case X, but you get an error if you try TEST('x^2+2*x') in home view, so you are forced to use TEST('X^2+2*X'), and then, inside the program, you cannot write something like CAS("subst(k, X='x')"), because nothing gets substututed, (only returns k), so you can't use the function with lower case 'x' for further processing with CAS commands/functions. RE: HP Prime: CAS Commands in Home Mode - cyrille de brébisson - 12-20-2013 09:12 AM Hello Quote:Inside the program, you cannot write something like CAS("subst(k, X='x')"), because nothing gets substututed, (only returns k), so you can't use the function with lower case 'x' for further processing with CAS commands/functions. HAve you tried using subst(k, "X='x'"); ? this would cause numerical mode to send the value of k and a CAS compiled "X='x'" to the CAS subst command... Cyrille RE: HP Prime: CAS Commands in Home Mode - Helge Gabert - 12-20-2013 10:49 PM I will try that. Thank you for the suggestion! RE: HP Prime: CAS Commands in Home Mode - Helge Gabert - 12-20-2013 11:13 PM No, that doesn't work. I get the message "Syntax Error" when I check my program, and the cursor is on the first inner " of the line (the second double quote from the left) CAS("subst(k,"X='x'")"); Anything else I can try, or do I need to write this as a "true" CAS program, and forget about calling the program from home? No, that doesn't work. I get the message "Syntax Error" when I check my program, and the cursor is on the first inner " of the line (the second double quote from the left) CAS("subst(k,"X='x'")"); Anything else I can try, or do I need to write this as a "true" CAS program, and forget about calling the program from home? No, that doesn't work. I get the message "Syntax Error" when I check my program, and the cursor is on the first inner " of the line (the second double quote from the left) CAS("subst(k,"X='x'")"); Anything else I can try, or do I need to write this as a "true" CAS program, and forget about calling the program from home? No, that doesn't work. I get the message "Syntax Error" when I check my program, and the cursor is on the first inner " of the line (the second double quote from the left) CAS("subst(k,"X='x'")"); Anything else I can try, or do I need to write this as a "true" CAS program, and forget about calling the program from home? RE: HP Prime: CAS Commands in Home Mode - Han - 12-21-2013 12:39 AM I'm going to add spacing into your command: CAS("subst(k," X='x' ")" ); This makes no sense. Your arguments consist of three objects (a string, the expression X='x', and another string) simply juxtaposed. The other caveat is that what you substitute must not be pre-defined. So the global variables will not work. You can verify this is CAS view by typing: subs('X^2-1', X=2) and you will see the warning. There are two approaches I know of: Code: ``` EXPORT TEST(k) BEGIN k:="subst('" + k + "', x='t')" ; CAS(k); END;``` This method requires you use a string for the input k (e.g. TEST("x^2-1") and use non-global variables). The next method (below) uses REPLACE(). Code: ``` EXPORT TEST(k) BEGIN k:=REPLACE(k, "X", "x"); k:="'" + k + "'"; // add quotes for non-evaluation CAS(k);  END;``` Now, try typing TEST("X^2-1"). RE: HP Prime: CAS Commands in Home Mode - Helge Gabert - 12-21-2013 05:44 AM Yes, the second method works! The first one doesn't, though. (And I know, the last try was non-sensical, but that was what Cyrille suggested). Thanks for the tip with REPLACE! Of course, one needs to input the symbolic expression as a string, but that is OK. RE: HP Prime: CAS Commands in Home Mode - Han - 12-21-2013 05:54 AM (12-21-2013 05:44 AM)Helge Gabert Wrote:  Yes, the second method works! The first one doesn't, though. (And I know, the last try was non-sensical, but that was what Cyrille suggested). Thanks for the tip with REPLACE! Of course, one needs to input the symbolic expression as a string, but that is OK. The first one only works if the input is a string, and the initial variable you used is not defined -- so no global variables for sure. So and input of "X^2-1" won't work, but "x^2-1" will. Note the lower case x in the code. And also note that x defined in Home view is different from x defined in CAS view. (So you need to make sure to delete x from the memory browser as well as use: purge(x) in the CAS view.) RE: HP Prime: CAS Commands in Home Mode - Helge Gabert - 12-21-2013 06:50 AM Alright - - but I have to say I prefer the second method - - it is a lot less cumbersome. I enjoy the Prime (speed and color), and it is fun in interactive mode, but in comparison to the elegance of the 50G, where every object gets processed according to consistent rules, the Prime's idiosyncrasies with respect to programming symbolic expressions, constitute a step backward. RE: HP Prime: CAS Commands in Home Mode - Miguel Toro - 12-21-2013 02:15 PM (12-19-2013 01:15 AM)John Colvin Wrote:   (12-19-2013 01:11 AM)Han Wrote:  Type: "zeros(x^3-4)" ENTER CAS(1) In RPN mode, commands have an "argument" specifying how many stack arguments to use. Hence the CAS(1). Also, remember that when using CAS, global variables like X get replaced with their actual values. Thus, X^3-4 will result in an empty vector (no solution) since you would be equivalently solving for the zeros of a constant function. So do note the lower case x in the commands above. Thanks Han, I didn't know that. Hi, "zeros(x^3-4,x)" [ENTER] CAS [ENTER] would do. Regards, Miguel RE: HP Prime: CAS Commands in Home Mode - Miguel Toro - 12-23-2013 12:46 PM Hi, To elaborate on the RPN syntax for calling CAS commands from HOME: 1. Simplify “simplify(4*atan(1/5)-atan(1/239))” [ENTER] CAS [ENTER] returns 1/4*pi 2. Expand a) If you use ‘X’ (uppercase): “expand(‘(X+3)^2’)” [ENTER] CAS [ENTER] returns X^2+6*X+9 b) if not: “expand((x+3)^2)” [ENTER] CAS [ENTER] returns x^2+6*x+9 3. Factor a) “factor(‘X^2-5*X+4’)” [ENTER] CAS [ENTER] returns (X-4)*(X-1) b) “factor(x^2-5*x+4)” [ENTER] CAS [ENTER] returns (x-4)*(x-1) 4. Differentiation “diff(‘COS(X)*SIN(X)’)” [ENTER] CAS [ENTER] returns -SIN(X)*SIN(X)+COS(X)*COS(X) “simplify(‘-SIN(X)*SIN(X)+COS(X)*COS(X)’)” [ENTER] CAS [ENTER] returns 2*COS(X)^2-1 5. Summation “sum(‘N^3’,’N’,1,9)” [ENTER] CAS [ENTER] returns 2025 6. Solving “zeros(‘X^3-6’)” [ENTER] CAS [ENTER] returns [1.81712059283]