Operational calculus in julia?

If it were possible to give functions types in Julia, it would ease the implementation of operational calculus in the language.

I’m thinking about ways to implement differential operators in julia, so that it would be possible to write something like the following:

 □ = (∇ - δₜ)

Where , and δₜ are functions with methods that accept tuples of the same type signature, modified by the - operator to give a new function as an output
By being able to give functions a type, like


abstract function LinearOperator(::FunctionSpace) <: Function end

function ∇(A::FunctionSpace) <: LinearOperator
     ~some code~
end

function δₜ(A::FunctionSpace) <: LinearOperator
     ~some code~
end

It would be possible to overload the - operator and other operators to give sensible functions as the output, with some special syntax to let the compiler know where in the syntax tree each atomic function should be evaluated, perhaps like

Base.*(f::LinearOperator, g::LinearOperator) = f(g(|>))

Base.-(f::LinearOperator, g::LinearOperator) = f(|>) - g(|>)

function Base.^(f::LinearOperator, n::Int) 
     out = (|>)
     for i in 1:n
         out = f*out
     end
     return out
end

Is this feasable? Already possible with different syntax?
Thanks for reading, I’d love to hear some thoughts on this :slight_smile:

1 Like

You can create types with objects that behave as functions

https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects-1

2 Likes

You’ve basically described the AbstractDiffEqOperator interface used in DifferentialEquations.jl, and how the lazy finite difference operators are built (using call-overloaded types).

1 Like

I’ve moved this topic from #dev to #user and tagged it as question rather than proposal since it’s already possible and the main question is how.

1 Like