Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

Re: New version, old bugs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44151] Re: New version, old bugs
  • From: Maxim <dontsendhere@.>
  • Date: Fri, 24 Oct 2003 04:24:24 -0400 (EDT)
  • References: <bn5e16$6ba$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

A few more glitches of Mathematica's pattern matcher:

In[1]:=
Module[{f},
  f[a] /. f[x_] /; True /; False :> 0
]

Module[{f},
  Attributes[f] = Flat;
  f[a] /. f[x_] /; True /; False :> 0
]

Out[1]=
f$37[a]

Out[2]=
0

It looks like there's still a long way to go to acquaint Flat with other
language constructs.

In[1]:=
Module[{f},
  Attributes[f] = {Flat, OneIdentity};
  f[x] /. f[x_, y_:1] -> {x}
]

Out[1]=
{f$37[x]}

I'm not sure about this one, should the result here be {x}?

Another example:

In[1]:=
Module[{a},
  {x^2, x^3} /. x^(p_) :>
    (a = p; a*x)
]

Module[{a},
  {x^2, x^3} /. x^(p_) :>
    (a = p; a*x /; True)
]

Out[1]=
{2*x, 3*x}

Out[2]=
{3*x, 3*x}

To understand how the last one works we need to know the evaluation
sequence; the number in parentheses shows whether rhs is evaluated for x^2
(1) or x^3 (2):

a=2  (1)
True (1)
a=3  (2)
True (2)
3*x  (1)
3*x  (2)

So the description of ReplaceAll in the Reference (saying that it tries
parts in the sequential order) is incomplete (or even not strictly true),
because it switches between parts in this weird manner. Just as in the
situation with

In[1]:=
Hold[x] /. x :> Module[{}, Random[]]
Hold[x] /. x :> Module[{}, Random[] /; True]
Hold[x] /. x :> Block[{}, Random[] /; True]

Out[1]=
Hold[Module[{}, Random[]]]

Out[2]=
Hold[Random[]]

Out[3]=
Hold[0.011784819818934053]

giving three different results, I cannot say that the expressions are
semantically equivalent because no one knows what the semantics should be in
the first place, but it is very confusing when adding True condition
suddenly changes the result.

Maxim Rytin
m.r at prontomail.com



  • Prev by Date: Re: NDSolve does not work in shooting method
  • Next by Date: Re: NotebookML & css
  • Previous by thread: Re: New version, old bugs
  • Next by thread: Re: Re: New version, old bugs