Skip to content

Function evaluation for segments with zero extent #126

@szabo137

Description

@szabo137

Hi!

I would like to understand the following behavior:

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> 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions