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
2answers
42 views

Different behaviour of Map and Inner in replace rules

Why does x[{1, 2}] /. {x[l_] -> Map[func, l]} {1, 2} not behave as expected, while for example ...
0
votes
2answers
49 views

How can I match some parts of an expression?

Suppose I have an expression like Abs[x+I y]+Sin[Abs [c+ I (d+e)]], and I want to replace all expressions in the form of ...
1
vote
3answers
141 views

How to do a Check for every element in the list?

I know how to do a Check for the list in general: ...
2
votes
4answers
218 views

How to switch from array to string?

Considering we have an array: a = {2/3, 4/5, 9/7, 3/7, 1/7, 1/9}; How can I get this to be: "2/3 4/5 9/7 3/7 1/7 1/9" ...
1
vote
2answers
78 views
2
votes
3answers
120 views

How to delete a pattern from String?

Having a string like : "{Aaaa -> a, Bbbb- > b, Cccc -> , Ddddd -> c, Eeeee -> , Fffff -> e}" I want to delete the parts that contain ...
3
votes
1answer
103 views

How can I solve my easy system of equations?

I am new to Mathematica and am afraid this is a silly question. I have this very easy substitution, it has three equations on three unknowns {w1, l1, t1}. I want to ...
0
votes
1answer
44 views

How to manipulate string parts?

Let's consider I have following string: "{a-> POR, b-> D610, c-> 0, d-> \"300/7\", e -> \"1/400\"}" How can I run over and update anything that is ...
0
votes
3answers
80 views

How to iterate through a list of rules?

Let's consider I have a list of rules: {Aa -> 1/2, Av -> 2/5, Bx -> 3/7, Ce -> 4/9, ...} I want to find all keys that contain the letter "A" and ...
1
vote
1answer
32 views

Replace Coefficients of multivariate expressions by numbered constants

I have an expression which is a polynomial in Delta, xi and phi. The prefactors are huge ...
1
vote
1answer
74 views

Applying functions repeatedly on parts of complicated expressions

I am dealing with expressions like $$ \textrm{expr}=5D_{4,1}\langle12\rangle\langle23\rangle\big(-\langle15\rangle^2\langle24\rangle\langle34\rangle + ...
0
votes
1answer
23 views

How to apply substitution when expression contains powers of the quanity

An expression like: a = TrigToExp[ 3 + 4 Cos[u] + Cos[ 2 u]] produces a list of exponential factors: 3 + 2 E^(-I u) + 2 E^(I u) + 1/2 E^(-2 I u) + 1/2 E^(2 ...
7
votes
4answers
439 views

Strange answer from StringReplace

I have a list of strings and I would check if there is an empty string element, that's "", because I need to replace it with a "0". I try the following ...
1
vote
2answers
58 views

Problem with Replace function [closed]

I recently started using Mathematica. I'm not able to understand my mistake. I'm trying to implement the Frangi vesselness for the enanchement of vessels in biomedical images. I wrote these functions: ...
1
vote
0answers
40 views

Substitution does not work while substituting with a value from list

I am writing a program which iteratively solve and make substitution from a list. As I have shown in the code substitution works when I enter the value directly (Input 100). When I extract the same ...
7
votes
2answers
103 views

Why does ToRules return a Sequence?

Why does ToRules return a Sequence expression? Why doesn't it return directly what ...
3
votes
2answers
162 views

How to rewrite the rules in a list when they satisfy a given condition

I think the best way to state my problem is to illustrate it with an example. Assume I have the following toy-list of rules: ...
0
votes
2answers
60 views

For the same function, why does /. give a complex result?

I define a very simple function like this, g[k_] := 1. + 2 Sum[1/(1 + (2 n)^2), {n, 1, k}] g[50] give the result is: 1.70279. But g[n] /. n -> 50 give aother result: ...
12
votes
1answer
326 views

Is everything in Mathematica ultimately stored as a rule?

My current understanding about Mathematica is that everything, at the lowest level, ends up as replacement rules. First question: is this true? Second question: does Mathematica "gloss over" these ...
4
votes
3answers
178 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 ...
2
votes
1answer
140 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: ...
4
votes
2answers
144 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
35 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
83 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] ...
1
vote
2answers
131 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
48 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 ...
0
votes
1answer
58 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
53 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
52 views
0
votes
0answers
112 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
75 views

Variable change

If I have the following Hamiltonian: ...
0
votes
1answer
53 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 ...
0
votes
2answers
40 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
306 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
56 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 ...
6
votes
3answers
206 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
117 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: ...
3
votes
3answers
121 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
2answers
91 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
47 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 ...
6
votes
5answers
131 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
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 ...
11
votes
2answers
191 views

Dispatch displays rules incorrectly and evaluates when displaying

Bug introduced in 10.0.0 and fixed in 10.0.1 Consider this a = 3; disp = Dispatch[Unevaluated[{a -> 2}]] We see the rule ...
1
vote
2answers
70 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
91 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
67 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
315 views
0
votes
0answers
101 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 ...