Post Reply 
concat in CAS
11-15-2014, 09:41 PM (This post was last modified: 11-15-2014 09:42 PM by Gilles.)
Post: #1
concat in CAS
In CAS :

f(n):={n²,n²+1}

CONCAT(f(1),f(2))
returns
{1,2,4,5} -> OK

CONCAT(f(1),f(2),f(3))
returns
{{1,2},{4,5},{9,10}} -> ??

expected is
{1,2,4,5,9,10}
Find all posts by this user
Quote this message in a reply
11-16-2014, 04:50 AM (This post was last modified: 11-16-2014 04:55 AM by Han.)
Post: #2
RE: concat in CAS
The CAS behavior is slightly different from the Home behavior because it has two ways to represent lists. Lists are either delimited by {}, or by []. This can be verified by typing (in CAS):

type([1,2]); // note the lower-case type() command and not TYPE()
type({1,2});

both report DOM_LIST as the CAS type. You may not be aware that simply typing in:

1,2,3,4

into the command line in the CAS view creates a (CAS) list of the form [1,2,3,4]. In fact, typing any sequence of values or expressions separated by commas will create a similar "list". The help text for the command indicates that when providing more than 2 arguments to the command, all arguments are then placed into a list. Thus,

CONCAT({1,2}, {3,4}, {5,6});

would result in [ {1,2} {3,4} {5,6} ] which is a list of the three arguments passed to CONCAT(). Strangely, the behavior in Home does not follow this rule, so that

CONCAT({1,2}, {3,4}, {5,6});

actually produces {1,2,3,4,5,6}. If there is a bug, I would think that it is more likely in the Home behavior than the CAS behavior (if we are to adhere to the Help screen for the command, that is).

P.S. The use of both {} and [] for lists (while I don't like it myself), is common in many various implementations of computer algebra system). What muddies the water even more is that {} are also used for sets.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
11-16-2014, 06:59 AM
Post: #3
RE: concat in CAS
concat takes 2 arguments. If it has more than 2 args, it returns the arguments. That's indeed not very useful, perhaps we can change this and concat all the arguments.
Find all posts by this user
Quote this message in a reply
11-16-2014, 09:36 AM
Post: #4
RE: concat in CAS
Thanks for explanations.

It would be fine if CONCAT would accept more than 2 arguments to avoid things like :

l:=concat(l1,concat(l2,concat(l3,concat ....))))

or a serie of concat

l:=concat(l1,l2)
l:=concat(l,l3)
...
Find all posts by this user
Quote this message in a reply
11-16-2014, 03:16 PM
Post: #5
RE: concat in CAS
(11-16-2014 06:59 AM)parisse Wrote:  concat takes 2 arguments. If it has more than 2 args, it returns the arguments. That's indeed not very useful, perhaps we can change this and concat all the arguments.

That's interesting -- returning the arguments is actually the same result as putting them all into a list delimited by []'s because of how the CAS interprets values separated by commas.

I think having it match the Home behavior is probably best (and what is most expected). The help screen would need to be modified since I think most people expect

CONCAT({1,2},3,{4,5})

to produce a single list containing {1,2,3,4,5} and not {{1,2},3,{4,5}} as suggested by the help text.

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)