# \[ANN\] RationalFunctionApproximation.jl

**URL:** <https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118>\
**Category:** Package Announcements\
**Tags:** package, announcement, complex-numbers, approximation\
**Created:** [September 21, 2023, 6:46pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118 "2023-09-21T18:46:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Post date:** [September 21, 2023, 6:46pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118/1 "2023-09-21T18:46:18Z")

</div>

I am pleased to announce the initial release of [RationalFunctionApproximation.jl](https://github.com/complexvariables/RationalFunctionApproximation.jl), which provides automatic rational function approximation in the complex plane.

It uses an updated version of the AAA algorithm ([Driscoll, Nakatsukasa, Trefethen](https://arxiv.org/abs/2305.03677)) to adaptively sample the domain of the function to ensure accurate approximations when a singularity is very close to or even on the domain.

The domain can be an interval or any path in the complex plane, and the algorithm iterates on the degree of the approximation until the domain, and optionally its interior or exterior, is free of poles. This usually is enough to overcome the problem of undesired poles in a rational approximation.

Example of a function with three zeros on the unit circle and a pole exterior to that:

 ![](https://global.discourse-cdn.com/julialang/original/3X/c/f/cf58415d7a02605f6a25c41338b011a91d6808e6.png)

(Plot courtesy of [Makie.jl](https://docs.makie.org/stable/) and [DomainColoring.jl](https://eprovst.github.io/DomainColoring.jl/stable/).) The rational approximant shown here is of type (9,9), interpolating the function at 10 points on the unit circle, and is accurate to more than 13 digits on the circle.

More lovely examples are in the [docs](https://complexvariables.github.io/RationalFunctionApproximation.jl/stable/).

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 21, 2023, 7:10pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118/2 "2023-09-21T19:10:00Z")

</div>

Thanks for this nice package. If you will, what is the rationale for publishing the reference [article](https://arxiv.org/abs/2305.03677) on arXiv, a free service for scientific articles, and then using proprietary Matlab code in it instead of Julia?

---

<div class="post-metadata">

**Author:** ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Post date:** [September 21, 2023, 7:27pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118/3 "2023-09-21T19:27:22Z")

</div>

The Matlab code we present in the paper is not itself proprietary, and it’s a language that is well understood by most of the readership of the journal we have targeted. A google search for “matlab” on [arxiv.org](http://arxiv.org) turns up over 12 million hits, so it’s widely recognized by the arXiv readership, as well.

If we publish Julia code alongside Matlab code, it’s going to do more to draw in current Matlab users than pretending Matlab doesn’t exist and offering only code they can’t read or use.

---

<div class="post-metadata">

**Author:** ![jondeuce](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jondeuce/32/16378_2.png) [@jondeuce](https://discourse.julialang.org/u/jondeuce)\
**Post date:** [September 21, 2023, 8:03pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118/4 "2023-09-21T20:03:56Z")

</div>

Really cool package. How does it compare to [Remez.jl](https://github.com/simonbyrne/Remez.jl)? It seems like a generalization with a more advanced underlying algorithm, is that right?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 21, 2023, 8:10pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118/5 "2023-09-21T20:10:17Z")

</div>

> [@tobydriscoll](#):
>
> It uses an updated version of the AAA algorithm ([Driscoll, Nakatsukasa, Trefethen](https://arxiv.org/abs/2305.03677)) to adaptively sample the domain of the function to ensure accurate approximations when a singularity is very close to or even on the domain.

How does it compare to the AAA implementation in [BaryRational.jl](https://github.com/macd/BaryRational.jl)?

---

<div class="post-metadata">

**Author:** ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Post date:** [September 22, 2023, 4:21pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118/6 "2023-09-22T16:21:38Z")

</div>

BaryRational works with the original discrete AAA algorithm, which uses an initial discretization of the domain that does not change. This is often fine, unless poles get as close to the domain as the spacing between the sample points.

This package uses a new, continuous form of AAA referenced in my post that adaptively samples the domain, which is possibly more efficient for smooth functions and more reliable for functions with singularities near the domain.

---

<div class="post-metadata">

**Author:** ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Post date:** [September 22, 2023, 4:23pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118/7 "2023-09-22T16:23:39Z")

</div>

The approximations are based on least squares minimization, as opposed to the max norm. However, there is an iterative reweighting scheme that can approach the minimax approximation. There’s a [page in the docs](https://complexvariables.github.io/RationalFunctionApproximation.jl/stable/minimax/) showing this a bit.
