Prof. J. E. Cremona on Thu, 30 Sep 2004 11:01:01 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

sorting problems


I'm having trouble searching for an element in a (sorted) vector/list of positive integers in GP. Using vecsort I can sort the vector and keep the associated permutation; but the only searching function is setsearch() which requires the list to be a set. It converts the object being searched for into a string but not the list itself. If you convert the list into a set then another permutation is applied (since lexicographical order is not the same as numerical order!) but not recorded...

trivial example:  3<12 but "12"<"3" :

(09:32) gp > a=[12,3]
%122 = [12, 3]
(09:40) gp > ia=vecsort(a,,1)
%123 = [2, 1]
(09:40) gp > sa=vecextract(a,ia)
%125 = [3, 12]
(09:41) gp > setsearch(sa,12)
%126 = 0
(09:41) gp > setsearch(Set(sa),12)
%127 = 1
(09:41) gp > Set(sa)
%128 = ["12", "3"]
(09:41) gp > setsearch(Set(sa),3)
%130 = 2

All I need in the end is: given a (large) vector [x_1,x_2,...,x_n] of (unsorted) integers, I want to be able to ask of any integer x if x=x_i for some i and of so which....surely a common task!

John

--
 Prof. J. E. Cremona             |
 University of Nottingham        | Tel.:  +44-115-9514920
 School of Mathematical Sciences | Fax:   +44-115-9514951
 University Park                 | Email: John.Cremona@nottingham.ac.uk
 Nottingham NG7 2RD, UK          |


This message has been scanned but we cannot guarantee that it and any
attachments are free from viruses or other damaging content: you are
advised to perform your own checks.  Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.