# Tagged Questions

Questions about Mathematica's rule-based replacement functionality, including functions such as Rule (->), Replace, ReplaceAll (/.) and ReplaceRepeated (//.).

816 views

### How to properly project a Graphics object consisting of line primitives

My problem starts from attempts at depicting overlapping lines of different thickness, i.e. ...
119 views

### Replace inverse function

I'm solving an expression like so: Solve[u[x] == u[a] + u[b], x] Mathematica returns {{x->(u^(-1))[u[a]+u[b]]}} If I ...
146 views

### Simple rule appears not to work

I have the following simple code ...
131 views

### How can I avoid this ReplaceAll trap? [duplicate]

I am having some difficulties with the ReplaceAll function. When I write: {1, 2, 3, 4, 5} /. x_?OddQ -> x^2 I expect: <...
167 views

### Strange behavior when replacing variables by numerical values [duplicate]

I have a rather complicated function with parameters {a, b, c, d, e, f, k}, and I'd like to know its behavior as a function of k alone given other parameters, so I try the following code: ...
222 views

### Variable scope in nested NMaximize, NMaxValue

I'm trying to use NMaxValue inside other statements (FindRoot and NMinimize). Those statements should bind variable names, but I'm getting weird warnings which seem to indicate that the variables ...
233 views

### Lowering the degree of an polynomial with an assumption that the polynomial has a factor x^2+ax+b

Let's assume $x^{10}+x^5+1$ has a factor $x^2+ax+b$ Then, If $x^2=-ax-b$, $x^{10}+x^5+1 =0$. If we successively apply $x^2=-ax-b$ to $x^{10}+x^5+1$, we can make $x^{10}+x^5+1$ to degree 1, ...
251 views

### Equating and solving equations that have been generated using table[]

I am in the process of trying to use Mathematica to find the coefficients of transmission and reflection for the wavefunction of a beam of particles tunnelling across any number of identical potential ...
151 views

### Generalization of a rule to N arguments

I am trying to apply a series expansion on a function x[t1,t2,...tn], with an expansion parameter a. For ...
187 views

### Shortening the syntax {var1, var2} /. # & /@ list

I noticed that I often turn out to have a list of substitutions in the form ...
93 views

### How to make rules for changing parameters

I have one boring problem with changing parameters in printing output. If I have equation ...
94 views

### How can you form a variable from a function and its arguments?

Is there a way to make the general replacement foo[x,y,z]->fooxyz so that I can treat the x_i as variables so that I will obtain foofgh from the following: <...
673 views

### rule-based implementation of an algorithm

When I first started learning about rule-based programming with Mathematica, I tried to translate this algorithm for computing the convex hull of a set of 2-D points in $O(n \log(n))$ time, to use ...
161 views

### Improving the plotting time of a very complicated expression

The quatity $R$ is defined by a complicated expression in terms of $a_1,a_2,\ldots,a_n$. Now each $a_i$ is a function of $x$, $a_i(x)$. I would like to know what is the most efficient way to ...
362 views

### Options which require RuleDelayed

For some functions in Mathematica it is important to use RuleDelayed. One prominent example is the EvaluationMonitor for ...
64 views

### Abridging Lists of Equations within NDSolve, Manipulate [duplicate]

I have a pretty little NDSolve function that I've finally decked out with manipulatable (by sliders) coefficients, which changes the graph in real time. However, I ...
362 views

### Performance of Dispatch and lists of Rules

The issue outlined here seems to be no longer present in version 10, if you use a Dispatch table! This because a Dispatch table ...
491 views

### substitution rules excluding subscripted variables

Suppose I have an expression containing p,Subscript[p,1],Subscript[p,2],etc. I want to ...
172 views

### How can I substitute something using only map?

For example, I have the equation x^2 + y^2 == x*y and I want to apply the rule y -> s*x I can do it easily by ...
1k views

### Simple problem with Manipulate and Plot

Would anyone have an idea why the following doesn't work: rule = {z -> x^2 + 2 x + y}; Manipulate[ Plot[z /. rule, {x, 0, 10}], {{y, 2, "y"}, 1, 5} ] But ...
513 views

### Mass Symbolic Manipulation with Subscripts? (from plaintext Input)

The simplest example of the change being sought is a greek letter, typed in as plaintext nu, and its may be replaced by the symbol, ν: expr = 3nu*kx*ky+ ...
502 views

### “Strange” behavior of Rule

According to the Help lhs->rhs evaluates rhs immediately. How to understand the output of the following code? ClearAll@x; {1, 3.5} /. x_?IntegerQ -> {x} ...
96 views

### Replace expression using a tuple

Given an expression in x, y, z (for example), and a list with three elements, like ...
59 views

### Problem using replace to simplify logarithms [duplicate]

Is there a way to combine logarithm terms like 9 m Log[m]-9 m Log[M]+16 m M Log[m]-16 m M Log[M] into ...
522 views

### Replace elements in a list

Suppose that I have a list: ...
334 views

### Arbitrary depth patterns/rules

Temporary message: I am now really confused. I am not sure how using Power and Unevaluated together works in the examples below. While answering this question, I stumbled upon the following. We ...
412 views

### characteristic polynomial based on differential equation

I have this differential equation: $$\ddot{x}-\frac{1}{6} \dot{x} - \frac{1}{6}x = e^t$$ When I DSolve it looks like this: ...
142 views

### Trouble with Replacements [duplicate]

I have the following line of code: Plus @@ Table[p[x], {x, 0, 20}] /. p[x_] -> Boole[MemberQ[{0, 5}, x]] The first part of this produces ...
104 views

### given n lists, get list of applications of function to n-tuples

Is there a built in function or an easy rule to do the following transformation? H[{A[0], A[1], ...},{B[0], B[1], ...},...] into ...
182 views

### Help me to find a way to do this repetitive stuff

I'm trying to do this: ...
354 views

### Why is ReplaceAll behaving like this?

I'm learning to use the ReplaceAll function and I found the behavior of which is quite confusing. For Sqrt[f[x, y]] /. f[___] -> u Mathematica returns <...
252 views

### Match and replace subexpression

I would like to replace the expresion $(n1-1)$ to $z1$ in following: In[1] := 2*n1*p[n1-1,n2] Out[1] := 2*(z1+1)*p[z1,n2] I have tried ...
327 views

### Unexpected behavior of rule matching a pattern

I am a beginner exploring the world of Mathematica. I expected the following code T[6, 5, 4, 1, 2, 3] /. {T[a___, 1, b___] -> Length[List[b]]} should return ...
539 views

### Replace operators

/. can be used to replace variables but how can one replace operators. For example in a * b, ...
777 views

The function ...
100 views

### Creating functions from output of other calculations

Apologies in advance if the title is vague, I'm not really sure what to call this. I have a function (call it 'foo') that generates a largeish polynomial, and it is natural to make the variables be ...
269 views

### Applying a transformation rule on an Image

I haven't been able to figure out why the following doesn't work: ...
135 views

### Replace an expression with a slightly tricky LHS transformation

I would like to make the substitution x^(11*y) -> r in the following equation x^(11 *y^z) - 1 to end up with: ...
449 views

### Why does this pattern for combining two lists require triple underscores (___) to work?

I understand that __ is a list of one or more elements, and that ___ is 0 or more elements, but when I try this rule with 2 ...
227 views

### Generating replacement rules programatically

I would like to generate sets of replacement rules programatically for predefining some permutations. So a function ...
2k views

### How to simplify a complicated Sum in terms of power Sums?

For example, I have: $a=\sum _{r=1}^n x_r \left(\left(\sum _{i=1}^n x_i-x_r\right){}^2-\sum _{i=1}^n x_i^2\right)$ ...
70 views

### Unique[] in RHS of rule

I have a function, explicit that takes dot product of two symbols, and replaces it with repeated dummy indices generated by ...
125 views

### Using a predicate to control the application of a rule in a replacement

How can I make a replacement rule that will only be applied to those parts of an expression that will not break a condition placed on the whole expression? For example, suppose I have \$\frac{xy}{(x-y)...
44 views

### plot[] with subsititution rule [duplicate]

I encounter this problem in Mathematica 9.0.1, I'm not sure if it ever happens in other version. Plot[{x, x + 1}, {x, 0, 10}, PlotStyle -> {Red, Green}] This ...
162 views

### Auto simplifications of power products

Mathematica automatically simplifies Exp[a]Exp[b] to Exp[a+b]. The problem is now that I can't do this ...
154 views

### How to transform an expression using algebraical instead of pattern rules [duplicate]

I would like to transform rules algebraically. A very simple example would be: - k^2 - 2 k x + x^2 /. {2*k -> 1} This transforms to: - $$k^2-2 k x+x^2$$ ...
214 views

### How do I write a function that can be used in a rule to modify both sides of an equation? [duplicate]

I sometimes need fine grain control over equations in Mathematica in order to help me understand how to solve a problem manually. A greatly simplified example of a session might be something like this:...
199 views

### Efficient way to give symbolic elements symmetry

I have a symbolic expression that represents a set of operators. These operators have quite a bit of symmetry to simplify expressions: ...