Skip to main content
Fix typo in function definition.
Source Link
gidds
  • 795
  • 4
  • 8

Other answers have explained this well in programming terms. But I think it's possible using only familiar mathematical notation, too. Here goes…

Suppose you have three functions: f, g, and h, so that:
f(x) = (some function of x)
g(x) = (some other function of x)
h(x) = (yet another function of x)

(Of course, those are three different ‘x’s!)

And suppose that you want to apply them in turn, i.e. to calculate
f(g(h(x)))
for some x. Or in other words, you want to compose the three functions.

To simplify this, let's define a couple of new functions, which I'm going to give the stunningly original names fg and gh:
let fg(x) = f(g(x))
and
let gh(x) = hg(gh(x))

So we can use them to express our desired result in three different ways:
fg(h(x))
f(gh(x))
f(g(h(x)))

All three of those give the same result (for all values of x). That's because it doesn't matter whether we compose f and g, and then compose the result with h, or we compose f with the result of composing g and h; the end result is the same.

I hope you can see the parallel with addition being associative. The above is saying that function composition is associative.


(‘Real’ mathematics would write this in a different notation, using the ring operator ‘∘’ to represent function composition:
(f ∘ g) ∘ h = f ∘ (g ∘ h)
That's simpler and makes the parallel clearer, but of course it's more abstract without the ‘x’s, and harder to follow if you're not used to it. But it means exactly the same.)

Other answers have explained this well in programming terms. But I think it's possible using only familiar mathematical notation, too. Here goes…

Suppose you have three functions: f, g, and h, so that:
f(x) = (some function of x)
g(x) = (some other function of x)
h(x) = (yet another function of x)

(Of course, those are three different ‘x’s!)

And suppose that you want to apply them in turn, i.e. to calculate
f(g(h(x)))
for some x. Or in other words, you want to compose the three functions.

To simplify this, let's define a couple of new functions, which I'm going to give the stunningly original names fg and gh:
let fg(x) = f(g(x))
and
let gh(x) = h(g(x))

So we can use them to express our desired result in three different ways:
fg(h(x))
f(gh(x))
f(g(h(x)))

All three of those give the same result (for all values of x). That's because it doesn't matter whether we compose f and g, and then compose the result with h, or we compose f with the result of composing g and h; the end result is the same.

I hope you can see the parallel with addition being associative. The above is saying that function composition is associative.


(‘Real’ mathematics would write this in a different notation, using the ring operator ‘∘’ to represent function composition:
(f ∘ g) ∘ h = f ∘ (g ∘ h)
That's simpler and makes the parallel clearer, but of course it's more abstract without the ‘x’s, and harder to follow if you're not used to it. But it means exactly the same.)

Other answers have explained this well in programming terms. But I think it's possible using only familiar mathematical notation, too. Here goes…

Suppose you have three functions: f, g, and h, so that:
f(x) = (some function of x)
g(x) = (some other function of x)
h(x) = (yet another function of x)

(Of course, those are three different ‘x’s!)

And suppose that you want to apply them in turn, i.e. to calculate
f(g(h(x)))
for some x. Or in other words, you want to compose the three functions.

To simplify this, let's define a couple of new functions, which I'm going to give the stunningly original names fg and gh:
let fg(x) = f(g(x))
and
let gh(x) = g(h(x))

So we can use them to express our desired result in three different ways:
fg(h(x))
f(gh(x))
f(g(h(x)))

All three of those give the same result (for all values of x). That's because it doesn't matter whether we compose f and g, and then compose the result with h, or we compose f with the result of composing g and h; the end result is the same.

I hope you can see the parallel with addition being associative. The above is saying that function composition is associative.


(‘Real’ mathematics would write this in a different notation, using the ring operator ‘∘’ to represent function composition:
(f ∘ g) ∘ h = f ∘ (g ∘ h)
That's simpler and makes the parallel clearer, but of course it's more abstract without the ‘x’s, and harder to follow if you're not used to it. But it means exactly the same.)

Source Link
gidds
  • 795
  • 4
  • 8

Other answers have explained this well in programming terms. But I think it's possible using only familiar mathematical notation, too. Here goes…

Suppose you have three functions: f, g, and h, so that:
f(x) = (some function of x)
g(x) = (some other function of x)
h(x) = (yet another function of x)

(Of course, those are three different ‘x’s!)

And suppose that you want to apply them in turn, i.e. to calculate
f(g(h(x)))
for some x. Or in other words, you want to compose the three functions.

To simplify this, let's define a couple of new functions, which I'm going to give the stunningly original names fg and gh:
let fg(x) = f(g(x))
and
let gh(x) = h(g(x))

So we can use them to express our desired result in three different ways:
fg(h(x))
f(gh(x))
f(g(h(x)))

All three of those give the same result (for all values of x). That's because it doesn't matter whether we compose f and g, and then compose the result with h, or we compose f with the result of composing g and h; the end result is the same.

I hope you can see the parallel with addition being associative. The above is saying that function composition is associative.


(‘Real’ mathematics would write this in a different notation, using the ring operator ‘∘’ to represent function composition:
(f ∘ g) ∘ h = f ∘ (g ∘ h)
That's simpler and makes the parallel clearer, but of course it's more abstract without the ‘x’s, and harder to follow if you're not used to it. But it means exactly the same.)