MathGroup Archive 2000

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

Search the Archive

Flat, OneIdentity Again

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21637] Flat, OneIdentity Again
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Tue, 18 Jan 2000 02:35:21 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Thanks to all who answered my question on Flat and OneIdentity.
I have more strange behavior on this subject.

At http://support.wolfram.com/Kernel/Symbols/System/Flat.html
it says in so many words ....
If (f) has the Flat attribute you better not have a definition like 
  f[p_]:=p
because if you do, then an attempt to evaluate f[1,2] will not work and the
kernel will have to quit when the infinite iteration limit is exceeded.

In addition I found that you can't even evaluate f[2] in the above case, and
it doesn't help if (f) also has the OneIdentity attribute!

I wanted to understand just what the kernel is doing to exceed the iteration
limit when we try to evaluate f[1,2] or f[2] above.  The lines below offer
some clues, but also add to the mystery. I wonder if any of you have an
explanation.

In[1]:=
ClearAll[f];
Attributes[f]={Flat};

After the input above (f) has the Flat attribute and no definitions.
f[1,2] as f[f[1,2]].


In[3]:=
f[1,2]/.f[p_]:>{p}
Out[3]=
{f[1,2]}

The idea that the pattern matcher treats 
f[1,2] as f[f[1,2]] is sort of verified 
at Out[4] below.

In[4]:=
MatchQ[f[1,2],f[_f]]
Out[4]=
True

But if the pattern matcher treats f[1,2] as f[f[1,2]]
why doesn't MatchQ return True in Out[4] below ?

In[5]:=
MatchQ[f[1,2],HoldPattern[f[f[_Integer,_Integer]]]]
Out[5]=
False

Even stranger is the next line where the pattern is much more general!
Notice that is a triple blank inside (f).

In[6]:=
MatchQ[f[1,2],HoldPattern[f[f[___]]]]
Out[6]=
False

All the results above come out the same if (f) has the attributes Flat,
OneIdentity.

I have a hunch what may be going on here. Perhaps this is a bug. Could it be
that the part of the pattern matcher that handles Flat is oblivious to
HoldPattern and checks for a match with the patterns f[_Integer,_Integer]
and  f[___] 
when it should check for a match with f[f[_Integer,_Integer]] and  f[f[___]]

respectively in the lines above?

I did all this using Version 4.

--------------------
Regards,
Ted Ersek

On 12-18-99 Mathematica tips, tricks at
http://www.dot.net.au/~elisha/ersek/Tricks.html
had a major update



  • Prev by Date: Re: Flat, OneIdentity attributes
  • Next by Date: Re: generating subsets
  • Previous by thread: Re: Help! Mathematica on my 500MHz outperforms my GHz machine!
  • Next by thread: Re: Flat, OneIdentity Again