# Unable to numerically differentiate in Calculus.jl Integers not Reals

**URL:** <https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211>\
**Category:** General Usage\
**Created:** [October 29, 2020, 1:08am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211 "2020-10-29T01:08:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 1:08am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/1 "2020-10-29T01:08:02Z")

</div>

```julia
using Calculs
f(x) = sin(x)
f'(1.0) - cos(1.0)

```

When I run this, I get an error saying it doesn’t accept 64bit integers. How do I change the type of a function to a real number?

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 29, 2020, 1:32am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/2 "2020-10-29T01:32:52Z")

</div>

you can use:

```julia
f(x) = sin(float(x)) 

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 1:40am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/3 "2020-10-29T01:40:59Z")

</div>

![Screenshot (4)](https://global.discourse-cdn.com/julialang/original/3X/a/5/a5437566210ebfb7fccc5171f156ca37a8ee9927.png)

I tried that and I got this error (both real and float)

the function b(x)=sin(real(x)) works though

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 29, 2020, 1:43am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/4 "2020-10-29T01:43:52Z")

</div>

for what i see, it seems that `x'` is not a valid syntax for the derivative of a function, can you try using  
`derivative(b, 1.0)` ?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 1:47am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/5 "2020-10-29T01:47:47Z")

</div>

Yes that works, but the documentation says that b’(1) should work too. The difference though, is that b’ is numeric, while differentiate() is symbolic, and I don’t know how to put symbolic outputs into functions. I can use ForwardDiff.jl to get a numeric result in a formula, but I thought this would look better.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 29, 2020, 1:49am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/6 "2020-10-29T01:49:44Z")

</div>

if you want something pretty, you can use unicode:

```julia
∂(f,x) = ForwardDiff.derivative(f,x)
∂(b,1.0)

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 1:52am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/7 "2020-10-29T01:52:09Z")

</div>

I do quite like that. Is there a way to save differentiate, so that I can plug it into a function, either as a function of x, or a function of an integer?

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 29, 2020, 1:53am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/8 "2020-10-29T01:53:18Z")

</div>

sorry, i didnt understand, can you give an example of what you want?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 1:56am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/9 "2020-10-29T01:56:34Z")

</div>

no idea what this will do, and I don’t expect it to work.

```julia
δ(x)=differentiate(x^2)
f(x)=δ+5x
f(1)
7

```

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 29, 2020, 1:57am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/10 "2020-10-29T01:57:23Z")

</div>

a working version

```julia
δ(x)=differentiate(x->x^2)
f(x)=δ(x)+5x
f(1)
7

```

EDIT; wait, it is symbolic?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 1:58am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/11 "2020-10-29T01:58:04Z")

</div>

Ok, that was surprisingly easy

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 2:00am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/12 "2020-10-29T02:00:55Z")

</div>

yes. that’s why I didn’t think I could, lol.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 29, 2020, 2:04am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/13 "2020-10-29T02:04:01Z")

</div>

ahh, i see, `differenciate` has as inputs an `String` an a series of` Symbol`s, and returns an expression. i dont think that you can add two expressions, the system in that way its not composable

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 2:06am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/14 "2020-10-29T02:06:08Z")

</div>

I didn’t think so, or that it might be way to complicated, and not at all worth my time for minor aesthetics, when I have a working numeric option. Do you get why f’(x) is described in the source code though?

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 29, 2020, 2:10am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/15 "2020-10-29T02:10:26Z")

</div>

i dont know. i checked the source code and i couldnt find any way where `'` are defined. maybe submit an issue on the repo?. asking to update the readme?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 2:15am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/16 "2020-10-29T02:15:44Z")

</div>

sure I can do that. like I said, it would be a nice feature, but by no means essential.

---

<div class="post-metadata">

**Author:** ![DavidA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davida/32/16174_2.png) [@DavidA](https://discourse.julialang.org/u/DavidA)\
**Post date:** [October 29, 2020, 3:18am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/17 "2020-10-29T03:18:46Z")

</div>

It looks like the prime notation was removed last year because it overwrote the adjoint operator: [https://github.com/JuliaMath/Calculus.jl/issues/143#issue-536837155](https://github.com/JuliaMath/Calculus.jl/issues/143#issue-536837155)

But weirdly this still worked for me just now…

```julia
julia> using Calculus

julia> f(x) = sin(x)
f (generic function with 1 method)

julia> f'(1) - cos(1)
0.0

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 29, 2020, 7:31pm UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/18 "2020-10-29T19:31:03Z")

</div>

That makes a lot of sense actually. having δ(function) as an opperator would be cool, and having δ(number) as a numeric opperator would be really handy and make neat code. I might suggest that on github. I think that can be done with dictonaries. It would also be cool if δ(x) was a generic function, but I don’t know if that’s practitcal.

something like

```julia
δ(x^3)
3x^2

δ(1)
3

δ(3)
27

δ(x)=δ(x^3)
generic function with 1 method

δ(3)
27

d(x)=(δ(x)/3)
generic function with 1 method

d(3)
3

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 29, 2020, 3:46am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/19 "2020-11-29T03:46:43Z")

</div>

Where did the b come from?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 29, 2020, 3:55am UTC](https://discourse.julialang.org/t/unable-to-numerically-differentiate-in-calculus-jl-integers-not-reals/49211/20 "2020-11-29T03:55:57Z")

</div>

> [@longemen3000](#):
>
> `f(x) = sin(float(x)) `

the b is a mistake, but otherwise this works good for finding the derivative at a certain value of x. can this be used with Roots.jl to find x at a certain derivative?
