# What do you call something that modifies the input and something that modifies the output?

If you have: `y=f(x)`
and you call a function to modify x before you pass it into f: `y=f(g(x))`, what do you call g?
or what do you call g if it modifies the output of f: `y=g(f(x))`

I think this is function composition, so would you call the outer function ‘left’ and the inner one ‘right’?
Or are there more specific terms, since I think that left and right (or inner and outer) don’t describe this well enough because they can apply to many scenarios?

I know the best thing to name them is dependent on the context, and that is what I will probably do, but I am curious about the general case

1 Like

I would refer to the “inner” or right as the parameter and the outside as just the function. Not sure if that’s the totally correct way to do it as I’m sure others might say it differently

I probably should have added an example, but I meant that the function ‘f’ is sort of the main function, such as math.noise(), and g would transform either the input/output of f
So if g is transforming the output, I don’t think calling it ‘function’ would really work, and if it were transforming the input, I think that parameter wouldn’t fit either since the input to g & the input of f (output of g) are the parameters, not the function g

Do you mean something like:

``````local x = f(y)
g(x)
-- x itself has been modified, and is no longer what it used to be
``````

Could you be referring to an output parameter?

I’m not sure I understand your example

@TrippyV
I do not think so, the only parameter is the input: x
y is the final output, but if the pattern is g(f(x)) then g’s input is the return value of f(x)

What you’re describing is just a normal parameter then, if I’m not mistaken.

I know that x is called a parameter, I’m wondering what to call g in these cases:

That is just function composition like you described, so yes left and right.

2 Likes

“Right” composition is common enough that it is often referred to by the slightly fancier name of “precomposition”. Usually when that is the case, the word “composition” is reserved for “left” composition. Just my experience, though.

2 Likes

I’m a little confused, are you talking about the order in which to apply the transformations in f∘g?
I mean to ask what to call the function applied first and the one applied last, ideally if one of them is applying a slight transformation to a big function like math.noise (my first reply to TrippyV)
Calling them pre and post sounds good too though if that’s what you were saying

There’s no particularly special name for g in the case of f(g(x)). Written this way, it’s presumed to be a simple composition of functions, and for any more complicated example it becomes sort of pointless to start trying to name the parts. Like what if you had f(g(x)+h(x)), now which is the “right” function?

Normally, for the case of f(g(x)) you would not describe g as the argument or operand to f, because f and g here are are presumably both functions that take values such as real numbers as input. That is to say, f operates on the codomain of g, it does not take a function itself as input. You could define an operator F, for which y=F(g), but this is a more general concept than function composition (F could be a function such that y(x) ends up being the same as f(g(x)), but it could also be an operation you can’t express as a function, like differentiation, such that y(x) could be g’(x)).

4 Likes