Questions tagged [replacement]
The replacement tag has no usage guidance.
1,666
questions
4
votes
5
answers
211
views
Transform a list of rules into a list of function definitions
I have a list of rules obtained by solving a system of equations, e.g.
{f[x] -> a + 3 h[x], g[x] -> 2 a + c + 6 h[x]}.
I wish to convert this list of rules ...
0
votes
0
answers
34
views
How to apply dependent rules in a complex expression?
I am working with a complex expression, $L_0$, which I need to simplify iteratively using a series of dependent replacement rules. Here's the structured approach I am trying to implement:
Start with ...
1
vote
0
answers
53
views
How to Prevent Short Name Character from Auto Converting [duplicate]
The following code creates the short name character aliasdelimiter, then selects it and reads and tests it.
...
0
votes
1
answer
70
views
Transforming an expression into function
I want to transform the expression a = 2 x + 1 into f=Exp[a], z=Log[x], and express the ...
0
votes
0
answers
37
views
Can I remove a rule from a built-in function?
Can I remove the rule DiracDelta[n x]==DiracDelta[x]/n when n is numeric from the definition of ...
0
votes
1
answer
28
views
How to put prime before value during a substitution?
Here is a sample Mathematica code:
...
1
vote
0
answers
85
views
Perturbation theory. Get xAct tensor component. Substitution for xAct tensors
I work with perturbations in FLRW metric with arbitary curvature. I'm following Weinberg's book.
In modified gravitation theory there is additional tensor S and I need to find it's perturbation in the ...
1
vote
1
answer
57
views
How to achieve automatic nesting of pattern application
I want to apply the following rules:
...
4
votes
0
answers
138
views
Limit of a PolyLog does not work [bug]
This is an issue I am having with Mathematica version 13.1.0.0. I tried the following code, but it does not work as expected:
...
0
votes
1
answer
35
views
Cross derivative rules
I am trying to generalize the condition
Derivative[1, 0][ℒp][t, ϕ] -> Derivative[0, 1][ℒp][t, ϕ]/l
for $\ell$ a constant, through the following rule
...
3
votes
2
answers
176
views
Modify Rules with new patterns
My Rules always have one instance of TR on the LHS, and several on the RHS, like this
TR[2] -> TR[5] + TR[h, g]
I want to generalize them by adding optional ...
0
votes
1
answer
58
views
Weird behavior when using Parallelize with LieART
I want to perform computation with the LieART package and Parallelize some long computation. But I run into the following ...
1
vote
0
answers
37
views
Replacing an expression with pre-defined function
I am asking Mathematica to do a long calculation with functions I am defining at the beginning of the script. Because the resulting expressions are long, I want to replace them with the functions I ...
3
votes
1
answer
98
views
Sort the arguments of a function using replace
I want to sort the arguments of a function f while multiplying with the signature of the permutation, i.e. f is totally antisymmetric function. My idea was something like
...
2
votes
2
answers
101
views
Why does Replace function not work the first time I try it?
Please explain why in the following mathematica code, the cos term was not replaced in the first try, but got replaced in the second try?
...
2
votes
4
answers
297
views
Ignore higher order terms in an expression
I am trying to ignore terms that are higher order (third or more) in an expression. For example, for the input function:
$$f_{in}= \alpha\beta + \alpha^2 + \beta^2 + \alpha\beta^2/2 +
\alpha^2 \beta $...
0
votes
0
answers
52
views
Mathematica solve with conditions on constants differ from replace
I have been trying to solve some complicated linear equations in Mathematica, with variables $y_{i}$, and constants $a, f_{j}$ where $0\leq j\leq10$. I only care about the case where $\sum_{i=1}^{10}...
4
votes
1
answer
127
views
How to write a rule that matches alternatives but return one of them always?
Consider the following rule:
$rule={"Period ID"|p:"Period":>p};
This rule will match ...
3
votes
1
answer
107
views
How to `Collect` where `var` is one expression?
Edit:
Clear["Global`*"];
expr1 = (a + c - b + 1)^3 + (-b + a + c + 2)^4 // Expand
For test case expr1, this is the ...
0
votes
0
answers
38
views
Replacement not working as desired [duplicate]
The following replacement works fine
ReplaceAll[1/F[x],F[x]->y]
(*1/y*)
but this doesn't
...
6
votes
4
answers
346
views
Transform sequence into ragged list
I want to transform
seq = {x, 1, 2, x, 3, x, 4, 5, y, y, 67, y};
into
{1, 2, {3, {4, 5}}, 67}
The only way I found is rather ...
0
votes
1
answer
64
views
Why does Mathematica fail to substitute some terms in an expression but not others?
I have an expression of the form:
$A-\frac{e^{-t/t_1} \; a \; b}{c \; t_1} \; U_1 - \frac{e^{-t/t_2} \; a \; d}{c \; t_2} \; U_2 -\frac{e^{-t/t_2} \; a \; e}{c \; t_2} \; U_2 - \frac{e^{-t/t_3} \; a \;...
4
votes
4
answers
300
views
Replacing string values with one of the sequence-functions
Given the following list of rules (which might contain duplicate
keys), I want to replace the string values with the first preceding numerical value.
...
1
vote
0
answers
43
views
Why list of replacement does not work in the following example? [closed]
I want to replace a long list but in the following format, but it does not work:
(Aa + Bb + Cc) /. {{Aa, Bb, Cc} -> {x + 2, y + 2, z + 2}}
1
vote
0
answers
59
views
Replacement rule runs for a long time [duplicate]
I have a simple expression that reads (some expression in b) q^(8/3):
...
1
vote
1
answer
41
views
How to do this replacement? Match the variable, but not the function [duplicate]
I have the following expression:
$$\frac{\left(-2 \lambda \lambda [\theta ]+\lambda [\theta ]^2+\lambda ^2+\lambda \right) \lambda '[\theta ]^2}{\lambda [\theta ]^2}$$
I want to replace every ...
1
vote
0
answers
40
views
Difference in pattern matching between Cases and ReplaceAll (Already searching at all levels and heads)
Why is there a difference between the pattern matching between Cases and ReplaceAll in the following:
...
1
vote
0
answers
60
views
Random replacement in array
In the spirit of this interesting article of Stephen Wolfram I also decided to study some issues related to mutations.
I’m working with simple {0,1} arrays and I’ve ...
1
vote
1
answer
82
views
How to replace C[1] in solutions of trigonometric equations into k?
This is my code
Table[{HoldForm[Cos[3 x + 2 Pi/5]] == Sqrt[i]/2,
Reduce[Sin[2 x] == Sqrt[i]/2, x, Reals]}, {i, 0, 4}]
How can I replace C1 to ...
3
votes
2
answers
103
views
Multiple replacements in a long expression
Why does the replace /. not work on the second argument in the following expression:
...
0
votes
0
answers
31
views
Time Complexity of Multiway System
I was wondering what the time complexity for the implementation of a Multiway System would be. For reference, we can implement a MultiwaySystem using the Resource Function
...
2
votes
1
answer
81
views
Generate variables in multiple integral
I want to do a multiple integrate with n variables. When I change the value of n, I do not want to rewrite the variables in the integral manually like here:
...
2
votes
1
answer
77
views
Removing `circular rules'
Say that I have a huge list (>300.000 elements) of polynomial equations and I want to simplify these by
looking for some simple equations of the form x[i] == _ ...
5
votes
3
answers
380
views
Reversing the order of function arguments by a replacement rule
I am facing an issue when I try to reverse the arguments of a function in a replacement rule.
Let me give an example :
...
1
vote
0
answers
39
views
Performing difference in extracting coefficients from a sum
I have an expression
...
2
votes
2
answers
61
views
Difference between variables and expressions for ReplaceAll
I'm doing some GR calculations with xAct. I get an expression that is heavy. In order to simplify the results, I try to use the function ReplaceAll in simple cases. ...
4
votes
5
answers
217
views
How to make expression-dependent replacements?
Consider as a toy example that I want a replacement
which acts on
{x,1,2,3}
by replacing $x$ with the length of the list itself. In this example this should output
...
9
votes
5
answers
382
views
Reconstruct list from its PositionIndex
Is there a more elegant or shorter way of reconstructing a list from its PositionIndex?
The following I regard quite cumbersome:
...
11
votes
5
answers
522
views
Isomorphic lists
Is there a function that outputs True if lists are isomorphic (there exists a rule that changes the first list into the second one and inverse of the rule changes ...
2
votes
0
answers
123
views
How to effectively substitute variables in xAct?
I am trying to find the gauge field equation by varying the Born-Infeld Action with the help of xact package. I use the following ...
1
vote
1
answer
57
views
Set the value of a parameter in a Series expression [closed]
I have a lengthy expression resulting from a series expansion in some dummy variable $e$ which I now wish to set equal to 1. However, when I try to use a ReplaceAll ...
7
votes
3
answers
270
views
Replace number in string with ? and /;
I am trying to make the following:
StringReplace[{"A4", "A#3"}, {"A" ~~ x_ -> "B" ~~ x}]
This should replace ...
3
votes
1
answer
43
views
How to Replace EdgeLabel in a Graph [duplicate]
I am working with Graphs in which I want to define a Graph with Symbols or Strings as EdgeLabels, and later replace these with functions of the symbols with symbols then replaced with numerical values....
1
vote
1
answer
64
views
Rules Being Ignored by Mathematica
Can someone explain to me why Mathematica is ignoring the replacement rules in the following code:
...
6
votes
1
answer
109
views
Substitute solution into ODE to verify it holds
I am struggling a lot to understand how to do the very basic exercise of substituting a solution into an ODE so see whether the solution is indeed valid. Consider the following ODE:
...
1
vote
2
answers
99
views
How do you remove parts of an element within a list? [closed]
I have a data set that is something like:
time={-2_ms, -1_ms, 0_ms, 1_ms, 2_ms};
How do I drop the _ms part such that its just a list of numbers?
9
votes
2
answers
509
views
What's the difference between With and ReplaceAll?
A wolfram Tutorial mentions that ReplaceAll and With are similar:
The way ...
2
votes
1
answer
148
views
How to correctly replace scalars with matrices?
How can a scalar be replaced with a matrix to perform operations on the matrix, not its elements?
For example,
...
2
votes
1
answer
79
views
Why can't I assign upvalues to NonCommutativeMultiply?
I'm trying to define a non-commutative product with respect to which, certain quantities (e.g. numbers, and some other quantities defined in my code) behave as "scalars" and can be pulled ...
1
vote
1
answer
41
views
How to check a group of solutions of partial differential equations?
There is the partial differential equations,
$$
\left.\left\{\begin{array}{c}u_t-3qu^2u_x+\frac{3}{2}q(uv)_x-\frac{1}{4}qu_{xxx}=0,\\v_t+\frac{3}{2}qvv_x-3q(u^2v)_x+3qu_xu_{xx}+\frac{3}{2}quu_{xxx}-\...