Questions tagged [pattern-matching]
Questions on expression testing and manipulation through pattern matching and constructing efficient patterns.
1,615 questions
3
votes
1
answer
221
views
What is the meaning/utility of __[] AKA BlankSequence[][]?
I understand BlankSequence in other contexts, but not this one __h means a pattern of one or more things each of which have head ...
3
votes
1
answer
156
views
What, if any, is the list analogue of KeyValuePattern?
I am trying to understand the function of KeyValuePattern. According to the documentation,
KeyValuePattern[{patt1, ...}] is a ...
4
votes
2
answers
139
views
Matching an expression in Hold
Trying to replace some of the expressions wrapped by Hold as below to get $\frac{k d\theta }{dt}$, ReplaceAll does not replacing ...
25
votes
3
answers
756
views
Pattern does not match with Orderless head
Why does the following pattern matching not succeed?
...
1
vote
0
answers
81
views
Replacement of I to -I not working [duplicate]
Let
$f(x) = A \exp(i k x) + B \exp (-i k x)$.
If we replace every $i$ by $-i$, we are supposed to get
$g(x) = A \exp(-i k x) + B \exp (i k x)$.
However, the Mathematica code does not work as expected.
...
3
votes
1
answer
124
views
Why is Position with level spec {1} evaluating on {0}?
The title says it all. These two examples both have StringEndsQ emit an error message because it's being evaluated on the head of the input list.
...
8
votes
1
answer
544
views
Why does 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
217
views
Operating on specific case given a general case match
I have an expression a which include parts of the form A[i,j], where i,j take a range of ...
1
vote
3
answers
211
views
Using Switch to return a value depending on the sign of a real number
I would like to use Switch to test if a real number myNum is negative, zero, or positive and to return "N", "Z&...
2
votes
0
answers
92
views
How to define the derivative of variables inside an expression so chain rule can be correctly applied to the full expression
I don't use Mathematica as much and only use it for some specific tasks from time to time (mostly simplifying expressions and calculating integrals and derivatives).
Lets say I have an large ...
1
vote
1
answer
149
views
How do we find an asymptotic approximation of the function $\mathbf{P}(r)=\left(t_1+\prod\limits_{k=1}^{r}(t_2+k^{s})\right)^n$?
Suppose we have the following function, where $s\in\mathbb{R}$ and $t_1,t_2,n\in\mathbb{N}\cup\{0\}$ are constants:
$$\mathbf{P}(r)=\left(t_1+\prod_{k=1}^{r}(t_2+k^{s})\right)^n$$
Question: What is ...
7
votes
6
answers
445
views
How do I locate non-numbers
If I have a list containing both numbers and non-numbers, such as
{1,2,3,4,5,6p6,7p7,8,9}
how do I locate the positions in the list which do not contain numbers. ...
8
votes
9
answers
2k
views
Given a symbolic expression how to find if starts with a minus or not?
I am using a Mathematica function which returns some error term in symbolic form. I needed a way to determine if this term starts with a minus sign or not. There will be only one term. This is to ...
2
votes
3
answers
154
views
Finding full-depth positions ("absolute positions") of elements within sublists satisfying a criterion
I have exampleList, a list of lists of lists:
...
8
votes
1
answer
472
views
What's happening when we execute a_b=1?
OK, of course I know that, as mentioned in e.g. here, symbol names in Mathematica cannot contain underscore _ because it's a reserved character, but, what's ...