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
0answers
26 views

NProbability and Rules

Hello i am trying to use Rules in Probability to replace negative values, however it seems that i am missing something basic. below is the code i use. the plot just shows that under normal ...
4
votes
3answers
145 views

Replace elements in matrix to make it symmetric using automated procedure

I am generating a matrix using (mat2 = Array[Subscript[a, ##] &, {4, 4}]) // MatrixForm but would like to force Mathematica to make it symmetric. Thereby I ...
0
votes
1answer
27 views

Force ReplaceAll to output vector of same length

I would like to do a replace in an expression... a = t; b = 1; a/.t->Range[1,5] (*returns: {1,2,3,4,5} *) b/.t->Range[1,5] (*returns: 1 *) but I ...
-2
votes
1answer
59 views

Transform differential equation to get equilibrium position

I would like to determine the equation in the equilibrium position. eq = 1/2 g l m Cos[θ[t]] == J (θ^′′)[t] ...
0
votes
2answers
36 views

FilterRules with pattern for name [duplicate]

I have a list of rules and I want to filter it using a pattern for the initial string representing the name of the rule. So that in the example below it filters linearBool even if it is called ...
2
votes
0answers
23 views

Define (conditional) substitution rule for sum/difference of radicals

I want to tell Mathematica to simplify some expressions applying the following substitutions, conditioned on the fact that $a\geq 0,b \geq 0, a^2-b\geq0 $ $$ \sqrt{a+\sqrt{a^2-b}} \pm ...
-3
votes
0answers
65 views

Question about ReplaceAll usage [closed]

I have the following code from the answer of the question (How to impose normalization condition (not initial condition) on DSolve or NDSolve?): ...
4
votes
2answers
116 views

Trying to get Arg[1 + I a] -> ArcTan[a]

Can Mathematica evaluate Arg[1+ I a] when a is a positive real in order to get ArcTan[a]? ...
0
votes
1answer
40 views

How to speed up ReplaceAll in Table?

I am writing a code which solve a list of equations and then create a Table with resulst of equation solving. In applications where I use this code, I create a bunch of equations and my computations ...
0
votes
1answer
43 views

EdgeRenderingFunction For 2 Vertices in a Loop

Assume there is a set of rules: set = {"A" -> "B", "B" -> "A", "B" -> "C", "C" -> "D", "D" -> "A", "C" -> "C"}; which we want to graph using ...
1
vote
1answer
32 views

Replacing Logic operator List and generate combination of variables

so I'm trying to do the following starting from a list of inequalities: ...
0
votes
0answers
95 views

A faster way to replace variables than ReplaceAll

I noticed that for large matrix, the rule /. is very slow. In the example below, the combination of memorization and the replacement "/.sol[n-1]" inside the definition of sol[n] turns the code ...
0
votes
1answer
65 views

Variable change

If I have the following Hamiltonian: ...
0
votes
1answer
38 views

Use of Replace function [closed]

I would like to replace in an expression two functions x[t] and D[x[t],t] by two variables x ...
1
vote
2answers
84 views

How to select elements from a list by condition?

Considering I have a list: F = {f1, f2, f3, f4} I want to perform exponent on the list F = Power[#, 2]& /@ F Now I ...
0
votes
2answers
32 views

ReplaceAll with serveral variables. get all combinations

How can achieve something like this? a * b /. {a -> {1, 2, 3}, b -> {10, 100}} I want {10,100,20,200,30,300} or ...
9
votes
1answer
245 views

How can I replace the Greek symbols in an expression with their plain text names?

Suppose I have an expression with Greek symbols in it. How would I convert that expression to another expression where the Greek symbols have been replaces with their names in plain text? I've ...
1
vote
1answer
42 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
66 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
182 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
96 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
31 views

Creating a lazy evaluator of th 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 would that be of help?
5
votes
2answers
79 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
41 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
47 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
111 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
56 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
74 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
59 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
297 views

Long list of similar rules

Given the following: ...
10
votes
5answers
330 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
51 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
52 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
83 views

Why does ToRules return a Sequence?

Why does ToRules return a Sequence expression? Why doesn't it return directly what ...
1
vote
2answers
154 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
125 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
39 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
62 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
112 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
166 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
171 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
40 views

Substitution breaking the scope

A novice's problem, perhaps: it seems that /. substitution does weird things to the scope. ...
2
votes
1answer
69 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
258 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
55 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
109 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
39 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 ...