MathGroup Archive 2003

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

Search the Archive

Re: New version, new bugs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43241] Re: New version, new bugs
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Wed, 20 Aug 2003 22:26:28 -0400 (EDT)
  • References: <bgq9q4$d50$1@smc.vnet.net> <bhaah2$kt6$1@smc.vnet.net> <bht3fl$n1l$1@smc.vnet.net>
  • Reply-to: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Sender: owner-wri-mathgroup at wolfram.com

In the second of the references at URL that Paul gives:

http://groups.google.com/groups?q=%2B%2B+withoff+increment&hl=en&lr=&ie=U
TF-8&selm=7n68mn%24gu3%40smc.vnet.net&rnum=2

We find:

"An unrelated problem with this example is that it tries to assign a value
to a number.  The expression x[[i]]++, where x is a list of numbers, picks
out an element from that list and tries to increment it.  Mathematica will
not let you do that."

But we can do this:
In[1]:=
    x = {1, 1, 1};
In[2]:=
    x[[2]]++
Out[2]=
    1
In[3]:=
    x
Out[3]=
    {1, 2, 1}

The outline evaluation of Increment[expr] (expr++) seems to be
- Save a copy of expr unevaluated (Increment is HoldFirst)
- Evaluate expr to val, say.
- Evaluate expr = val +1;
- Output val ( PreIncrement[expr] (++expr) outputs val+1)

Allan
---------------
Allan Hayes
hay at haystack.demon.co.uk
Voice: +44 (0)116 241 8747
Fax: +44 (0)870 164 0565



"Paul Abbott" <paul at physics.uwa.edu.au> wrote in message
news:bht3fl$n1l$1 at smc.vnet.net...
> In article <bhaah2$kt6$1 at smc.vnet.net>, Maxim <dontsendhere@.> wrote:
>
> > 1) when writing out sums of rising factorials:
> >
> > In[1]:=
> > Module[
> >   {c = Pochhammer[-2, -1 + k]},
> >   Sum[c,{k,1,Infinity}]
> > ]
> >
> > Out[1]=
> > Infinity*Pochhammer[-2, -1 + k]
> >
> > in version 4.2 this sum is left unevaluated -- hardly an improvement;
>
> Because Sum does not evaluate its arguments (it is HoldAll), Evaluate is
> required:
>
>   Module[
>     {c = Pochhammer[-2, -1 + k]},
>      Sum[Evaluate[c],{k,1,Infinity}]
>   ]
>
> You can avoid such a convoluted construct by writing
>
>   Sum[Pochhammer[-2, k - 1], {k, 1, Infinity}]
>
> > 3) at first I was scanning the lists of coefficients in a more
procedural
> > way, and noticed a strange behaviour or Increment; here's an example to
> > demonstrate it more clearly:
> >
> > In[1]:=
> > Compile[
> >     {},
> >     Module[
> >       {L={10,20,30},a=1},
> >       L[[a++]]++;
> >       Append[L,a]
> >       ]
> >     ][]
> >
> > Out[1]=
> > {10,31,30,4}
> >
> > Imagine using a C compiler with this sort of glitches. Once again the
bug
> > appears in a function that doesn't have a precise definition; all this
> > certainly would have been of little importance for an educational
software,
> > but not for a serious development tool.
>
> Perhaps a previous posting to this group (in 1999),
>
> http://groups.google.com/groups?q=%2B%2B+withoff+increment&hl=en&lr=&ie=U
>
>
> explains your problem here?
>
> Cheers,
> Paul
>
> -- 
> Paul Abbott                                   Phone: +61 8 9380 2734
> School of Physics, M013                         Fax: +61 8 9380 1014
> The University of Western Australia      (CRICOS Provider No 00126G)
> 35 Stirling Highway
> Crawley WA 6009                      mailto:paul at physics.uwa.edu.au
> AUSTRALIA                            http://physics.uwa.edu.au/~paul
>


  • Prev by Date: Re: a bug in mathematica 5?
  • Next by Date: Re: Random Number Generation : Is there a faster way of doing this?
  • Previous by thread: Re: New version, new bugs
  • Next by thread: Re: New version, new bugs