Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [replacement]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
54 views

Simplifying polynomial in one variable by substitution

I want to simplify a polynomial in variable $x$ with integer coefficients by substitution $x\to{x}/d$ so that the coefficients become smallest possible integers. Input: ...
2
votes
1answer
28 views

ReplaceRepeated multi-part pattern

This workaround does what I'd like to have happen: ...
0
votes
0answers
32 views

Delayed Rule right-hand-side mis-evaluation

Outline I am trying to create a rule that will give me a minus sign if the number of times A is applied on X is odd where A is some οperator and X a random quantity. Some of the configurations of ...
1
vote
1answer
38 views

Filter out terms that include any combination of F[X] and G[-X]

I have the following problem which is closely linked to a previous question I asked some time ago (Replacement rule for terms that are separated by operators?). In this specific instance, suppose I ...
0
votes
0answers
30 views

Rule Replacement Fails with Embedded Conditional

I was using a rule replacement that creates a matrix. At one rule, I added a conditional to return one vector and then added that (after the conditional and within the same replacement) to another. ...
1
vote
1answer
32 views

Replace expressions

Let's consider the following example ...
1
vote
0answers
34 views

The replacement function is an integral and the double integral yields a different answer than the normal double integral

I am fairly new to Mathematica. I have a quick inquiry. The code is simple and just 3 lines. Trying to do a replacement rule as follows ...
6
votes
1answer
84 views

ReplaceList Except Alternatives bug

Bug introduced in 11.3 or earlier and persisting through 12.0 or later [CASE:4352435] and [CASE:4354378] In Mathematica 11.3 and 12.0, ...
0
votes
1answer
29 views

Suppress arguments in output for pretty print [closed]

I would like to define a rule that suppress any arguments of a function for visibility. I tried: rule = f_[x__] -> f While this works well with individual ...
2
votes
1answer
55 views

Handling a list of variable assignments to be used with `With` [duplicate]

Is there a way to use With as follows? variables := {a = 2, b = 3}; With[variables, a^b] Desired output ...
0
votes
0answers
35 views

making replacements when patterns don't match exactly

I want to simplified some mathematical expressions, and they are similar to ...
1
vote
1answer
46 views

TagSetDelayed for spotting zero derivatives

I am trying to implement my own differential operator, d[arg_, var_], that computes the derivative of arg w.r.t. ...
0
votes
0answers
31 views

Tracing & Modifying a Function (Replace All) [duplicate]

For the function: f[x_Plus] := Apply[Times, x] f[a + b + c] Out[]= abc This is clear, as the Times is applied to the list with Plus head in f. However, when ...
1
vote
2answers
35 views

Manipulation replacements rules from Solve [closed]

Assume the call to the routine Solve[eqn==0,{x1,x2}] returns: {{x1->a1,x2->a2},{x1->b1,x2->b2}} I would like to ...
0
votes
0answers
31 views

Replacing in FeynCalc

I started to take the trace of some terms in FeynCalc package. I encountered a problem in replacing. Here is my problem: ...
3
votes
3answers
59 views

Assign Values from Array to Array [duplicate]

I am trying to simply do the following cVec = {a,b,c,d} From another expression, I obtain another vector, say, ...
0
votes
0answers
25 views

Variable subscript substitution - easy way?

I have a Mathematica expression with about 900 terms, that looks roughly like this: $X_{1,1} + Y_{1,2} + Z_{1,3} + XX_{1,4} + XY_{1,5} + ... $ Is it possible to perform a fast method to copy this ...
0
votes
0answers
35 views

Implementing a generic product rule

I'd like to implement a generic rule for expanding differential forms by the product rule. For instance, I'd like to transform the following PDE: $\phi \frac{\partial \phi}{\partial t} = \phi \nabla^...
3
votes
1answer
35 views

Prevent argument substitution in held expression when injecting into unevaluated code

I want to write a custom sow/reap pair to wrap any piece of code in sow[code] and call reap ...
0
votes
0answers
47 views

Derivative operator w.r.t a vector index and change of variables

Description and code lines: Define a scalar product to represent $A_i·A_j$ , $A_i ·B_j$ and $B_i ·B_j$, such that $A_i · A_i$ = 0. This is implemented in the following way: ...
1
vote
0answers
35 views

ReplaceAll on a Plot - Can you reproduce this error?

The weird thing is that it occurs only the first time I evaluate it! The same happens with Plot but not with Graphics. I can ...
0
votes
1answer
24 views

Plot with substitution of domain values before evaluation of function

I have a function of two variables $f(x,y)$. I find the maximum value of $f(x_0,y)$ by first substituting the value of $x=x_0$ and then maximizing in the range $0<y<1$. My question is: How to <...
4
votes
5answers
307 views

Applying rules on rules

So I tried taking a total derivative, with constants, but then the ouput had Dt[ ..., Constants -> ...] as an output. I tried to use a rule to remove it from tha output, but it did not work. See below....
0
votes
1answer
32 views

Retrieve the independent variables from a linear replacement list

Is there a good way to convert a linear replacement list into a list of the independent variables? For example, I would like to take {n1->n3+n4, n2->n3+2n4} and get {n3,n4}, the variables that n1 and ...
1
vote
1answer
54 views

I want $(t+x)^n$ to be replaced with $f(n,x)$ throughout expression, what should I do?

I want $(t+x)^n$ to be replaced with some function $f(n,x)$ throughout any expression, what should I do?
0
votes
0answers
48 views

Why is a certain replacement rule not succeeding?

I've been trying to apply the replacement rule /. Sqrt[-(-1 + 2 l3) (2 - l3 + 2 Sqrt[1 - l3 - 2 l3^2])] -> (1 - 2 l3 + Sqrt[1 - l3 - 2 l3^2]) on certain ...
3
votes
2answers
73 views

ReplaceRepeated problem

I am driving myself nuts. I have a list of data consisting of team number, team names and results from a tournamet (the results are called imps, vp, and cum). {teamNumber1, teamName1, teamNumber2, ...
0
votes
1answer
57 views

What's wrong with this input? [closed]

Can anybody with all my gratitude tell what's wrong with the input in the attached file? why Mathematica doesn't return the answer? Thanks in advanceHere is the Attached file
0
votes
0answers
37 views

ReplaceAll and complex numbers

I am currently trying to "canonicalize" my expressions with complex numbers. One thing I want to do is to replace expressions such as x x* (where * denotes complex ...
1
vote
1answer
61 views

How to get ReplaceAll to happen before function call

I have a problem I am attempting to solve with NMinimize. I have a scoring function, which will give me a final score. The problem has many variables, so instead of having them as parameters, they ...
7
votes
3answers
138 views

How to replace $x$ and $x^2$ with different value?

I have an expression now expr = x + x^2 what I want to do is to replace $x$ with $k\times p$ , and $x^2$ with $[k\times p + k\times(k - 1)\times p^2]$. The ...
2
votes
2answers
54 views

Hiding variable names in function definitions

I have a problem where Table and similar functions' substitution variable name can conflict with names in my function it self. Here's a minimal example ...
0
votes
1answer
64 views

Replace does not substitute in function

I have the following expression with functions ...
0
votes
0answers
32 views

ReplaceAll in a vector

I have the following code: ...
1
vote
1answer
72 views

Variable substitution like usual maths

So... I'm trying to get some simplifications on equations using own defined variables, but the tries I gave didn't result on what I wanted. The problem: I have 2 variables defined as: ...
2
votes
1answer
59 views

Replacement patterns

I wanted to ask if there was a way to quickly replace multiples of the same thing, instead of writing it so many times, for example: ...
2
votes
1answer
39 views

Replace sub-expressions matching a pattern unless located under specific heads

Suppose I have some rule, e.g. Re[x_] :> (x + Conjugate[x])/2. I want to apply it to all matching sub-expressions in some expression, excluding any sub-...
0
votes
0answers
25 views

Contracting the KroneckerDelta should bring it back

I would like to define a function $$V[\phi] = \sum_{1\leq i,j,k,l\leq dim}\lambda_{ijkl} \phi_i\phi_j\phi_k\phi_l, $$ with $\lambda_{ijkl}$ defined by contractions of the type $\delta_{ij}\delta_{kl}$...
2
votes
2answers
118 views

Add a suffix to the end of every number in a string [duplicate]

I have some polynomial e.g. $2x^2 + 3x + 4$ In Mathematica I can define this, and convert it to a string simply enough ...
4
votes
3answers
66 views

All possible replacements of an expression, considering each term separately

Say I have an expression: f[a, f[a, b]] I would like to replace each a with either x or <...
2
votes
1answer
52 views

Replacement Help, Patterns, Rules?

I have been trying to replace multiples of one thing in an expression, for example: (E^(4 s - 2 z) + E^(8 s - 4 z) + E^(12 s - 6 z)) //. {(4 s - 2 z) -> meow} However, I end up with the ...
3
votes
3answers
77 views

Identify complex expression and replace

I'm having trouble finding a way (if there is) to analyse an expression, identify a complex pattern in it and then replace it with another thing. I think it will be easier to explain my problem with ...
1
vote
1answer
40 views

Drop-down menu to globally change definition of a function `t[x]`?

If have a function t[x_] which is used extensively in a long notebook, but which has a variety of definitions, and which is used in a variety of ways. I'm looking ...
2
votes
3answers
86 views

Replacement rule with all possible permutations

I have a list with expressions like {1,3,5,a,c,b,3,d} I want to generate all outputs with permutations of {a,b,c,d}, so for example a rule like ...
0
votes
1answer
58 views

defining rule for derivative on arbitrary function

Is there a way in Mathematica for defining rules for derivatives on undefined functions? For example, I would like to define a rule such that for any function $f(x,y)$, when I take the $x$-derivative ...
3
votes
1answer
36 views

Replacement rules for partial derivatives

I have a system of PDEs, and it contains terms of the form $A^{(n,m)}(x,t)$, which is shorthand for $$\frac{\partial^n}{\partial x^n}\frac{\partial^m}{\partial t^m}A(x,t),$$ (ie ...
0
votes
0answers
53 views

How to use replace for only one term in a long expression in Mathematica?

I am doing some Cauchy integration and in some intermediate steps I have something that looks like that: (..many_terms...+I*\epsilon(k1-p1))/k1 where ...
2
votes
1answer
44 views

How to construct multible rules for replacement at once?

After generating a list for which I used //N, I want to replace some values with the exact one. What I had in mind is to generate something like: ...
7
votes
1answer
217 views

A “Replace” sort problem. Basic but haunts me

Here's my problem when doing my codes. I need an output similar to {{p->1},{p->2},{p->3},{p->4}},where p is a ...