Maybe asAs an alternative to Szabolcs' answer I would sugest a different approach, whichthat quite literally follows the mathematical defintiondefinition of $G(f)$. Note that we may avoid the premature evaluation of any argument that is not numeric by using Divisible
instead of EvenQ
or OddQ
:
g[ f_Function ] := Function[ x,
Piecewise[
{
{ f[ FractionalPart @ x ], EvenQ @ Divisible[ Floor[x], 2 ] },
{ 1 / f[ FractionalPart @ x ], OddQNot @ Divisible[ Floor[x], 2 ] }
},
Indeterminate (* in all other cases *)
]
]
Then weWe may dothen use this for numeric arguments:
f = Function[ x, 2 + Sin[x] ];
h = g[f]; (* or directly g[f] @ x *)
h[ 5/2 ]
$2 + \text{Sin}[\frac{1}{2}]$
In the given form we can now also work symbolically:
h[x] // Head
Piecewise