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

learn more… | top users | synonyms (4)

0
votes
1answer
24 views

Replace all instances of Integrate by NIntegrate and add a Method option

I have an analytic expression which involves several integrals Integrate[f[x], {x, lb, ub}] where the functions f and bounds ...
2
votes
1answer
62 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 ...
3
votes
3answers
129 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 ...
0
votes
0answers
43 views

Replacing variables [on hold]

I guess this is a common issue and I tried to search it in this forum. However, I did not find a solution. Suppose I have a function $$f = x + x^2 + x^3$$ I want to replace $x$ as $k x$, namely ...
5
votes
1answer
212 views

Mma10 mystery: Failure of pure function substitution with Interpretation?

I had code to display with subscripts from Displaying index as subscript on output: e.g. C[i] -> C_i with Notation[...] or Interpretation[..]? which is now breaking an innocuous pure function ...
5
votes
2answers
145 views

How to make Missing[] invariant for some functions without redefining them

Missing[...] "is a symbolic object, with no default evaluation rules defined." Missing data can be tagged and enables use of filters like DeleteMissing. So it's worthwhile to normalize various types ...
1
vote
3answers
116 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: ...
1
vote
1answer
149 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: ...
10
votes
2answers
125 views

Dispatch displays rules incorrectly and evaluates when displaying

Consider this a = 3; disp = Dispatch[Unevaluated[{a -> 2}]] We see the rule 3 -> 2, rather than ...
2
votes
3answers
154 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 ...
5
votes
1answer
53 views

Using PatternSequence on its own in ReplaceAll?

Say I have this list: list = {0, 1, 2, 0, 1, 3, 0, 1, 4} and say I want to remove consecutive sequences of 0 and 1. I'd normally go for this: ...
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
152 views

Equivalent of ReplaceAll for Associations?

Is there a nice (built-in) way to apply Replace-style rules to key-value pairs in an association? Something like ...
6
votes
1answer
351 views

ReplaceAll inside an Iterator

I'd like to apply a set of rules to an expression defining the iterators of the table, like this: ...
0
votes
1answer
74 views

How can I represent this automorphism of Q(i,a)?

Let $a$ represent some real irrational number. I am trying to perform computations with an automorphism $f:\mathbb{Q}(i,a)\to\mathbb{Q}(i,a)$ which fixes $\mathbb{Q}(i)$ pointwise and maps $a$ to $i ...
0
votes
1answer
68 views

Replacing powers of $n$-th partial sums in the output of a function with $S[i]$ for $i = 1,\ldots,n$

I've written some simple code that, for various $N \geq 1$ and $k = 1,\ldots,N+1$ computes the $n$-th derivative of $\log S_N$ where $S_N(z) = \sum_{k=0}^N \frac{1}{k!}z^k$ as follows: ...
1
vote
4answers
176 views

How to find all symbols in an expression and perform an operation on them?

========== motivation =========== Suppose, for example, I have an incoming expression like m = (3-I)x + 4(x y)/(Cos[y]) I want to find all the symbols in ...
8
votes
8answers
828 views

How can a power of 0 or 1 be replaced?

Consider this given example for ReplaceAll 1 + x^2 + x^4 /. x^p_ -> f[p] This returns ...
0
votes
2answers
84 views

how can tangent half angle substitution be done in Mathematica?

Is it possible to replace sine and cosine in terms of tangent half-angles and again the tangent half-angles by a variable say t?
1
vote
2answers
95 views

Looking for an elegant way to solve a (system of) ODEs/functional equations with undetermined coefficients

I want to solve an ODE using undetermined coefficients/guess-and-verify and am looking for an elegant way to use this technique. I am running into a few ugly warts. Here is a basic implementation for ...
1
vote
1answer
76 views

Nest Replace Function with different rules

I have a table of data that I want to filter. Any value of zero in the table means that value was not calculated, so it should get populated with the tag "NC". Next the table is filtered for all ...
2
votes
1answer
56 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 ...
4
votes
2answers
127 views

Replacing one element of list

I have a list of sequences of x's and y's. I want to switch the last position to the "opposite" symbol - if ...
17
votes
3answers
276 views

Options which require RuleDelayed

For some functions in Mathematica it is important to use RuleDelayed. One prominent example is the EvaluationMonitor for ...
6
votes
5answers
201 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, ...
1
vote
2answers
64 views

Replacing a specific pattern of values at level 2 in a list

I've a list of lists, tl = {{True, False, m12}, {False, m22, m33}, {m32, False, True}} and each nested list has the same length, What is the proper way to ...
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 ...
0
votes
4answers
63 views

Replace a sum of squared variables by a new variable squared

Is there any way to tell Mathematica to replace $\kappa^2 + k_z^2 \rightarrow k^2$ in an expression? I want to make a result more readable, e.g. something like this: $$\frac{2 k_z^3 \sqrt{k_z^2 + ...
1
vote
1answer
99 views

Matrix/tensor addition behaving funny under replacement?

I have two matrices I want to add, and one of the matrices is a tensor product of two vectors. I've used a SetDelayed to define the summed matrix, because I want to evaluate it for different values of ...
2
votes
3answers
357 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 ...
5
votes
2answers
80 views

ReplaceAll performance problem: packed arrays on the LHS are unpacked when the RHS is too long

The following is one of the most mysterious performance problems I encountered and came up while extending the booleval function mentioned here. I am looking for a ...
2
votes
4answers
165 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. ...
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. ...
2
votes
1answer
60 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 ...
0
votes
1answer
45 views

What's wrong with my rule? [duplicate]

Consider a simple code to form a SparseArray: Q = 5; a = Table[i, {i, Q}]; SparseArray[{{j_} /; j > 2 -> a[[j]]}, {Q}] Part::pspec: Part specification j ...
0
votes
0answers
38 views

Hashing by Equals instead of SameQ

I have some numerical code involving complex numbers representing points on a plane. Some of these are equal but not identical, ie ...
0
votes
2answers
102 views

How to assign special colors to the output of DensityPlot?

I have created the following function for plotting ...
2
votes
2answers
126 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 ...
4
votes
1answer
211 views

Apply color function to matrix plot

I want to apply the following color rules to a large table of numbers. I have extracted a part of the table to use as an example. I would like to assign 5 different colors to 5 different ranges of ...
1
vote
1answer
67 views

How can I get the functionality of a command ReplaceAllList?

I'm trying to use ReplaceList to match subexpressions. I expected the command: ReplaceList[{p, {p, p}}, {x_, y_} -> x y] to output two results, equivalent to: ...
0
votes
2answers
87 views

Replace one order of derivative inside higher one

How could I replace for example: Derivative[2][f][x] by Derivative[1][g][x] where ...
2
votes
2answers
138 views

Create Table of replacement rules

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

Why does Mathematica not replace the derivative of $theta$1'[t]?

I want to know the velocity of point $p$, given that I know the coordinate. $p_x=L_1\cos(\theta1)+L_2\cos(\theta1+\theta2)$ I calculate $\frac{dp_x}{dt}$ to achieve the velocity of point $p$ about ...
0
votes
2answers
52 views

Evaluate differentiation after replacement

The problem is Find two linearly independent solutions of $2x^2y'' -xy' + (-4 x + 1)y = 0, \, x>0$ of the form $y_1 = x^{r_1}(1 + a_1 x + a_2 x^2 + a_3 x^3 + \cdots)$ and $y_2 = x^{r_2}(1 + b_1 x ...
10
votes
1answer
206 views

StringReplace, ReplaceAll and Rule interact in a bizarre way

I have the following pair of things: ClearAll[foo, labeledFoo]; labeledFoo = {"FooBarBazQuux", foo}; This works like you'd expect: ...
4
votes
2answers
121 views

Replacing a function in defined expressions

I'm having a little trouble with substituting functions into an expression. A minimal example is as follows: ...
0
votes
1answer
64 views

Append subscript to variable name [duplicate]

I'm importing equations from Word document and transforming them into input form. But subscripts look ugly. Is is possible to programmatically append subscript to variable name? e.g. ...
1
vote
0answers
37 views

How can I use the Rules returned by FindFit? [closed]

When I evlauate data = RandomReal[10, {5, 10, 2}]; fit[i_] := FindFit[data[[i]], a Sin[x] + b, {a, b}, x] fit[1] I get something like: ...
11
votes
4answers
262 views

Replacing parts of a held expression with held parts of another expression

I'm applying the Trott-Strzebonski technique in order to replace inside a held expression. ...
0
votes
0answers
123 views

Calculating the Lyapunov Exponent/Spectrum for the Duffing Oscillator

Some fellow students and I are trying to calculate and plot the Lyapunov spectrum for the Duffing oscillator (currently a test approach). Each of us has Mathematica knowledge based purely on past ...