       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:=
Module[{f},
f[a] /. f[x_] /; True /; False :> 0
]

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

Out=
f\$37[a]

Out=
0

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

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

Out=
{f\$37[x]}

Another example:

In:=
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=
{2*x, 3*x}

Out=
{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:=
Hold[x] /. x :> Module[{}, Random[]]
Hold[x] /. x :> Module[{}, Random[] /; True]
Hold[x] /. x :> Block[{}, Random[] /; True]

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

Out=
Hold[Random[]]

Out=
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