Extensions

IncreasePrecisionExt

This extension allows increasing the precision of tabulated embedded cubature. To use this extension you must add the package ForwardDiff.

using HAdaptiveIntegration
using ForwardDiff

For example if we want to increase the precision of the rule HAdaptiveIntegration.SQUARE_CH21, we do:

tec0 = HAdaptiveIntegration.SQUARE_CH21
tec0.nodes
21-element Vector{Vector{String}}:
 ["5.000000000000000000000000000000000000e-01", "5.000000000000000000000000000000000000e-01"]
 ["9.530899229693320005789205883895798105e-01", "5.000000000000000000000000000000000000e-01"]
 ["5.000000000000000000000000000000000000e-01", "9.530899229693320005789205883895798105e-01"]
 ["4.691007703066799942107941161042018947e-02", "5.000000000000000000000000000000000000e-01"]
 ["5.000000000000000000000000000000000000e-01", "4.691007703066799942107941161042018947e-02"]
 ["7.692346550528415200375282027103137048e-01", "7.692346550528415200375282027103137048e-01"]
 ["2.307653449471584799624717972896862952e-01", "7.692346550528415200375282027103137048e-01"]
 ["7.692346550528415200375282027103137048e-01", "2.307653449471584799624717972896862952e-01"]
 ["2.307653449471584799624717972896862952e-01", "2.307653449471584799624717972896862952e-01"]
 ["9.530899229693319571124065987079251159e-01", "9.530899229693319571124065987079251159e-01"]
 ⋮
 ["4.691007703066804288759340129207488409e-02", "4.691007703066804288759340129207488409e-02"]
 ["9.530899229693320081691800769275475942e-01", "7.692346550528415524068181972304942518e-01"]
 ["7.692346550528415524068181972304942518e-01", "9.530899229693320081691800769275475942e-01"]
 ["4.691007703066799183081992307245240580e-02", "7.692346550528415524068181972304942518e-01"]
 ["7.692346550528415524068181972304942518e-01", "4.691007703066799183081992307245240580e-02"]
 ["9.530899229693320081691800769275475942e-01", "2.307653449471584475931818027695057482e-01"]
 ["2.307653449471584475931818027695057482e-01", "9.530899229693320081691800769275475942e-01"]
 ["4.691007703066799183081992307245240580e-02", "2.307653449471584475931818027695057482e-01"]
 ["2.307653449471584475931818027695057482e-01", "4.691007703066799183081992307245240580e-02"]
tec1 = HAdaptiveIntegration.increase_precision(
    tec0, BigFloat; x_atol=big"1e-64", f_atol=big"1e-64"
)
[ Info: Increasing to target precision 64 from tabulated precision 35. This may take some time.
[ Info: iter   1: |xₙ - xₙ₋₁| = 3.96e-38, |f(xₙ)| = 1.16e-37
[ Info: iter   2: |xₙ - xₙ₋₁| = 6.73e-74, |f(xₙ)| = 2.26e-75
┌ Info: Newton convergence report:

      iteration = 2 / 16
    |xₙ - xₙ₋₁ | = 6.73e-74 ≤ 1.00e-64
        |f(xₙ)| = 2.26e-75 ≤ 1.00e-64
tec1.nodes
21-element Vector{Vector{String}}:
 ["0.4999999999999999999999999999999999999982213851754709631884816406137113604246799", "0.4999999999999999999999999999999999999982213851754709631884816406137113604125072"]
 ["0.9530899229693320005789205883895798105223193134839831874164781263671271860711774", "0.4999999999999999999999999999999999999998459567123802915150035977327656154833857"]
 ["0.4999999999999999999999999999999999999998459567123802915150035977327656154694081", "0.9530899229693320005789205883895798105223193134839831874164781263671271861017235"]
 ["0.04691007703066799942107941161042018947733281333972961108762555909031749163802912", "0.4999999999999999999999999999999999999998459567123802915150035977327656154812439"]
 ["0.4999999999999999999999999999999999999998459567123802915150035977327656154693994", "0.04691007703066799942107941161042018947733281333972961108762555909031749166454486"]
 ["0.7692346550528415200375282027103137047931600686128846368644846829910603597064122", "0.7692346550528415200375282027103137047931600686128846368644846829910603597487639"]
 ["0.2307653449471584799624717972896862952049935849822725131053815342287701087238417", "0.769234655052841520037528202710313704794401227675805002754709965445986107609818"]
 ["0.7692346550528415200375282027103137047944012276758050027547099654459861076128321", "0.2307653449471584799624717972896862952049935849822725131053815342287701087101274"]
 ["0.2307653449471584799624717972896862952037524259193521472151562517738443608163941", "0.2307653449471584799624717972896862952037524259193521472151562517738443608553626"]
 ["0.9530899229693319571124065987079251159160657333910708523579591058987239102509191", "0.9530899229693319571124065987079251159160657333910708523579591058987239102386989"]
 ⋮
 ["0.04691007703066804288759340129207488408174916973089781735697912697081010531155385", "0.04691007703066804288759340129207488408174916973089781735697912697081010529524931"]
 ["0.9530899229693320081691800769275475941988675518635660699264550005155568815047789", "0.7692346550528415524068181972304942517999779453859381711369011772988930236526333"]
 ["0.7692346550528415524068181972304942517999779453859381711369011772988930236412594", "0.9530899229693320081691800769275475941988675518635660699264550005155568815529688"]
 ["0.04691007703066799183081992307245240580187761997364183391392548231637123942923074", "0.7692346550528415524068181972304942518001124903388710857150939722637942882597455"]
 ["0.7692346550528415524068181972304942518001124903388710857150939722637942881967015", "0.04691007703066799183081992307245240580187761997364183391392548231637123941484342"]
 ["0.95308992296933200816918007692754759419770207371160535296421219029425547823963", "0.2307653449471584475931818027695057482013229298900554866362689789172706768402058"]
 ["0.230765344947158447593181802769505748201322929890055486636268978917270676785405", "0.9530899229693320081691800769275475941977020737116053529642121902942554781883916"]
 ["0.04691007703066799183081992307245240580304309812560255087616829253767264269419991", "0.2307653449471584475931818027695057482011883849371225720580761839523694122342314"]
 ["0.2307653449471584475931818027695057482011883849371225720580761839523694122298356", "0.0469100770306679918308199230724524058030430981256025508761682925376726427769954"]

Complete workflow: Arbitrary precision integration

Now let's use the increased precision rule in an actual integration. First define a function to integrate over a domain:

domain = Rectangle((big"0", big"0"), (big"1", big"1"))
f = x -> x[1]^2 + x[2]^2

Create an embedded cubature with the high-precision rule and a lower-order pair:

using HAdaptiveIntegration.Rule: embedded_cubature
ec_big = embedded_cubature(tec1, BigFloat)
┌ Warning: The embedded cubature `Cools-Haegemans with 21 nodes (SQUARE_CH21) (increased precision)` has fewer significant digits than type BigFloat, which may lead to inaccurate computations.
@ HAdaptiveIntegration.Rule ~/work/HAdaptiveIntegration.jl/HAdaptiveIntegration.jl/src/Rule/tabulated.jl:81

Now integrate with arbitrary precision:

I, E = HAdaptiveIntegration.integrate(
    f, domain;
    embedded_cubature = ec_big,
    rtol = big"1e-64"
)
I = 0.6666666666666666666666666666666666666666666666666666666666666666666666666666695
E = 8.636168555094444625386351862800399571116000364436281385023703470168591803162427e-78

The result is now computed with arbitrary precision (BigFloat), enabling high-precision numerical integration when needed for sensitive applications or validation studies.