# Package for limits

**URL:** https://discourse.julialang.org/t/package-for-limits/49286
**Category:** General Usage
**Tags:** package, math, calculus
**Created:** [October 30, 2020, 4:58am UTC](https://discourse.julialang.org/t/package-for-limits/49286 "2020-10-30T04:58:29Z")
**Posts on this page:** 4
**Page:** 2

<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 31, 2020, 7:04pm UTC](https://discourse.julialang.org/t/package-for-limits/49286/21 "2020-10-31T19:04:47Z")

</div>

Ok, I might try that with interval, to see what I can get. I’m not sure of the math of Richardson extrapolation. I’m thinking it must use standard analysis to find the limit. I was using an infentesimal to find a one sided limit.

```julia
using SymEngine
ε=10^-308 #smallest 64 bit number
subs(x/((x^2)-1),x=>ε)

```

then I get Inf.0 as a result (technically incorrect, although if I could get it to say ω.0 or H.0, then it be a correct hyperreal answer.

I suppose I could do the same with extrapolate.

---

<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: [October 31, 2020, 9:25pm UTC](https://discourse.julialang.org/t/package-for-limits/49286/22 "2020-10-31T21:25:49Z")

</div>

> [@brett\_knoss](#):
>
> ```julia
> using SymEngine
> ε=10^-308 #smallest 64 bit number
> subs(x/((x^2)-1),x=>ε)
> 
> ```

Richardson extrapolation works fine for this function, giving the correct result (zero):

```julia
julia> extrapolate(x -> x / (x^2 - 1), 0.1, x0=0)
(0.0, 0.0)

```

[These course notes](http://www.cs.rpi.edu/~flaherje/pdf/ode4.pdf) are a pretty good explanation of how it works.

I’m not sure why you are using `1e-308` (which is between `floatmin(Float64) ≈ 2.22507e-308` and `nextfloat(0.0) = 5.0e-324`). It is probably not what you want — in non-symbolic calculations it might lead to erroneous results due to underflow or similar roundoff errors. For example, consider (e^x - 1) / x, which goes to 1 as x \to 0. If you plug in `1e-308` (or any sufficiently small number) you get the wrong answer (`0.0`) due to rounding:

```julia
julia> f(x) = (exp(x) - 1) / x
f (generic function with 1 method)

julia> f(1e-308)
0.0

julia> f(1e-20)
0.0

```

whereas Richardson extrapolation gives the correct answer:

```julia
julia> extrapolate(f, 0.1, x0=0)
(1.0000000000021632, 5.938805003324887e-12)

```

(In this particular case, you could also use the `expm1` function to compute e^x - 1 more accurately for small x, but of course such a special function is not always available.)

---

<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 31, 2020, 9:31pm UTC](https://discourse.julialang.org/t/package-for-limits/49286/23 "2020-10-31T21:31:52Z")

</div>

Ok thanks, I’m not familiar with expm1, but I can do this. Is underflow because the number is too large, I was afraid there would be problems with a 256 bit infinitesimal, but I will definitely look into this extrapolation function, it seems like it would work better.

---

<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 31, 2020, 9:37pm UTC](https://discourse.julialang.org/t/package-for-limits/49286/24 "2020-10-31T21:37:36Z")

</div>

> [@stevengj](#):
>
> ` extrapolate(x -> x / (x^2 - 1), 0.1, x0=0)`

I was going to say the limit is infinity, but the right limit of x=1 is infinity, I think I can put in Inf, and get 0, but if I get the domain, then this would be more useful.

[Previous page](https://discourse.julialang.org/t/package-for-limits/49286.md?page=1)
