Hi Jaime,
I think this is a very nice extension to makelist, I vote to integrate
it into maxima.
makelist is supported by maxima to lisp translator so that it runs
faster if it is compiled:
(%i1) f(n) := makelist(random(1.0), i, 1, n)$
(%i2) f(10^5)$
(%i3) time(%);
(%o3) [1.17]
(%i4) compile(f);
(%o4) [f]
(%i5) f(10^5)$
(%i6) time(%);
(%o6) [0.3]
which is very nice compared to create_list and makelist2 (makelist is
the slowest before compilation and the fastest after compilation):
(%i7) g(n) := create_list(random(1.0), i, 1, n)$
(%i8) g(10^5)$
(%i9) time(%);
(%o9) [0.42]
(%i10) compile(g)$
(%i11) g(10^5)$
(%i12) time(%);
(%o12) [0.46]
(%i13) cload("Downloads/makelist2.lisp")$
(%i14) h(n) := makelist2(random(1.0), n)$
(%i15) h(10^5)$
(%i16) time(%);
(%o16) [0.86]
(%i17) compile(h);
(%o17) [h]
(%i18) h(10^5)$
(%i19) time(%);
(%o19) [0.81]
The translation is defined in src/trans1.lisp, I think it should be
easy to extend it.
Andrej
On Sat, Apr 10, 2010 at 5:45 AM, Jaime Villate <villate at fe.up.pt> wrote:
> On Sat, 2010-04-10 at 01:39 +0100, Jaime Villate wrote:
>> Here is how to obtain exactly the same results with makelist2
>> (attached to this message). There are two cases that fail (identified
>> with xxxxxxxx) but both would be very easy to implement;
>
> OK, I have fixed it and makelist2 now solves all the problems in the
> list that John sent, and even some where his Table function fails:
>
> (%i3) Table ( f(i), [i, 10, -5, -2] );
> (%o3) ? ? ? ?[f(10), f(8), f(6), f(4), f(2), f(0), f(- 2), f(- 4)]
> (%i4) makelist2 ( f(i), i, 10, -5, -2 );
> (%o4) ? ? ? ?[f(10), f(8), f(6), f(4), f(2), f(0), f(- 2), f(- 4)]
>
>
> (%i6) Table ( 2^x + x, [x, a, a + 2* n, n] );
> ? ? ? ? ? ? ? ? ? a ? ? ? n + a ? ? ? ? ? 2 n + a
> (%o6) ? ? ? ? ? ?[2 ?+ a, 2 ? ? ?+ n + a, 2 ? ? ? ?+ 2 n + a]
> (%i7) makelist2 ( 2^x + x, x, a, a + 2* n, n );
> ? ? ? ? ? ? ? ? ? a ? ? ? n + a ? ? ? ? ? 2 n + a
> (%o7) ? ? ? ? ? ?[2 ?+ a, 2 ? ? ?+ n + a, 2 ? ? ? ?+ 2 n + a]
>
>
> (%i8) Table ( 2^x + x, [x, a + 2*n , a, -n] );
>
> argument '[X,[A,[2,N]],A,[N]]' does not have the correct form for an
> iterator
> ?-- an error. To debug this try: debugmode(true);
>
> (%i9) makelist2 ( 2^x + x, x, a + 2*n , a, -n );
> ? ? ? ? ? ? ? ? ? 2 n + a ? ? ? ? ? ? n + a ? ? ? ? ? a
> (%o9) ? ? ? ? ? ?[2 ? ? ? ?+ 2 n + a, 2 ? ? ?+ n + a, 2 ?+ a]
>
>
> (%i10) Table ( 1 );
> (%o10) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1
> (%i11) makelist2 ( 1 );
> (%o11) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[1]
> (%i12) Table( random ( 10 ) );
> (%o12) ? ? ? ? ? ? ? ? ? ? ? ? ? ?random(10)
> (%i13) makelist2 ( random ( 10 ) );
> (%o13) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[2]
>
> In these last two tests Table works but, regardless of Mathematicas
> behavior in that case, I think that the correct thing to do is to return
> a list.
>
> Regards,
> Jaime
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima