Post Reply 
CASE and PIECEWISE in CAS programs
07-21-2014, 10:45 PM
Post: #1
CASE and PIECEWISE in CAS programs
Hi,
I wrote a CAS program that contains the CASE command, like this
Code:
(x)->BEGIN
LOCAL k,s:=0;
CASES
IF x=0 THEN RETURN(s) END;
IF x=1 THEN RETURN(s+1) END;
DEFAULT
FOR k FROM 2 TO x DO
s:=s+1/(k^2-k);
END;
END;
RETURN(s);
END;

The "Check" soft-key returns No errors in the program. So I exit the program editor and confirm that the program works OK. When I return to this program for further editing, I find that the Prime has rewritten it like so:

Code:
(x)->BEGIN
 LOCAL k,s;
    s:=0;
    piecewise([x=0, RETURN(s), x=1, RETURN(s+1), FOR k FROM 2 TO x DO s:=s+1/(k^2-k); END;]);
    RETURN(s);
END;

So the CASE has been changed to piecewise. The program also runs OK, but no the "Check" soft-key returns
Error:Syntax Error and upon exiting the program editor (Shift+Programs), the Prime displays Syntax error in program line 3

I wonder if anyone knows what is going on. Thank you.
Find all posts by this user
Quote this message in a reply
07-22-2014, 09:50 AM (This post was last modified: 07-22-2014 10:49 AM by parisse.)
Post: #2
RE: CASE and PIECEWISE in CAS programs
There is an extra ; after END before ] in piecewise (and [] should not be there).
I'm going to fix piecewise printing on the Prime.
Find all posts by this user
Quote this message in a reply
07-22-2014, 03:13 PM (This post was last modified: 07-22-2014 03:20 PM by Alberto Candel.)
Post: #3
RE: CASE and PIECEWISE in CAS programs
(07-22-2014 09:50 AM)parisse Wrote:  There is an extra ; after END before ] in piecewise (and [] should not be there).
I'm going to fix piecewise printing on the Prime.

yes, removing the extra ; after END shows no errors. But the prime will put the ; back, and it will move the closing parenthesis from the two RETURN() to the end. This renders the program unusable, as there is no way to correct it; it has to be rewritten with CASE.
Find all posts by this user
Quote this message in a reply
07-22-2014, 04:13 PM
Post: #4
RE: CASE and PIECEWISE in CAS programs
If you edit your CAS program in the programming editor, it will be stored as is (not parsed and re-printed), and you can modify it without any problem.
Find all posts by this user
Quote this message in a reply
07-22-2014, 09:23 PM
Post: #5
RE: CASE and PIECEWISE in CAS programs
(07-22-2014 04:13 PM)parisse Wrote:  If you edit your CAS program in the programming editor, it will be stored as is (not parsed and re-printed), and you can modify it without any problem.

I am pretty sure I was doing Shift+Program, then select, then Edit. I also had the Algebraic entry in the Home settings (it appears that piecewise behaves differently with Textbook entry).
Find all posts by this user
Quote this message in a reply
Post Reply 




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