A inconsistency with maplist (or with my understanding of maplist).
Subject: A inconsistency with maplist (or with my understanding of maplist).
From: Mark Skilbeck
Date: Tue, 09 Jul 2013 11:28:15 +0100
Hi, Jaime.
Yeah, I gained a better understanding of how Maxima "sees" expressions
after a discussion with a friend (it was taking some time for my email
to get past the moderation queue), but I would've learned the same from
you if I had been patient.
Anyway, I came up with the following for getting a list of "terms" from
an expression:
termsof(exp):=if not atom(exp) and op(exp)="+" then args(exp) else [exp];
I'm not convinced this is the best way to work with the terms of an
expression (read: I think something like this ought to be native in
Maxima, but what do I know?).
Thanks for your reply,
Mark.
On 09/07/13 10:51, Jaime Villate wrote:
> On 08-07-2013 15:17, Mark Skilbeck wrote:
>> (%i188) maplist(identity, x/(x-2));
>> (%o188) [x,x-2]
>> (%i189) maplist(identity, x/(x-2)+1);
>> (%o189) [x/(x-2),1]
>>
>> My initial belief was that maplist would map over the "terms" of the
>> second input (the expression x/(x-2), etc.), although maybe my
>> understand of what constitutes a "term" is wrong; however, the above
>> doesn't play ball! I would've thought in the first example that I would
>> receive [x/(x-2)].
>>
>> What am I missing?
> Hi,
> there is no inconsistency at all. In the first case, x/(x-2) is regarded
> as a product between x and (x-2)^(-1); maplist will act on the two
> elements x and (x-2)^(-1).
> The second example, x/(x-2)+1, is regarded as a sum of the expression
> x/(x-2) and the number 1. maplist acts on the two elements x/(x-2) and 1.
>
> You can see how the expressions are stored internally in lisp using the
> following syntax:
>
> (%i1) :lisp #$x/(x-2)$;
>
> ((MTIMES SIMP) ((MEXPT SIMP) ((MPLUS SIMP) -2 $X) -1) $X)
>
> (%i1) :lisp #$x/(x-2)+1$;
>
> ((MPLUS SIMP) 1 ((MTIMES SIMP) ((MEXPT SIMP) ((MPLUS SIMP) -2 $X) -1) $X))
>
> See more details in section 37 of the manual:
> http://maxima.sourceforge.net/docs/manual/en/maxima_37.html
>
> Regards,
> Jaime