Karim Belabas on Thu, 20 Jun 2013 19:06:41 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: setsearch flags |
* Charles Greathouse [2013-06-20 18:57]: > I just sent in a bug with setsearch, where > > setsearch([1.1,1.3],1.2,1) > and > > setsearch([1.1,2],1.2,1) > give different results despite the element being in the same position in > both cases. (Wrapping the vectors with Set() gives the same results.) Doesn't look like a bug to me. The documentation for Set() doesn't state that elements are ordered with respect to standard ordering of the real line [ which would be absurd since PARI sets can contain arbitrary elements ]. And in fact, they aren't: (19:02) gp > \p3 realprecision = 19 significant digits (3 digits displayed) (19:02) gp > Set([1.1,1.2,1.3]) %5 = [1.10, 1.20, 1.30] (19:02) gp > Set([1.1,1.2,2]) %6 = [2, 1.10, 1.20] See ??cmp for details. > I discovered this while writing some code looking for the number of > elements in a set in an interval. This is impossible to do efficiently given the current implementation of sets: you must check individually whether each element in your set belongs to the interval... UNLESS your sets consist only of integers (in which case sets are ordered as you expected) Cheers, K.B. -- Karim Belabas, IMB (UMR 5251) Tel: (+33) (0)5 40 00 26 17 Universite Bordeaux 1 Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux1.fr/~kbelabas/ F-33405 Talence (France) http://pari.math.u-bordeaux1.fr/ [PARI/GP] `