Skip to main content

All Questions

3 votes
1 answer
98 views

Prevent argument substitution in held expression when injecting into unevaluated code

I want to write a custom sow/reap pair to wrap any piece of code in sow[code] and call reap ...
István Zachar's user avatar
7 votes
3 answers
472 views

How to replace $x$ and $x^2$ with different value?

I have an expression now expr = x + x^2 what I want to do is to replace $x$ with $k\times p$ , and $x^2$ with $[k\times p + k\times(k - 1)\times p^2]$. The ...
Yuejiang_Li's user avatar
2 votes
1 answer
49 views

Replace sub-expressions matching a pattern unless located under specific heads

Suppose I have some rule, e.g. Re[x_] :> (x + Conjugate[x])/2. I want to apply it to all matching sub-expressions in some expression, excluding any sub-...
Vladimir Reshetnikov's user avatar
0 votes
0 answers
81 views

How to use replace for only one term in a long expression in Mathematica?

I am doing some Cauchy integration and in some intermediate steps I have something that looks like that: (..many_terms...+I*\epsilon(k1-p1))/k1 where ...
MZP_user's user avatar
1 vote
2 answers
143 views

How can I ask the Wolfram Language to tell me if a hypothetical expression with a particular head would be atomic or not?

Integers in the Wolfram Language are atomic expressions, while uses of the Map function are not atomic. But if you didn't know this, how could you find out using only the Wolfram Language? The best I ...
MadEmperorYuri's user avatar
0 votes
3 answers
474 views

How to simplify an expression by substitution?

Sometime Solve and DSolve give a finial form of the solution, which is fine in may applications. However, in some cases, one may ...
Enter's user avatar
  • 1,229
1 vote
1 answer
757 views

Convert String in Expression to Integer

I have reviewed many string replacement Q&A but I have been unable to apply them to this case (MWE): ...
Julian Moore's user avatar
  • 2,560
1 vote
0 answers
50 views

Do replacement only on certain specific forms

If I want to replace, say, a with a1 + a2 in an expression, I can write ...
usumdelphini's user avatar
1 vote
2 answers
68 views

Question about replace command

I want to replace the common part in the equation by different value. Here is my equation ...
Jensen Kang's user avatar
0 votes
1 answer
185 views

Expression replacement with variable exponents

I have an expression that consists of a large sum of variables of powers like: X[1]^(2p) X[2]^2 + X[1]^2 X[2]^(2p) + X1[1]^(1+p) X[2]^(1+p) ... Now I would like ...
divB's user avatar
  • 231
0 votes
3 answers
282 views

Replacements within a mathematica expression?

Say I have many expressions of the form $$\text{expr} = \frac{1}{AB(C+D)^n E^m}$$ where $A,B,C,D$ and $E$ are symbols and $n,m$ arbitrary powers. In order to convert between the mathematica output and ...
CAF's user avatar
  • 510
3 votes
2 answers
387 views

Expanding powers in an expression and Hold

Let an expression like -(1/2) + (3 x^5)/2 be given. How can this be turned into -(1/2) + (3 x x x x x)/2? All powers of ...
JHT's user avatar
  • 1,005
1 vote
3 answers
180 views

Elimination of terms not containing at least one variable from a set

I have an expression with each term therein either containing at least one $n_i \in \left\{ n_1 , n_2 \dots , n_{5} \right\}$ or no $n_i$ at all. I would like to easily eliminate all the terms that ...
CAF's user avatar
  • 510
6 votes
5 answers
373 views

First evaluate in place all subexpressions matching pattern before substituting result

ReplaceAll[expr, {patt1:>rhs1, patt2:>rhs2, …}] works by looking for and making all possible replacements of subexpressions in ...
QuantumDot's user avatar
  • 19.7k
2 votes
1 answer
204 views

Replacement involving Log not working

In the following expression Log[a/6] + Log[b/7]+Log[c/7] + Log[b/8] I want $log(\frac{b}{7})$ and $log(\frac{b}{8})$ to be replaced by $log(b)-log(7)$ and $...
m. bubu's user avatar
  • 565

15 30 50 per page