Subject: how can I make a variable local inside "product"?
From: Albert Reiner
Date: 11 May 2006 18:51:58 +0200
["van Nek" <van.Nek at gmx.net>, Thu, 11 May 2006 18:12:54 +0200]:
> > As a workaround you might try something like ... := block([m],
> > subst(n, m, product(m+1, ...))) or maybe use a gensym instead of i.
>
> Hi Albert,
> subst and gensym do not help here on 5.9.3 GCL/Windows.
As I cannot reproduce the problem with 5.9.2 in the first place, I
cannot try this out. But the following:
,----
| (%i6) m: 1;
|
| (%o6) 1
| (%i7) block([m], product(m-i, i, 1, 3));
|
| (%o7) (m - 3) (m - 2) (m - 1)
| (%i8) subst(i, m, block([m], product(m-i, i, 1, 3)));
|
| (%o8) (m - 3) (m - 2) (m - i)
| (%i9) subst(i, 'm, block([m], product(m-i, i, 1, 3)));
|
| (%o9) (i - 3) (i - 2) (i - 1)
`----
seems to suggest to me that
t2(n) := subst(n, 'm, block([m], product(m-i, i, 1, 3))) $
(note the quote, in case n contains an m) should work.
At any rate,
,----
| (%i14) t3: buildq([body: block([x], product(x-i, i, 1, 3))],
| lambda([x], body));
|
| (%o14) lambda([x], (x - 3) (x - 2) (x - 1))
| (%i15) [ t3(i), t3(j) ];
|
| (%o15) [(i - 3) (i - 2) (i - 1), (j - 3) (j - 2) (j - 1)]
`----
should work, too, but I am sure people will find it a disgusting
solution.
Regards,
Albert.