MathGroup Archive 2003

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

Search the Archive

Re: New version, new bugs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43250] Re: New version, new bugs
  • From: Maxim <dontsendhere@.>
  • Date: Sat, 23 Aug 2003 08:08:24 -0400 (EDT)
  • References: <bgq9q4$d50$1@smc.vnet.net> <bhaah2$kt6$1@smc.vnet.net> <bht3fl$n1l$1@smc.vnet.net> <bi197b$al5$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Allan Hayes wrote:

> 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}]
> >

Still there is a problem because Sum works differently for finite range:

In[1]:=
Module[
  {c=k},
  Sum[c,{k,1,2}]
  ]

Out[1]=
3

If c is always left unevaluated, here we should get 2*k.

>
> > > 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?

The Compile example has nothing to do with trying to assign values to raw
objects; the problem is that a++ is evaluated *three* times and the list is
modified accordingly. The Built-In Function reference for Compile indicates
that it is possible.

Maxim Rytin
m.r at prontomail.com



  • Prev by Date: Re: a bug in mathematica 5?
  • Next by Date: Re: Are points co-planar in (numDimensions-1)?
  • Previous by thread: Re: New version, new bugs
  • Next by thread: Re: Re: New version, new bugs