# Cannot build Rational{Poly}

**URL:** <https://discourse.julialang.org/t/cannot-build-rational-poly/1119>\
**Category:** Numerics\
**Created:** [December 23, 2016, 6:40pm UTC](https://discourse.julialang.org/t/cannot-build-rational-poly/1119 "2016-12-23T18:40:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [December 23, 2016, 6:40pm UTC](https://discourse.julialang.org/t/cannot-build-rational-poly/1119/1 "2016-12-23T18:40:06Z")

</div>

Hi,

I tried creating a polynomial ratio:

```julia
using Polynomials

julia> a=Rational{Poly}(Poly([1,2]),Poly([3]))

```

, but got the following error:

```julia
ERROR: TypeError: Rational: in T, expected T<:Integer, got Type{Polynomials.Poly{T<:Number}}

```

It seems that the JuliaDSP group has crated a workaround, called the `PolynomialRatio`:

```julia
DSP.Filters.PolynomialRatio{T<:Number}

```

Would it not be preferable to instead find a way to support `Poly` directly from `Rational`, given that polynomial ratios are not an uncommon occurance?

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [December 23, 2016, 8:12pm UTC](https://discourse.julialang.org/t/cannot-build-rational-poly/1119/2 "2016-12-23T20:12:31Z")

</div>

Since `Rational{T} <: Number`, I’m not sure `Rational{Poly}` makes sense…it’s probably better to make your own type that replicates the behaviour of `Rational`

---

<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:** [December 23, 2016, 10:11pm UTC](https://discourse.julialang.org/t/cannot-build-rational-poly/1119/3 "2016-12-23T22:11:04Z")

</div>

The built in `Rational{T}` type is designed for integer `T`. Designing a type to represent rational functions (ratios of polynomials) would seem to have very little code in common with this except for a few trivial methods, so I’m not sure how much you could gain by making the built-in type more abstract—you would end up having to redefine most of the methods anyway.

(Making the built-in type more abstract is technically difficult because Julia does not have multiple inheritance. You might want to define an `AbstractRational{T}` type that allows `T` to be anything and defines a few simple methods, and then define `Rational{T<:Integer} <: AbstractRational{T}, Number`, but Julia doesn’t allow that. So you can only make `Rational` more abstract at the price of it not being a subtype of `Number`, and that is too high a price to pay for sharing a trivial amount of code.)

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [December 23, 2016, 11:47pm UTC](https://discourse.julialang.org/t/cannot-build-rational-poly/1119/4 "2016-12-23T23:47:46Z")

</div>

There is [https://github.com/aytekinar/RationalFunctions.jl](https://github.com/aytekinar/RationalFunctions.jl)

That may be of help for the task at hand.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [December 24, 2016, 3:30am UTC](https://discourse.julialang.org/t/cannot-build-rational-poly/1119/5 "2016-12-24T03:30:00Z")

</div>

> [@dlfivefifty](#):
>
> Since Rational{T} \<: Number, I’m not sure Rational{Poly} makes sense

Well, `Rational{Poly}` is sort of a number… it just has an unknown in there.

In all seriousness:  
I see what you and Steven are saying. I was not thinking that `Rational` was a `<: Number`.

@j_verzani: I see that you also created your own “rational” object: `RationalFunction` to get your module working.

Maybe we could just define the `//(Poly, Poly)` operator to help construct the DSP module’s `PolynomialRatio` in order to keep things easier to read… or maybe even have it added directly to the Polynomials module.

I noticed @j_verzani uses `/(Poly, Poly)` to construct his polynomials, but I feel like the `//(Poly, Poly)` operator is more consistent with Julia’s current implementation.

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [December 24, 2016, 7:16pm UTC](https://discourse.julialang.org/t/cannot-build-rational-poly/1119/6 "2016-12-24T19:16:17Z")

</div>

The RationalFunctions.jl package is the contribution of @aytekinar. At first, I thought `//` was a better choice, but the focus of that package seems more for polys over Float64 or Complex{Float64}, so it seems to me now that `/` is the better choice.
