1
$\begingroup$

This question already has an answer here:

I am trying to understand the true difference/usage of a pure function vs a "normal" function. Besides the argument that a pure function is particularly handy when it comes to a single usage, are there any deeper reasons on why one should go for them rather than the "normal" ones?

$\endgroup$

marked as duplicate by Kuba Mar 31 at 7:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

They are inevitable to apply when you use such functions as Map or MapThread mapping binary functions on some expressions. Under binary here I mean functions taking two arguments. In this case, you want that only one position of the binary function is active. Let me give an elementary example. Let

eq = a*x == b;

be a simple equation and assume that we want to divide both parts by a. This can be done as follows:

    Map[Divide[#, a] &, eq]
(*  x == b/a   *)

This is the place, where the pure function is extremely useful.

Disclaimer: yes, I know, that in the latest MMa version there is a special function, DivideSides, to make such things. But this is only an example of operations of this sort. There are many others.

$\endgroup$
  • 1
    $\begingroup$ Suggestion for a better readability : to replace "binary function" by "two variables function". I think that a lot of people will think that binary means some kind of 0/1 or True/False function. (I'm not sure) $\endgroup$ – andre314 Mar 30 at 21:06
  • $\begingroup$ @andre314: Correct as to avoiding misleading the reader. But alas, a "unary" relation (or function) takes one argument, a "binary" relation (or function) takes two arguments, a "ternary" relation", etc.... $\endgroup$ – murray Mar 30 at 22:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.