# Questions tagged [replacement]

The tag has no usage guidance.

1,474 questions
Filter by
Sorted by
Tagged with
47 views

### Replacement question

I have this equation F2 + F4 - V1 + V3==0 I want it to be converted automatically via a replacement rule to ...
• 1,203
1 vote
211 views

### How to define replacement rule for Minkowski inner product

following question, I have an expression that consists of several Minkowski inner products between 2 four vectors written as in Mathematika: ...
• 21
29 views

### Get Complete form of a function from a nested definition [closed]

I have pretty basic question. Assume the Following system: F[x]:=2*x G[x]:=2*F[x] How do I substitute F[x] in ...
• 101
81 views

### Replacing symbolic variables inside of a compile

As the result of a symbolic integration, I have a very long array with symbolic variables u[i] which I would like to substitute for real number values. Moreover, I ...
• 43
29 views

• 221
91 views

### Replace repeated items differently

So I have a simple replacement rule of the following form: expr/.f[a_,b_]:> g[a,#]g[b,#]&@func[] i.e. I want to replace each function f[a,b] with two ...
• 651
76 views

### Transforming A Complicated Expression

I am trying to transform an expression according to these rules I've defined: $$L_1^m L_2^n L_3^p L_4^q \rightarrow \frac{m!n!p!q!}{(m+n+p+q+3)!}6V \\ \text{constant } k \neq 0 \rightarrow kV$$ Some ...
108 views

### Function with optional argument that depends on other argument

I'm trying to do a simple thing: I want the optional argument to depend on another argument, i.e. f[x_,y_:Subscript[m,x]] := x-y This should give: ...
• 651
265 views

### Simplify with given equality

Clear[id, kn, vt, vdd, vo]; id = kn*(vi - vt)^2/2; vo = vdd - id*rd; Solve[D[vo, vi] == -1, vi] Output: ...
• 143
145 views

### How to replace generic function with another one?

I have complicated expression in terms of derivatives of a multivariable function F[x,y,z] say ...
• 33
86 views

### Replacing a term according to a given criterion in an expression with non-commutative multiplication (for any sign and location)

There is the following expression: ...
• 1,881
1 vote
98 views

### Replace with non-commutative product

I'm trying to evaluate some scattering amplitudes terms in Mathematica using the spinor helicity formalism. For that, I need to turn products like $\epsilon_i\cdot k_j$ into spinor product which can ...
• 209
743 views

### When did this global rules change happen in Mathematica? Is this change documented?

In this Wolfram talk video titled "Professor Richard J. Gaylord's Wolfram Language Fundamentals Part Two" he shows at time 36:45 the following Where there are two definitions for ...
• 115k
54 views

### How to do the following symbolic substitution?

In the algorithm that I am trying to implement, I have the following symbolic substitution to be done $z^{-2 n} \rightarrow \frac{(i t)^{2 n-1}}{(2n-1)!}$. I tried to do the above as ...
• 155
75 views

### How to Programmatically Replace a Word in a Text Cell with a Button (for popup definitions)

I am attempting to create popup definitions for important words in my lecture notebooks. I plan to create a glossary containing a list of words and their definitions and then search through my lecture ...
• 4,825
37 views

### Finding variables that are arbitrary (undefined) functions of other variables with arbitrary names (such as n1, n2,n3)

I have expressions that could look like: $$n = n0 + n1[x,\tau_0, \tau_1]+n2[x,\tau_0, \tau_1]+n3[x,\tau_0, \tau_1]+ \dots$$ Where the $n_i$ are undefined functions of the variables listed inside ...
• 1
1 vote
54 views

### Replacement Rules and Function Definitions

I have this code currently: ...
• 221
63 views

...
• 121
1 vote
53 views

### How to get rid of "/." in my result, when I evaluate a term containing ReplaceAll?

In the previous code I defined Bchoice and pchoice In one line I defined ...
• 111
251 views

### Replace items of list except items that are member of another list

I want to replace all items in li1 that are not members of li2 with x. ...
• 3,735
32 views

• 2,366
1k views

### What is the fastest method to set the diagonals of a matrix to 1?

I am trying to replace the zeros along diagonal of a distance matrix to a list of constants. In this case, a diagonal of 1's. It appears that the LinearAlgebra ...
• 2,779
58 views

### Back-substitution

Suppose that we have an expression (expr in the code below) and replace a long term with a new parameter (K). For a simple example; ...
• 507
1 vote
56 views

### function/module to achive a replacement as follows

I want to shorten some long expressions by using some new parameters. So, I want to create a function/module to achive a (multiple) replacement as follows: ...
• 507
93 views

### Use rules on list elements one by one [closed]

I have two list list1 = {1, 1, 2, 4, 1, 1, 8, 7}; list2 = {a, b, c, d, e, f, g, h}; I want to build rule,...
• 885
1 vote
33 views

### Keep arguments of a function unevaluated after replacement rules

Consider an expression of type f[a,b]+a+b and a set of replacement rules sub={a->1,b->2} If I evaluate now the ...
• 131
1 vote
27 views

### Replace subexpression with variable in result from Laplace transform

I'd like to clean up the result I obtained from an inverse Laplace transform: First of all, I'd like to replace the square root expressions in the hyperbolic function arguments (part encircled in ...
• 11
1 vote
31 views

### Using ReplaceAll to simplify derivatives

I'm struggling trying to simplify the derivative of a function. I know that ReplaceAll works like that: What I want is to replace the function itself that should ...
1 vote
51 views

### How can I collect the sum of any number of gradients without using ReplaceRepeated[]?

Recently, I have run into the problem where I need to collect the the sum of any number of gradients. I have defined a function grad[] to represent the gradient, ...
• 443
38 views

### How to replace functions with their Fourier transform [duplicate]

I have a function \deltaG given by ...
452 views

### How to replace anti diagonal elements of a matrix

I want to assign new values to the anti-diagonal elements of a square matrix m with the values of its diagonal elements. For that, I want to make use of ...
• 319
125 views

### Replacing a trigonometric value

It looks like MMA cannot evaluate Tan[42°] but it can be written as (-Sqrt[6 - 2 Sqrt] + Sqrt[6 (5 + Sqrt)])/(2 Sqrt[7 - ...
• 1,273
44 views

### Timing Discontinuity with Replace[] Function

When constructing certain square matrices I noticed a sharp jump in the time required to build them. I've included code and a plot of time required to make the matrix vs dimensionality of the matrix. ...
• 187
581 views

### Replacing large numbers

Imagine I have the following list l = {{1,2,3},{4,10^(16),5}} How do I efficiently replace the large number by a number (zero, for example). I can't seem to do it ...
• 4,388
116 views

### Constructing a RootSum object changes existing internal syntax

Bug introduced in 9.0 or earlier and persisting through 13.0.1 or later I noticed that initially valid syntax becomes invalid within nested RootSum objects. ...
• 2,939
211 views

### How to use a rule such that it substitutes the value x and derivatives of x in the expression?

For example, I have gotten the value for a certain function H[t,r]: $H[t,r] \to -\frac{2r(K[t,r]+K^{(0,1)}[t,r]+2m+r+...)}{(2m-r)}$ I want to replace its value, ...
313 views

### Simple, fast re-defining a part of 2D list

A[[{2, 3, 5}]] = {97,98,99} changes 2,3,5-th elements of A to 97,98,99 respectively. Similary A[[{2, 3, 5}]] = 100 changes 2,3,...
• 3,221
28 views

### MatchQ returns False for a match for e1 ** e2 while matching both e1 and e2

I used a simple predicate realQ[x_] := MemberQ[{Real, Integer, Rational}, Head[x]]. With that predicate both ...
• 21
58 views

### Can substitution rules be used in function definitions?

Simple input like this f[x_]:=2x f has the predicted output of 4. However, this r={a->2x}; f[x_] := a/.r f Produces ...
• 187
58 views

### FindFit with Replace error

I am trying to fit my data, and I keep having error messages as below. Could anybody help me to solve this problem? The codes are written after the error messages. ...
75 views

### Terms of expressions with non-commutative multiplication that meet the given criteria

There is the following expression: expr=a^3**x**Transpose[x]**y+x+y**Transpose[y]**x**a^3+x**Transpose[y] It is necessary to apply the ...
• 1,881
425 views

### 'Mapping' the values of a list to variable

Suppose I have the variable expr1 = a[n] + b[n], and the list stencil={-1,0,1}. I want to make a function ...
• 957
41 views

### Replace Derivative[ i ][ f ][ t ] with f[ i, t]

Assume the PadeApproximant is carried over f[t0] * g[t0] with the order {1, 1}, that is <...
189 views

### Tropical Operation Conversions: Multiple Operations

I apologize if my syntax is bad. I looked around, but didn't see anything on this in the stack exchange. I would like to be able to transform a classical real-valued polynomial to a tropical ...
• 143