Playing with function composition, is there a name for what I'm doing?

For AC analysis of circuits the following is handy:

using Plots

ZL(L) = f -> im*2π*f*L
ZC(C) = f -> 1/(im*2π*f*C)
ZR(R) = f -> R
series(a,b,c...) = f -> sum([x(f) for x in [[a,b]; [c...]]])
parallel(a,b,c...) = f -> 1/(sum([1/x(f) for x in [[a,b]; [c...]]]))
voltage_divider(top,bottom) = f -> bottom(f)/(top(f)+bottom(f))

# textbook example from p 157 of https://web.stanford.edu/class/archive/engr/engr40m.1178/reader/chapter7.pdf
G = voltage_divider(series(ZR(4.7e3),ZC(47e-9)), parallel(ZC(1e-9),ZR(2.2e3)))
plot([10^x for x in 1.9:0.001:7.1],f->20*log(abs(G(f))),leg=false,xscale=:log10)

This lets me write simple expressions for complicated circuit structures and avoid tons of algebra (see the referenced book for an example).

I’m curious if there is a name for this type of manipulation of functions with a common argument.

Thanks.

3 Likes

I don’t know if there is a more specific term for this than “functional programming”.

By the way, I think it’s neat that you’ve found a functional style that happens to be very similar to the way Mux.jl handles web requests: https://github.com/JuliaWeb/Mux.jl/blob/c3f12af75de425bfc3c7a6fdb400332398be3005/src/Mux.jl#L9-L18

1 Like

That’s cool! I asked the question because I couldn’t figure out how to search for the pattern - it’s pretty simple but just a little different arrangement from the basic f∘g thing.