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

learn more… | top users | synonyms (4)

0
votes
0answers
23 views

Mathematical symbol and name for Symbolic Replacement

(Originally from math.SE, but might be better here) I'm searching for a mathematical symbol, that describes the symbolic replacement done for instance in Mathematica: ...
11
votes
6answers
392 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: ...
1
vote
1answer
125 views

Making ReplaceAll faster

I have a list of functions ncalc that is calculated by ...
0
votes
1answer
104 views

Replacement of terms/Pattern matching involving products of derivatives of a function

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 ...
2
votes
1answer
43 views

Pattern matching & simple replacement

I have a question about an expression that I want to modify. Here is the expression: ...
8
votes
1answer
198 views

Why is `Block` significantly faster than `ReplaceAll` for inputting variable values

Given that the documentation for FindMinimum uses ReplaceAll for its various examples of what to do with the found solution to ...
10
votes
1answer
247 views

Is there a programmatic equivalent of Edit > Find…?

Most things that can be done via the front-end interface in Mathematica can also be accomplished by some function. Is that the case for find-and-replacing? That is, is there some code I could execute ...
16
votes
1answer
295 views

Why is ReplaceAll behaving like this?

I'm learning to use the ReplaceAll function and I found the behavior of which is quite confusing. For Sqrt[f[x, y]] /. f[___] -> u Mathematica returns ...
0
votes
1answer
68 views
1
vote
1answer
137 views

Why does it matter at what point I replace?

I need to find four orthogonal linear combinations of complicated functions, that vanish at four different points. I use (LK4 is defined below, but its shape should have nothing to do with my ...
10
votes
9answers
951 views

How can a power of 0 or 1 be replaced?

Consider this given example for ReplaceAll 1 + x^2 + x^4 /. x^p_ -> f[p] This returns ...
2
votes
1answer
49 views

Define (conditional) substitution rule for sum/difference of radicals

I want to tell Mathematica to simplify some expressions applying the following substitutions, conditioned on the fact that $a\geq 0,b \geq 0, a^2-b\geq0 $ $$ \sqrt{a+\sqrt{a^2-b}} \pm ...
1
vote
1answer
76 views

Why does ReplaceAll behave so oddly?

ReplaceAll can behave a bit oddly. Consider ...
14
votes
4answers
1k views

How to change element color in Periodic Table?

The command ColorData["Atoms", "Panel"] generates a periodic table. As I don't want to reinvent the wheel, I asked myself how to change the color of each cell ...
1
vote
1answer
37 views

What particular situation do we have to use RuleDelayed after replacement? [closed]

On the answer of How to impose normalization condition (not initial condition) on DSolve or NDSolve? k = vars /. sol /. cs[[1]] /. C[_] :> 0 // N; I see that ...
0
votes
0answers
57 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. ...
2
votes
1answer
38 views

Mathematica does not replace \[ImaginaryI] inside Hold

Mathematica 10.1 does not replace I (i.e. \[ImaginaryI], the square root of -1) inside functions with the Hold attribute. Example: ...
0
votes
0answers
32 views

Replace instanced variables within module-return functions for dynamic Tooltip

Currently I am stuck with the issue of renaming an instanced variable like r1$38655 to a global one. The function is created within a "localizeAll" Module. Here's ...
1
vote
1answer
34 views

Replace symbols in output without evaluation

I found the Wolfram example for ExpandNCM but I want a more human-readable output form. I want to evaluate ExpandNCM, for example with ...
0
votes
0answers
66 views

Matrix iteration failing after second step

I am calculating 11x6 matrix using different logics as in below code. Problem is in Do loop in below code where I have two different criteria to update matrix "fd". I am expecting logic in IF which ...
0
votes
1answer
49 views

Replace element of matrix based on rule which invloves other element of same matrix

I am trying to replace 1s row of matrix d iteratively from right by multiplying last element in 1st row with (1-int*dt) to generate 2nd last element. The replacement continues till I reach the 1st ...
0
votes
0answers
54 views

How to replace a part of array based on certain rules which involves usage of other array

I am trying to replace outermost column of array "fd" in below code. fd is matrix of dimension (nas1,nts) which is initially filled with 1. I want to replace outermost column of fd with result of Max ...
0
votes
0answers
25 views

Convert the output of solve into equality [duplicate]

I know this is has been asked before but seriously, none of the ones I checked helped because they referred to a single variable assignation. Apologies if this is a duplicate. I have many variables ...
0
votes
0answers
28 views

Subtracting Series

When I input the following $\sum_{n=0}^{m+1}x[n]-\sum_{n=0}^{m}x[n]$ which in InputForm is: Sum[x[n], {n, 1, 1 + m}] - Sum[x[n], {n, 1, m}] it returns ...
0
votes
2answers
42 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 ...
0
votes
2answers
49 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 ...
1
vote
3answers
135 views

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

I know how to do a Check for the list in general: ...
2
votes
4answers
209 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" ...
3
votes
4answers
232 views
1
vote
2answers
74 views
2
votes
3answers
115 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 ...
3
votes
1answer
102 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 ...
0
votes
1answer
42 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 ...
0
votes
3answers
74 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 ...
1
vote
1answer
25 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 ...
1
vote
1answer
63 views

Applying functions repeatedly on parts of complicated expressions

I am dealing with expressions like $$ \textrm{expr}=5D_{4,1}\langle12\rangle\langle23\rangle\big(-\langle15\rangle^2\langle24\rangle\langle34\rangle + ...
0
votes
1answer
23 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 ...
7
votes
4answers
437 views

Strange answer from StringReplace

I have a list of strings and I would check if there is an empty string element, that's "", because I need to replace it with a "0". I try the following ...
1
vote
2answers
50 views

Problem with Replace function [closed]

I recently started using Mathematica. I'm not able to understand my mistake. I'm trying to implement the Frangi vesselness for the enanchement of vessels in biomedical images. I wrote these functions: ...
1
vote
0answers
40 views

Substitution does not work while substituting with a value from list

I am writing a program which iteratively solve and make substitution from a list. As I have shown in the code substitution works when I enter the value directly (Input 100). When I extract the same ...
7
votes
2answers
98 views

Why does ToRules return a Sequence?

Why does ToRules return a Sequence expression? Why doesn't it return directly what ...
3
votes
2answers
156 views

How to rewrite the rules in a list when they satisfy a given condition

I think the best way to state my problem is to illustrate it with an example. Assume I have the following toy-list of rules: ...
0
votes
2answers
56 views

For the same function, why does /. give a complex result?

I define a very simple function like this, g[k_] := 1. + 2 Sum[1/(1 + (2 n)^2), {n, 1, k}] g[50] give the result is: 1.70279. But g[n] /. n -> 50 give aother result: ...
12
votes
1answer
321 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 ...
4
votes
3answers
163 views

Replace elements in matrix to make it symmetric using automated procedure

I am generating a matrix using (mat2 = Array[Subscript[a, ##] &, {4, 4}]) // MatrixForm but would like to force Mathematica to make it symmetric. Thereby I ...
2
votes
1answer
138 views

Replacing powers of $n$-th partial sums in the output of a function with $S[i]$ for $i = 1,\ldots,n$

I've written some simple code that, for various $N \geq 1$ and $k = 1,\ldots,N+1$ computes the $n$-th derivative of $\log S_N$ where $S_N(z) = \sum_{k=0}^N \frac{1}{k!}z^k$ as follows: ...
4
votes
2answers
135 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]? ...
0
votes
1answer
32 views

Force ReplaceAll to output vector of same length

I would like to do a replace in an expression... a = t; b = 1; a/.t->Range[1,5] (*returns: {1,2,3,4,5} *) b/.t->Range[1,5] (*returns: 1 *) but I ...