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

learn more… | top users | synonyms (4)

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 ...
3
votes
1answer
168 views

Pattern matching a multivariate derivative

I can extract the parameters of a single variable derivative with the rule D[f[x], x] /. Derivative[order_][fcn_][variable_] -> {order, fcn, variable} ...
3
votes
1answer
59 views

Replacing multiple instances of a symbol with different variables and assignments

I have an expression of the form: expr=x+y+n+Sin[n]+n^2 I would like to replace each of the variables n with a different ...
3
votes
1answer
89 views

some confusion about ReplaceRepeated

This is Right. NestWhile[Log, 100, # > 1 &] {100} //. {x_} /; x > 1 :> {Log[x]} 100. //. x_ /; x > 1 :> Log[x] This is wrong,why? ...
3
votes
1answer
147 views

Is there a way to simplify this replacement rule

I have a rather big expression which contains many sums of form q x + w y. I know that y is much smaller than ...
3
votes
3answers
137 views

Multivariate Polynomial Manipulation

I have a large homogenous multivariate polynomial in, say, 5 variables $a,b,c,d,e$. As an example take the polynomial $$a^4+2abcd+a^2 b^2+e^4+cde^2.$$ Now I would like to replace $k$-th power of any ...
3
votes
2answers
117 views

Replacing Patterns In a List of Varying Length

I am working with an array of data that may look something like this. ...
3
votes
3answers
349 views

StreamPlot using NDSolve gives error messages

StreamPlot[{x[0], x'[0]} /. NDSolve[{x''[t] == 1, x'[0] == v0, x[0] == x0}, {x, x'}, {t, 0, 1}], {x0, -2, 2}, {v0, -2, 2}] The above code gives me the errors ...
3
votes
1answer
110 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: ...
3
votes
3answers
121 views

Transformation of Derivatives under change of coordinates [duplicate]

I have an expression depending on the two variables z and t, and the derivative of a known function $f(t,z)$. Something like: $$myexp \ =\ t\ z\ \partial_z\ f(t,z)$$ Now I want to make a change of ...
3
votes
1answer
199 views
3
votes
2answers
116 views

truncating terms in symbolic expression basing on their values

I need to simplify big symbolic solution of equations system by truncating terms that are orders of magnitude less then others in subexpressions like a + b. The solution is big fraction with sum of ...
3
votes
1answer
207 views

Replace elements in a list

Suppose that I have a list: ...
3
votes
3answers
72 views

Replacing a sum of expressions

I have an equation which Mathematica solves but gives a huge output. However I notice in this output that the same expression occurs many times. Namely: $E=864 a^6 - 432 a^4 b^2 + 54 a^2 b^4 - b^6 + ...
3
votes
1answer
68 views

Have transformation rules to be explicitly set?

I think this problem is not the hardest one, but I can't hit on it. I want to NSolve an equation. For this equation I use a transformation rule "ampTimes". First I used it like this: ...
3
votes
0answers
63 views

Why doesn't ReplaceAll work on Image? [duplicate]

ReplaceAll seems not to reach inside Image, and I don't see why it shouldn't. Here is an example. Create a black and white image ...
2
votes
3answers
173 views

Slow image processing using ReplaceAll

Can anyone explain me, why this line of simple code is so slow? And can it be improved somehow? ...
2
votes
2answers
423 views

How to do substitution of variable with power in Mathematica?

I want to replace $x^{i+1}$ with $z_i$. EDIT: I have some latex equations, and wish to import them to MMa. How to replace x_i (NOT $x_i$) with $x[i]$ But it seems the underscore "_" has a special ...
2
votes
2answers
141 views

Create Table of replacement rules

I want to create a table of replacement rules. ...
2
votes
2answers
136 views

Matrix exponential via Cayley-Hamilton Theorem

I'm attempting to calculate the exponential of a matrix via Cayley-Hamilton theorem. (Following the "concrete example" from http://en.wikipedia.org/wiki/Cayley%E2%80%93Hamilton_theorem) I am having ...
2
votes
3answers
153 views

How to manipulate log arguments?

A common problem I have with Mathematica is needing to manipulate the arguments of logarithms. Typically, I need to take ratios of the log arguments Mathematica gives me by default. That's to say ...
2
votes
2answers
367 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. ...
2
votes
4answers
210 views

Extracting RHS from Rule

In an example from another question, the rhs of a list of rules can be simply extracted: ...
2
votes
3answers
368 views

How to manipulate nested expressions?

I have the following expression, only slightly complicated, and I'd like to do two things: Plot the elements of the lists (though messy, all are in the same ...
2
votes
3answers
150 views

What is the order of faces on a D20? How can I optimize the order of faces on a D-n?

I am creating a customizable D20 for 3D printing using OpenSCAD, with the following code: ...
2
votes
3answers
157 views

Simplify system functions

Consider the code defining two constants: a=Cos[t] b=Sin[t] Suppose that we have another value in terms of Cos[t] and ...
2
votes
2answers
100 views

Converting a date to a calendar quarter

I have a list that includes dates. I need to convert each date to be the last day of the quarter that it's in. So for example I want {2013,7,1,0,0,0} to become {2013,9,30,0,0,0}. Actually I don't ...
2
votes
1answer
108 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 ...
2
votes
4answers
168 views

Replacing High Densities of 1.s in Very Large Binary Arrays

I am working with very large binary arrays on the order of {100,100000}. It may look something like this. ...
2
votes
1answer
61 views

ReplaceAll in an expression including large InterpolatingFunction

I have a large InterpolatingFunction that I'm transforming to another basis with a few simple multiplications and additions by (symbolic) constants. The ...
2
votes
2answers
131 views

How to plot complex values given by Solve

Update Solve[N[Table[BernoulliB[n, z], {n, 10, 10}] == 0]] ...
2
votes
1answer
153 views

Add Pattern to List Removing Duplicates

Lets say I have a list of patterns ...
2
votes
2answers
110 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 ...
2
votes
2answers
152 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: ...
2
votes
1answer
60 views

Table with some editable cells

I have a table: I want it to be editable only where the zeros appear. I read this post Generating an editable table that can be used as input because it's almost exactly what I want, but I couln't ...
2
votes
1answer
69 views

Using Total on a list supplied by a rule

I'm confused as to why Total complains about a nonatomic expression here: ...
2
votes
1answer
76 views

Applying rules to rewrite expressions that contain patterns

I'm trying to write a rule that can rewrite a pattern that exists in another expression. For some reason, this is proving to be more challenging than I expected ... most likely because I'm not totally ...
2
votes
1answer
128 views

Derivation after substitution not working

I have a code that will output an expression in form of a functions like this ...
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: ...
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
1answer
191 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, ...
2
votes
2answers
57 views

Pattern evaluation in nested function call

I'll put the question right here, but will add some context below in case someone wonders why the heck I'm trying to do this. Why is it that I have to do two passes to get the value of the arguments ...
2
votes
1answer
56 views

Ordering for Pattern matching in Subscripts

I have some transformation rules acting on subscripted variables. When I match the a product the order matters. ...
2
votes
2answers
167 views

Applying rules with functions to expressions with derivatives

I have a function that I want to see applied, potentially within a derivative. The use of delayed vs. non-delayed rules seems irrelevant. See the following: ...
2
votes
1answer
86 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 ...
2
votes
2answers
352 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+ ...
2
votes
1answer
74 views

How to program a clickPanel for chemical elements (like a periodic table)?

The command ColorData["Atoms", "Panel"] indicates RGBColors of "Atoms" by clicking a panel. As I don't want to reinvent the wheel, I asked myself: How to ...
2
votes
2answers
130 views

Generating an editable table that can be used as input

Say I have a number $n_{max}$. I want a command to generate a table like 1 1 2 2 3 3 4 4 ... nmax nmax where the second column is editable, and this table can be ...
2
votes
1answer
71 views

Convert Integer to Numeric with Replacement rules

I have a long list of triples, each looking something like {AGO, 1988, 2345.23}. Some of these, however, have an integer in the third spot, like this: ...
2
votes
1answer
134 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: ...