Linked Questions

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: ...
user avatar
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 ...
user avatar
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, ...
user avatar
  • 264k
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 ...
user avatar
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 ...
user avatar
  • 1,799
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 ...
user avatar
  • 7,759
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: ...
user avatar
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: ...
user avatar
  • 597
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 ...
user avatar
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 ...
user avatar
  • 9,859
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 ...
user avatar
  • 183
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 ...
user avatar
  • 3,395
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\...
user avatar
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, ...
user avatar
  • 1,205
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 ...
user avatar