Post Reply 
CAS.part() behaviour
12-21-2018, 12:20 PM
Post: #1
CAS.part() behaviour
One for M. Parisse I think...

I'm trying to split and process an expression a bit at a time using a NUMERIC mode program.

Mostly CAS.part() will let me do this but there are some inconsistencies that might be the result of me missing the bigger picture. An explanation would be helpful.

Firstly the bit I understand:
Code:
Expression      length(x)    part(x,0)   part(x,1)   part(x,2)
----------      ---------    ---------   ---------   ---------
'SIN(30)'       1            "sin"       30          error
'COMB(10,2)'    2            "COMB"      10          2
'5+6'           2            "+"         5           6
'SIN(5+6)'      1            "sin"       5+6         error
'5+SIN(30)'     2            "+"         5           SIN(30)
The above seems simple enough: a single parameter function has length 1 and its parts are the function name and the parameter. Functions with two or more parameters have a proportionately longer length and proportionately more parts available. Infix operator expressions are treated as two-parameter functions. Lastly, more complicated expressions are nested, meaning that they can be processed recursively. So far so good.


User defined expressions are treated differently.
Code:
Expression      length(x)    part(x,0)   part(x,1)   part(x,2)
----------      ---------    ---------   ---------   ---------
userdef(1,2,3)  2            "of"        "userdef"   [1,2,3]
Getting back the word "of" for the function name is a bit unexpected but at least I can use that to detect a user-defined function.


However...
Code:
Expression      length(x)    part(x,0)   part(x,1)   part(x,2)
----------      ---------    ---------   ---------   ---------
'NOT 5'         2            "of"        NOT         5
Hmm, so maybe "of" can't be used to identify user-defined functions after all.


And lastly...
Code:
Expression      length(x)    part(x,0)   part(x,1)   part(x,2)
----------      ---------    ---------   ---------   ---------
'RANDOM()'      1            "RANDOM"    RANDOM      error
Why doesn't this just return length 0 to signify no parameters?


Possibly (probably?) some of this behaviour is because I'm running in NUMERIC mode, however I have to because, in the CAS environment, I can't find a way to pass expressions as parameters to a CAS mode program without them being simplified before the program gets hold of them, even when quoted.

Version: 2.1.14181 (2018 10 16)
CAS Version: 1.4.9
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
CAS.part() behaviour - BruceH - 12-21-2018 12:20 PM
RE: CAS.part() behaviour - Albert Chan - 12-21-2018, 01:36 PM
RE: CAS.part() behaviour - parisse - 12-21-2018, 06:52 PM
RE: CAS.part() behaviour - BruceH - 12-23-2018, 12:28 AM
RE: CAS.part() behaviour - parisse - 12-23-2018, 07:09 AM



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