Skip to main content

Questions tagged [pattern-matching]

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

1 vote
0 answers
106 views

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 ...
Arbuja's user avatar
  • 51
1 vote
0 answers
376 views

Suppose, we have the following code (i.e., f[r] and g[r] can be any function, where ...
Arbuja's user avatar
  • 51
0 votes
0 answers
188 views

I want to decrease the computation time of the following code. If c is a large constant, how do we show when: ...
Arbuja's user avatar
  • 51
7 votes
2 answers
280 views

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 ...
MA-'s user avatar
  • 11.5k
4 votes
3 answers
232 views

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 ...
lesobrod's user avatar
  • 2,710
1 vote
1 answer
68 views

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 ...
Hugh's user avatar
  • 17.7k
6 votes
5 answers
378 views

Is it possible to replace all x-s that are a direct child of e which is a direct child of c? ...
azerbajdzan's user avatar
  • 38.5k
2 votes
3 answers
277 views

I wrote a simple function that factors out a trivial zeros: FactorZeroOut[Times[args___] == 0 ] := (# == 0) & /@ (Or @@ args) Which works well enough for these ...
Dehbop's user avatar
  • 199
1 vote
1 answer
104 views

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 ...
Soon's user avatar
  • 1,671
1 vote
1 answer
53 views

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}{...
MrBetadine's user avatar
4 votes
1 answer
276 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
168 views

I am trying to understand the function of KeyValuePattern. According to the documentation, KeyValuePattern[{patt1, ...}] is a ...
Andrew's user avatar
  • 10.9k
4 votes
2 answers
144 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,671
1 vote
0 answers
82 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
131 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,527

15 30 50 per page
1
2 3 4 5
109