JuliaMath / JuliaMath/QuadGK.jl

Function evaluation for segments with zero extent

Open
#126 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
314
Forks
41
PR merge metrics
No merged PRs in 30d

Description

Hi!

I would like to understand the following behavior:

```Julia
julia> using QuadGK

julia> quadgk_count(x->x,0,0)
(0.0, 0.0, 15)
```

A 1D integral with the same upper and lower bound should always return zero. For `quadgk`, I assumed a shortcut that returns just zero without evaluating the integrand, but it is evaluated 15 times instead.

This is also the case for segmented integration:

```Julia
julia> using QuadGK

julia> quadgk_print(x->x,0,0,1)
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.0) = 0.0
f(0.5) = 0.5
f(0.39610752249605075) = 0.39610752249605075
f(0.6038924775039493) = 0.6038924775039493
f(0.025446043828620757) = 0.025446043828620757
f(0.9745539561713792) = 0.9745539561713792
f(0.004272314439593694) = 0.004272314439593694
f(0.9957276855604063) = 0.9957276855604063
f(0.12923440720030277) = 0.12923440720030277
f(0.8707655927996972) = 0.8707655927996972
f(0.06756778832011545) = 0.06756778832011545
f(0.9324322116798845) = 0.9324322116798845
f(0.2970774243113014) = 0.2970774243113014
f(0.7029225756886985) = 0.7029225756886985
f(0.20695638226615443) = 0.20695638226615443
f(0.7930436177338456) = 0.7930436177338456
(0.5, 0.0, 30)
```

The integrand is evaluated 15 times in the first segment before going to the segment with a finite extent.

In my opinion, a shortcut for segments with no extent could help to save some evaluations.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two examples in the issue and trace how quadgk handles each supplied segment, especially the zero-extent segment. Done means zero-extent segments return zero without evaluating the integrand, while the finite segment still produces the reported integral and error result.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.