# BudanTables.jl

**URL:** <https://discourse.julialang.org/t/budantables-jl/75944>\
**Category:** Package Announcements\
**Tags:** package, plotting, roots, polynomials, recipe\
**Created:** [February 7, 2022, 10:53am UTC](https://discourse.julialang.org/t/budantables-jl/75944 "2022-02-07T10:53:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmo/32/14820_2.png) [@BMO](https://discourse.julialang.org/u/BMO)\
**Post date:** [February 7, 2022, 10:53am UTC](https://discourse.julialang.org/t/budantables-jl/75944/1 "2022-02-07T10:53:51Z")

</div>

I implemented a package for plotting the Budan’s table of a polynomial (Budan-Fourier theorem uses it for root counting, see [Improved Budan-Fourier Count for Root Finding](https://hal.inria.fr/hal-00653762/document)).

[https://github.com/LauraBMo/BudanTables.jl](https://github.com/LauraBMo/BudanTables.jl)

By default, polynomials and polynomials operations are represented using [Polynomials.jl](https://github.com/JuliaMath/Polynomials.jl), but the user may use other implementations.

Comments are highly welcome!  
Actually, I have two questions:

1.- Is there a more generic way to use [Polynomials.jl](https://github.com/JuliaMath/Polynomials.jl)?  
For example, (it is not its intended use, but) with [Requires.jl](https://github.com/JuliaPackaging/Requires.jl) I could use [Polynomials.jl](https://github.com/JuliaMath/Polynomials.jl) only when Polynomials.jl is loaded by the user.  
But how do I implement functions depending on `derivative` or `degree` outside of the `@require Polynomials="..."` block?

An option could be to adapt the trick

```julia
const _ROOTS = Ref{Function}(roots)

function set_getting_roots(f)
    _ROOTS[] = f
end

```

to something like

```julia
  const _ROOTS = Ref{Function}()
  const _DERIVATIVE = Ref{Function}()
  const _DEGREE = Ref{Function}()

  function set_getting_roots(f)
      _ROOTS[] = f
  end
  # add equivalent functions for derivative and degree

  function __init__ ()
      @require Polynomials="..." begin
            set_getting_roots(Polynomials.roots)
           # add equivalents for derivative and degree 
      end
  end

```

But it sounds too demanding for users who don’t want to use Polynomials.jl. As they have to define/load the functions `roots`, `derivative`, `degree` and then pass them to ButanTables.jl via the functions `set_getting_roots`, `set_getting_derivative`…

2.- It is my first time using [RecipesBase.jl](https://github.com/JuliaPlots/RecipesBase.jl) for [Plots.jl](https://github.com/JuliaPlots/Plots.jl), does it look good?  
I feel the way I implemented the legend is way too hacky.

Many thanks!

---

<div class="post-metadata">

**Author:** ![BMO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmo/32/14820_2.png) [@BMO](https://discourse.julialang.org/u/BMO)\
**Post date:** [February 8, 2022, 3:04pm UTC](https://discourse.julialang.org/t/budantables-jl/75944/3 "2022-02-08T15:04:57Z")

</div>

I think question 1 falls into [Optionnal dependencies](https://discourse.julialang.org/t/optional-dependencies-requires-jl/3294/20) and [allow options for packages](https://github.com/JuliaLang/julia/issues/20082).

I end up using Polynomials.jl to represent polynomials and, via Requires.jl, the user can choose between `Polynomials.roots` and `PolynoamialRoots.roots`. It is also possible not to use Polynomials.jl but some redundant code will be loaded anyways.
