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~

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

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
     return out

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



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