Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASCII alternative to the Julia function composition (∘) operator?

Is there an ASCII alias for the function composition operator in Julia, ?

In general, is there a way to find ASCII/Unicode variants of operators?

julia> ∘
∘ (generic function with 2 methods)

^Tried this, for example has an alternative:

julia> ≈
isapprox (generic function with 8 methods)
like image 255
ᅙᄉᅙ Avatar asked Sep 03 '25 09:09

ᅙᄉᅙ


2 Answers

For there is no alternative AFAICT. You can check by running:

julia> methods(∘)
# 3 methods for generic function "∘":
[1] ∘(f) in Base at operators.jl:874
[2] ∘(f, g) in Base at operators.jl:875
[3] ∘(f, g, h...) in Base at operators.jl:876

and opening the respective function definition (if you have a properly configured Julia installation just press e.g. 1 and then CTRL-Q) to get:

function ∘ end
∘(f) = f
∘(f, g) = (x...)->f(g(x...))
∘(f, g, h...) = ∘(f ∘ g, h...)

However, it is easy enough just to write:

const compose = ∘

and now you can use compose(f, g) instead of f ∘ g.

For and isapprox it is the case that in the code isapprox function is defined and then:

const ≈ = isapprox

definition is added in floatfuncs.jl.

like image 59
Bogumił Kamiński Avatar answered Sep 04 '25 23:09

Bogumił Kamiński


You can use ComposedFunction(f, g) on Julia 1.6 and above:

julia> ComposedFunction(-, exp)
(-) ∘ exp

Of course, it's a bit cumbersome, because you'd need to nest to compose more functions:

julia> ComposedFunction(-, ComposedFunction(exp, adjoint))
(-) ∘ (exp ∘ adjoint)
like image 30
brainandforce Avatar answered Sep 04 '25 23:09

brainandforce