Charles Greathouse on Thu, 20 Jun 2013 19:29:14 +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, whereDoesn't look like a bug to me.
> > 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.)
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.
This is impossible to do efficiently given the current implementation of sets:
> I discovered this while writing some code looking for the number of
> elements in a set in an interval.
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]
`