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

learn more… | top users | synonyms (4)

1
vote
1answer
53 views

Don't understand why my Taylor expansion results in a message and an unexpected result

Trying to do something simple: Taylor expand a generic function of t around a point t and substitute ...
0
votes
0answers
69 views

Replace Part of a matrix

I have to generate a ne numbers of matrices with 1 and 0 and then replace some elements. ...
6
votes
3answers
201 views

Obtaining the number of iterations used in ReplaceRepeated

ReplaceRepeated has an option MaxIterations which indicates Mathematica is keeping track of the number of iterations. Is there ...
7
votes
1answer
112 views

Why does an inert ReplaceAll modify this Dataset?

I cannot see any reason for this behavior besides a bug, but I've been wrong before so I put it before the community: ...
0
votes
0answers
57 views

Creating a lazy evaluator of the lambda calculus

I have a sub project in my research to write a lazy evaluator of the lambda calculus. How should I approach this problem? I already have a implementation of the lambda calculus in another language. ...
5
votes
2answers
87 views

Replace expression in series expansion [duplicate]

A test case: I'm trying to replace an expression inside a series expansion: Series[f[x],{x,x0,4}] ./ (x-x0)->h but it still returns ...
0
votes
1answer
43 views

Replace bunch of numbers by letter

I want to do following: ArcTan[1/Sqrt[-1 + (4 Sqrt[2] x^2)/(5 xc^2)]] /.4 Sqrt[2]/5->a^2 I expect to have ...
1
vote
1answer
50 views

Correct interpretation of /. (ReplaceAll)

Consider that you have a complicated expression, which is expensive in terms of running time and memory, and depends on some (initial) parameters. You want to test it for some simple values of the ...
6
votes
5answers
123 views

Setting value of a rule

How do I change the value of a rule? For example, If I have a = x->3, how do I reset the value of x/.a to 4, so that ...
1
vote
2answers
65 views

Why doesn't ToString work in ReplaceAll? [duplicate]

I'm trying to use ReplaceAll in a subscript. However, it doesn't seem to work as expected if I want to use the output the subscript in a ...
0
votes
0answers
34 views

Substitute all known values in matrix [duplicate]

There is probably a very simple way of doing the following, but I cannot find it. I have a an array of symbolic variables: coefficients = Array[c, 3] I then ...
2
votes
1answer
85 views

Limits and transformation rules

I can calculate this limit: Limit[(c^(1 - g) - 1)/(1 - g), g -> 1] and obtain the correct value: Log[c] but if I try ...
0
votes
1answer
65 views

What to use instead of ReplaceAll to replace a parameter with a number before the evaluation of an integral?

This is probably very simple but I don't see the solution now. Let us say I have a variable e defined as e=n ReplaceAll can subsitute n with value 3 using ...
5
votes
4answers
311 views

Long list of similar rules

Given the following: ...
10
votes
5answers
351 views

For a given expression: if it appears, remove it, but if it is absent, add it

While reformatting Szabolcs's code from (42660) I noticed this interesting operation: ...
0
votes
1answer
72 views

Replacement of terms/Pattern matching involving products of derivatives of a function

In delving into Ramanujan summation, I'm trying to get a hold of the relations of the form $$\sum_{n=0}^\infty f(n)=\dfrac{h\frac{d}{dx}}{{\mathrm{e}^{h\frac{d}{dx}}}-1}\int_{0}^\infty ...
0
votes
0answers
79 views

Writing rules for Einstein summation

I'm trying to write a list of rules for tensor manipulations and in particular, Einstein summation convention. What I've tried, so far is to write something that would take a generic functions with ...
7
votes
2answers
98 views

Why does ToRules return a Sequence?

Why does ToRules return a Sequence expression? Why doesn't it return directly what ...
1
vote
2answers
176 views

Turn list of rules from radians to degrees, match all greek letters

Is there a easy way to match Greek letters only. I am trying to lower the angst of bachelors level students by keeping things as low level familiar as possible. Now understandably Mathematica counts ...
3
votes
2answers
136 views

Replace expression, but only “outside” of a function [duplicate]

I have a horrid expression, which is basically a sum of exponents with coefficients. Here's a taste: What I want to do is to replace ks with another expression, ...
1
vote
0answers
45 views

How to substitute inside Hold? How to create table of summation (with Sigma symbol) expressions? [duplicate]

I would like to create table of summation expressions, which are not evaluated, but summation limits are substituted. I can't accomplish this so far. If I write I get summation expanded. If I ...
1
vote
0answers
76 views

Speed up replacement using Rule Dispatch Associtation

I knew that this has asked many times, but I hope there is something more could be done to speed this up. The expression kappa is here. ...
5
votes
2answers
116 views

Why does Rule behave like this?

Why does {x, x^2, x^3, a, b} /. x^n_ -> f[n] result in {x, f[2], f[3], a, b} when ...
3
votes
4answers
178 views

Question about ReplacePart

This is a question about ReplacePart but if there's a better that's great. If I have a list a= {1,2,3,4,5} and I want to replace elements ...
3
votes
3answers
185 views

How to Update 2D List based on a binary array

I have 3 lists: numbers = {{1, 2}, {3, 4}, {5, 6}}; toUpdate = {{1, 0}, {0, 0}, {1, 1}}; newValues = {{10, 20}, {30, 40}, {50,60}}; I have to update the list ...
2
votes
1answer
42 views

Substitution breaking the scope

A novice's problem, perhaps: it seems that /. substitution does weird things to the scope. ...
2
votes
1answer
72 views

Return the incomming expression on false

when I have an expression, that is unknown to mathematica, it is returned exactly the same, as it was called. For example SeeFlyingPigs[1,2] called on the line ...
8
votes
5answers
283 views

Select a particular rules out of a list

rule = {beta -> 4, alpha -> 2, x -> 4, z -> 2, w -> 0.8} Select[rule, beta] Select[rule, beta &] Select[rule, beta -> _ &] How would I ...
2
votes
0answers
56 views

Drop all powers from multinomial [closed]

How to automatically replace an expression like x^3 y + x y z^2 by x y + xyz in Mathematica, i.e. replace all ...
0
votes
2answers
140 views

Replace variables and redefine a function

I would like to redefine a function f(x)=1+2x^2 to a new function g(y)=1+2y by using the replacement ...
0
votes
1answer
42 views

How to use rules in simplify this expression?

D[1/(1 + Exp[-x]), x] % /. {1/(1 + Exp[-x]) -> p} Suppose I know that the rule can be applied, but Mathematics just won't do it straight away as the expression ...
2
votes
2answers
111 views

Derivative of Vectoral NDSolve Interpolated Function / Rule Solutions,/., and Vector NDSolve [duplicate]

I need to find the instantaneous phase and instantaneous frequency for a rotating system. I am having difficulty making the math work with interpolating functions. First, here is a problem without ...
3
votes
3answers
117 views

ReplacePart equivalent for Associations

I have a fairly complicated Association. I wish to use/create a function such as ReplacePart to operate on certain Keys within this multi-level Association. Here's ...
5
votes
3answers
343 views

Simple image processing very slow

I have compared the speed of some simple image processing routines between Mathematica an IDL. 1. Reading of a grey scale png image of (720,577) pixels: The image is: Mathematica: ...
6
votes
1answer
206 views

Better replacement rules to perform this change of variables?

In cosmology, it is common to work with both a normal time variable t and a “conformal” time variable τ, which is defined such ...
3
votes
4answers
156 views

ReplaceImageValue and ReplacePixelValue extremely slow

I have a grey scale image: and I am doing the following: bin = Binarize[image, 0.18] ...
4
votes
4answers
127 views

How to replace all symbols except several?

I'm doing some heavy symbolic calculations and for preliminary simple tests I need to replace all coefficients except chosen with 1, e.g.: ...
7
votes
2answers
110 views

Is Replace doing double work?

In an answer to this question, rm -rf used the function Replace with level spefication to do a series of replacements inside out. As far as I can see, the order of substitutions when more than one ...
1
vote
1answer
96 views

What's wrong with this tutorial? [closed]

Disclaimer: This code is not mine. Source. I'm trying to follow along with it, though, but it seems that this code no longer produces a working manipulatable plot at the end -- and I'd like to know ...
0
votes
0answers
45 views

How to solve ReplaceAll problem inside Manipulate

I'm running into some trouble when I try and use Manipulate (code included below). Instead of letting me manipulate the plot, I get an empty plot and this: ReplaceAll::reps: ...
1
vote
0answers
42 views

Question on Function in Replacement Operation

I am trying to create a replacement function which, depending on the input, gives an additional minus. In my example I have an undefined function a with two ...
2
votes
0answers
110 views

Is this a bug in NCAlgebra library?

In course of my work with NCAlgebra package for Mathematica, http://math.ucsd.edu/~ncalg/ , I encountered unexpected behavior of replacements. I am using ...
2
votes
3answers
503 views

Replace all integers by 1?

Let list1 be a list of variables of the form {c1 a, c2 b, ...} where $a,b,...\in\mathbb{C}$ and $c1,c2,...\in\mathbb{Z}$. I am ...
2
votes
1answer
139 views

replace RHS of rule

is there an elegant way of replacing the RHS of a rule with the value of some function of it. Say I have {{a -> 1.2}, {a -> 2.3}} and I want to replace ...
2
votes
3answers
90 views
15
votes
2answers
234 views

Why Infinity /. _?(# < 6 &) -> 0 replaces Infinity with ComplexInfinity?

Suppose I define a matrix: mat = { {Infinity, 4, 9}, {6, Infinity, 10}, {8, 9, Infinity} }; Now I want to replace all values smaller than ...
4
votes
2answers
296 views

Replace x, but not x[a]

I want to replace all occurences of the symbol x with x[a], as long as it is not in the form ...
3
votes
1answer
108 views

Why does the replace all (/.) evaluate differently in plot

I'm plotting this function: Plot[(2 (l/2 π)^2 ((2 π f)/c)^2 /. {f -> (f 10^9), l -> .01, c -> 3 10^8}), {f, 17.5, 26.5}] but it does not plot ...