# Alter evaluation order when applying scalar multiplication to function

Consider the following program:

g = 2f;
g[x] (* (2f)[x] *)


Is there any way I can change the above expression to have it return 2 f[x]?

With Hold construct perhaps? Sorry, I'm really not familiar with these Hold* functions.

I know I could easily define g=2f[#]& and it would work fine, but in my case what I'm really trying to achieve is something like that :

Transpose @ MapThread[Standardize[{##}, Mean, 2 StandardDeviation] &, xs]


Unfortunately, (2 StandardDeviation) is taken as a single entity. Having a whole Function would make it much more messy.

• There isn't really a better way, just alternatives with similar level of complexity: For example: g = (2#)&@*f uses Composition.
– Jens
Apr 12, 2015 at 4:53
• Yeah, I think I'll just settle for Function[2 StandardDeviation[##]] Apr 12, 2015 at 4:54
– Jens
Dec 16, 2015 at 21:59

As mentioned in the comments, you could use Composition as follows:

g = (2 #) &@*f

(* ==> 2 #1 &@*f *)

g[x]

(* ==> 2 f[x] *)


Your own solution using Function is of course also fine, and one could make it slightly more user-friendly by defining the corresponding scalar multiplication operation something like this:

CenterDot[x_, y_] := Function[z, x y[z]]

g = 2·f

(* ==> Function[z$, 2 f[z$]] *)

g[x]

(* ==> 2 f[x] *)


This would allow you to use CenterDot to define similar constructs on the fly in a more readable form, by using the keyboard shortcut esc.esc ot enter the scalar multiplication. So as an in-line definition this would look like this:

(2·h)[x]

(* ==> 2 h[x] *)