Skip to main content

Questions tagged [pattern-matching]

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

3 votes
1 answer
221 views

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

I am trying to understand the function of KeyValuePattern. According to the documentation, KeyValuePattern[{patt1, ...}] is a ...
4 votes
2 answers
139 views

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

Why does the following pattern matching not succeed? ...
1 vote
0 answers
81 views

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

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

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

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

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

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

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

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

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 ...
8 votes
1 answer
472 views

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 ...

15 30 50 per page
1
2 3 4 5
108