The Museum of HP Calculators

HP Forum Archive 21

 HP-Prime/Xcas: vector/list indexingMessage #1 Posted by fhub on 27 Oct 2013, 2:55 p.m. I don't know if this has already been addressed here, but I just found this issue when I experimented a bit with ODEs in Xcas and the HP-Prime. There's an inconsistency between the 'Home' and CAS mode: in Home mode vector/list elements are counted starting with 1 (which is the usual way in math), but in CAS mode (and Xcas itself) the indices start with 0. :-( Argh, that's really terrible and absolutely unusual (and unacceptable) in mathematics. I know that starting array indexing with 0 is usual practice in some programming languages, but NOT in math, and I can't believe that someone could come up with this idea. In [a,b,c] there's a 1st, 2nd and 3rd element, but definitely no 'element 0'! Franz Edited: 27 Oct 2013, 2:56 p.m.

 Re: HP-Prime/Xcas: vector/list indexingMessage #2 Posted by Les Koller on 27 Oct 2013, 3:00 p.m.,in response to message #1 by fhub I agree. I can understand (but loathe) the need to start at 0 in a programming language, but I always write my code around this to make element 1, element 1. True, in math, this should be totally unacceptable.

 Re: HP-Prime/Xcas: vector/list indexingMessage #3 Posted by fhub on 27 Oct 2013, 3:13 p.m.,in response to message #2 by Les Koller Yes, just think of a program you wrote in CAS mode which uses vector elements, and now you call this program in Home mode - you'll get a complete nonsense. Example: define v:=[a,b,c] in CAS mode Now v[1] returns b in CAS mode and a in Home mode!? Franz

 Re: HP-Prime/Xcas: vector/list indexingMessage #4 Posted by Les Koller on 27 Oct 2013, 3:18 p.m.,in response to message #3 by fhub Hear this HP? This HAS to be fixed. Preferably starting with ONE instead of ZERO. I can work around starting with ZERO, but it HAS to be consistent between modes on a single calculator.

 Re: HP-Prime/Xcas: vector/list indexingMessage #5 Posted by parisse on 27 Oct 2013, 3:35 p.m.,in response to message #4 by Les Koller Inside the CAS (and Xcas) you have two choices for array indices: start at 0 using [] delimiters or start at 1 using (). You just need to take care inside loop for () notation that f(j):=j+1 is ambiguous (function definition or assignation). In Xcas, you can use [[]] instead of ().

 Re: HP-Prime/Xcas: vector/list indexingMessage #6 Posted by Les Koller on 27 Oct 2013, 3:36 p.m.,in response to message #5 by parisse Thanks for that information. Making a note now..

 Re: HP-Prime/Xcas: vector/list indexingMessage #7 Posted by fhub on 27 Oct 2013, 4:52 p.m.,in response to message #5 by parisse Quote: Inside the CAS (and Xcas) you have two choices for array indices: start at 0 using [] delimiters or start at 1 using (). Thanks for the info, I didn't know that () could be used for indexing. I've just tried it and this also works in Prime's Home mode, i.e. with () the results for Home and CAS mode are the same. So unless this issue with [] has been solved, it's definitely better to only use () for list or vector indices in the Prime. Franz Edited: 27 Oct 2013, 4:53 p.m.

Go back to the main exhibit hall