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
2answers
82 views

Converting a date to a calendar quarter

I have a list that includes dates. I need to convert each date to be the last day of the quarter that it's in. So for example I want {2013,7,1,0,0,0} to become {2013,9,30,0,0,0}. Actually I don't ...
2
votes
1answer
107 views

Confused behavior using Dispatch to sort one list relative to another

I have a need to sort the entries of one list into the same sequence as the entries in a reference list. Because I have rather large lists involving strings, I'm trying to use Dispatch to accomplish ...
2
votes
2answers
129 views

How to plot complex values given by Solve

Update Solve[N[Table[BernoulliB[n, z], {n, 10, 10}] == 0]] ...
2
votes
1answer
135 views

Add Pattern to List Removing Duplicates

Lets say I have a list of patterns ...
2
votes
2answers
108 views

Using a predicate to control the application of a rule in a replacement

How can I make a replacement rule that will only be applied to those parts of an expression that will not break a condition placed on the whole expression? For example, suppose I have ...
2
votes
2answers
132 views

Modify a sub-part of a sub-list only

I have this list: a = {{{0, 0}, {1, 7}, {2, 0}, {3, 2}, {4, 7}}, {{0, 0}, {1, 0}, {2, 1}, {3, 2}, {4, 7}}} and I'd like to transform it to this: ...
2
votes
1answer
63 views

Using Total on a list supplied by a rule

I'm confused as to why Total complains about a nonatomic expression here: ...
2
votes
1answer
58 views

Applying rules to rewrite expressions that contain patterns

I'm trying to write a rule that can rewrite a pattern that exists in another expression. For some reason, this is proving to be more challenging than I expected ... most likely because I'm not totally ...
2
votes
1answer
107 views

Replace an expression with a slightly tricky LHS transformation

I would like to make the substitution x^(11*y) -> r in the following equation x^(11 *y^z) - 1 to end up with: ...
2
votes
1answer
60 views

Unique[] in RHS of rule

I have a function, explicit that takes dot product of two symbols, and replaces it with repeated dummy indices generated by ...
2
votes
1answer
177 views

A Sierpinski-ish structure, via 2D automata

The project is originally based on a puzzle proposed by EIORU at http://www.ptt.cc/bbs/puzzle/M.1342451949.A.00F.html (若您懂得讀中文 / if anyone happen to read Chinese^^) last July. The descriptions, ...
2
votes
1answer
42 views

Ordering for Pattern matching in Subscripts

I have some transformation rules acting on subscripted variables. When I match the a product the order matters. ...
2
votes
1answer
102 views

Derivation after substitution not working

I have a code that will output an expression in form of a functions like this ...
2
votes
2answers
127 views

Applying rules with functions to expressions with derivatives

I have a function that I want to see applied, potentially within a derivative. The use of delayed vs. non-delayed rules seems irrelevant. See the following: ...
2
votes
1answer
86 views

Replace inverse function

I'm solving an expression like so: Solve[u[x] == u[a] + u[b], x] Mathematica returns {{x->(u^(-1))[u[a]+u[b]]}} If I ...
2
votes
2answers
283 views

Mass Symbolic Manipulation with Subscripts? (from plaintext Input)

The simplest example of the change being sought is a greek letter, typed in as plaintext nu, and its may be replaced by the symbol, ν: expr = 3nu*kx*ky+ ...
2
votes
2answers
104 views

Generating an editable table that can be used as input

Say I have a number $n_{max}$. I want a command to generate a table like 1 1 2 2 3 3 4 4 ... nmax nmax where the second column is editable, and this table can be ...
2
votes
1answer
65 views

Convert Integer to Numeric with Replacement rules

I have a long list of triples, each looking something like {AGO, 1988, 2345.23}. Some of these, however, have an integer in the third spot, like this: ...
2
votes
1answer
126 views

Strange behavior when replacing variables by numerical values [duplicate]

I have a rather complicated function with parameters {a, b, c, d, e, f, k}, and I'd like to know its behavior as a function of k alone given other parameters, so I try the following code: ...
2
votes
2answers
221 views
2
votes
1answer
119 views

How to transform an expression using algebraical instead of pattern rules [duplicate]

I would like to transform rules algebraically. A very simple example would be: - k^2 - 2 k x + x^2 /. {2*k -> 1} This transforms to: - $$k^2-2 k x+x^2$$ ...
2
votes
1answer
135 views

#[[1]]//FullForm = 1?

I have a set of symbolic algebraic expressions that I'm trying to get some speed into. To illustrate the issue, I'll use a simple form like { k0 X, k1 Y, k1 Z}, ...
2
votes
1answer
29 views

Table doesn't replace inside conditionals (If, Which) [duplicate]

This: Table[If[cond, y], {y, 1, 3}] outputs this: {If[cond, y], If[cond, y], If[cond, y]} The ...
2
votes
0answers
98 views

Generalization of a rule to N arguments

I am trying to apply a series expansion on a function x[t1,t2,...tn], with an expansion parameter a. For ...
1
vote
1answer
123 views

Simple rule appears not to work

I have the following simple code ...
1
vote
3answers
108 views

Replace inside a Held expression separate context

How do I replace content inside a Held expression without local values coming through? For example if you run the following code you get g[2] instead of ...
1
vote
2answers
148 views

Using patterns in ReplaceAll to extract elements from tuples at arbitrary depths

Please consider the following: I need to extract from MyList all last parts of each 3-tuple. ...
1
vote
2answers
70 views

Changing all link destinations in a notebook

I have a bunch of cells containing text and hyperlinks. i.e. of the form: ...
1
vote
3answers
86 views

How can you form a variable from a function and its arguments?

Is there a way to make the general replacement foo[x,y,z]->fooxyz so that I can treat the x_i as variables so that I will obtain foofgh from the following: ...
1
vote
3answers
164 views

Help me to find a way to do this repetitive stuff

I'm trying to do this: ...
1
vote
2answers
125 views

How to replace subscript symbols

I have an expression with subscripted variables. I would like to replace all those terms with other symbols. For example, $P_1 + P_2^3 \rightarrow P1 + P2^3$ I used the following code but it doesn't ...
1
vote
2answers
272 views

Generating a list of rules [closed]

This is my first time asking a question on this forum. I would like to generate a list with a range of numbers and use this list for a function to read from. Ok, now for the good part, it would look ...
1
vote
2answers
80 views

How to define a rule to simplify the notation for derivatives of chain rule?

Suppose that $u(x,y)$ is a function, and $x=r \cos t$, $y= r \sin t$, then we can define a new function $v(r,t):=u(x,y)$ with $x,y$ replaced by the above equations. It is quite easy to compute $v$'s ...
1
vote
3answers
319 views

How to manipulate nested expressions?

I have the following expression, only slightly complicated, and I'd like to do two things: Plot the elements of the lists (though messy, all are in the same ...
1
vote
2answers
80 views

How to “reversely” replace definitions?

I have the following problem at hand. 1.) I have a list of definitions like ...
1
vote
2answers
63 views

How do I use a passed-in symbol as a tag to define UpValues?

ClearAll@foo; foo[tag_] := ( tag /: tag[i_] := tag[[i]] ); a = {7, 8, 9}; foo[a]; a[2] I wanted the above to output 8, ...
1
vote
3answers
162 views

How to debug error triggered by replacement rule?

The second line below produces the errors shown: ...
1
vote
3answers
111 views

Conditional Check on Matrix

Suppose I have the following matrix (i,j): ...
1
vote
2answers
88 views

How to get a rule for, e.g., (x + y) to apply to (-x - y), etc.?

For example, the substitution (x + y) -> s fails here: In[1]:= (-x - y) /. (x + y) -> s Out[1]= -x - y Of course, I ...
1
vote
2answers
57 views

How do I avoid vector variables being treated as scalars in the course of replacements?

I often work with a mixture of symbolic and concrete values as I develop teaching materials. I introduce variables symbolically and then need to instantiate them to specific values while continuing ...
1
vote
1answer
191 views

Equating and solving equations that have been generated using table[]

I am in the process of trying to use Mathematica to find the coefficients of transmission and reflection for the wavefunction of a beam of particles tunnelling across any number of identical potential ...
1
vote
1answer
1k views

Converting polar coordinate expression to cartesian coordinates

An intermediate step in my analysis requires me to work in polar coordinates, but I would like to convert the results back into cartesian coordinates. The conversion is very simple but tedious for ...
1
vote
1answer
94 views

Matrix substitution

I'm newbie in Mathematica and would like to ask one simple question. Let's say I have matrix with some elements == -1 ...
1
vote
1answer
44 views

Different ordering for KroneckerDelta?

I have an expression like this: Assuming[m [\Element] Integers && n [\Element] Integers, 1/2 I J n (4-m n+n^2) KroneckerDelta[m,-n]]//FullSimplify Now, ...
1
vote
1answer
135 views

Improving the plotting time of a very complicated expression

The quatity $R$ is defined by a complicated expression in terms of $a_1,a_2,\ldots,a_n$. Now each $a_i$ is a function of $x$, $a_i(x)$. I would like to know what is the most efficient way to ...
1
vote
3answers
107 views

Auto simplifications of power products

Mathematica automatically simplifies Exp[a]Exp[b] to Exp[a+b]. The problem is now that I can't do this ...
1
vote
1answer
38 views

Commutative algebra by generators and quadratic relations

My apologies if this has been asked before. Please also be gentle, as this is my first question here. I am trying to define a commutative algebra by generators and relations in the following way. ...
1
vote
1answer
52 views

How do I extend (prepend or append to) an existing TagSetDelayed rule? [duplicate]

I have a TagSetDelayed rule associated with, say, tag: ...
1
vote
1answer
129 views

How to properly substitute values into variables?

I have an array of functions in terms of a[0] through a[n] and I wish to replace the a[]'s with previously calculated values p[0] through p[n], as in below: ...
1
vote
1answer
42 views

How to substitue local variables into expression with free variables?

I'm wondering how to do the following: expr = L + R; foo[L_, R_] := expr; foo[1, 2] (* L + R *) and have it substitute the function variables ...