Karim BELABAS on Sun, 19 Jan 2003 11:41:45 +0100 (MET)


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

Re: gp: lex("x",y)


On Sat, 18 Jan 2003, Michael Somos wrote:
> pari-dev,
>
> ? lex(x,"y")
>   ***   incorrect type in comparison.
>
> is probably correct in flagging an error, but how about this :
>
> ? lex("x",y)
> %1 = 1
>
> why is this not also an error as well? Shalom, Michael

Actually, it should not give an error. Currently, a t_STR is assumed to be
larger than any other non t_STR object [ for two t_STR, lexicographic string
comparison is performed ].

I am afraid this was not documented [ it is, now ].

The reason for this non-obvious behaviour is that to implement Sets, we need
"universal" comparison functions. The easy way of providing this total order
on PARI objects is to stringify set elements, which is rather inefficient.
The other way is to use ordinary objects, comparable in the standard
mathematical sense [ e.g integers ]. With the convention above, both are
compatible ( sort of, we have 1 < "1" ).

I am afraid this is not documented either [ and still is not, since it is
rather a kludge. It might be a good idea to reimplement sets in a more clever
way ].

Cheers,

    Karim.
-- 
Karim Belabas                    Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425  Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud             Email: Karim.Belabas@math.u-psud.fr
F-91405 Orsay (France)           http://www.math.u-psud.fr/~belabas/
--
PARI/GP Home Page: http://www.parigp-home.de/