All Questions
Tagged with replacement expression-manipulation
75
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 ...
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 ...
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-...
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 ...
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 ...
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 ...
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):
...
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
...
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
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 $...