CARVIEW |
Select Language
HTTP/2 200
date: Fri, 25 Jul 2025 07:26:37 GMT
content-type: text/html; charset=utf-8
cf-ray: 9649ee190f8fea32-BLR
cf-cache-status: DYNAMIC
cache-control: private
set-cookie: prov=6cd080af-c2a6-4f07-8b21-8b1ccbf0656a; expires=Sat, 25 Jul 2026 07:26:37 GMT; domain=.stackexchange.com; path=/; secure; httponly
strict-transport-security: max-age=31536000; includeSubDomains
vary: Accept-Encoding
content-security-policy: upgrade-insecure-requests; frame-ancestors 'self' https://stackexchange.com
x-clacks-overhead: GNU Terry Pratchett
x-frame-options: SAMEORIGIN
x-request-guid: 36e79324-7b1b-4ea3-b0d5-58c3fa5fa72b
x-worker-origin-response-time: 580000000
x-dns-prefetch-control: off
set-cookie: prov=6cd080af-c2a6-4f07-8b21-8b1ccbf0656a; Path=/; HttpOnly; Domain=stackexchange.com
set-cookie: __cf_bm=gKyxAyoGEmeQ59a7ePc9NIQ3CsVQuw5RHTljb3yy80U-1753428397-1.0.1.1-7O5vD39RwESn9zBF_jFw3PrGYRVmqw9yGXS014hc5iMV8OiUA8CE2nka23by2DHT1FpPQ428PjXRfGsFB23UFxMNunWuclLSSjShfRSsAcA; path=/; expires=Fri, 25-Jul-25 07:56:37 GMT; domain=.stackexchange.com; HttpOnly; Secure; SameSite=None
set-cookie: _cfuvid=qCWQCGoFbgLwbMj5HeduyAibY8kuwx.RVWfBFZ3Kpzo-1753428397566-0.0.1.1-604800000; path=/; domain=.stackexchange.com; HttpOnly; Secure; SameSite=None
server: cloudflare
content-encoding: gzip
Newest 'pattern-matching' Questions - Mathematica Stack Exchange
Skip to main content
Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeTeams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about TeamsQuestions tagged [pattern-matching]
Questions on expression testing and manipulation through pattern matching and constructing efficient patterns.
1,603 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
7
votes
1
answer
418
views
Why `MatchQ[ 3 + x, _ + _ ]` return `False`?
Consider
MatchQ[ 3 + x, _ + _ ]
It returns False. Why?
After some research, I concluded that it's due to the ...
2
votes
1
answer
101
views
Difference in pattern matching before & after Expand
The goal is to substitute m2/m1 in expr with k. Code1 does not match the pattern, but if it is pre-processed with Expand like in code2, it matches the pattern. Could I know why there is this ...
2
votes
0
answers
81
views
Unexpected result with Position using pattern
I use Mathematica 12 and have the following code
t1 = {1, 2, 3.1, 4, 5, 6, 7.1}
Position[t1, x_ /; Not[IntegerQ[x]]]
which gives me
...
0
votes
1
answer
110
views
Generalizing a function to ignore Missing
When the arguments contains Missing[] at the start of the data I find myself doing /.Missing->Nothing to the arguments and <...
2
votes
3
answers
154
views
Removing unmatched elements from nested list after ReplaceAll
I'm doing some heavy symbolic calculations and for preliminary simple tests I need to replace all coefficients except some choosings, e.g.:
...
5
votes
2
answers
155
views
Quickly checking Missing[] is only at the start of a list
I am working with Tabular data and I want to check if Missing[] is only the first contiguous part of list. e.g.:
...
0
votes
2
answers
100
views
Why does a replacement rule fail for a custom defined function but works for a generic symbol?
I'm pretty new to Mathematica and I have a question about how to deal with replacement rules in presence of function definitions.
Basically I want to implement a mean/covariance calculator, in the ...
4
votes
4
answers
261
views
How to Determine Whether Number or Symbol
I want to implement a function looking like this:
func1[func2[k],m,n]
If m and n are ...
3
votes
4
answers
703
views
Why cannot "a" be 0 in this pattern matching?
Why does the pattern matching not work if k is 0 (either explicitly or implicitly)? Is there any method to make it work?
...
1
vote
4
answers
210
views
Any More Flexible Pattern Matching?
I tried to define a simple function with pattern matching:
F[(n_ - k)*T[n_ + 1 - k]/m_] := k*n/m
But when I run ...
1
vote
1
answer
97
views
Why Cannot I Apply the Replace Rule Here?
I want to replace
$p_\_\sum_{i=1}^{m_\_}Log[x[i]]^{b_\_} x[i]^{a_\_}$ with $p*T[a,b,m]$, but it doesn't work. Can anyone give me a help? Thanks in advance!
Codes:
...
4
votes
2
answers
296
views
How to set to 0 all terms in a matrix which contain a minus, revisited
The previous question How to set to 0 all terms in a matrix which contain a minus seems to have a wrong answer. For the matrix
...
0
votes
1
answer
65
views
Counting matching elements in two lists or vectors, excluding blank or Null elements
I need some help with a pattern-matching problem. I want to count the number of matching elements in two lists (or vectors) of equal length. To be concrete, consider a multiple-choice test with 5 ...
2
votes
2
answers
193
views
Partial derivative of function with restricted pattern like _List doesn't evaluate
I am having trouble where Mathematica won't evaluate my partial derivatives. I have the function below.
...
1
vote
1
answer
109
views
Attribute based pre-processing of arguments
I work with hashes that can be related to various data structures.
I find it convenient to have my functions work either when a hash argument is provided or when the required data structure is ...
- The Overflow Blog
-
-
- Featured on Meta
-
-
Related Tags
list-manipulation × 293
replacement × 257
string-manipulation × 184
function-construction × 115
filtering × 81
functions × 71
argument-patterns × 63
rule × 61
evaluation × 48
core-language × 41
symbolic × 40
bugs × 38
performance-tuning × 37
programming × 33
associations × 28
matrix × 26
sequence × 26
regular-expressions × 25
hold × 24
attributes × 22
expression-test × 21
optional-arguments × 20
more related tags
Hot Network Questions
- Can a humanoid that fell supine and is then Levitated alter his orientation?
- Why are police personnel of all ranks called officers?
- When was the last time all alive humans stayed on earth?
- Why does my laptop's display turn off when I'm away from the keyboard?
- When was the last time all humans were on the ground not in the air?
- How much of a really big a spaceship could a nuke take out?
- Was Hermann Ganswindt's helicopter actually the first manned heavier-than-air motor-powered flight?
- How do mechanical gyros maintain rotational speed?
- Surjectively universal Polish space
- Source that Eliyahu Hanavi was an angel at the creation
- What does "Store Name" mean on the Tokyo-Narita Airport Bus timetable?
- Is it decidable wether a CFL can be recognized by a linear CFG?
- Why is the Schrödinger wave equation totally different from the classical wave equation?
- How to 'scale' a square list?
- Most practical way to determine concentration of reducing sugar in frozen French fries?
- Where did the name of Windows XP come from? Was it connected to the Cairo project?
- Make a Mulenère encryption program
- Why is Shunt Voltage Reference (LM4040DBZ-3) Not outputting a stable 3V supply
- Is the appearance of certain kinds of clouds at altitude of > 30000 feet a recent phenomenon?
- Do standing sound waves sound different?
- Making a arrow in Tikz increasing thickness
- How do I increase maximum file upload size in Drupal 10?
- tac-command is it a bug or a misinterpretation of the manual?
- Wie soll man "to choke up while singing" übersetzen?