On 6/11/07, Robert Dodier <robert.dodier at gmail.com> wrote:
>
> On 6/11/07, Thomas Widlar <twidlar at yahoo.com> wrote:
>
> > A beginner's question. Say I obtain a list a of solutions for x., e.g.
> >
> > (%i19) a : solve(x^4-1);
> > (%o19) [x=%i,x=-1,x=-%i,x=1]
> >
> > How do I process a into a list b : [%i,-1,-%i,1] so I can say
> >
> > for x in b do something(x);
>
> Something that I find useful with stuff like [x = foo, y = bar] etc.
> is to pass that list or an element of it to ev in order to evaluate
> some expression with those values of x and y or whatever.
>
> e.g.
>
> solve ([x^2 + y^2 = 1, x = y], [x, y]);
> map (lambda ([e], ev (foo (x, y), e)), %);
> => [foo (-1/sqrt(2), -1/sqrt(2)), foo (1/sqrt(2), 1/sqrt(2))]
>
> In the lambda expression above, subst(e, foo(x, y)) would probably also
> work.
> Also sublis(e, foo(x, y)).
I would strongly recommend sublis(e, ...) rather than ev(..., e), which has
complicated semantics which may surprise you.
-s