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
48 views

Issue with replacement rules screwing up a matrix [on hold]

I am pretty new to using Mathematica as more than a calculator. Essentially my problem is that I am trying to calculate a quantity vector quantity $x=x_0 - A^{-1}F(x_0)$ where $x_0$ is a 3-entry ...
4
votes
1answer
75 views

Why a part of this expression, similar to another, is left unchanged?

An expression has one of its part replaceable and one, strictly similar, that isn't. Please, can you point at the difference ? I can't pinpoint the complication ... The FullForm of ...
12
votes
2answers
259 views

why MatchQ is fast and Replace slow?

Consider a large expression, say a polynomial with 25 terms expr=Product[Unique["a"],{i,1,25}]; to which you apply the following replacement rule: ...
0
votes
1answer
35 views

Filter pattern from a list

I have group elements, that I'd like to condense down according to group rules. Take the modular group. This has generators $S,T$ that satisfy the groups relations $S^2 = I, (ST)^3 = I$. So given a ...
1
vote
2answers
71 views

Symbolic derivatives and substitution [duplicate]

I have troubles substituting functions when I have symbolic derivatives and I need to substitute more symbolic derivatives in my expression. Take for example ...
6
votes
1answer
103 views

Using two rules for the same variable

I am a newbie in the field so please not angry. I am reading the tutorial below and having a problem. Link: How to Create and Use Rules From the link: If you give two rules for the same ...
2
votes
2answers
55 views

Rewriting the set of equations in terms of new variables, using replacement rules when the expression contains partial derivatives [duplicate]

I am working with cumbersome equations, that contain a lot of terms. Here I will consider simple example: ...
3
votes
1answer
43 views

Replacing elements of a matrix

I'm trying to write a program that takes a given matrix $A$ of 1's and 0's and flips a designated amount of 1's to -1's. ...
3
votes
2answers
65 views

Assigning multiple solutions different replacement names

Let's say we are solving a homogeneous differential equation, such as $$y^{\prime\prime} + a y^{\prime} + b y = 0$$ with characteristic equation $$s^2 + a s+ b = 0.$$ Using the ...
6
votes
2answers
89 views

Condition and RuleDelayed

On this site I found, for example here, some very interesting questions and answers on the use of delayed rules with conditions. I would very much like to understand these answers, but so far I failed ...
8
votes
2answers
115 views

Why is a longer pattern matched rather than a short pattern?

I was reading the Mathematica V5 Book and am a bit perplexed on the behavior of a particular pattern matching example where it seems to be choosing a longer pattern rather than a shorter pattern. The ...
0
votes
0answers
25 views

Simplifying self-reciprocal rational function [duplicate]

I have trouble transforming self-reciprocal rational functions in one variable like ...
5
votes
3answers
73 views

How can I pass replacement rules to a package-defined function and have it understand their context?

I am writing a package where I would like to be able to pass replacement rules to a function inside the package and have the function manipulate its symbols using those replacement rules. However, I'm ...
1
vote
1answer
58 views

how to replace one calaculation result to another one in a loop?

I am doing the calculation in a loop. I gain a digit for rzin in ...
8
votes
0answers
139 views
1
vote
1answer
35 views

How to substitude a^n->D[u[t,x],{x,n}] for n=0,1,2,

I have expression which have terms a, a^2, a^3, ..., How can i replace a^n -> D[u[t,x],{x,n}] for n=0,1,2,....
2
votes
0answers
28 views
1
vote
3answers
115 views

Symbolic differentiation [closed]

I have two symbolic differential equations and I want to used them in another equation as follows: ...
14
votes
3answers
214 views

ReplaceAll with Associations instead of Rules

I have just noticed that x /. <|x -> 123|> evaluates to 123 In other words, the association seems to behave as a ...
3
votes
0answers
81 views
1
vote
1answer
28 views

ReleaseHold NIntegrate after Replace variable

I would like to calculate the sum of square of two integral(Ex and Ey). I first hold this two integral because two variables(tx, ty) are not specified.Then, I replace tx,ty and releasehold ...
1
vote
1answer
51 views

How to force a replacement in an order that I want?

This is a follow-up to this question. I have a big sum, with lots of terms of the form ...
0
votes
0answers
56 views

How do I use Replace All? [duplicate]

I have an expression: a + b 2^(1/2) + (c + d 2^(1/2))*I I want to replace each occurrence of 2^(1/2) with ...
2
votes
1answer
69 views

Replacement producing unexpected result

If I use a replacement rule like ...
3
votes
1answer
30 views

TensorContract with KroneckerProduct instead of ordinary Times

Is it possible somehow to contract two tensors, say A={{a1,a2,a3},{a4,a5,a6}} and B={b1,b2,b3}, where the elements ...
9
votes
1answer
168 views

What kind of patterns in a list of rules would benefit from being Dispatched?

I have a long list of rules for manipulating expressions. They are of the form: ...
2
votes
1answer
117 views

Function not returning number [closed]

I am quite new to Mathematica and I guess this question is really basic, but I can't figure it out myself. I'm making a simple notebook that plots a Hamiltonian function, a plane of constant energy, ...
6
votes
4answers
592 views

How to replace a space by a comma

in this expression = "{1 2 3 4 5 6 7 8}", I want to replace each space by a comma , to get ...
0
votes
0answers
46 views

Can't operate on vector within a list of rules

I'm trying to set up a list of rules which includes the following: ...
0
votes
2answers
41 views

Unevaluated derivatives of known functions after replacement

I want to make the following replacement work correctly: Array[(2 D[xM[[#1]][t], t] * D[xM[[#2]][t], t]) &, {3, 3}] /. {xM -> {Sin[ω t], Cos[ω t], 0}} ...
0
votes
0answers
35 views

Replace function and its derivatives [duplicate]

When I have a complicated expression that depends on some variable, say, $f$, the following usually works ok: Expression ./ { f-> x^2 } But if $f$ is a ...
5
votes
3answers
772 views

Replacing Tan[x] with Sin[x]/Cos[x]

Why doesn't this work? (1 - Tan[x])/(Sin[x] - Cos[x]) /. Tan[x] -> Sin[x]/Cos[x] I get back: ...
9
votes
1answer
68 views

Replace and Association

I'm surprised that I can't find this question already, so perhaps I'm missing something obvious. I would like to take a list of associations and remove any with value ...
0
votes
1answer
37 views

Solving a trigonometric equation for all $x$ using constant coefficients

I want to find the coefficients $a$, $b$, $c$, etc. that make an equation like $a+bx=x$ true for all $x$, but for trigonometric functions of $x$. For example ...
3
votes
2answers
52 views

Composition of rules: a->b + b->c = a->c

I am trying to compose two rules to form a new one: {a -> b, b -> d} and {b -> c} should become ...
3
votes
1answer
60 views

Convert an expression to use a specific analytic form

I have an expression that evaluates to an expression containing multiple ExpIntegralEi expressions. However, I would prefer that Mathematica use ...
1
vote
1answer
37 views

Pattern matching for product of two terms fails if one factor is 1

I have a long set of replacement rules that I utilize to solve some longish integrals over trigonometric functions. Just look at this snippet (from this answer): ...
4
votes
2answers
130 views

ReplaceRepeated as a Looping construct?

There are a lot of discussions about looping constructs (notable example here). Wolfram language guides, as usually, contain most relevant links. Looping constructs guide has the following part on ...
0
votes
0answers
39 views

Replacing parts of a complicated expression with shorthand symbols

I have a list, each element of which contains a different complicated expression. Here is a simplified example of the first three entries of the list, displayed one above the other: $\frac{Ey \ \mu \ ...
2
votes
1answer
74 views

How to do literal replacement to format expression?

I can do a replacement of an expression with some variables to alternate symbols: ...
0
votes
1answer
50 views

Misunderstanding of Replace code

I am looking for the right way to replace $\delta \, \, \text{by} \, \, 0.05 \, \, \, \beta \, \, \, \text{by} \, \, \, 1.77 \, \, \, \text{and} \, \, \, n \, \, \, \text{by} \, \, \, 12$ in this ...
1
vote
2answers
114 views

Apply tranformation to particular list elements

I have a list with elements {a -> -1, b -> -2, c -> -3} If I now wanted to apply a tranformation to b and ...
3
votes
1answer
64 views

Is the replacement operator associative?

In mathematics, a given operation $\circ$ is said to be associative if there is equality $$(f\circ g)\circ h=f\circ(g\circ h)$$ for any $f$, $g$ and $h$. Intuitively, this means ...
5
votes
5answers
419 views

Random character change in a random place

I would like to ask for help in a Random Replace of character. For example: ORANGE and change 1 character randomly (random place and random character from ORANGE) in it into any character of ORANGE, ...
2
votes
1answer
50 views

Replacing elements in a list if contains X (string)

I want to replace T1 with T2 if the list contains X (It's a string with something more) or else return unevaluated. Input:...
0
votes
2answers
36 views

How to replace a hole mathematical expression? [closed]

I have the following function: Input: f=-a n^2/v^2 +v/n I want to Replace v/n by v_new ...
0
votes
1answer
94 views

Getting mathematica to factor out constants and apply euler's identity to a table

I'm doing some quantum mechanics homework that I'm going to eventually generalize to higher spin states, so the solutions are going to need to be decently independent of the dimensions of the table ...
7
votes
3answers
168 views

A replacement question

I have: {{θ -> 0}, {θ -> (2 π)/ 3}, {θ -> π}, {θ -> (4 π)/3}} I would like to create a list of points $(\cos\theta,\sin\theta)$ using each of the ...
4
votes
2answers
64 views

Type error before replacement rule is applied

When I type a <> "0" /. {a -> "1"} I get the error ...
2
votes
2answers
138 views

Replacement rule not having desired effect

So I have this replacement rule that tends to work in most cases, except occasionally in cases like this: ...