Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.1K Views
|
6 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Why does f /@ x give x

Posted 2 years ago

Hello,everybody! I begin to learn Mathematica. I know /@ means “apply to each element”. so f/@{x} is {f[x]}. But when I try f /@ x, the result is x.I don't know why. What is the meaning of f /@ x. Would you be kind enough to give me an explanation?

POSTED BY: Q Wang
6 Replies
Posted 2 years ago

Actually, your wording is still confusing, because:

g[Nothing]
Out[] = g[Nothing]

I would compare g[Nothing] with List[Nothing] as follows:

f /@ g[Nothing]
Out[]= g[f[Nothing]]

f /@ List[Nothing]
Out[]= {}

The reason for the difference is that List auto-reduces the Nothing to emptiness. Other than that minor difference, List[] and g[] are made indistinguishable when mapping into.

POSTED BY: Brad Klee
Posted 2 years ago

Thanks so much!

POSTED BY: Q Wang

It’s a bit of an edge case. Map[f, expr] applies f to each element of expression at level 1. Note that it works with any expression, not just lists:

In[12]:= Map[g, f[1,2,3]]
Out[12]= f[g[1],g[2],g[3]]

Since x is a symbol, it doesn’t have any parts. Compare to

In[13]:= Map[f,g[]]
Out[13]= g[]
POSTED BY: Victor Kryukov
Posted 2 years ago

Thank you very much! Inspired by you, I wrote the following words. Are they right?

For g[ ], it has no element at level 1. In other words, we can think that the element of g[ ] at level 1 is "nothing". When f applies to "nothing", the result is "nothing"(or just indicated by a backspace). So f/@g[ ] is g[ ].

POSTED BY: Q Wang

Happy to help!

As @Brad Klee pointed out, Nothing is a pre-defined symbol in Wolfram Language, so your reformulation might still be confusing. I would say something like "the set of elements at level 1 for expression g[] is empty, so applying f to an empty set yields an empty set."

POSTED BY: Victor Kryukov
Posted 2 years ago

Thank you very much!

POSTED BY: Q Wang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard