Re: Possible Bug Report: CoefficientList
- To: mathgroup at smc.vnet.net
- Subject: [mg88861] Re: [mg88844] Possible Bug Report: CoefficientList
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Mon, 19 May 2008 06:45:08 -0400 (EDT)
- References: <200805190915.FAA12556@smc.vnet.net>
On 19 May 2008, at 18:15, anglewyrm at yahoo.com wrote:
> Here is a function using CoefficientList[] that produces a list:
> Chances[dice_, sides_] := CoefficientList[Expand[(Sum[x^i, {i,
> sides}])^dice], x];
>
> (* This works: *)
> Chances[3, 6]
> Chances[4,6]
> Chances[5,6]
>
> (* This fails: *)
> Table[ Chances[x, 6], {x, 3, 5}]
>
> CoefficientList::ivar: 1 is not a valid variable. >>
> CoefficientList::ivar: 2 is not a valid variable. >>
> CoefficientList::ivar: 3 is not a valid variable. >>
> General::stop: Further output of CoefficientList::ivar will be
> suppressed during this calculation. >>
>
This is not a bug but a question of understanding the way Mathematica
evaluates certain expressions; in particular case Table.
Chances[dice_, sides_] := CoefficientList[Expand[Sum[x^i, {i,
sides}]^dice], x];
Table[Evaluate[Chances[x, 6]], {x, 3, 5}]
{{1302170688}, {888731494560000}, {2841261564746499300000}}
Note the need for Evaluate.
Andrzej Kozlowski
PS. Did it not seem to you rather remarkable that a bug as basic as
this would survive till version 6 of Mathematica?
- Follow-Ups:
- Re: Re: Possible Bug Report: CoefficientList
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Re: Possible Bug Report: CoefficientList
- References:
- Possible Bug Report: CoefficientList
- From: anglewyrm@yahoo.com
- Possible Bug Report: CoefficientList