# Operational calculus in julia?

**URL:** <https://discourse.julialang.org/t/operational-calculus-in-julia/24415>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 20, 2019, 10:29pm UTC](https://discourse.julialang.org/t/operational-calculus-in-julia/24415 "2019-05-20T22:29:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xtalax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xtalax/32/35293_2.png) [@xtalax](https://discourse.julialang.org/u/xtalax)\
**Post date:** [May 20, 2019, 10:29pm UTC](https://discourse.julialang.org/t/operational-calculus-in-julia/24415/1 "2019-05-20T22:29:15Z")

</div>

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:

```julia
 □ = (∇ - δₜ)

```

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

```julia

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

```julia
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 🙂

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [May 20, 2019, 11:30pm UTC](https://discourse.julialang.org/t/operational-calculus-in-julia/24415/2 "2019-05-20T23:30:34Z")

</div>

You can create types with objects that behave as functions

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

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 21, 2019, 1:07am UTC](https://discourse.julialang.org/t/operational-calculus-in-julia/24415/3 "2019-05-21T01:07:19Z")

</div>

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

> **[GitHub - SciML/DiffEqOperators.jl: Linear operators for discretizations of...](https://github.com/SciML/DiffEqOperators.jl)**
>
> Linear operators for discretizations of differential equations and scientific machine learning (SciML) - GitHub - SciML/DiffEqOperators.jl: Linear operators for discretizations of differential equa...

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 21, 2019, 12:16pm UTC](https://discourse.julialang.org/t/operational-calculus-in-julia/24415/4 "2019-05-21T12:16:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xtalax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xtalax/32/35293_2.png) [@xtalax](https://discourse.julialang.org/u/xtalax)\
**Post date:** [January 12, 2023, 4:00pm UTC](https://discourse.julialang.org/t/operational-calculus-in-julia/24415/5 "2023-01-12T16:00:02Z")

</div>

This is a historic post for me, I think this was when I learned of DiffEqOperators, which has led to me being lead dev of MethodOfLines. Thanks Chris!
