Karim BELABAS on Tue, 16 Nov 1999 20:26:05 +0100 (MET) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Turning a sequence of expr into expr |
[Ilya:] > I got an impression that functions which take a chunk of code as an > argument always take a statement, though the parser gives them a > sequence of statements. Otherwise I cannot explain what happens here: > > \p 9 > ploth(t=100,110,z=zeta(0.5+I*t);[real(z),imag(z)]) > *** impossible assignment t_COMPLEX --> t_REAL. > > As you see, the execution started (so the skipwhatever() was expecting > a sequence), but apparently the second statement is ignored. > > If we suppose that this is not a bug in ploth(), then how to wrap > these statements into one? I hate to use > > ploth(t=100,110,[real(z=zeta(0.5+I*t)),imag(z)]) The usual trick to feed a "seq" to an "expr-reader" is to group the statements into an "if (TRUE, seq)". ploth(t=100, 110, if (1, z=zeta(0.5+I*t); [real(z),imag(z)]) ) > and defining a function is a performance hit. For that specific example, this is definitely exagerated. The "side-effect" solution is indeed ugly, but as efficient as you can get: (20:08) gp > ploth(t=100,110,[real(z=zeta(0.5+I*t)),imag(z)]) time = 17,542 ms. The "performance impaired" version is not that bad: (20:08) gp > f(t)= local(z); z=zeta(0.5+I*t);[real(z),imag(z)] (20:09) gp > ploth(t=100,110,f(t)) time = 17,547 ms. [ the "if" solution is slightly faster ] For really trivial examples, the function call overhead is about 40ms on my (very slow) machine (20:09) gp > f(t) = [0, 0] (20:10) gp > ploth(t=100,110,f(t)) time = 76 ms. %2 = [100.000000, 110.000000, 100.000000, 109.999969] (20:10) gp > ploth(t=100,110,[0,0]) time = 33 ms. Karim. __ Karim Belabas email: Karim.Belabas@math.u-psud.fr Dep. de Mathematiques, Bat. 425 Universite Paris-Sud Tel: (00 33) 1 69 15 57 48 F-91405 Orsay (France) Fax: (00 33) 1 69 15 60 19 -- PARI/GP Home Page: http://hasse.mathematik.tu-muenchen.de/ntsw/pari/