Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

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?





  • Prev by Date: Re: Filtering a list of list for certain elements that are neighbours
  • Next by Date: Re: An Elegant way of plotting the Pole-Zero diagram
  • Previous by thread: Possible Bug Report: CoefficientList
  • Next by thread: Re: Re: Possible Bug Report: CoefficientList