# Unnormalized sinc

**URL:** https://discourse.julialang.org/t/unnormalized-sinc/25015
**Category:** General Usage
**Tags:** question
**Created:** [June 6, 2019, 4:25pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015 "2019-06-06T16:25:51Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![adamnemecek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamnemecek/32/4173_2.png) [@adamnemecek](https://discourse.julialang.org/u/adamnemecek)
#### Post date: [June 6, 2019, 4:25pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/1 "2019-06-06T16:25:52Z")

</div>

The current implementation of `sinc` is the normalized one. I think it’s a good idea to also have the unnormalized one. I’m not sure what name to pick.  
Would there be any interest in this function?

> **[Sinc function](https://en.wikipedia.org/wiki/Sinc_function)**
>
> In mathematics, physics and engineering, the sinc function, denoted by sinc(x), has two forms, normalized and unnormalized.
> In mathematics, the historical unnormalized sinc function is defined for x ≠ 0 by
> Alternatively, the unnormalized sinc function is often called the sampling function, indicated as Sa(x).

---

<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: [June 6, 2019, 4:36pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/2 "2019-06-06T16:36:50Z")

</div>

> [@adamnemecek](#):
>
> The current implementation of `sinc` is the normalized one

Note that this is the same `sinc` definition as the one used in Matlab, Numpy, and R. (But SymPy and Mathematica use the unnormalized definition.) It seems like most languages picked one definition and stuck with it, so I don’t see a pressing need to have both in Julia.

However, it wouldn’t be terrible to add something like this to the SpecialFunctions package. I can’t find a standard naming convention to distinguish the two, so it seems you’d have to make up something, perhaps `sincu`.

---

<div class="post-metadata">

### Author: ![adamnemecek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamnemecek/32/4173_2.png) [@adamnemecek](https://discourse.julialang.org/u/adamnemecek)
#### Post date: [June 6, 2019, 4:51pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/3 "2019-06-06T16:51:43Z")

</div>

Ok will do.

The simplest implementation is probably sincu(x) = sinc(x/pi). Or should I just copy paste the sinc implementation and remove the pi multiplication?

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [June 6, 2019, 4:56pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/4 "2019-06-06T16:56:28Z")

</div>

I suggest the name “sphj0” since this function is the spherical bessel function of the first kind of order zero: [Bessel function - Wikipedia](https://en.wikipedia.org/wiki/Bessel_function#Spherical_Bessel_functions)

---

<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: [June 6, 2019, 5:04pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/5 "2019-06-06T17:04:09Z")

</div>

> [@adamnemecek](#):
>
> The simplest implementation is probably sincu(x) = sinc(x/pi). Or should I just copy paste the sinc implementation and remove the pi multiplication?

To my mind, the only reason for defining a `sincu` special function would be to remove the cost of the division. If you just define `sincu(x) = sinc(x/pi)` there’s not much point — it’s just as easy (and probably clearer) for the caller to write `sinc(x/pi)` themselves. But even saving the cost of the division only saves about 10% of the time on my machine, so I still don’t think this is worth the effort.

---

<div class="post-metadata">

### Author: ![adamnemecek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamnemecek/32/4173_2.png) [@adamnemecek](https://discourse.julialang.org/u/adamnemecek)
#### Post date: [June 6, 2019, 9:23pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/6 "2019-06-06T21:23:11Z")

</div>

I guess the reason to introduce it is to make it clear that the other is normalized.

I spent some time debugging my numerics until I realized that it’s normalized and that’s where the numbers were off due to that.

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [June 7, 2019, 5:39am UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/7 "2019-06-07T05:39:41Z")

</div>

I’d say the main reason to define both the unnormalized and the normalized `sinc` functions is the same reason that both `sin` and `sinpi` are defined, namely the accuracy near multiples of pi and 1 respectively,

`sinc(Float64(pi), normalized=false)` should return approximately 3.9e-17 based on the difference between `pi` and `Float64(pi)`.

I would use a keyword argument with the existing function rather than inventing a new name. Julia is probably smart enough to avoid any performance penalty.

---

<div class="post-metadata">

### Author: ![adamnemecek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamnemecek/32/4173_2.png) [@adamnemecek](https://discourse.julialang.org/u/adamnemecek)
#### Post date: [June 14, 2019, 7:39pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/8 "2019-06-14T19:39:43Z")

</div>

Keyword argument is not a bad idea. Should I implement this?

---

<div class="post-metadata">

### Author: ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)
#### Post date: [January 29, 2021, 5:15am UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/9 "2021-01-29T05:15:56Z")

</div>

Sorry for invoking an old post. But how does this discussion turns out? I’d like to have sinc = sin(x)/x to eliminate the cost of a division.

---

<div class="post-metadata">

### Author: ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)
#### Post date: [January 29, 2021, 7:34am UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/10 "2021-01-29T07:34:38Z")

</div>

Is one division/multiplication of `sin(x*pi) ` really that critical for you?

If yes, you could copy paste the code from Base.Math and remove the division.

---

<div class="post-metadata">

### Author: ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)
#### Post date: [January 29, 2021, 7:37am UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/11 "2021-01-29T07:37:37Z")

</div>

Not at all. But if there is a better choice, why not use it?

---

<div class="post-metadata">

### Author: ![fph](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fph/32/17159_2.png) [@fph](https://discourse.julialang.org/u/fph)
#### Post date: [January 29, 2021, 8:58am UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/12 "2021-01-29T08:58:51Z")

</div>

> [@roflmaostc](#):
>
> Is one division/multiplication of `sin(x*pi) ` really that critical for you?

I think that the main point is being able getting an exact result for rational multiples of pi: for the sine function, for instance, `sinpi(1) == 0`, while `sin(1*Float64(pi)) != 0`. `sinc` is similar.

This suggests that it makes sense to have the normalized version as the first-class object: defining `sincu(x) = sinc(x/pi)` is harmless (because at that point you have anyway an inexact `x` to start with) while defining `sinc(x) = sincu(x*pi)` will lose accuracy for rational values of `x`.

As for the naming, uniformity would suggest `sincpi` for the normalized version and `sinc` for the normalized version, in analogy to `sinpi` and `sin`, but I am afraid it is too late to revert the choice now.

---

<div class="post-metadata">

### Author: ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)
#### Post date: [April 27, 2021, 11:16am UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/13 "2021-04-27T11:16:42Z")

</div>

> [@fph](#):
>
> As for the naming, uniformity would suggest `sincpi` for the normalized version and `sinc` for the normalized version, in analogy to `sinpi` and `sin` , but I am afraid it is too late to revert the choice now.

That really is a shame. That would have been such a consistent way of doing it.

---

<div class="post-metadata">

### Author: ![waldyrious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waldyrious/32/80_2.png) [@waldyrious](https://discourse.julialang.org/u/waldyrious)
#### Post date: [April 28, 2021, 11:27am UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/14 "2021-04-28T11:27:12Z")

</div>

Maybe that’s something that could be added to [#36954](https://github.com/JuliaLang/julia/issues/36954) for 2.0?

---

<div class="post-metadata">

### Author: ![fph](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fph/32/17159_2.png) [@fph](https://discourse.julialang.org/u/fph)
#### Post date: [April 28, 2021, 11:49am UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/15 "2021-04-28T11:49:34Z")

</div>

I support the idea, of course, but I’m not sure if I should get more consensus before posting it there. Maybe there are other naming clashes that I am overlooking.

EDIT: also, there is the fact that this change isn’t simply introducing a new name and deprecating the old one; it actively breaks existing code in a way that cannot be fixed simply by adding a deprecation.

---

<div class="post-metadata">

### Author: ![jecs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jecs/32/1781_2.png) [@jecs](https://discourse.julialang.org/u/jecs)
#### Post date: [August 2, 2023, 3:08pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/16 "2023-08-02T15:08:45Z")

</div>

Why not use `sinc(x) = sin(x)/x` and `sincpi(x) = sinpi(x)/(pi*x)` for consistency with sin/sinpi, cos/cospi, etc., as fph suggested? It seems like the most elegant solution.

---

<div class="post-metadata">

### Author: ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)
#### Post date: [August 2, 2023, 3:32pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/17 "2023-08-02T15:32:44Z")

</div>

I think that has been suggested in [julia/issues/36954](https://github.com/JuliaLang/julia/issues/36954#issuecomment-833020887)

---

<div class="post-metadata">

### Author: ![jecs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jecs/32/1781_2.png) [@jecs](https://discourse.julialang.org/u/jecs)
#### Post date: [August 2, 2023, 3:40pm UTC](https://discourse.julialang.org/t/unnormalized-sinc/25015/18 "2023-08-02T15:40:46Z")

</div>

Cool, thanks for the info!
