# Package interoperability showcases

**URL:** <https://discourse.julialang.org/t/package-interoperability-showcases/33734>\
**Category:** General Usage\
**Created:** [January 24, 2020, 11:12am UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734 "2020-01-24T11:12:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [January 24, 2020, 11:12am UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734/1 "2020-01-24T11:12:15Z")

</div>

Picking up on our discussion on nice packages of the Julia ecosystem, [What packages are state of the art…](https://discourse.julialang.org/t/what-package-s-are-state-of-the-art-or-attract-you-to-julia-and-make-you-stay-there-not-easily-replicateable-in-e-g-python-r-matlab/11294/54) I argued that naming isolated packages does the ecosystem disregard because things julia-magically work together and therefore packages do not only add to the ecosystem but multiply. For example you model a trebuchet with `RigidBodyDynamics` on one day and find the optimal proportions on the next day with `ForwardDiff` . I still (2020) owe you to do that actually.

What kind of short and nice examples with maybe surprising and creative use of package combinations can we come up?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 24, 2020, 12:06pm UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734/2 "2020-01-24T12:06:05Z")

</div>

Eg

- ForwardDiff with anything, Zygote with a lot of things
- various `<: AbstractArray` implementations with anything that uses, well, arrays
- various packages implementing operations on numbers, eg Unitful.jl, with anything involving these operations

For reasonably complex projects, it is more or less inevitable to have examples of [the unreasonable effectiveness of multiple dispatch](https://www.youtube.com/watch?v=kc9HwsxE1OY&t=107s).

But as for _showcasing_, especially to people who do not yet use Julia, I am not sure these things are useful. If someone has not used multiple dispatch before, it is difficult to imagine how nice it is.

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [November 28, 2020, 10:30pm UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734/3 "2020-11-28T22:30:48Z")

</div>

An example by Luca Ferranti what illustrates very well what I am looking for. Context is the question, how to _prove_ that a function is convex.

> Since a 1D-function is convex/concave over an interval if it has positive/negative second derivative, you can use interval arithmetic to get a certificate of the convexity of the function. Here is a MWE
> 
> ```julia
> using ForwardDiff, IntervalArithmetic
> df = x -> ForwardDiff.derivative(exp, x)
> ddf = x -> ForwardDiff.derivative(df, x)
> 
> ```
> 
> ```julia
> julia> ddf(0..1)
> [1, 2.71829]
> 
> ```
> 
> the last result tells you that the second derivative is always above zero and hence the function is convex over that interval.

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [March 23, 2021, 2:26pm UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734/4 "2021-03-23T14:26:21Z")

</div>

Via @Keno’s Twitter

> <https://twitter.com/KenoFischer/status/1369853531423993858?s=20>

![EwKyDrfXEAAcDTt](https://global.discourse-cdn.com/julialang/original/3X/a/9/a971068b9ab7eea494e480de78de06a6c878038d.png)

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [June 16, 2021, 1:48pm UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734/5 "2021-06-16T13:48:07Z")

</div>

One more via @dlfivefifty 's Twitter:

> <https://twitter.com/dlfivefifty/status/1404785545474097159?s=20>

```julia
# InfiniteLinearAlgebra.jl+IntervalArithmetic.jl

julia> J̃ = z -> (SymTridiagonal(-2*(0:∞)/z, ones(∞)) \ [1; zeros(∞)])[1];

julia> roots(J̃, 2.4..2.405)[1].interval
[2.40482, 2.40483]

```

---

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [June 16, 2021, 2:00pm UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734/6 "2021-06-16T14:00:56Z")

</div>

We have a few long-form examples under the “Ecosystem Integration” section of the [Agents.jl documentation](https://juliadynamics.github.io/Agents.jl/stable/).

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [June 24, 2021, 4:58pm UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734/7 "2021-06-24T16:58:31Z")

</div>

Four-way 🙂

```julia

using Turing, Distributions, IntervalArithmetic, ForwardDiff
@model model() = begin
    X ~ Normal()
end

v = Turing.VarInfo(model())
sampler = Turing.SampleFromPrior()
ctx = DynamicPPL.DefaultContext()

function ℓ(θ)
    new_vi = Turing.VarInfo(v, sampler, [θ])
    model()(new_vi, sampler, ctx)
    logp = Turing.getlogp(new_vi)
    return logp
end

C = sup(ForwardDiff.derivative(ℓ, -1..2))

```

(This computes the upper bound of a gradient of a probability density generated by `Turing` model, relevant for sampling this posterior with PDMP methods )

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [July 2, 2021, 7:49am UTC](https://discourse.julialang.org/t/package-interoperability-showcases/33734/8 "2021-07-02T07:49:35Z")

</div>

> Question on slack: wonder if any symbolic package can perform the completing the square in the Gaussian density `f(x,F,Γ) = exp(((-x^2) /2)*(Γ)+ x*F)`

Yes:

```julia
using Mitosis
using Symbolics
@variables F,Γ
p = convert(Mitosis.Gaussian{(:μ,:Σ)}, Mitosis.Gaussian{(:F,:Γ)}(F, Γ))

```

There it is

```julia
julia> p
Gaussian{(:μ, :Σ)}((μ = F*(Γ^-1), Σ = Γ^-1))

```
