HP Forums
Bug with CONCAT - 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: Bug with CONCAT (/thread-307.html)



Bug with CONCAT - Helge Gabert - 01-02-2014 04:23 PM

I've come across a problem with CONCAT and two arguments (firmware 5447).

Try CONCAT(5,6) returns 0. ???

CONCAT(5,6,7) returns [ 5 6 7 ], as it should.

In a program, for now, one can get around this problem with defining a list first, e.g.,

l:= {}

l:=CONCAT(l,5);

l:=CONCAT(l,6);

RETURN (l); returns the list {5, 6}.

I thought I should mention this because I got unexpected results in my program, and was finally able to trace it - - I called RETURN(CONCAT(v1,v2)) and obtained 0.

Also CAS programs really should be debuggable (just like PPL programs) - - why is the DEBUG soft key missing for CAS programs in the editor?


RE: Bug with CONCAT - Helge Gabert - 01-02-2014 04:34 PM

The above problem occurs in CAS view, and with a CAS program, I should add.


RE: Bug with CONCAT - Michael de Estrada - 01-02-2014 05:52 PM

I find it interesting that if the first entry is a list, then it works, i.e. CONCAT({5},6) --> {5,6}. However, you can only have one item after the list, e.g. CONCAT({5},6,7) --> [{5} 6 7], but CONCAT({5},{6,7}) --> {5,6,7}. Also, CONCAT(5,{6,7}) --> {5,6,7} works as well.


RE: Bug with CONCAT - Helge Gabert - 01-02-2014 05:58 PM

Yes, that is interesting. Same with my workaround with an empty list at the beginning. Works for two arguments.


RE: Bug with CONCAT - Michael de Estrada - 01-02-2014 06:10 PM

I also found that as long as one of the arguments is a list, then it works ok, i.e. CONCAT(5,{6}) --> {5,6} also works.


RE: Bug with CONCAT - Alberto Candel - 01-02-2014 06:39 PM

And with strings:

CONCAT("5","6") -> "56"

and

CONCAT("5",6) -> "56"


RE: Bug with CONCAT - Mark Hardman - 01-02-2014 07:51 PM

I wonder if this is a case of xcas attempting to parse the argument (5,6) as an imaginary number.

There was a thread in the old forums with a similar issue. I've searched and could not find a link.

Mark Hardman


RE: Bug with CONCAT - Michael de Estrada - 01-02-2014 09:47 PM

(01-02-2014 07:51 PM)Mark Hardman Wrote:  I wonder if this is a case of xcas attempting to parse the argument (5,6) as an imaginary number.

There was a thread in the old forums with a similar issue. I've searched and could not find a link.

Mark Hardman

I don't think so, since it would not recognize it as such w/o a second set of parentheses. Also, I think you meant to say complex number. For example:

CONCAT(1,2) --> 0

but,

CONCAT((1,2)) --> CONCAT((1,2))
CONCAT(1+2*i) --> CONCAT(1+2*i)

because it can't further combine a complex number into itself

however,

CONCAT((1,2),(3,4)) --> 0
CONCAT(1+2*i,3+4*i) --> 0

but,

CONCAT((1,2),(3,4),(5,6)) --> [(1,2),(3,4),(5,6)]
CONCAT(1+2*i,3+4*i,5+6*i) --> [1+2*i,3+4*i,5+6*i]


RE: Bug with CONCAT - Terje Vallestad - 01-02-2014 11:07 PM

(01-02-2014 04:23 PM)Helge Gabert Wrote:  I've come across a problem with CONCAT and two arguments (firmware 5447).

Try CONCAT(5,6) returns 0. ???

CONCAT(5,6,7) returns [ 5 6 7 ], as it should.

In a program, for now, one can get around this problem with defining a list first, e.g.,

l:= {}

l:=CONCAT(l,5);

l:=CONCAT(l,6);

RETURN (l); returns the list {5, 6}.

I thought I should mention this because I got unexpected results in my program, and was finally able to trace it - - I called RETURN(CONCAT(v1,v2)) and obtained 0.

Also CAS programs really should be debuggable (just like PPL programs) - - why is the DEBUG soft key missing for CAS programs in the editor?

I think if you try the function \( cat \) you will get the response you are looking for?

The user manual only states CONCAT to be used with lists so you may be confusing the parser?

Cheers, Terje


RE: Bug with CONCAT - Michael de Estrada - 01-02-2014 11:16 PM

(01-02-2014 11:07 PM)Terje Vallestad Wrote:  I think if you try the function \( cat \) you will get the response you are looking for?

The user manual only states CONCAT to be used with lists so you may be confusing the parser?

Cheers, Terje

The problem is that the Prime Help for CONCAT does not say this, and simply states that it joins items (values) into a list. One of the examples is CONCAT(1,2,3,4) which returns {1,2,3,4}.


RE: Bug with CONCAT - Helge Gabert - 01-02-2014 11:21 PM

(01-02-2014 11:07 PM)Terje Vallestad Wrote:  
(01-02-2014 04:23 PM)Helge Gabert Wrote:  I've come across a problem with CONCAT and two arguments (firmware 5447).

Try CONCAT(5,6) returns 0. ???

CONCAT(5,6,7) returns [ 5 6 7 ], as it should.

In a program, for now, one can get around this problem with defining a list first, e.g.,

l:= {}

l:=CONCAT(l,5);

l:=CONCAT(l,6);

RETURN (l); returns the list {5, 6}.

I thought I should mention this because I got unexpected results in my program, and was finally able to trace it - - I called RETURN(CONCAT(v1,v2)) and obtained 0.

Also CAS programs really should be debuggable (just like PPL programs) - - why is the DEBUG soft key missing for CAS programs in the editor?

I think if you try the function \( cat \) you will get the response you are looking for?

The user manual only states CONCAT to be used with lists so you may be confusing the parser?

Cheers, Terje

I'm not sure I understand you at all.

I'm trying to join two elements into a list (in CAS view, or in a CAS program). CONCAT is the correct command, and it doesn't work, because it returns zero.

Does it work for you?


RE: Bug with CONCAT - Terje Vallestad - 01-02-2014 11:40 PM

(01-02-2014 11:21 PM)Helge Gabert Wrote:  
(01-02-2014 11:07 PM)Terje Vallestad Wrote:  I think if you try the function \( cat \) you will get the response you are looking for?

The user manual only states CONCAT to be used with lists so you may be confusing the parser?

Cheers, Terje

I'm not sure I understand you at all.

I'm trying to join two elements into a list (in CAS view, or in a CAS program). CONCAT is the correct command, and it doesn't work, because it returns zero.

Does it work for you?

Yes. On the calculator. For instance cat(5,6) gives "56", but maybe that was not what you were looking for?

Cheers, Terje


RE: Bug with CONCAT - Helge Gabert - 01-02-2014 11:58 PM

No, unfortunately, that is not what I'm looking for. But thanks for your response!


RE: Bug with CONCAT - Michael de Estrada - 01-03-2014 12:11 AM

I just discovered something. CONCAT is not a CAS command, so if you run it in Home view it works correctly, i.e. CONCAT(5,6) --> {5,6}. So, if you run it in a program, it should work if you don't CAS it.

I just wrote this short program and it worked:

EXPORT Ctest(v1,v2)
BEGIN
RETURN CONCAT(v1,v2);
END;


RE: Bug with CONCAT - Helge Gabert - 01-03-2014 01:19 AM

Yes it works correctly in Home View; I know that.

Unfortunately, my program is a CAS program, and there is where I run into trouble. Is there an equivalent CAS function for CONCAT? To your knowledge?

(Actually, this is all kind of silly - - CONCAT should work in both modes (CAS and Home), and it does work correctly in CAS for arguments of three or more. It makes absolutely no sense why it should not work in the CAS environment for two arguments only).


RE: Bug with CONCAT - Michael de Estrada - 01-03-2014 01:49 AM

(01-03-2014 01:19 AM)Helge Gabert Wrote:  Yes it works correctly in Home View; I know that.

Unfortunately, my program is a CAS program, and there is where I run into trouble. Is there an equivalent CAS function for CONCAT? To your knowledge?

(Actually, this is all kind of silly - - CONCAT should work in both modes (CAS and Home), and it does work correctly in CAS for arguments of three or more. It makes absolutely no sense why it should not work in the CAS environment for two arguments only).

I'm not aware of a CAS-specific function for Concatenation, but the CAS problem goes beyond what you've identified. For example CONCAT({5},{6},7) returns {5,6,7} in Home view, but it returns [{5} {6} 7] in CAS view. IOW, in Home view it properly combines the three items into a single list, but in CAS view it simply creates a size 3 vector containing those items.


RE: Bug with CONCAT - Helge Gabert - 01-03-2014 02:03 AM

Yes, good observation!

It appears, generally speaking, that vectors and lists are somewhat interchangeable in CAS (a concept that I don't like myself, but there it is).

For example, you can save the aforementioned vector of yours to a list, e.g.,

store [ 5 6 7 ] in L1. It works! Then, recall L1. Voila! Now it morphed into a list.

{5 6 7 }.

Funny . . .