Linked Questions
15 questions linked to/from Using ReplaceAll to replace a head
2
votes
0
answers
57
views
How exactly does ReplaceAll work? [duplicate]
I am not sure if this question has been asked before but anyway, Consider these two examples:
...
49
votes
4
answers
30k
views
How to remove redundant {} from a nested list of lists?
There are numerous examples here, whose end result is the removal of empty brackets {} and empty lists. I still can't find an example of simply removing redundant ...
31
votes
5
answers
2k
views
How to perform a depth-first preorder traversal of an expression?
Mathematica provides functions that perform a depth-first postorder traversal, or which use such a traversal, including: Scan, ...
22
votes
3
answers
2k
views
Converting hierarchies of rules to associations
The impossibility of MatchQ-ing inside and Association MatchQ-ing Associations (MMA 10) explains a problem I have. I would like ...
22
votes
2
answers
4k
views
Determine whether some expression contains a given symbol
Given a symbol t and an expression expr, how can I determine whether or not the symbol t ...
10
votes
5
answers
565
views
Replace heads to match a pattern
Is it possible to replace the heads to match a pattern?
eg
f[f[f[]]] -> a[b[c[]]]
or
...
16
votes
2
answers
556
views
ReplaceRepeated seemingly omits some rules
Is there a simple way in Mathematica to prevent rule reordering? Let me give an example:
...
8
votes
3
answers
240
views
Prevent testing Head with ReplaceAll
I have a list of strings list. I am trying to get rid of some elements that match string pattern patt:
...
10
votes
2
answers
262
views
Unexpected behavior using `ReplaceAll[]` for nested lists [duplicate]
ReplaceAll[] might lead to unexpected behavior (at least it surprised me).
I use ReplaceAll[] to convert a list (basically data ...
7
votes
2
answers
183
views
Is Replace doing double work?
In an answer to this question, rm -rf used the function Replace with level spefication to do a series of replacements inside out. As far as I can see, the order of substitutions when more than one ...
2
votes
2
answers
155
views
Sets of identical equality/inequalities
So I've used Mathematica for some months, but I never noticed this sort of thing about it, namely:
(a > b) == (b < a)
which are supposed to be identical ...
2
votes
2
answers
92
views
Slow replacement rule while combining symbolic summands
Edit:
I attempted to use the method of repeatedly using Replace instead of ReplaceRepeated as suggested by Mr.Wizard, but the ...
1
vote
1
answer
179
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 + \langle14\rangle\langle15\rangle\langle24\rangle\...
2
votes
0
answers
199
views
Understanding the order of applying Rule to expression [closed]
I am a little confused about:
In what order is a Rule tried to apply to an expression? In a depth-first order or otherwise?
For example,
...
1
vote
0
answers
135
views
How does pattern matching in expression work?
I have been trying to understand how mathematica does pattern matching:
{Sin[x] + 1} /. Sin -> Cos
returns
Cos[x] + 1
...