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

learn more… | top users | synonyms (4)

17
votes
3answers
277 views

Options which require RuleDelayed

For some functions in Mathematica it is important to use RuleDelayed. One prominent example is the EvaluationMonitor for ...
1
vote
0answers
60 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 ...
9
votes
1answer
219 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 ...
9
votes
3answers
226 views

substitution rules excluding subscripted variables

Suppose I have an expression containing p,Subscript[p,1],Subscript[p,2],etc. I want to ...
5
votes
1answer
106 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 ...
9
votes
2answers
417 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 ...
2
votes
2answers
337 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+ ...
11
votes
4answers
332 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} ...
0
votes
2answers
72 views

Replace expression using a tuple

Given an expression in x, y, z (for example), and a list with three elements, like ...
0
votes
1answer
107 views

Problem with Replace rules [closed]

I am struggling with a Project Euler problem with Mathematica, what I want to do is to Replace a list like this {5,6,x,x,3} with the rule {x -> i} to {5,6,0,0,3}, {5,6,1,1,3}etc,and here is my code: ...
0
votes
0answers
54 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 ...
3
votes
1answer
203 views

Replace elements in a list

Suppose that I have a list: ...
0
votes
1answer
255 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 ...
0
votes
2answers
203 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: ...
5
votes
2answers
124 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 ...
1
vote
1answer
99 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 ...
1
vote
3answers
172 views

Help me to find a way to do this repetitive stuff

I'm trying to do this: ...
1
vote
1answer
120 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 ...
9
votes
3answers
305 views

Replace operators

/. can be used to replace variables but how can one replace operators. For example in a * b, ...
2
votes
2answers
279 views
4
votes
2answers
86 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 ...
7
votes
3answers
229 views

Applying a transformation rule on an Image

I haven't been able to figure out why the following doesn't work: ...
2
votes
1answer
110 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: ...
5
votes
1answer
163 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 ...
5
votes
1answer
166 views

Generating replacement rules programatically

I would like to generate sets of replacement rules programatically for predefining some permutations. So a function ...
6
votes
6answers
845 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)$ ...
2
votes
1answer
63 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 ...
2
votes
2answers
108 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 ...
1
vote
0answers
43 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 ...
1
vote
3answers
114 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 ...
2
votes
1answer
123 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$$ ...
8
votes
2answers
184 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 ...
1
vote
1answer
150 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: ...
7
votes
3answers
316 views

Piping and Replacement

I haven't been able to figure out how to use piping with certain functions. Specifically, I would like to apply a replacement at the end of a pipe, like the following: ...
0
votes
2answers
193 views

Converting a list of replacement rules into a list of real values [duplicate]

The following command outputs a list of replacement rules. ...
0
votes
1answer
118 views

How to change variable that has been defined in PDE?

I have a PDE function that contains a variable (named ka). I want to plot the result of my PDE in 1 plot using several different ka values. However, I'm not sure about how to write down this equation. ...
2
votes
2answers
345 views

Replacing values of a function

I have recently starting using Mathematica and have recently come to what seems as an impasse in my understanding of the language. If this is too "tell me how to do it" I would certainly understand. ...
4
votes
1answer
104 views

Replacing a combination of terms

I have a quite simple question. I have an expression that looks similar to $T=\frac{1}{a_1}-\frac{1}{a_2}+1$ and I'd like Mathematica to use $A=\frac{a_1}{a_2}$ to reformat the expression (if ...
3
votes
2answers
167 views

Efficient way of setting up a rule

I tried to define a simple rule defining how λ acts on ψ[n]: myrule1 = λ ψ[n_] -> α[n + 1] ψ[n + 1]; The result I get is ...
1
vote
2answers
322 views

Generating a list of rules [closed]

This is my first time asking a question on this forum. I would like to generate a list with a range of numbers and use this list for a function to read from. Ok, now for the good part, it would look ...
0
votes
1answer
264 views

Make Mathematica wait before replacing?

How can I force Mathematica to completely evaluate a subexpression before using a replacement rule? For example, consider the following definition (for the series of ...
0
votes
1answer
144 views

simplification rule with symmetry

What rule can you think of to replace the first line by the second? I have a bunch of expression like these, which I would like to simplify. All dependent cross terms must be written in the same ...
2
votes
1answer
186 views

A Sierpinski-ish structure, via 2D automata

The project is originally based on a puzzle proposed by EIORU at http://www.ptt.cc/bbs/puzzle/M.1342451949.A.00F.html (若您懂得讀中文 / if anyone happen to read Chinese^^) last July. The descriptions, ...
0
votes
1answer
135 views

Apply rule only if applicable? Check rule applicability? Custom unapplicable rule?

How to avoid recursion in the following example? ...
0
votes
0answers
36 views

How do I replace a variable with the answer from a solve function in the form k-> number + variables? [duplicate]

Possible Duplicate: Using the result of Solve in subsequent calculations extract values from replacement list I am trying to define a variable (k1) as ...
2
votes
1answer
107 views

Confused behavior using Dispatch to sort one list relative to another

I have a need to sort the entries of one list into the same sequence as the entries in a reference list. Because I have rather large lists involving strings, I'm trying to use Dispatch to accomplish ...
20
votes
1answer
582 views

replacement rules from a pattern and a matching expression

(This seems to be a very basic necessity in a language having pattern-matching capabilities such as Mathematica, yet I struggled for many hours to find a common solution to this problem.) Suppose ...
2
votes
2answers
147 views

Modify a sub-part of a sub-list only

I have this list: a = {{{0, 0}, {1, 7}, {2, 0}, {3, 2}, {4, 7}}, {{0, 0}, {1, 0}, {2, 1}, {3, 2}, {4, 7}}} and I'd like to transform it to this: ...
9
votes
1answer
229 views

error when defining a compiled function with ReplacePart

I always have difficulty in writing a non-trivial compiled function. I'm using Mathematica 9. Please see the following code ...
0
votes
2answers
140 views

How to use Solve rules as a function body?

Solve gives me an expression which I want to use as the body of a function. Rather than run Solve every time inside my function ...