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

learn more… | top users | synonyms (4)

2
votes
4answers
135 views

Symbolic cut-off of high-order terms

I know that I can cut-off high-order terms of a $1$-variable polynomial P = a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5; simply by doing for example ...
1
vote
1answer
55 views
1
vote
1answer
62 views

Apply solution rules to new functions as parameters [duplicate]

Update: I put an screenshot of how my code and problem look like at the end. Say that Mathematica solved a system of equations and got two answers {{a -> 3, b -> c, d -> 0}, {a -> -3, b -> 0, c -> ...
0
votes
4answers
49 views

How to trim out sequence of blank-spaces?

Considering we have few strings: s1 = "dasbdk " s2 = "asdnkal asn knkl nkn dvklsn " s3 = " jbjkbasd nklnkln " Q1: How can the blank-spaces in ...
0
votes
0answers
58 views

Replacing function in Sum

I have this expression, which, after execution, gives these $F[s,r]$ in output. $$ S_{1,1}=\sum _{s=1}^{16} \sum _{r=1}^{16} F(s,r) \text{Tr}\left[G_r.G_1.G_s.G_1\right] $$ Here is a piece of ...
2
votes
3answers
84 views

How to check keys and values in nested Associations?

Considering we have a an association: ...
1
vote
1answer
43 views

Concatenated rule applications (applying rules to rules correctly)

I am trying to apply a series of individual rules onto an expression sequentially, but also not have to write out the repeated ReplaceAll functions each time I want ...
0
votes
1answer
53 views

Replacing every nth comma in string output with “\n” [closed]

Feels like a strange question to ask, but I basically have a string with sets within sets, and it seems like the simplest formatting solution to seeing the data without needing to import everything ...
1
vote
1answer
39 views

Conditional replacement syntax

Why does the following expression not do what I expect Array[a, 6, 0] /. a[__?MemberQ[{1, 2}, #] &] -> 0 I expect ...
2
votes
1answer
73 views

What's the difference between functions and replacement?

I used to thought that calling a function is equal to applying a rule, i.e. applying a rule of f[x_]->sth. is equal to calling a function f with definition f[x_]:=sth. However, given ...
0
votes
1answer
56 views

Setting a range of values to one value [closed]

My question is perhaps worded a little vaguely, but it's a problem I'm running into defining my own function. I'm drawing some shapes with variable height, and sometimes this height is 0. For it still ...
1
vote
1answer
63 views

Substituting inside a differential equation

x y''[x]+2y'[x]+l^2 x y[x]==0/.y[x]->Cos[x] I think above code shows what I want to do quite clearly. How do I make it happen. Only y[x] is replaced.
1
vote
1answer
102 views

A puzzling result of the `ReplaceAll` [duplicate]

I tried to do something below Log[PDF[NormalDistribution[m, s], x]] /. Log[u_[x__] ] :> Plus @@ Log[List[x]] which gives a desirable result that splits the ...
1
vote
1answer
46 views

Using HoldForm for a changing list

I have a 'list' of the form an expansion: F = (A[1] + A[2])(B[1] + B[2]), such that F[[1]] produces the result ...
1
vote
2answers
82 views

why does replacement rule not work

Why does the following replacement rule not work? term = x^2/y^2 + x^3/y^3 term /. u_^p_/v_^p_ -> z^p I expected it to return ...
3
votes
3answers
63 views

How to apply ReplaceAll to denominator?

Here is the simple task. In reality, it's far more complicated, but it comes down to this. I want to take the expression $\frac{y}{x^2}$ and replace $x^2$ with $k$. This doesn't work: ...
0
votes
0answers
31 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: ...
1
vote
1answer
129 views

Making ReplaceAll faster

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

Pattern matching & simple replacement

I have a question about an expression that I want to modify. Here is the expression: ...
8
votes
1answer
203 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
252 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 ...
0
votes
1answer
70 views

Applying ReplaceAll to I (imaginary unit) [closed]

Why does I/.I->-I return -I but Exp[-I]/.I->-I yields ...
1
vote
1answer
138 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 ...
1
vote
1answer
81 views

Why does ReplaceAll behave so oddly?

ReplaceAll can behave a bit oddly. Consider ...
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 ...
2
votes
1answer
41 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
1answer
48 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
40 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
67 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
52 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
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
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
1answer
47 views
0
votes
0answers
29 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
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
141 views

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

I know how to do a Check for the list in general: ...
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 ...
2
votes
4answers
218 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" ...
6
votes
5answers
291 views

How to switch from List of rules to Association?

Considering we have a list of rules: ...
6
votes
4answers
311 views

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

Considering we have a list of rules: ...
1
vote
2answers
78 views

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

Why is "Xabcde" /. "X" ~~ e__ -> e "Xabcde" and not "abcde"
2
votes
3answers
119 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 ...
0
votes
1answer
43 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 ...
3
votes
1answer
103 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
3answers
80 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
32 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 ...
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 ...
1
vote
1answer
70 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 + ...
7
votes
4answers
439 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
58 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: ...