0

I find these to be very convenient, particularly since I use the base-10 log fairly frequently:

  • Log[2, n]=> Log2@n
  • Log[10, n] => Log10@n

These represent a very specific type of syntactic sugar, in which the parameter modifying the function (in this case, the base) is subsumed into the function name.

Thus I'm wondering: Are there any other constructions like these?

These are qualitatively different from the main class of Mathematica keystroke-savers, namely the extensive set of operator short forms, such as /@ for Map (see Mathematica Operator Input Forms). Indeed, Wolfram itself seems not to consider Log2 and Log10 special Operator Input Forms, since they can't be found in the latter list.

Again, I'm specifically refering to constructions in which a parameter is subsumed into a function name. In case this is still a bit unclear, just for the purpose of illustration, consider Drop, and imagine that Rest didn't exist. It's common to use Drop to remove the first element of an expression, using the parameter 1, as in Drop[expr, 1]. Thus a nice bit of syntactic sugar (if Rest didn't exist) would be if there were, say, Drop1 to do this. I.e., Drop1@expr instead of Drop[expr, 1].

Another hypothetical example would be if there existed, say, FormatT and FormatS as short forms for Format[expr, TraditionalForm] and Format[expr, StandardForm].

Note that, by contrast, LegendreP and LegendreQ don't count, because each of these is a distinct function in its own right. I.e., there is no Legendre function, for which P and Q are possible parameters.

theorist
  • 3,633
  • 1
  • 15
  • 27
  • Besides the newly added |->, you can see a complete list in What the @#%^&*?! do all those funny signs mean? – Ben Izd Jun 16 '21 at 04:20
  • @BenIzd I'm familiar with that list of operator short forms. As I explained, I'm instead looking specifically for short forms for function-value combinations – theorist Jun 16 '21 at 04:44
  • 1
    The short forms you describe are similar to what the docs call Operator Forms. There is a (short) list of functions that have operator forms in this Guide. Also OperatorApplied can be used to create operator forms. – LouisB Jun 16 '21 at 05:30
  • @LouisB No, those are qualitatively different. I'm talking specifically about existing functions that take certain values as options, for which Wolfram has created a new combined function that incorporates that function-value combination. – theorist Jun 16 '21 at 06:00
  • @Ben Izd I tried but did not manage to find the meaning of |-> in the documentation. Could you please kindly shortly explain, what is it and give a reference? – Alexei Boulbitch Jun 16 '21 at 09:50
  • @AlexeiBoulbitch It was a feature added in 12.2 (also with //=), it's just an easy way to type \[Function]. Syntax was mentioned in Function but as of now, I couldn't see an example in the examples section. You can see examples in the 12.2 announcement blog under the "Making Code Just a Bit More Beautiful" section. – Ben Izd Jun 16 '21 at 10:44
  • I notice you clarified your question a bit, but do you have any examples of functions that are not Log that match your criteria? It seems that there may not be others like that, and that those only satisfy your criteria by chance/on a technicality. – CA Trevillian Jul 05 '21 at 22:22
  • 1
    There could be some hidden internal functions that do this. The hashes might do this though it's more of a reduction of compounded functions and a value ("Base64Encoding") into one function - e.g you can replace StringTake[Hash["1234", "Expression", "Base64Encoding"], ;; -2] with GeneralUtilities`Base64Hash["1234"] – flinty Jul 05 '21 at 22:33
  • 1
    Note also that Log[b, x] is short for Log[x]/Log[b] (and this shows that Log2 and Log10 are really short for such forms and that Log[x]/Log[2] really has two short forms). But at this point, if it’s merely about some code transforming into other code, I think the boundaries of what can and cannot be included will disappear. – Michael E2 Jul 06 '21 at 00:02
  • 1
    @CATrevillian I don't know of any others. But it certainly looks like there are other good candidates for abbreviating common function-value combinations, so I was wondering if there were. For quite a while I'd been using Log[10,x], and always thought it was cumbersome (plus I always had to test it or look it up, since I could never remember if it was Log[x, 10] or Log[10,x]). Thus I was chagrined to discover that there was a simple, easily-remembered shortcut I could have been using all along: Log10. Consequently, I am wondering if are others like this of which I'm unaware. – theorist Jul 06 '21 at 01:32
  • @MichaelE2: "Log[b, x] is short for Log[x]/Log[b] (and this shows that Log2 andLog10 are really short for such forms...." Agreed. ".... and that Log[x]/Log[2] really has two short forms". Not following—it seems Log[x]/Log[2] has one short form: Log2. Also: I think there's a clear distinction between the class of functions I'm asking about, and the usual operator short forms, as indicated by the fact that Wolfram didn't include Log2 and Log10 on their Operator Input Form List (https://reference.wolfram.com/language/tutorial/OperatorInputForms.html) – theorist Jul 06 '21 at 01:40
  • The two forms Log[2, x] and Log2[x] are short for Log[x]/Log[2]. Note that this is not true for numeric x: x = 1.4; Log2[x x] - Log[2, x] and Log2[xx] - Log[xx]/Log[2]. Try it for x = 0.9 and x = 0.499 and see that all three are different. -- Also, I'm not talking about operator forms, but code (e.g. Log2[x]) that expands to other code (Log[x]/Log[2]). The first is a way to get the second, and if it's shorter, we can call it a "short form." – Michael E2 Jul 06 '21 at 04:05
  • I suppose you would include other special values of parameters like Hypergeometric2F1[a, b, c, z] being short for HypergeometricPFQ[{a, b}, {c}, z]? (There are a few other hypergeometric examples.) – Michael E2 Jul 06 '21 at 04:12
  • @MichaelE2 Sure, you can come up with all sorts of definitions of long form vs. short form, such as the one you offered based on whether a longer form can be obtained using Expand. But—and forgive me if I'm missing something—that doesn't seem to have anything to do with what I mean by short form, so I'm afraid I don't see the relevance here. Again, I'm talking specifically about functions (esp. commonly-used function) that take some value as a modifier to what the function does (Wolfram calls it a "value", but that word has an overly broad meaning, so let's call it a "parameter").... – theorist Jul 06 '21 at 05:22
  • where the syntatic sugar is that the parameter is subsumed into the funcition name. For instance, just for the purpose of illustration, consider Drop, and imagine that Rest didn't exist. It's common to use Drop to remove the first element of an expression, using the parameter 1, as Drop[expr, 1]. Thus a nice bit of syntatic sugar (if Rest didn't exist) would be if there were, say, Drop1 to do this. I.e., Drop1@expr instead ofDrop[expr, 1]` . That's the kind of construction I'm talking about. – theorist Jul 06 '21 at 05:29
  • Hypergeometric2F1[a, b, c, z] is a nice convenience vs. HypergeometricPFQ[{a, b}, {c}, z], though this is a different class of convenience from what I'm referring to. Here, instead of subsuming a parameter into the function name, the syntactic convenience is that you can drop a bunch of curly braces. Also: I'm afraid I didn't follow what you were trying to say with your numerical example. Is x x =x^2, and is xx a new variable? [N.B.: I just rewrote my OP, incorporating language I used in my comments to you; hopefully that will make it clearer.] – theorist Jul 06 '21 at 07:13
  • Would ListLinePlot vs. ListPlot count? Apart from potentially minor differences I am not aware of, the main one is that ListLinePlot is effectively ListPlot with the option Joined->True – Lukas Lang Jul 06 '21 at 07:23
  • 1
    @LukasLang It wasn't quite what I had in mind, since they are slightly different functions* but, yes, effectively, that would count. [*If you don't want to bother to manually adjust the the point sizes, ListLinePlot gives more distinctive (larger) points than ListPlot w/ Joined->True. Compare, for instance ListPlot[Table[Sin[x], {x, 0, 2 Pi, 0.1}], Mesh -> All, Joined -> True] with ListLinePlot[Table[Sin[x], {x, 0, 2 Pi, 0.1}], Mesh -> All]]. – theorist Jul 06 '21 at 08:05
  • For xx read x. That was a typo I didn't catch. -- So, for things like FuncA[x] being short for Func[A, x] or Func[x, A], there are no others I believe. For things like ListLinePlot, perhaps NDSolveValue[ode, {y1, y2,...}, ...] as short for {y1, y2,...} /. First@NSolve[ode, {y1, y2,...},...] (ignoring some trivial checking for more than one solution) would likewise count? – Michael E2 Jul 06 '21 at 13:58
  • Another way to look at Log2 is that it is an implementation of an IEEE 754 recommendation. Others include Internal`Log1p and Internal`Expm1. Or they could be looked as exposing some of the MKL functions. This includes Internal`ReciprocalSqrt and Internal`Square. But not Internal`AbsSquare, which is in neither IEEE 754 nor MKL. Again they are not merely short forms, but separate implementations that reduce round-off error and/or improve speed. – Michael E2 Jul 11 '21 at 16:42

0 Answers0