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) User defined expressions are treated differently. Code: Expression length(x) part(x,0) part(x,1) part(x,2) However... Code: Expression length(x) part(x,0) part(x,1) part(x,2) And lastly... Code: Expression length(x) part(x,0) part(x,1) part(x,2) 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 |
|||
12-21-2018, 01:36 PM
Post: #2
|
|||
|
|||
RE: CAS.part() behaviour
(12-21-2018 12:20 PM)BruceH Wrote: However... FYI, tried that on Xcas 1.4.9-57 (win32): length('NOT 5') ==> 1 part('NOT 5', 0) ==> not length('random()') ==> 0 part('random()', 0) ==> random |
|||
12-21-2018, 06:52 PM
Post: #3
|
|||
|
|||
RE: CAS.part() behaviour
I don't understand why you can not run a CAS program from the CAS. Nothing is simplified before a CAS program is called, but of course arguments are evaluated unless they are quoted.
RANDOM is not a CAS command, try with rand. I get "not" for part('NOT 0',0) (and 0 for part('NOT',1)) |
|||
12-23-2018, 12:28 AM
Post: #4
|
|||
|
|||
RE: CAS.part() behaviour
(12-21-2018 06:52 PM)parisse Wrote: I don't understand why you can not run a CAS program from the CAS. Nothing is simplified before a CAS program is called, but of course arguments are evaluated unless they are quoted. You say nothing is simplified - that is not what I am seeing. Try the following: Starting with the emulator, freshly reset via the menu and running version "Build: 2.1.14181 (2018 10 16)", I created this program: Code: #cas If I create this program: Code: test(a) If CAS does not simplify, as you say, then how do I get the CAS program to return 1+1 rather than 2? |
|||
12-23-2018, 07:09 AM
Post: #5
|
|||
|
|||
RE: CAS.part() behaviour
As I explained, it does not simplify but it evaluates. When you run test('1+1'), quote(1+1) is evaled to 1+1, then test is called with argument a==1+1, and when return(a) is evaled, a is replaced by 1+1 and evaled to 2.
You must run test(quote(quote(1+1))) to get '1+1'. (Assuming postprocessing with regroup or simplify is disabled in your settings). It's almost impossible to prevent evaluation. Evaluation will only do simple operations, like adding integers or rational fractions. It will not simplify polynomials or do more complex tasks. Evaluation is required to do most CAS tasks, otherwise some strange things could happen (for example sqrt or division will not work correctly). |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)