Search code examples
functionmathfunctional-programmingfunction-compositionmathematical-expressions

Mathematical relations between functions


I'm going to use an exemple to ask my question, lets suppose we have a function G composed of 3 functions f1, f2 and f3, like this picture : g1 the function G = f3(f2(f1(input))) or g = f3 º f2 º f1 an other example when G is composed of 4 functions like so : g2 where f1 and f2 are not necessarily parallel, how can we write G?


Solution

  • You will want to have a look at arrows. With them, your functions could be expressed as follows:

    G1 = f1 >>> f2 >>> f3
    G2 = (f1 *** f2) >>> f3 >>> f4
    

    Notice that there is no difference between one and two lines between two function blocks - two arguments is equivalent to one tuple argument. It only will matter if the lines point to different blocks.