Tagged Questions

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

53 views

How can I match some parts of an expression?

Suppose I have an expression like Abs[x+I y]+Sin[Abs [c+ I (d+e)]], and I want to replace all expressions in the form of ...
149 views

How to do a Check for every element in the list?

I know how to do a Check for the list in general: ...
55 views

Different behaviour of Map and Inner in replace rules

Why does x[{1, 2}] /. {x[l_] -> Map[func, l]} {1, 2} not behave as expected, while for example ...
295 views

How to switch from array to string?

Considering we have an array: a = {2/3, 4/5, 9/7, 3/7, 1/7, 1/9}; How can I get this to be: "2/3 4/5 9/7 3/7 1/7 1/9" ...
475 views

How to switch from List of rules to Association? [duplicate]

Considering we have a list of rules: ...
405 views

How to delete Missing[“NotAvailable”] from list of rules? [duplicate]

Considering we have a list of rules: ...
140 views

How do I use ReplaceAll to replace strings of a specified form?

Why is "Xabcde" /. "X" ~~ e__ -> e "Xabcde" and not "abcde"
185 views

How to delete a pattern from String?

Having a string like : "{Aaaa -> a, Bbbb- > b, Cccc -> , Ddddd -> c, Eeeee -> , Fffff -> e}" I want to delete the parts that contain ...
49 views

How to manipulate string parts?

Let's consider I have following string: "{a-> POR, b-> D610, c-> 0, d-> \"300/7\", e -> \"1/400\"}" How can I run over and update anything that is ...
108 views

How can I solve my easy system of equations?

I am new to Mathematica and am afraid this is a silly question. I have this very easy substitution, it has three equations on three unknowns {w1, l1, t1}. I want to ...
96 views

How to iterate through a list of rules?

Let's consider I have a list of rules: {Aa -> 1/2, Av -> 2/5, Bx -> 3/7, Ce -> 4/9, ...} I want to find all keys that contain the letter "A" and ...
84 views

Replace Coefficients of multivariate expressions by numbered constants

I have an expression which is a polynomial in Delta, xi and phi. The prefactors are huge ...
31 views

How to apply substitution when expression contains powers of the quanity

An expression like: a = TrigToExp[ 3 + 4 Cos[u] + Cos[ 2 u]] produces a list of exponential factors: 3 + 2 E^(-I u) + 2 E^(I u) + 1/2 E^(-2 I u) + 1/2 E^(2 ...
114 views

195 views

Trying to get Arg[1 + I a] -> ArcTan[a]

Can Mathematica evaluate Arg[1+ I a] when a is a positive real in order to get ArcTan[a]? ...
77 views

How to speed up ReplaceAll in Table?

I am writing a code which solve a list of equations and then create a Table with resulst of equation solving. In applications where I use this code, I create a bunch of equations and my computations ...
67 views

EdgeRenderingFunction For 2 Vertices in a Loop

Assume there is a set of rules: set = {"A" -> "B", "B" -> "A", "B" -> "C", "C" -> "D", "D" -> "A", "C" -> "C"}; which we want to graph using <...
106 views

Replacing Logic operator List and generate combination of variables

so I'm trying to do the following starting from a list of inequalities: ...
181 views

A faster way to replace variables than ReplaceAll

I noticed that for large matrix, the rule /. is very slow. In the example below, the combination of memorization and the replacement "/.sol[n-1]" inside the definition of sol[n] turns the code ...
85 views

Variable change

If I have the following Hamiltonian: ...
76 views

Use of Replace function [closed]

I would like to replace in an expression two functions x[t] and D[x[t],t] by two variables x ...
281 views

How to select elements from a list by condition?

Considering I have a list: F = {f1, f2, f3, f4} I want to perform exponent on the list F = Power[#, 2]& /@ F Now I ...
46 views

ReplaceAll with serveral variables. get all combinations

How can achieve something like this? a * b /. {a -> {1, 2, 3}, b -> {10, 100}} I want {10,100,20,200,30,300} or ...
448 views

How can I replace the Greek symbols in an expression with their plain text names?

Suppose I have an expression with Greek symbols in it. How would I convert that expression to another expression where the Greek symbols have been replaces with their names in plain text? I've ...
100 views

Don't understand why my Taylor expansion results in a message and an unexpected result

Trying to do something simple: Taylor expand a generic function of t around a point t and substitute ...
156 views

Replace part of a matrix

I have to generate a ne numbers of matrices with 1 and 0 and then replace some elements. ...
283 views

Obtaining the number of iterations used in ReplaceRepeated

ReplaceRepeated has an option MaxIterations which indicates Mathematica is keeping track of the number of iterations. Is there ...
131 views

Why does an inert ReplaceAll modify this Dataset?

I cannot see any reason for this behavior besides a bug, but I've been wrong before so I put it before the community: ...
90 views

Creating a lazy evaluator of the lambda calculus

I have a sub project in my research to write a lazy evaluator of the lambda calculus. How should I approach this problem? I already have a implementation of the lambda calculus in another language. ...
105 views

Replace expression in series expansion [duplicate]

A test case: I'm trying to replace an expression inside a series expansion: Series[f[x],{x,x0,4}] ./ (x-x0)->h but it still returns ...
57 views

Replace bunch of numbers by letter

I want to do following: ArcTan[1/Sqrt[-1 + (4 Sqrt[2] x^2)/(5 xc^2)]] /.4 Sqrt[2]/5->a^2 I expect to have ...
84 views

Correct interpretation of /. (ReplaceAll)

Consider that you have a complicated expression, which is expensive in terms of running time and memory, and depends on some (initial) parameters. You want to test it for some simple values of the ...
184 views

Setting value of a rule

How do I change the value of a rule? For example, If I have a = x->3, how do I reset the value of x/.a to 4, so that ...
105 views

Why doesn't ToString work in ReplaceAll? [duplicate]

I'm trying to use ReplaceAll in a subscript. However, it doesn't seem to work as expected if I want to use the output the subscript in a ...
135 views

Limits and transformation rules

I can calculate this limit: Limit[(c^(1 - g) - 1)/(1 - g), g -> 1] and obtain the correct value: Log[c] but if I try ...
84 views

What to use instead of ReplaceAll to replace a parameter with a number before the evaluation of an integral?

This is probably very simple but I don't see the solution now. Let us say I have a variable e defined as e=n ReplaceAll can subsitute n with value 3 using ...
331 views

Long list of similar rules

Given the following: ...
409 views

For a given expression: if it appears, remove it, but if it is absent, add it

While reformatting Szabolcs's code from (42660) I noticed this interesting operation: ...
In delving into Ramanujan summation, I'm trying to get a hold of the relations of the form \sum_{n=0}^\infty f(n)=\dfrac{h\frac{d}{dx}}{{\mathrm{e}^{h\frac{d}{dx}}}-1}\int_{0}^\infty f(x)\,{\mathrm{...