MathGroup Archive 2000

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

Search the Archive

Re: A question about pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21914] Re: A question about pattern matching
  • From: Rolf Mertig <rolf at mertig.com>
  • Date: Fri, 4 Feb 2000 02:54:43 -0500 (EST)
  • Organization: Mertig Research & Consulting
  • Sender: owner-wri-mathgroup at wolfram.com

There is nothing wrong with the pattern patcher in Mathematica;
maybe it could be made more efficient but I doubt that this is
really necessary.
Instead people (like book authors) should stop encourage 
users using these kind of primitive pattern constructions 
you were trying to do.

Everybody should just learn about pure functions and
simply use Select or Split (or Cases) :
(timings with Mathematica 4.0 on a Linux 433 Celeron machine:)

In[1]:= !!mymatch
mymatch1[f[x___]] := {Select[{x}, Head[#1] =!= Rule & ], 
    Select[{x}, Head[#1] === Rule & ]}; 
mymatch2[f[x___]] := Split[{x}, 
    Head[#1] === Rule && Head[#2] === Rule || 
      Head[#1] =!= Rule && Head[#2] =!= Rule & ]; 
test = f @@ Union[Table[Random[], {kk, 10000}], 
     Table[Random[] -> Random[], {kk, 10000}]]; 
First /@ {Timing[mymatch1[test]], Timing[mymatch2[test]]}

In[1]:= <<mymatch

Out[1]= {0.53 Second, 0.83 Second}


Rolf
----------------------------
http://www.mertig.com
http://www.feyncalc.com
http://www.mathdepot.com


  • Prev by Date: Re: assumptions question
  • Next by Date: Re: Set in Scan
  • Previous by thread: Re: A question about pattern matching
  • Next by thread: Protein Folding