# How do I fix the Calculus.jl module

**URL:** https://discourse.julialang.org/t/how-do-i-fix-the-calculus-jl-module/21811
**Category:** New to Julia
**Created:** [March 13, 2019, 8:16am UTC](https://discourse.julialang.org/t/how-do-i-fix-the-calculus-jl-module/21811 "2019-03-13T08:16:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [March 13, 2019, 8:16am UTC](https://discourse.julialang.org/t/how-do-i-fix-the-calculus-jl-module/21811/1 "2019-03-13T08:16:30Z")

</div>

The calculus module is great for performing finite differences for derivative, jacobian and hessian

But when I tried to use it with my own type of floating point numbers, it fails and I track down why it fails.

```julia
julia> using PDFPs

julia> Base.float(x::PDFP) = x

julia> using Calculus

julia> Calculus.derivative( x->x^2 , PDFP(7) ) # returns 14
PDFP(0, 1, [1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

julia> Calculus.gradient(x -> sin(x[1]) + cos(x[2]), [PDFP(0), PDFP(0)])
2-element Array{Float64,1}:
 0.99999999999
 0.0  

```

Now Calculus.gradient return an Array of Float64 instead of Array of PDFP

I have track down the problem to  
URL https : [//github.com/JuliaMath/Calculus.jl/blob/master/src/finite\_difference.jl](https://github.com/JuliaMath/Calculus.jl/blob/master/src/finite_difference.jl)

![25%20PM](https://global.discourse-cdn.com/julialang/original/3X/c/f/cfdd1ad71090080f0bcfe4c68c1a87434047fa99.png)

Now, I have ZERO experiences with github and I have no idea how to fix the issue.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 13, 2019, 8:38am UTC](https://discourse.julialang.org/t/how-do-i-fix-the-calculus-jl-module/21811/2 "2019-03-13T08:38:23Z")

</div>

There a two questions here:

1. github and `Pkg` workflow: you will find many discussions on the forum, eg [this one](https://discourse.julialang.org/t/guide-for-contributing-to-julia-package-on-github/17401), and also general introductions to git online,

2. regarding this particular problem: you could use `T` for the element type as a quick fix, but this may fail if `finite_difference!` widens. Then it would need to calculate the type. I have written

> **[GitHub - tpapp/AlgebraResultTypes.jl: result type calculations for algebraic...](https://github.com/tpapp/AlgebraResultTypes.jl)**
>
> result type calculations for algebraic operations. Contribute to tpapp/AlgebraResultTypes.jl development by creating an account on GitHub.

for this purpose, but the calculation is simple.

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [March 13, 2019, 8:51am UTC](https://discourse.julialang.org/t/how-do-i-fix-the-calculus-jl-module/21811/3 "2019-03-13T08:51:11Z")

</div>

Re:

> [@Tamas\_Papp](#):
>
> github and `Pkg` workflow

There’s a useful guide to gitting going with Julia and Github on [Katie Hyatt](http://kshyatt.github.io/post/firstjuliapr/)’s blog.
