# Equivalent of the Python Package PaCAL in Julia

**URL:** <https://discourse.julialang.org/t/equivalent-of-the-python-package-pacal-in-julia/79978>\
**Category:** Statistics\
**Tags:** package, statistics, python, random\
**Created:** [April 25, 2022, 8:50am UTC](https://discourse.julialang.org/t/equivalent-of-the-python-package-pacal-in-julia/79978 "2022-04-25T08:50:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [April 25, 2022, 8:50am UTC](https://discourse.julialang.org/t/equivalent-of-the-python-package-pacal-in-julia/79978/1 "2022-04-25T08:50:33Z")

</div>

The [ChebFun MATLAB package](https://github.com/chebfun/chebfun) links to a nice Python package called [`PaCAL`](http://pacal.sourceforge.net).

This nice package allows doing some arithmetic with random variables / distributions and get and object which basically represents the PDF without sampling.  
Behind the scenes it works similarly to the ideas of [ChebFun](https://github.com/chebfun/chebfun) / [`ApproxFun.jl`](https://github.com/JuliaApproximation/ApproxFun.jl).

I was wondering if there is a wrapper around `ApproxFun.jl` which allows similar functionality.

---

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [April 26, 2022, 3:43pm UTC](https://discourse.julialang.org/t/equivalent-of-the-python-package-pacal-in-julia/79978/2 "2022-04-26T15:43:41Z")

</div>

With @sethaxen permission, I am writing his answer to a specific problem I raised on Slack.

### Specific Example

The random variable b is distributed by b \sim \mathcal{Gamma} \left( \alpha, \beta \right) how could one symbolically represent the variable \frac{a}{b} for a constant a ?

### Seth’s Answer

@sethaxen suggested this particular example can be solved using [`Bijectors.jl`](https://github.com/TuringLang/Bijectors.jl) and [`Distributions.jl`](https://github.com/JuliaStats/Distributions.jl):

```julia-auto
using Bijectors, Distributions
d = Gamma(2, 3)
a = 5.0
dtrans_actual = InverseGamma(d.α, inv(d.θ)) * a
bijector = Bijectors.Scale(a) ∘ Bijectors.Exp() ∘ Bijectors.Scale(-1) ∘ Bijectors.Log()
dtrans = Bijectors.transformed(d, bijector)
x = range(quantile(dtrans_actual, [0.01, 0.99])...; length=1000)
logpdf.(dtrans, x) ≈ logpdf.(dtrans_actual, x)

```

The actual answer on Slack:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/8/18d69d00712f8f56494291271db21fcc922d3919.png)

Yet, to @sethaxen knowledge, the examples at `PaCAL` page currently can not be reproduced in Julia’s eco system.
