Skip to main content

Questions tagged [pattern-matching]

Questions on expression testing and manipulation through pattern matching and constructing efficient patterns.

84 votes
4 answers
7k views

My last question to the site resulted in several answers that involve using pattern matching in Mathematica, a feature I wasn't very familiar with at the time. I am currently reading Mathematica ...
Alfred Fazio's user avatar
  • 1,175
60 votes
1 answer
3k views

This question was split from this one. While that question is now about how to match two particular patterns (mostly using Verbatim or ...
István Zachar's user avatar
58 votes
3 answers
2k views

Mathematica has a notion of pattern specificity, which is a partial ordering on patterns. The rules (e.g. DownValues, SubValues,...
Kim Morrison's user avatar
  • 1,291
46 votes
10 answers
7k views

I'm looking for a function that finds the index of the zero-crossing points of a list. Before I go making my own subroutine to do this, I was wondering if anyone knows of any built-in Mathematica ...
dthor's user avatar
  • 1,011
39 votes
1 answer
2k views

Edit: as noted by Albert Retey the performance difference is only seen when sub expression extraction is performed. If this test is used below the timings are similar: ...
Mr.Wizard's user avatar
  • 275k
38 votes
4 answers
6k views

I'm looking for robust code to solve the "Longest Common Substring" problem: Find the longest string (or strings) that is a substring (or are substrings) of two or more strings. I can just code it ...
Reb.Cabin's user avatar
  • 8,873
38 votes
3 answers
3k views

EDIT: As several respondents have noted in the answers and comments below, the original example had a default value that would never be used because of the way patterns and default values are ...
StackExchanger's user avatar
34 votes
12 answers
7k views

I have a list which is something like this: {3,4,5,6,7,10,11,12,15,16,17,19,20,21,22,23,24,42,43,44,45,46} What I'd like to to is get the intervals which are in ...
mgm's user avatar
  • 1,039
34 votes
2 answers
4k views

What are, and how do I use Mathematica's string matching and replacement tools?
Mr.Wizard's user avatar
  • 275k
34 votes
2 answers
919 views

Consider this expression in Mathematica 10.3 (and above) on MacOS X: expr = a b c d e f g h i j k l m n o p q r s t myG[u] myF[a, b] Now compare the time it ...
QuantumDot's user avatar
  • 19.9k
34 votes
1 answer
832 views

Lately, and by lately I mean since version 7 or so, the number of atomic expressions in Mathematica constantly grew. In former times only the native types like integers and optimised arrays were ...
halirutan's user avatar
  • 114k
32 votes
5 answers
3k views

I want to generate a couple of plots/graphs with Area 51 statistics. Since Area 51 doesn't work with the SE API, I'm forced to find another way to get the information I want. That other way is with <...
CHM's user avatar
  • 3,455
31 votes
9 answers
3k views

Pure functions may be handy if you don't want to assign your function a name. For example I would calculate $x(x-1)$ for some numbers $x$ by ...
sjdh's user avatar
  • 7,917
30 votes
2 answers
1k views

Inspired by this answer, I am interested to know if there are best practices or rules of thumb for constructing patterns, for example for use in function definitions (...
Verbeia's user avatar
  • 34.5k

15 30 50 per page
1
2 3 4 5
108