Questions tagged [pattern-matching]
Questions on expression testing and manipulation through pattern matching and constructing efficient patterns.
1,624 questions
1
vote
0
answers
106
views
How do we simplify the inequality 'Q3' at the bottom of this post?
Question: At the end of the post, how do we simplify all cases of Q3[r,1,2] and combine them into one expression?
I provided working examples at the end of this ...
1
vote
0
answers
376
views
How do we change the five sign functions, in each criteria of the final code, to get what I want? [closed]
Suppose, we have the following code (i.e., f[r] and g[r] can be any function, where ...
0
votes
0
answers
188
views
How do we decrease the computation time of this code?
I want to decrease the computation time of the following code.
If c is a large constant, how do we show when:
...
7
votes
2
answers
280
views
How to get the entire sequence of updated options within a function?
Consider the following example function:
Options[f]={f1->a,f2->b};
f[x_,options:OptionsPattern[f]]:=options;
What is the canonical way to access the entire ...
4
votes
3
answers
232
views
Special Flatten in ragged arrays
I'm working on a project in the spirit of Wolfram’s Ruliad concept.
A nested ragged arrays appear in the process e.g. {0}, {0,{1}}, {{1}, {{0}, 1}}} etc.
And ...
1
vote
1
answer
68
views
Sorting "almost conjugate" poles and residues together
I have a list of poles and residues i.e. complex numbers that are "almost" complex conjugate pairs. "Almost" needs defining as some sort of tolerance. Some of the poles and ...
6
votes
5
answers
378
views
Replace parent or child of a symbol
Is it possible to replace all x-s that are a direct child of e which is a direct child of c?
...
2
votes
3
answers
277
views
Pattern matching mismatch
I wrote a simple function that factors out a trivial zeros:
FactorZeroOut[Times[args___] == 0 ] := (# == 0) & /@ (Or @@ args)
Which works well enough for these ...
1
vote
1
answer
104
views
Replace all $r$ but not $\hat{r}$
My goal is to replace $r$ with $a$, excluding the part $\hat{r}$. If I just apply the rule to replace $r$ with $a$, $\hat{r}$ also changes to $\hat{a}$, so I tried using ...
1
vote
1
answer
53
views
Issues with Plot/Delayed Assignment/Replacement [duplicate]
I would like to plot the $|x\rangle$-representation wave functions of the first few energy eigenstates of a harmonic oscillator. The formula is $$ \varphi_n(x)=\left[\frac{1}{2^n n!}\left(\frac{\hbar}{...
4
votes
1
answer
276
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
168
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
144
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 ...
1
vote
0
answers
82
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
131
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.
...