how to calculate all of possible variants of expression?



On 7/18/07, toter at mail.ru <toter at mail.ru> wrote:

> excuse me for my english :)

It's no problem at all. But perhaps you would be interested in
the Russian language mailing list:
https://lists.sourceforge.net/lists/listinfo/maxima-lang-ru

> for example I have something like that
> a:[1,2];
> b:[3,4];
>
> how to do so that c=a*b;
>
> must be ?=[3,4,6,8] (?=[1*3=3, 1*4=4, 2*3=6, 2*4=8])

Here are two more ways to accomplish that.

outermap (lambda ([x, y], x*y), a, b);
 => [[3, 4], [6, 8]]
flatten (%);
 => [3, 4, 6, 8]

cartesian_product (setify (a), setify (b));
 => {[1, 3], [1, 4], [2, 3], [2, 4]}
map (lambda ([xy], apply ("*", xy)), %);
 => {3, 4, 6, 8}
listify (%);
 => [3, 4, 6, 8]

Hope this helps,
Robert Dodier