Karim Belabas on Thu, 10 Apr 2014 21:21:39 +0200

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

Re: +oo / -oo (infinity)

* Charles Greathouse [2014-04-10 17:13]:
> Has gp2c been informed of the changes?

Of course ! As an unwanted side effect, gp2c must currently translate
poldegree() to the wrapper gppoldegree() -- which returns a GEN, either a
t_INT or a t_INFINITY -- , instead of 'degpol' (which returns a long).

> Do we need a new union type (like mp
> = int U real) which includes infinities?

I don't think so. No "ordinary" computation can produce +oo / -oo from
scratch: currently only valuations / degree (and negation, but you have
to start from an infinity to get back one).

It's rather a "name" (well, two names). Besides the uses already
mentionned in my previous mail, it can be used as a sentinel, e.g.

  MAX(v) = my(m = -oo); for (i = 1, #v, if (v[i] > m, m = v[i])); m;

which is slightly more elegant than

  MAXold(v) =
    if (#v == 0, return ("undef"));
    my(m = v[1]); for (i = 2, #v, if (v[i] > m, m = v[i])); m;

(of course, vecmax is available !).

N.B. before this new symbol, 
- valuation(0) returned the "impossible value" 2^31-1 or 2^63-1
  (LONG_MAX, the recommanded old construction was to test
  valuation(x) == valuation(0) ...)

- poldegree(0) returned "a negative number whose precise value should
  not be used". Unfortunately the test poldegree(T) < 0 was not perfect
  since poldegree also allows rational functions (t_RFRAC)

- \pm\infty was coded as [1] or [-1] in numerical integration routines.

Etc. It felt right to introduce a convenient common name for all these
situations, to replace the old (working but awkward) "hacks".


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]