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

My immediate purpose was an implementation of Hooley's Î function, which I tried to define as:


For each divisor d < n of n, this finds the number of divisors in the interval [d, de]. So my vector does consist only of integers. Unfortunately neither flag gives the desired behavior, since one or both of floor(de) and floor(de+1) may be in the set.

Thus my feature request for another flag on setsearch.

Now that you've clarified, I wonder if it might be helpful to add a note at ?setsearch as well.

Charles Greathouse
Case Western Reserve University

On Thu, Jun 20, 2013 at 1:06 PM, Karim Belabas <> wrote:
* 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

UNLESS your sets consist only of integers (in which case sets are ordered as
you expected)


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  Â
Talence (France) Â Â Â Â[PARI/GP]