Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement sinc #67

Open
PerezHz opened this issue Oct 11, 2016 · 7 comments
Open

Implement sinc #67

PerezHz opened this issue Oct 11, 2016 · 7 comments

Comments

@PerezHz
Copy link
Contributor

PerezHz commented Oct 11, 2016

(Edit: I corrected the expression for sinc(x); the way I originally wrote it was mistaken)

Currently (TaylorSeries v0.3.0.), one can implement $sinc(x)=sin(\pi x)/(\pi x)$ for Taylor1 variables manually, doing, for example

julia> using TaylorSeries #one of the most awesome Julia packages in the world

julia> import Base.sinc #so that we don't overwrite any methods for sinc

julia> sinc{T}(x::Taylor1{T}) = sin(pi*x)/(pi*x) #implementing manually sinc(x)=sin(pi*x)/(pi*x)
sinc (generic function with 7 methods)

julia> x = Taylor1([0.0, 1.0], 16) #a Taylor1 variable
 1.0 t + 𝒪(t¹⁷)

julia> sinc(x) #evaluate sinc for a Taylor1 variable
 1.0 - 1.6449340668482262+ 0.8117424252833536 t⁴ - 0.1907518241220842 t⁶ + 0.026147847817654793 t⁸ - 0.002346081035455823 t¹⁰ + 0.00014842879303107094 t¹² - 6.975873661656378e-6 t¹⁴ + 𝒪(t¹⁷)

But perhaps it would be nice to have this implemented within TaylorSeries without having to do it manually :)

@lbenet
Copy link
Member

lbenet commented Oct 11, 2016

Indeed, it would be a good idea to implement it from scratch!

Cc: @blas-ko

@dpsanders
Copy link
Contributor

What do you mean by "from scratch"? Isn't the definition given by @PerezHz enough?

@lbenet
Copy link
Member

lbenet commented Oct 11, 2016

What I mean is that you may write down a differential equation, whose solution is the sinc function. That differential equation will define a recursion formula which you can implement and get the result.

I agree that the solution of @PerezHz is good enough (though, does it work with TaylorN?), and eventually (if needed) the recursion formula could be implemented...

@PerezHz
Copy link
Contributor Author

PerezHz commented Oct 12, 2016

My solution doesn't work for TaylorN :(

julia> using TaylorSeries

julia> x, y = set_variables("x y", order=25)
2-element Array{TaylorSeries.TaylorN{Float64},1}:
  1.0 x + 𝒪(‖x‖²⁶)
  1.0 y + 𝒪(‖x‖²⁶)

julia> sin(pi*x)/(pi*x)
ERROR: AssertionError: b0 != zero(b0)
 in /(::TaylorSeries.TaylorN{Float64}, ::TaylorSeries.TaylorN{Float64}) at /Users/Jorge/.julia/v0.5/TaylorSeries/src/TaylorN.jl:496

Would it be feasible to implement sinc for TaylorN's using a recursion formula as you described, @lbenet ?

@freemin7
Copy link

freemin7 commented Aug 2, 2020

Why sin(x*pi) and not sinpi(x)?

@lbenet
Copy link
Member

lbenet commented Aug 2, 2020

Why sin(x*pi) and not sinpi(x)?

Thanks for bringing this up @freemin7 ! The short answer, I think, is because we haven't implemented sinpi and related functions. As far as I know, sinpi(x) is more accurate than sin(pi*x), but I do not know the details. You are welcome to make a pull request!

@lbenet
Copy link
Member

lbenet commented Aug 2, 2020

Would it be feasible to implement sinc for TaylorN's using a recursion formula as you described, @lbenet ?

@PerezHz Sorry for having overlooked this, and getting back too it sooo late. First, the reason that it doesn't work for TaylorN essentially is because the division for Taylor1 allows "to factorize", whereas this is not (yet) possible to do for TaylorN. Now, would it work if we implement it from a "differential equation" (recursion formula); I think so, but I do not know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants