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

learn more… | top users | synonyms (4)

7
votes
3answers
168 views

A replacement question

I have: {{θ -> 0}, {θ -> (2 π)/ 3}, {θ -> π}, {θ -> (4 π)/3}} I would like to create a list of points $(\cos\theta,\sin\theta)$ using each of the ...
4
votes
2answers
64 views

Type error before replacement rule is applied

When I type a <> "0" /. {a -> "1"} I get the error ...
0
votes
1answer
114 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 ...
2
votes
2answers
142 views

Replacement rule not having desired effect

So I have this replacement rule that tends to work in most cases, except occasionally in cases like this: ...
8
votes
1answer
81 views

On an existing notebook, how to transform all “double brackets” into “DoubleBracket”

Sometimes, having all double brackets [[...]] transformed into \\[LeftDoubleBracket] ... \\[RightDoubleBracket] can really ...
6
votes
2answers
189 views

How can you resize all the images in a notebook section?

I've pasted a large number of photos and they are too big which makes scrolling hard. Is there a way to automatically have Mathematica size them to 10% or something reasonable without have to click on ...
2
votes
1answer
58 views

Using strings in defining rules

I am very new using Mathematica and I would like to define a rule of replacement which operates as below, keeping freedom for what concern the pre-factors that can appear in the equation: $$e^{\pm ix} ...
1
vote
0answers
26 views

Why variable in SparseArray can't be replaced? [duplicate]

SparseArray[{1, 1} -> t] /. t -> 1 Still contains t. Why t is not replaced by 1?
2
votes
1answer
71 views

how to change Symbol to other symbol?

I have Input =a**b**c I want to have output such as {a,b,c} So I want to change **->, but replace code does not work. How ...
0
votes
1answer
128 views

Using NDSolve initial conditions as parameters for a function and then a replacement rule

I am trying to make a function based on two initial conditions of a set of differential equations: ...
2
votes
1answer
79 views
1
vote
1answer
112 views
3
votes
1answer
77 views

Simplifying an expression with complex variables

The other day I was trying to simplify the following expression of $w \in \mathbb{C}$ and $|w| < 1$: $$f(w) = \left|\frac{2}{(\frac{w+1}{1-w}+1)^2}\right|^{-\Delta} \cdot \frac{1}{\left|{\rm ...
1
vote
0answers
45 views

Collect fails to collect all powers of my variable [closed]

I am fairly new to mathematica and have not used it to really code anything at all, but just used it as an kind of advanced calculator. My issue is the following: I need to extract the power of a ...
3
votes
1answer
90 views

How could I perform this replacement?

I essentially have something of the form pm[1, 2] pm[3, 4] pm[5, 6] c[{1, 2, 5, 6}, "+"] c[{3, 4}, "-"] I want to add next to each pm a corresponding plus or ...
1
vote
2answers
167 views

Find the explicit solution of the integral

I want to calculate the integral: assuming that we are familiar with the relation: The answer should be: The code that I've used is the following: ...
1
vote
0answers
59 views

How can I perform this replacement? [closed]

I want to take an expression of the form p[1,2]p[3,4] and have an output of something like {{1,2},{3,4}} If I do the ...
0
votes
1answer
52 views

How to do this replacement without a for loop?

I'm new to Mathematica and I'm trying to get past my desire to use For loops for everything; can somebody tell me a simple way to make this replacement? I want my input to be ...
0
votes
2answers
177 views

Approximate UnitStep for use in Enterprise CDF

The following Manipulate code displays the VectorPlot for all functions. (This code is a subset of a more extensive notebook which is based on the structure you see below. Consequently, I need to ...
9
votes
1answer
108 views

MapAt with Replace(All) causing kernel crash

Bug introduced in 10.1 and fixed in 10.2 I wanted to roll a function that works like /. but only acts on the very first match it encounters. ...
5
votes
1answer
84 views

How to transform abstract finite group to permutation group?

It seems that Mathematica only has group functionality for permutation groups? Then there is a step to transform the abstract finite one to a permutation one. As an example, consider the following ...
9
votes
3answers
211 views

How to make a ReplaceAll Rule for adjacent items in a list?

I would like to make only one pass of a list of 2D items and replace adjacent items that have matching $x$ or $y$ coordinates with a series of linearly interpolated points between the two points. My ...
5
votes
3answers
179 views

How to change symbols in differential equation with a single rule?

Problem Suppose I have a differential equation such as $\qquad f'(x)+f(x)=0$ and I want to change it into $\qquad y'+y=0$ My Method Using ...
2
votes
1answer
91 views

How avoid error message with Range?

Evaluating Range[1, n] /. n -> 3 produces an error message ...
1
vote
1answer
229 views

Duplicate Mathematica functionality in Mathematica clone or lisp [closed]

What is the easiest way to accomplish the following in a Mathematica clone or in any version of Lisp? Also it doesn't appear in any lisps have a similar replace function. ...
0
votes
1answer
29 views

Substitute ratios

Suppose that I have the expression (x+y+z)/y. I want to substitute the rules Phix -> x/y, Phiz ->z/y. Is there a way to ...
4
votes
0answers
92 views

Optimization of recursive functions by using the //. operator [duplicate]

In some cases, recursion in Mathematica (without storing values) is not very efficient. For example, the recursive implementation of Fibonacci numbers (version which doesn't store the values) : ...
1
vote
1answer
101 views

How to assert that a list of variables is real in a nice and clean way

You can use the function Element to say e.g. $x,y,z\in\mathbb{R}$ via Element[x | y | z, Reals]. Now if I have a list of ...
0
votes
1answer
73 views

Changing notations for probability moments with subscripts

Suppose I have have two kinds of variables $X_{\alpha_j}, X_{\beta_k}$ in the form of Subscript[x,Subscript[α,j]] and ...
0
votes
1answer
88 views

Overriding the behavior of Dot

I would like to override the behavior of Dot, so that Dot[u,v] will return a scalar instead of a 1x1 matrix in the case that the ...
1
vote
1answer
67 views

Replace symbol with numerical value

How do I get the same result, i.e., how can I get Mathematica to replace a with 1? ...
6
votes
2answers
330 views

Matrix exponential via Cayley-Hamilton Theorem

I'm attempting to calculate the exponential of a matrix via Cayley-Hamilton theorem. (Following the "concrete example" from http://en.wikipedia.org/wiki/Cayley%E2%80%93Hamilton_theorem) I am having ...
1
vote
2answers
52 views

Replace function with multiple functions while respecting the inputs

I want to replace a function with either one or two functions and also combine their arguments. Say I have an original expression expr = u[i + 1] r[i] r[i-1] ...
3
votes
0answers
62 views

Why is the evaluation of f different using rules and using arguments to it as a function? [closed]

I will provide all the code I used at the end of the question. I was trying to evaluate a function f with the following signature (which I'll give the details at ...
3
votes
3answers
113 views
2
votes
3answers
179 views

How does one unpack the contents of a list while using rules to substitute values for each variable?

My intention is having a large collection of variables (symbols to be more specific) in a list and substituting all the variables at once with a value using rule instead of going through each one, one ...
0
votes
1answer
86 views

Using Simplify to perform substitutions [closed]

I have a matrix element $k_x$ and I want to substitute it as $-i\kappa$, I tried ...
2
votes
2answers
75 views

Replace All using a list

I have a more complicated case however a basic example is; ...
4
votes
1answer
128 views

How to transform a list (of sums) into list of summands

Suppose you have the list list={a,Sin[b+c],d+c}. What I want is to transform all elements of list with head ...
1
vote
1answer
97 views

Replace empty spaces with zero (0.0) after Import .csv data

I imported data from .csv file and it looks like: ...
0
votes
2answers
82 views

Replacement rules do not apply for an expression inside a root

Say, you have an expression which looks like this: myexpr = (mess)+(some other mess)/( (mess)^3+(some other mess)^2 )^(1/3) Here the 'mess' in the name of terms ...
8
votes
1answer
307 views

Mma10 mystery: Failure of pure function substitution with Interpretation?

Bug introduced in 10.0.0 and fixed in 10.0.1 I had code to display with subscripts from Displaying index as subscript on output: e.g. C[i] -> C_i with Notation[...] or Interpretation[..]? which ...
4
votes
1answer
117 views

Substitute a function's definition for its name

I'm having trouble with a function which is supposed to work on another function. Simplified version: ...
2
votes
2answers
76 views

Trouble simplifying using Replace

I have the following expression: w.a.b.r+w.c.d.r I want to get: w.(a.b+c.d).r So far I used ReplaceRepeated: ...
2
votes
2answers
114 views

Replace elements in some region in a list

I want to replace some elements in list. Assume that we have A={{1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,16}} and we want to replace elements ...
26
votes
3answers
3k views

Extracting values from nested rules in JSON data

I have been using Mathematica to analyse some data from the StackExchange API. It is conveniently available in JSON form, which Mathematica interprets as replacement rules. However, some of the rules ...
3
votes
1answer
82 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 ...
5
votes
4answers
339 views

ReplaceAll is not working correctly

The line of code -E^(-I k) x /. {-x -> -x, -E^(-I k) x -> -E^(I k) x} is not properly replacing the exponential of (-I k) with the exponential of (I k), as ...