# Tagged Questions

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

201 views

### What is the principle behind Dispatch?

I want to know what Dispatch actually does to rule the list. Why is it so fast? The documentation says Dispatch generates a dispatch table which uses hash ...
246 views

### replace is not happening for specific vector valued expression

Given x[t_] := {Subscript[x, 1][t], Subscript[x, 2][t]} following replace works fine x[t] /. x[t] -> 0 0 but following ...
94 views

### How do I avoid vector variables being treated as scalars in the course of replacements?

I often work with a mixture of symbolic and concrete values as I develop teaching materials. I introduce variables symbolically and then need to instantiate them to specific values while continuing ...
191 views

### How to define a rule to simplify the notation for derivatives of chain rule?

Suppose that $u(x,y)$ is a function, and $x=r \cos t$, $y= r \sin t$, then we can define a new function $v(r,t):=u(x,y)$ with $x,y$ replaced by the above equations. It is quite easy to compute $v$'s ...
52 views

### is there a way to speed up rule replace? [duplicate]

I am currently doing calculation with 7 parameters, each parameter set corresponding to a value. And I store the data in the format as a list of rule, like following ...
297 views

### How to split a list with respect to its nested sublists?

I have a problem with the following task: having some nested list list = {{k6},{k1,k3,k5},{k7}} I would like to replace all sublists by their permutations and ...
443 views

### Replace doesn't replace the denominator [duplicate]

I have the following expression in Mathematica -((E^(2 - 2 Sqrt[(x[1] - x[2])^2]) (x[1] - x[2]))/Sqrt[(x[1] - x[2])^2]) I want to replace anything of the ...
226 views

### Derivation after substitution not working

I have a code that will output an expression in form of a functions like this ...
111 views

### Operations on expressions within Hold [duplicate]

I want to convert {Hold[1 + 2], Hold[3 + 4], Hold[5*6]} into Hold[{1 + 2, 3 + 4, 5*6}]. I have tried ...
218 views

### How to return the rhs of a transformation rule from within Compile[]

I have defined the following function: ...
118 views

### Function generating a rule with a Patterns: e.g. toRule[ lhs, rhs] into lhs[x_] -> rhs [duplicate]

I want to create a rule as a function of z from a left and right hand side. My (non-working) code and usage is: ...
374 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 ...
201 views

### BezierCurve in EdgeShapeFunction fails when used on multiedges graph

I would like to create a network graph with curved edges. To do this, I wrote this function: ...
182 views

### How to plot complex values given by Solve

Update Solve[N[Table[BernoulliB[n, z], {n, 10, 10}] == 0]] ...
225 views

### Simplifying expression with patterns (Replace)

Q1: I need to simplify some algebraic expression, according to particular pattern, namely: \begin{equation*} x^m = \left\{ \begin{array}{ll} 1 & \text{if } m \text{ is even} \\ x & \text{if }...
179 views

### Rearrange graph

I have to rearrange graph described by j = {1 -> 2, 2 -> 3, 3 -> 1}; appling some function to all vertices on the right so rearrange[j] output should ...
91 views

### An equivalent in Mathematica [duplicate]

Let's say I have a $n$x$m$ matrix $M$ in Matlab and I want to substitute the elements of $M$ that exceed $15$ for $-1$. In Matlab I just write M(M>15)=-1 and ...
382 views

### How to replace every possible $A+B$ and $AB$ in expansion of $(A+B)^{10}-A^{10}-B^{10}$ with $x$ and $y$, respectively?

I would like to replace every possible $A+B$ and $AB$ in expansion of $(A+B)^{10}-A^{10}-B^{10}$ with $x$ and $y$, respectively. How to do it with the simplest code in Mathematica? For example, \...
79 views

### Manipulate that remembers its own input code and can show it by request

This question is a further question to my previous one. The solution for that question works well as long as the original input Manipulate code is still provided in ...
372 views

### How to replace subscript symbols

I have an expression with subscripted variables. I would like to replace all those terms with other symbols. For example, $P_1 + P_2^3 \rightarrow P1 + P2^3$ I used the following code but it doesn't ...
256 views

### Is there a way to simplify this replacement rule

I have a rather big expression which contains many sums of form q x + w y. I know that y is much smaller than ...
119 views

### Problem with List Dimension Outer Map [duplicate]

I am currently handling a big list which has the following dimension: {6, 3, 4, 2, 2, 1, 8} where the last number 8 represent a ...
144 views

### obtaining real roots of negative numbers in a long expression [duplicate]

I have a complicated symbolic expression which contains many terms like $(a/(a-2))^{1/m}$, where $a/(a-2)$ could be positive or negative after replacement. I only need the real root after ...
340 views

### Embedding StreamPlot in Graphics3D

I am trying to visualise the action of the infinitesimal generator of a Lie group on the solution of a 2-ODE system drawn in the 3D space (t,y1,y2): t is time and y1,y2 are the two dependent variables....
1k views

### StreamPlot using NDSolve gives error messages

StreamPlot[{x[0], x'[0]} /. NDSolve[{x''[t] == 1, x'[0] == v0, x[0] == x0}, {x, x'}, {t, 0, 1}], {x0, -2, 2}, {v0, -2, 2}] The above code gives me the errors ...
581 views

### How to debug error triggered by replacement rule?

The second line below produces the errors shown: ...
294 views

### Checking differential equation solution

I have this differential equation: eq=D[ψ[r],r]+A*ψ[r]-(B/(A*r))ψ[r]==0; And DSolve sucessfully solves it: ...
446 views

### Applying rules with functions to expressions with derivatives

I have a function that I want to see applied, potentially within a derivative. The use of delayed vs. non-delayed rules seems irrelevant. See the following: ...
449 views

### How to manipulate log arguments?

A common problem I have with Mathematica is needing to manipulate the arguments of logarithms. Typically, I need to take ratios of the log arguments Mathematica gives me by default. That's to say ...
150 views

### Replace inside a Held expression separate context

How do I replace content inside a Held expression without local values coming through? For example if you run the following code you get g[2] instead of ...
166 views

### Appending to sublists using “anchor” values

Say I have a set of lists that look like this: ...
484 views

### Can I ask Mathematica to replace the arguments of my functions with a replacement rule?

I have an equation that I evaluate at some point (let's say $x=1$) that have terms of the form f[1,y] D[g[1,y],{y,2}] Is there an easy way to replace [1,y] by [x,...
280 views

### Writing intelligent replacement rules for symbols

I am learning about quaternions right now, and I wanted to play around with some concepts I am learning. e.g. take rotation of a point about an axis with specified angle. ...
554 views

### How to speed up calculations with large number of replacement rules?

In my program I have an expression which looks like: ...
195 views

### Add Pattern to List Removing Duplicates

Lets say I have a list of patterns ...
56 views

### Best way to power series expand in multiple variables? [duplicate]

A power series expansion of a multivariate function can be performed with the Series command, which performs each expansion consecutively. The results can be a bit ...
82 views

### Scope of expression in a user-defined function

I have the following code: fbasic = A + R + Z*Z *Z*Z; f[A_, Z_, R_] := fbasic + R; f[0, 2, 3] The answer I am getting is ...
87 views

### Changing all link destinations in a notebook

I have a bunch of cells containing text and hyperlinks. i.e. of the form: ...
806 views

### How to properly project a Graphics object consisting of line primitives

My problem starts from attempts at depicting overlapping lines of different thickness, i.e. ...
119 views

### Replace inverse function

I'm solving an expression like so: Solve[u[x] == u[a] + u[b], x] Mathematica returns {{x->(u^(-1))[u[a]+u[b]]}} If I ...
146 views

### Simple rule appears not to work

I have the following simple code ...
131 views

### How can I avoid this ReplaceAll trap? [duplicate]

I am having some difficulties with the ReplaceAll function. When I write: {1, 2, 3, 4, 5} /. x_?OddQ -> x^2 I expect: <...
166 views

### Strange behavior when replacing variables by numerical values [duplicate]

I have a rather complicated function with parameters {a, b, c, d, e, f, k}, and I'd like to know its behavior as a function of k alone given other parameters, so I try the following code: ...
221 views

### Variable scope in nested NMaximize, NMaxValue

I'm trying to use NMaxValue inside other statements (FindRoot and NMinimize). Those statements should bind variable names, but I'm getting weird warnings which seem to indicate that the variables ...
233 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, ...
251 views

### Equating and solving equations that have been generated using table[]

I am in the process of trying to use Mathematica to find the coefficients of transmission and reflection for the wavefunction of a beam of particles tunnelling across any number of identical potential ...
151 views

### Generalization of a rule to N arguments

I am trying to apply a series expansion on a function x[t1,t2,...tn], with an expansion parameter a. For ...
187 views

### Shortening the syntax {var1, var2} /. # & /@ list

I noticed that I often turn out to have a list of substitutions in the form ...