Linked Questions

62 votes
9 answers
5k views

Levels: how do they work?

I cannot understand how Mathematica manages levels, and so it's always a painful try-and-fail to use Flatten. Can someone please give me a very clear definition? ...
Lorenzo Pistone's user avatar
33 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, ...
Mr.Wizard's user avatar
  • 271k
24 votes
2 answers
5k 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 ...
Ian Hincks's user avatar
  • 1,859
7 votes
2 answers
3k views

Using ReplaceAll to replace a head

Why would this work to replace the head b with newHead: ...
seismatica's user avatar
  • 5,091
9 votes
5 answers
278 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: ...
amrods's user avatar
  • 637
5 votes
1 answer
1k views

What do brackets around a levelspec option do?

The following code returns the first three integer elements of Sqrt[Range[100]]: ...
M6299's user avatar
  • 1,461
3 votes
3 answers
156 views

Why Graph does not recognize chains of vertexes like NetGraph

Cross posted on Wolfram Community. Perfect logic: NetGraph[{1, 1, 1}, {1 -> 2 -> 3}] But this does not make sense: ...
Fortsaint's user avatar
  • 2,060
7 votes
2 answers
187 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 ...
Fred Simons's user avatar
  • 10.2k
5 votes
1 answer
219 views

How to make a postordered ReplaceAll that operates just once per subtree?

The answers to this question provide code for a function I'll call postOrderReplaceAll to replace from the inside-out: ...
Seth's user avatar
  • 434
2 votes
0 answers
211 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, ...
Naitree's user avatar
  • 1,235