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 ...
Tapiocaweasel's user avatar
3 votes
1 answer
156 views

I am trying to understand the function of KeyValuePattern. According to the documentation, KeyValuePattern[{patt1, ...}] is a ...
Andrew's user avatar
  • 10.6k
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 ...
Soon's user avatar
  • 1,484
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. ...
rasi's user avatar
  • 73
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. ...
Adam's user avatar
  • 4,293
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&...
Andrew's user avatar
  • 10.6k
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 ...
Gabriel de Castro Biage's user avatar
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 ...
Arbuja's user avatar
  • 81
2 votes
3 answers
154 views

I have exampleList, a list of lists of lists: ...
Andrew's user avatar
  • 10.6k
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 ...
xzczd's user avatar
  • 71.6k
3 votes
2 answers
214 views

With a naive thought, it seems that rule as below can match in expr. However, it does not match. Could I know what mistake I ...
Soon's user avatar
  • 1,484
9 votes
2 answers
978 views

The behavior of pattern matching in functions surprised me at the unexpected behavior of this example ...
Somos's user avatar
  • 5,252
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 ...
lezambranof's user avatar
2 votes
1 answer
134 views

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 ...
Soon's user avatar
  • 1,484
2 votes
0 answers
92 views

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 ...
user57467's user avatar
  • 3,150

15 30 50 per page
1
2 3 4 5
108