@rec-math/math
Advanced tools
| // Export the default method. | ||
| export { quad } from './integrate/quad.js'; |
| import { quadrature } from './quad/adaptive-quadrature.js'; | ||
| import { integrationStep } from './quad/gauss-kronrod-g7k15.js'; | ||
| const rangeErrorMessage = 'integration range must be an array of at least two endpoints'; | ||
| /** | ||
| * Numerically compute a definite integral. | ||
| * | ||
| * @param f Callback returning value of integrand. | ||
| * @param range A range of at least 2 endpoints. | ||
| * @param options Options for the computation. | ||
| * | ||
| * @returns The results of the computation. | ||
| */ | ||
| export const quad = (f, range, options = {}) => { | ||
| // Interpret the range. | ||
| if (!Array.isArray(range)) { | ||
| throw new RangeError(rangeErrorMessage); | ||
| } | ||
| if (range.length === 2) { | ||
| // Integrate over a single range. | ||
| const [a, b] = range; | ||
| return quadrature(integrationStep, f, a, b, options); | ||
| } | ||
| if (range.length < 2) { | ||
| // Can't integrate at a point! | ||
| throw new RangeError(rangeErrorMessage); | ||
| } | ||
| // Integrate over multiple ranges. | ||
| let result = 0; | ||
| const points = []; | ||
| const info = { | ||
| steps: 0, | ||
| errorEstimate: 0, | ||
| points, | ||
| depth: 0, | ||
| }; | ||
| for (let i = 0; i < range.length - 1; ++i) { | ||
| const single = quadrature(integrationStep, f, range[i], range[i + 1], options); | ||
| info.points.push(single); | ||
| // Update the result. | ||
| result += single[0]; | ||
| // Update the cumulative statistics. | ||
| info.steps += single[1].steps; | ||
| info.errorEstimate += single[1].errorEstimate; | ||
| info.depth = Math.max(info.depth, single[1].depth); | ||
| } | ||
| return [result, info]; | ||
| }; |
@@ -1,6 +0,6 @@ | ||
| /*! @rec-math/math v1.1.0 2022-06-13 01:56:51 | ||
| /*! @rec-math/math v1.2.0 2022-06-14 11:50:09 | ||
| * https://github.com/rec-math/ts-math#readme | ||
| * Copyright pbuk (https://github.com/pb-uk) MIT license. | ||
| */ | ||
| var RecMath=function(t){"use strict";const e={epsilon:16*Number.EPSILON,maxDepth:Number.POSITIVE_INFINITY},r=(t,r,n,i,o={})=>{const a=Object.assign(Object.assign({},e),o),{epsilon:u,maxDepth:c}=a,p={steps:0,errorEstimate:0,depth:1},[h,l,b]=((t,e,r)=>{if(!isFinite(r))return isFinite(e)?[r=>{const s=1/(1-r);return t(e+r*s)*s*s},0,1]:[e=>{const r=e*e,s=1/(1-r);return t(e*s)*(1+r)*s*s},-1,1];if(!isFinite(e))return[e=>t(r-(1-e)/e)/(e*e),0,1];return[t,e,r]})(r,n,i);let[f,g]=s(t,h,l,b,1,1,0,Object.assign({},p));const m=Math.abs(u*f/(b-l));return[f,g]=s(t,h,l,b,1,c,m,p),[f,Object.assign(Object.assign({},p),{errorEstimate:g})]},s=(t,e,r,n,i,o,a,u)=>{const c=t(e,r,n);let p=c[0];const h=c[1];let l=Math.abs(h-p);if(i>=o)return++u.steps,[p,l];if(l<=a*(n-r))return++u.steps,[p,l];const b=(r+n)/2;if(r>=b||b>=n){u.isUnreliable=!0;const t=isNaN(l)?0:l;return p===Number.POSITIVE_INFINITY?[0,t]:[p,t]}++i>u.depth&&(u.depth=i);const f=s(t,e,r,b,i,o,a,u),g=s(t,e,b,n,i,o,a,u);return p=f[0]+g[0],l=f[1]+g[1],[p,l]},n=(t,e,r)=>{const s=(r-e)/2,n=(e+r)/2,i=.20778495500789848*s,o=.4058451513773972*s,a=.5860872354676911*s,u=.7415311855993945*s,c=.8648644233597691*s,p=.9491079123427585*s,h=.9914553711208126*s,l=.4179591836734694*s,b=.3818300505051189*s,f=.27970539148927664*s,g=.1294849661688697*s,m=.20948214108472782*s,d=.20443294007529889*s,I=.19035057806478542*s,E=.1690047266392679*s,N=.14065325971552592*s,O=.10479001032225019*s,_=.06309209262997856*s,j=.022935322010529224*s,w=t(n),F=t(n+i),M=t(n-i),v=t(n+o),y=t(n-o),P=t(n+a),T=t(n-a),x=t(n+u),R=t(n-u),S=t(n+c),A=t(n-c),D=t(n+p),V=t(n-p);return[m*w+d*(F+M)+I*(v+y)+E*(P+T)+N*(x+R)+O*(S+A)+_*(D+V)+j*(t(n+h)+t(n-h)),l*w+b*(v+y)+f*(x+R)+g*(D+V)]},i="integration range must be an array of at least two endpoints";var o=Object.freeze({__proto__:null,quad:(t,e,s={})=>{if(!Array.isArray(e))throw new RangeError(i);if(2===e.length){const[i,o]=e;return r(n,t,i,o,s)}if(e.length<2)throw new RangeError(i);let o=0;const a={steps:0,errorEstimate:0,points:[],depth:0};for(let i=0;i<e.length-1;++i){const u=r(n,t,e[i],e[i+1],s);a.points.push(u),o+=u[0],a.steps+=u[1].steps,a.errorEstimate+=u[1].errorEstimate,a.depth=Math.max(a.depth,u[1].depth)}return[o,a]}});return t.integrate=o,t.version="1.1.0",Object.defineProperty(t,"__esModule",{value:!0}),t}({}); | ||
| var RecMath=function(t){"use strict";const e={epsilon:16*Number.EPSILON,maxDepth:Number.POSITIVE_INFINITY},r=(t,r,n,i,o={})=>{const a=Object.assign(Object.assign({},e),o),{epsilon:u,maxDepth:c}=a,p={steps:0,errorEstimate:0,depth:1},[h,l,b]=((t,e,r)=>{if(!isFinite(r))return isFinite(e)?[r=>{const s=1/(1-r);return t(e+r*s)*s*s},0,1]:[e=>{const r=e*e,s=1/(1-r);return t(e*s)*(1+r)*s*s},-1,1];if(!isFinite(e))return[e=>t(r-(1-e)/e)/(e*e),0,1];return[t,e,r]})(r,n,i);let[f,g]=s(t,h,l,b,1,1,0,Object.assign({},p));const m=Math.abs(u*f/(b-l));return[f,g]=s(t,h,l,b,1,c,m,p),[f,Object.assign(Object.assign({},p),{errorEstimate:g})]},s=(t,e,r,n,i,o,a,u)=>{const c=t(e,r,n);let p=c[0];const h=c[1];let l=Math.abs(h-p);if(i>=o)return++u.steps,[p,l];if(l<=a*(n-r))return++u.steps,[p,l];const b=(r+n)/2;if(r>=b||b>=n){u.isUnreliable=!0;const t=isNaN(l)?0:l;return p===Number.POSITIVE_INFINITY?[0,t]:[p,t]}++i>u.depth&&(u.depth=i);const f=s(t,e,r,b,i,o,a,u),g=s(t,e,b,n,i,o,a,u);return p=f[0]+g[0],l=f[1]+g[1],[p,l]},n=(t,e,r)=>{const s=(r-e)/2,n=(e+r)/2,i=.20778495500789848*s,o=.4058451513773972*s,a=.5860872354676911*s,u=.7415311855993945*s,c=.8648644233597691*s,p=.9491079123427585*s,h=.9914553711208126*s,l=.4179591836734694*s,b=.3818300505051189*s,f=.27970539148927664*s,g=.1294849661688697*s,m=.20948214108472782*s,d=.20443294007529889*s,I=.19035057806478542*s,E=.1690047266392679*s,N=.14065325971552592*s,O=.10479001032225019*s,_=.06309209262997856*s,j=.022935322010529224*s,w=t(n),F=t(n+i),M=t(n-i),v=t(n+o),y=t(n-o),P=t(n+a),T=t(n-a),x=t(n+u),R=t(n-u),S=t(n+c),A=t(n-c),D=t(n+p),V=t(n-p);return[m*w+d*(F+M)+I*(v+y)+E*(P+T)+N*(x+R)+O*(S+A)+_*(D+V)+j*(t(n+h)+t(n-h)),l*w+b*(v+y)+f*(x+R)+g*(D+V)]},i="integration range must be an array of at least two endpoints";var o=Object.freeze({__proto__:null,quad:(t,e,s={})=>{if(!Array.isArray(e))throw new RangeError(i);if(2===e.length){const[i,o]=e;return r(n,t,i,o,s)}if(e.length<2)throw new RangeError(i);let o=0;const a={steps:0,errorEstimate:0,points:[],depth:0};for(let i=0;i<e.length-1;++i){const u=r(n,t,e[i],e[i+1],s);a.points.push(u),o+=u[0],a.steps+=u[1].steps,a.errorEstimate+=u[1].errorEstimate,a.depth=Math.max(a.depth,u[1].depth)}return[o,a]}});return t.integrate=o,t.version="1.2.0",Object.defineProperty(t,"__esModule",{value:!0}),t}({}); | ||
| //# sourceMappingURL=rec-math.min.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"rec-math.min.js","sources":["../esm/integrate/quad/adaptive-quadrature.js","../esm/integrate/quad/gauss-kronrod-g7k15.js","../esm/integrate/quad/index.js","../esm/index.js"],"sourcesContent":["// Export the API.\r\nexport { quadrature };\r\nconst defaults = {\r\n epsilon: Number.EPSILON * 16,\r\n maxDepth: Number.POSITIVE_INFINITY,\r\n};\r\n/**\r\n * Perform a substitution with an appropriate change of variables to deal with\r\n * infinite ranges.\r\n *\r\n * @param f Intgrand callback.\r\n * @param a Lower limit.\r\n * @param b Upper limit.\r\n * @returns An array with any necessary substitution.\r\n */\r\nconst changeOfVariables = (f, a, b) => {\r\n if (!isFinite(b)) {\r\n if (!isFinite(a)) {\r\n // Change variables to integrate between - and + infinity.\r\n const _f = (t) => {\r\n const tSquared = t * t;\r\n const oneOverOneMinusTSquared = 1 / (1 - tSquared);\r\n return (f(t * oneOverOneMinusTSquared) *\r\n (1 + tSquared) *\r\n oneOverOneMinusTSquared *\r\n oneOverOneMinusTSquared);\r\n };\r\n return [_f, -1, 1];\r\n }\r\n // Change variables to integrate up to infinity.\r\n const _f = (t) => {\r\n const oneOverOneMinusT = 1 / (1 - t);\r\n return f(a + t * oneOverOneMinusT) * oneOverOneMinusT * oneOverOneMinusT;\r\n };\r\n return [_f, 0, 1];\r\n }\r\n if (!isFinite(a)) {\r\n // Change variables to integrate up from negative infinity.\r\n const _f = (t) => {\r\n return f(b - (1 - t) / t) / (t * t);\r\n };\r\n return [_f, 0, 1];\r\n }\r\n return [f, a, b];\r\n};\r\nconst quadrature = (integrationStep, f, a, b, options = {}) => {\r\n // Establish settings.\r\n const settings = Object.assign(Object.assign({}, defaults), options);\r\n const { epsilon, maxDepth } = settings;\r\n const info = { steps: 0, errorEstimate: 0, depth: 1 };\r\n // Allow for a change of variables to deal with infinite limits.\r\n const [_f, _a, _b] = changeOfVariables(f, a, b);\r\n // Get estimate so we can work out the acceptable global error.\r\n // Use a depth of 1 to calculate a 15 point Kronrod quadrature.\r\n let [result, errorEstimate] = integrate_part(integrationStep, _f, // Integrand.\r\n _a, // Lower limit.\r\n _b, // Upper limit.\r\n 1, // New depth.\r\n 1, // Maximum depth.\r\n 0, Object.assign({}, info));\r\n // Now calculate using the target global error.\r\n const acceptableUnitError = Math.abs((epsilon * result) / (_b - _a));\r\n [result, errorEstimate] = integrate_part(integrationStep, _f, // Integrand.\r\n _a, // Lower limit.\r\n _b, // Upper limit.\r\n 1, // New depth.\r\n maxDepth, // Maximum depth.\r\n acceptableUnitError, // Acceptable error per unit step.\r\n info);\r\n return [result, Object.assign(Object.assign({}, info), { errorEstimate })];\r\n};\r\nconst integrate_part = (integrationStep, f, a, // Lower limit.\r\nb, // Upper limit.\r\ndepth, // New depth.\r\nmaxDepth, // Maximum depth.\r\nacceptableUnitError, // Acceptable error per unit step.\r\ninfo) => {\r\n // Initialize things.\r\n const estimates = integrationStep(f, // Integrand.\r\n a, // Lower limit.\r\n b);\r\n let currentEstimate = estimates[0];\r\n const poorEstimate = estimates[1];\r\n let errorEstimate = Math.abs(poorEstimate - currentEstimate);\r\n if (depth >= maxDepth) {\r\n // Reached the maximum allowable depth so return the partial sum.\r\n ++info.steps;\r\n return [currentEstimate, errorEstimate];\r\n }\r\n const acceptableError = acceptableUnitError * (b - a);\r\n if (errorEstimate <= acceptableError) {\r\n // Error is acceptable for the size of step so return the partial sum.\r\n ++info.steps;\r\n return [currentEstimate, errorEstimate];\r\n }\r\n const mid = (a + b) / 2;\r\n if (a >= mid || mid >= b) {\r\n // We can't make this step any smaller: looks like a discontinuity.\r\n info.isUnreliable = true;\r\n const safeErrorEstimate = isNaN(errorEstimate) ? 0 : errorEstimate;\r\n if (currentEstimate === Number.POSITIVE_INFINITY) {\r\n return [0, safeErrorEstimate];\r\n }\r\n return [currentEstimate, safeErrorEstimate];\r\n }\r\n // Recurse deeper.\r\n ++depth;\r\n if (depth > info.depth) {\r\n info.depth = depth;\r\n }\r\n const leftResult = integrate_part(integrationStep, f, // Integrand.\r\n a, // Lower limit.\r\n mid, // Upper limit.\r\n depth, // New depth.\r\n maxDepth, // Maximum depth.\r\n acceptableUnitError, // Acceptable error per unit step.\r\n info);\r\n const rightResult = integrate_part(integrationStep, f, // Integrand.\r\n mid, // Lower limit.\r\n b, // Upper limit.\r\n depth, // New depth.\r\n maxDepth, // Maximum depth.\r\n acceptableUnitError, // Acceptable error per unit step.\r\n info);\r\n currentEstimate = leftResult[0] + rightResult[0];\r\n errorEstimate = leftResult[1] + rightResult[1];\r\n return [currentEstimate, errorEstimate];\r\n};\r\n","// Export the API.\r\nexport { integrationStep };\r\n// Gauss-Kronrod constants (G7, K15) on [-1, 1].\r\n// https://www.advanpix.com/2011/11/07/gauss-kronrod-quadrature-nodes-weights/\r\n// node_g0k0 = 0;\r\n// node_g1k2 = 4.058451513773971669066064120769615e-01 exact;\r\nconst node_g1k2 = 0.4058451513773972;\r\n// node_g2k4 = 7.415311855993944398638647732807884e-01 exact;\r\nconst node_g2k4 = 0.7415311855993945;\r\n// node_g3k6 = 9.491079123427585245261896840478513e-01 exact;\r\nconst node_g3k6 = 0.9491079123427585;\r\n// node_k1 = 2.077849550078984676006894037732449e-01 exact;\r\nconst node_k1 = 0.20778495500789848;\r\n// node_k3 = 5.860872354676911302941448382587296e-01 exact;\r\nconst node_k3 = 0.5860872354676911;\r\n// node_k5 = 8.648644233597690727897127886409262e-01 exact;\r\nconst node_k5 = 0.8648644233597691;\r\n// node_k7 = 9.914553711208126392068546975263285e-01 exact;\r\nconst node_k7 = 0.9914553711208126;\r\n// weight_g0 = 4.179591836734693877551020408163265e-01 exact;\r\nconst weight_g0 = 0.4179591836734694;\r\n// weight_g1 = 3.818300505051189449503697754889751e-01 exact;\r\nconst weight_g1 = 0.3818300505051189;\r\n// weight_g2 = 2.797053914892766679014677714237796e-01 exact;\r\nconst weight_g2 = 0.27970539148927664;\r\n// weight_g3 = 1.294849661688696932706114326790820e-01 exact;\r\nconst weight_g3 = 0.1294849661688697;\r\n// weight_k0 = 2.094821410847278280129991748917143e-01 exact;\r\nconst weight_k0 = 0.20948214108472782;\r\n// weight_k1 = 2.044329400752988924141619992346491e-01 exact;\r\nconst weight_k1 = 0.20443294007529889;\r\n// weight_k2 = 1.903505780647854099132564024210137e-01 exact;\r\nconst weight_k2 = 0.19035057806478542;\r\n// weight_k3 = 1.690047266392679028265834265985503e-01 exact;\r\nconst weight_k3 = 0.1690047266392679;\r\n// weight_k4 = 1.406532597155259187451895905102379e-01 exact;\r\nconst weight_k4 = 0.14065325971552592;\r\n// weight_k5 = 1.047900103222501838398763225415180e-01 exact;\r\nconst weight_k5 = 0.10479001032225019;\r\n// weight_k6 = 6.309209262997855329070066318920429e-02 exact;\r\nconst weight_k6 = 0.06309209262997856;\r\n// weight_k7 = 2.293532201052922496373200805896959e-02 exact;\r\nconst weight_k7 = 0.022935322010529224;\r\n/**\r\n * Perform a single integration step.\r\n *\r\n * @param f Integrand callback.\r\n * @param a Lower limit.\r\n * @param b Upper limit.\r\n * @returns [current best estimate, poor estimate]\r\n */\r\nconst integrationStep = (f, // Integrand.\r\na, // Lower limit.\r\nb) => {\r\n // Gauss-Kronrod (G7, K15).\r\n const scale = (b - a) / 2;\r\n const offset = (a + b) / 2;\r\n // const scaled_g0k0 = 0;\r\n const scaled_k1 = node_k1 * scale;\r\n const scaled_g1k2 = node_g1k2 * scale;\r\n const scaled_k3 = node_k3 * scale;\r\n const scaled_g2k4 = node_g2k4 * scale;\r\n const scaled_k5 = node_k5 * scale;\r\n const scaled_g3k6 = node_g3k6 * scale;\r\n const scaled_k7 = node_k7 * scale;\r\n const scaled_weight_g0 = weight_g0 * scale;\r\n const scaled_weight_g1 = weight_g1 * scale;\r\n const scaled_weight_g2 = weight_g2 * scale;\r\n const scaled_weight_g3 = weight_g3 * scale;\r\n const scaled_weight_k0 = weight_k0 * scale;\r\n const scaled_weight_k1 = weight_k1 * scale;\r\n const scaled_weight_k2 = weight_k2 * scale;\r\n const scaled_weight_k3 = weight_k3 * scale;\r\n const scaled_weight_k4 = weight_k4 * scale;\r\n const scaled_weight_k5 = weight_k5 * scale;\r\n const scaled_weight_k6 = weight_k6 * scale;\r\n const scaled_weight_k7 = weight_k7 * scale;\r\n const f_g0k0 = f(offset);\r\n const f_k1_h = f(offset + scaled_k1);\r\n const f_k1_l = f(offset - scaled_k1);\r\n const f_g1k2_h = f(offset + scaled_g1k2);\r\n const f_g1k2_l = f(offset - scaled_g1k2);\r\n const f_k3_h = f(offset + scaled_k3);\r\n const f_k3_l = f(offset - scaled_k3);\r\n const f_g2k4_h = f(offset + scaled_g2k4);\r\n const f_g2k4_l = f(offset - scaled_g2k4);\r\n const f_k5_h = f(offset + scaled_k5);\r\n const f_k5_l = f(offset - scaled_k5);\r\n const f_g3k6_h = f(offset + scaled_g3k6);\r\n const f_g3k6_l = f(offset - scaled_g3k6);\r\n const f_k7_h = f(offset + scaled_k7);\r\n const f_k7_l = f(offset - scaled_k7);\r\n const poorEstimate = scaled_weight_g0 * f_g0k0 + // g0\r\n scaled_weight_g1 * (f_g1k2_h + f_g1k2_l) + // g1\r\n scaled_weight_g2 * (f_g2k4_h + f_g2k4_l) + // g2\r\n scaled_weight_g3 * (f_g3k6_h + f_g3k6_l); // g3\r\n const currentEstimate = scaled_weight_k0 * f_g0k0 + // k0\r\n scaled_weight_k1 * (f_k1_h + f_k1_l) + // k1\r\n scaled_weight_k2 * (f_g1k2_h + f_g1k2_l) + // k2\r\n scaled_weight_k3 * (f_k3_h + f_k3_l) + // k3\r\n scaled_weight_k4 * (f_g2k4_h + f_g2k4_l) + // k4\r\n scaled_weight_k5 * (f_k5_h + f_k5_l) + // k5\r\n scaled_weight_k6 * (f_g3k6_h + f_g3k6_l) + // k6\r\n scaled_weight_k7 * (f_k7_h + f_k7_l); // k7\r\n return [currentEstimate, poorEstimate];\r\n};\r\n","import { quadrature } from './adaptive-quadrature.js';\r\nimport { integrationStep } from './gauss-kronrod-g7k15.js';\r\nconst rangeErrorMessage = 'integration range must be an array of at least two endpoints';\r\n/**\r\n * Numerically compute a definite integral.\r\n *\r\n * @param f Callback returning value of integrand.\r\n * @param range A range of at least 2 endpoints.\r\n * @param options Options for the computation.\r\n *\r\n * @returns The results of the computation.\r\n */\r\nexport const quad = (f, range, options = {}) => {\r\n // Interpret the range.\r\n if (!Array.isArray(range)) {\r\n throw new RangeError(rangeErrorMessage);\r\n }\r\n if (range.length === 2) {\r\n // Integrate over a single range.\r\n const [a, b] = range;\r\n return quadrature(integrationStep, f, a, b, options);\r\n }\r\n if (range.length < 2) {\r\n // Can't integrate at a point!\r\n throw new RangeError(rangeErrorMessage);\r\n }\r\n // Integrate over multiple ranges.\r\n let result = 0;\r\n const points = [];\r\n const info = {\r\n steps: 0,\r\n errorEstimate: 0,\r\n points,\r\n depth: 0,\r\n };\r\n for (let i = 0; i < range.length - 1; ++i) {\r\n const single = quadrature(integrationStep, f, range[i], range[i + 1], options);\r\n info.points.push(single);\r\n // Update the result.\r\n result += single[0];\r\n // Update the cumulative statistics.\r\n info.steps += single[1].steps;\r\n info.errorEstimate += single[1].errorEstimate;\r\n info.depth = Math.max(info.depth, single[1].depth);\r\n }\r\n return [result, info];\r\n};\r\n","export const version = '1.1.0';\r\nexport * as integrate from './integrate/index.js';\r\n"],"names":["defaults","epsilon","Number","EPSILON","maxDepth","POSITIVE_INFINITY","quadrature","integrationStep","f","a","b","options","settings","Object","assign","info","steps","errorEstimate","depth","_f","_a","_b","isFinite","t","oneOverOneMinusT","tSquared","oneOverOneMinusTSquared","changeOfVariables","result","integrate_part","acceptableUnitError","Math","abs","estimates","currentEstimate","poorEstimate","mid","isUnreliable","safeErrorEstimate","isNaN","leftResult","rightResult","scale","offset","scaled_k1","scaled_g1k2","scaled_k3","scaled_g2k4","scaled_k5","scaled_g3k6","scaled_k7","scaled_weight_g0","scaled_weight_g1","scaled_weight_g2","scaled_weight_g3","scaled_weight_k0","scaled_weight_k1","scaled_weight_k2","scaled_weight_k3","scaled_weight_k4","scaled_weight_k5","scaled_weight_k6","scaled_weight_k7","f_g0k0","f_k1_h","f_k1_l","f_g1k2_h","f_g1k2_l","f_k3_h","f_k3_l","f_g2k4_h","f_g2k4_l","f_k5_h","f_k5_l","f_g3k6_h","f_g3k6_l","rangeErrorMessage","range","Array","isArray","RangeError","length","points","i","single","push","max"],"mappings":";;;;qCAEA,MAAMA,EAAW,CACbC,QAA0B,GAAjBC,OA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E,EAAG,CACvC,MAAMC,EAAS9E,EAAWC,EAAiBC,EAAGqE,EAAMM,GAAIN,EAAMM,EAAI,GAAIxE,GACtEI,EAAKmE,OAAOG,KAAKD,GAEjBxD,GAAUwD,EAAO,GAEjBrE,EAAKC,OAASoE,EAAO,GAAGpE,MACxBD,EAAKE,eAAiBmE,EAAO,GAAGnE,cAChCF,EAAKG,MAAQa,KAAKuD,IAAIvE,EAAKG,MAAOkE,EAAO,GAAGlE,OAEhD,MAAO,CAACU,EAAQb,qCC7CG"} | ||
| {"version":3,"file":"rec-math.min.js","sources":["../esm/integrate/quad/adaptive-quadrature.js","../esm/integrate/quad/gauss-kronrod-g7k15.js","../esm/integrate/quad.js","../esm/index.js"],"sourcesContent":["// Export the API.\r\nexport { quadrature };\r\nconst defaults = {\r\n epsilon: Number.EPSILON * 16,\r\n maxDepth: Number.POSITIVE_INFINITY,\r\n};\r\n/**\r\n * Perform a substitution with an appropriate change of variables to deal with\r\n * infinite ranges.\r\n *\r\n * @param f Intgrand callback.\r\n * @param a Lower limit.\r\n * @param b Upper limit.\r\n * @returns An array with any necessary substitution.\r\n */\r\nconst changeOfVariables = (f, a, b) => {\r\n if (!isFinite(b)) {\r\n if (!isFinite(a)) {\r\n // Change variables to integrate between - and + infinity.\r\n const _f = (t) => {\r\n const tSquared = t * t;\r\n const oneOverOneMinusTSquared = 1 / (1 - tSquared);\r\n return (f(t * oneOverOneMinusTSquared) *\r\n (1 + tSquared) *\r\n oneOverOneMinusTSquared *\r\n oneOverOneMinusTSquared);\r\n };\r\n return [_f, -1, 1];\r\n }\r\n // Change variables to integrate up to infinity.\r\n const _f = (t) => {\r\n const oneOverOneMinusT = 1 / (1 - t);\r\n return f(a + t * oneOverOneMinusT) * oneOverOneMinusT * oneOverOneMinusT;\r\n };\r\n return [_f, 0, 1];\r\n }\r\n if (!isFinite(a)) {\r\n // Change variables to integrate up from negative infinity.\r\n const _f = (t) => {\r\n return f(b - (1 - t) / t) / (t * t);\r\n };\r\n return [_f, 0, 1];\r\n }\r\n return [f, a, b];\r\n};\r\nconst quadrature = (integrationStep, f, a, b, options = {}) => {\r\n // Establish settings.\r\n const settings = Object.assign(Object.assign({}, defaults), options);\r\n const { epsilon, maxDepth } = settings;\r\n const info = { steps: 0, errorEstimate: 0, depth: 1 };\r\n // Allow for a change of variables to deal with infinite limits.\r\n const [_f, _a, _b] = changeOfVariables(f, a, b);\r\n // Get estimate so we can work out the acceptable global error.\r\n // Use a depth of 1 to calculate a 15 point Kronrod quadrature.\r\n let [result, errorEstimate] = integrate_part(integrationStep, _f, // Integrand.\r\n _a, // Lower limit.\r\n _b, // Upper limit.\r\n 1, // New depth.\r\n 1, // Maximum depth.\r\n 0, Object.assign({}, info));\r\n // Now calculate using the target global error.\r\n const acceptableUnitError = Math.abs((epsilon * result) / (_b - _a));\r\n [result, errorEstimate] = integrate_part(integrationStep, _f, // Integrand.\r\n _a, // Lower limit.\r\n _b, // Upper limit.\r\n 1, // New depth.\r\n maxDepth, // Maximum depth.\r\n acceptableUnitError, // Acceptable error per unit step.\r\n info);\r\n return [result, Object.assign(Object.assign({}, info), { errorEstimate })];\r\n};\r\nconst integrate_part = (integrationStep, f, a, // Lower limit.\r\nb, // Upper limit.\r\ndepth, // New depth.\r\nmaxDepth, // Maximum depth.\r\nacceptableUnitError, // Acceptable error per unit step.\r\ninfo) => {\r\n // Initialize things.\r\n const estimates = integrationStep(f, // Integrand.\r\n a, // Lower limit.\r\n b);\r\n let currentEstimate = estimates[0];\r\n const poorEstimate = estimates[1];\r\n let errorEstimate = Math.abs(poorEstimate - currentEstimate);\r\n if (depth >= maxDepth) {\r\n // Reached the maximum allowable depth so return the partial sum.\r\n ++info.steps;\r\n return [currentEstimate, errorEstimate];\r\n }\r\n const acceptableError = acceptableUnitError * (b - a);\r\n if (errorEstimate <= acceptableError) {\r\n // Error is acceptable for the size of step so return the partial sum.\r\n ++info.steps;\r\n return [currentEstimate, errorEstimate];\r\n }\r\n const mid = (a + b) / 2;\r\n if (a >= mid || mid >= b) {\r\n // We can't make this step any smaller: looks like a discontinuity.\r\n info.isUnreliable = true;\r\n const safeErrorEstimate = isNaN(errorEstimate) ? 0 : errorEstimate;\r\n if (currentEstimate === Number.POSITIVE_INFINITY) {\r\n return [0, safeErrorEstimate];\r\n }\r\n return [currentEstimate, safeErrorEstimate];\r\n }\r\n // Recurse deeper.\r\n ++depth;\r\n if (depth > info.depth) {\r\n info.depth = depth;\r\n }\r\n const leftResult = integrate_part(integrationStep, f, // Integrand.\r\n a, // Lower limit.\r\n mid, // Upper limit.\r\n depth, // New depth.\r\n maxDepth, // Maximum depth.\r\n acceptableUnitError, // Acceptable error per unit step.\r\n info);\r\n const rightResult = integrate_part(integrationStep, f, // Integrand.\r\n mid, // Lower limit.\r\n b, // Upper limit.\r\n depth, // New depth.\r\n maxDepth, // Maximum depth.\r\n acceptableUnitError, // Acceptable error per unit step.\r\n info);\r\n currentEstimate = leftResult[0] + rightResult[0];\r\n errorEstimate = leftResult[1] + rightResult[1];\r\n return [currentEstimate, errorEstimate];\r\n};\r\n","// Export the API.\r\nexport { integrationStep };\r\n// Gauss-Kronrod constants (G7, K15) on [-1, 1].\r\n// https://www.advanpix.com/2011/11/07/gauss-kronrod-quadrature-nodes-weights/\r\n// node_g0k0 = 0;\r\n// node_g1k2 = 4.058451513773971669066064120769615e-01 exact;\r\nconst node_g1k2 = 0.4058451513773972;\r\n// node_g2k4 = 7.415311855993944398638647732807884e-01 exact;\r\nconst node_g2k4 = 0.7415311855993945;\r\n// node_g3k6 = 9.491079123427585245261896840478513e-01 exact;\r\nconst node_g3k6 = 0.9491079123427585;\r\n// node_k1 = 2.077849550078984676006894037732449e-01 exact;\r\nconst node_k1 = 0.20778495500789848;\r\n// node_k3 = 5.860872354676911302941448382587296e-01 exact;\r\nconst node_k3 = 0.5860872354676911;\r\n// node_k5 = 8.648644233597690727897127886409262e-01 exact;\r\nconst node_k5 = 0.8648644233597691;\r\n// node_k7 = 9.914553711208126392068546975263285e-01 exact;\r\nconst node_k7 = 0.9914553711208126;\r\n// weight_g0 = 4.179591836734693877551020408163265e-01 exact;\r\nconst weight_g0 = 0.4179591836734694;\r\n// weight_g1 = 3.818300505051189449503697754889751e-01 exact;\r\nconst weight_g1 = 0.3818300505051189;\r\n// weight_g2 = 2.797053914892766679014677714237796e-01 exact;\r\nconst weight_g2 = 0.27970539148927664;\r\n// weight_g3 = 1.294849661688696932706114326790820e-01 exact;\r\nconst weight_g3 = 0.1294849661688697;\r\n// weight_k0 = 2.094821410847278280129991748917143e-01 exact;\r\nconst weight_k0 = 0.20948214108472782;\r\n// weight_k1 = 2.044329400752988924141619992346491e-01 exact;\r\nconst weight_k1 = 0.20443294007529889;\r\n// weight_k2 = 1.903505780647854099132564024210137e-01 exact;\r\nconst weight_k2 = 0.19035057806478542;\r\n// weight_k3 = 1.690047266392679028265834265985503e-01 exact;\r\nconst weight_k3 = 0.1690047266392679;\r\n// weight_k4 = 1.406532597155259187451895905102379e-01 exact;\r\nconst weight_k4 = 0.14065325971552592;\r\n// weight_k5 = 1.047900103222501838398763225415180e-01 exact;\r\nconst weight_k5 = 0.10479001032225019;\r\n// weight_k6 = 6.309209262997855329070066318920429e-02 exact;\r\nconst weight_k6 = 0.06309209262997856;\r\n// weight_k7 = 2.293532201052922496373200805896959e-02 exact;\r\nconst weight_k7 = 0.022935322010529224;\r\n/**\r\n * Perform a single integration step.\r\n *\r\n * @param f Integrand callback.\r\n * @param a Lower limit.\r\n * @param b Upper limit.\r\n * @returns [current best estimate, poor estimate]\r\n */\r\nconst integrationStep = (f, // Integrand.\r\na, // Lower limit.\r\nb) => {\r\n // Gauss-Kronrod (G7, K15).\r\n const scale = (b - a) / 2;\r\n const offset = (a + b) / 2;\r\n // const scaled_g0k0 = 0;\r\n const scaled_k1 = node_k1 * scale;\r\n const scaled_g1k2 = node_g1k2 * scale;\r\n const scaled_k3 = node_k3 * scale;\r\n const scaled_g2k4 = node_g2k4 * scale;\r\n const scaled_k5 = node_k5 * scale;\r\n const scaled_g3k6 = node_g3k6 * scale;\r\n const scaled_k7 = node_k7 * scale;\r\n const scaled_weight_g0 = weight_g0 * scale;\r\n const scaled_weight_g1 = weight_g1 * scale;\r\n const scaled_weight_g2 = weight_g2 * scale;\r\n const scaled_weight_g3 = weight_g3 * scale;\r\n const scaled_weight_k0 = weight_k0 * scale;\r\n const scaled_weight_k1 = weight_k1 * scale;\r\n const scaled_weight_k2 = weight_k2 * scale;\r\n const scaled_weight_k3 = weight_k3 * scale;\r\n const scaled_weight_k4 = weight_k4 * scale;\r\n const scaled_weight_k5 = weight_k5 * scale;\r\n const scaled_weight_k6 = weight_k6 * scale;\r\n const scaled_weight_k7 = weight_k7 * scale;\r\n const f_g0k0 = f(offset);\r\n const f_k1_h = f(offset + scaled_k1);\r\n const f_k1_l = f(offset - scaled_k1);\r\n const f_g1k2_h = f(offset + scaled_g1k2);\r\n const f_g1k2_l = f(offset - scaled_g1k2);\r\n const f_k3_h = f(offset + scaled_k3);\r\n const f_k3_l = f(offset - scaled_k3);\r\n const f_g2k4_h = f(offset + scaled_g2k4);\r\n const f_g2k4_l = f(offset - scaled_g2k4);\r\n const f_k5_h = f(offset + scaled_k5);\r\n const f_k5_l = f(offset - scaled_k5);\r\n const f_g3k6_h = f(offset + scaled_g3k6);\r\n const f_g3k6_l = f(offset - scaled_g3k6);\r\n const f_k7_h = f(offset + scaled_k7);\r\n const f_k7_l = f(offset - scaled_k7);\r\n const poorEstimate = scaled_weight_g0 * f_g0k0 + // g0\r\n scaled_weight_g1 * (f_g1k2_h + f_g1k2_l) + // g1\r\n scaled_weight_g2 * (f_g2k4_h + f_g2k4_l) + // g2\r\n scaled_weight_g3 * (f_g3k6_h + f_g3k6_l); // g3\r\n const currentEstimate = scaled_weight_k0 * f_g0k0 + // k0\r\n scaled_weight_k1 * (f_k1_h + f_k1_l) + // k1\r\n scaled_weight_k2 * (f_g1k2_h + f_g1k2_l) + // k2\r\n scaled_weight_k3 * (f_k3_h + f_k3_l) + // k3\r\n scaled_weight_k4 * (f_g2k4_h + f_g2k4_l) + // k4\r\n scaled_weight_k5 * (f_k5_h + f_k5_l) + // k5\r\n scaled_weight_k6 * (f_g3k6_h + f_g3k6_l) + // k6\r\n scaled_weight_k7 * (f_k7_h + f_k7_l); // k7\r\n return [currentEstimate, poorEstimate];\r\n};\r\n","import { quadrature } from './quad/adaptive-quadrature.js';\r\nimport { integrationStep } from './quad/gauss-kronrod-g7k15.js';\r\nconst rangeErrorMessage = 'integration range must be an array of at least two endpoints';\r\n/**\r\n * Numerically compute a definite integral.\r\n *\r\n * @param f Callback returning value of integrand.\r\n * @param range A range of at least 2 endpoints.\r\n * @param options Options for the computation.\r\n *\r\n * @returns The results of the computation.\r\n */\r\nexport const quad = (f, range, options = {}) => {\r\n // Interpret the range.\r\n if (!Array.isArray(range)) {\r\n throw new RangeError(rangeErrorMessage);\r\n }\r\n if (range.length === 2) {\r\n // Integrate over a single range.\r\n const [a, b] = range;\r\n return quadrature(integrationStep, f, a, b, options);\r\n }\r\n if (range.length < 2) {\r\n // Can't integrate at a point!\r\n throw new RangeError(rangeErrorMessage);\r\n }\r\n // Integrate over multiple ranges.\r\n let result = 0;\r\n const points = [];\r\n const info = {\r\n steps: 0,\r\n errorEstimate: 0,\r\n points,\r\n depth: 0,\r\n };\r\n for (let i = 0; i < range.length - 1; ++i) {\r\n const single = quadrature(integrationStep, f, range[i], range[i + 1], options);\r\n info.points.push(single);\r\n // Update the result.\r\n result += single[0];\r\n // Update the cumulative statistics.\r\n info.steps += single[1].steps;\r\n info.errorEstimate += single[1].errorEstimate;\r\n info.depth = Math.max(info.depth, single[1].depth);\r\n }\r\n return [result, info];\r\n};\r\n","export const version = '1.2.0';\r\nexport * as integrate from './integrate.js';\r\n"],"names":["defaults","epsilon","Number","EPSILON","maxDepth","POSITIVE_INFINITY","quadrature","integrationStep","f","a","b","options","settings","Object","assign","info","steps","errorEstimate","depth","_f","_a","_b","isFinite","t","oneOverOneMinusT","tSquared","oneOverOneMinusTSquared","changeOfVariables","result","integrate_part","acceptableUnitError","Math","abs","estimates","currentEstimate","poorEstimate","mid","isUnreliable","safeErrorEstimate","isNaN","leftResult","rightResult","scale","offset","scaled_k1","scaled_g1k2","scaled_k3","scaled_g2k4","scaled_k5","scaled_g3k6","scaled_k7","scaled_weight_g0","scaled_weight_g1","scaled_weight_g2","scaled_weight_g3","scaled_weight_k0","scaled_weight_k1","scaled_weight_k2","scaled_weight_k3","scaled_weight_k4","scaled_weight_k5","scaled_weight_k6","scaled_weight_k7","f_g0k0","f_k1_h","f_k1_l","f_g1k2_h","f_g1k2_l","f_k3_h","f_k3_l","f_g2k4_h","f_g2k4_l","f_k5_h","f_k5_l","f_g3k6_h","f_g3k6_l","rangeErrorMessage","range","Array","isArray","RangeError","length","points","i","single","push","max"],"mappings":";;;;qCAEA,MAAMA,EAAW,CACbC,QAA0B,GAAjBC,OAAOC,QAChBC,SAAUF,OAAOG,mBAyCfC,EAAa,CAACC,EAAiBC,EAAGC,EAAGC,EAAGC,EAAU,MAEpD,MAAMC,EAAWC,OAAOC,OAAOD,OAAOC,OAAO,GAAId,GAAWW,IACtDV,QAAEA,EAAOG,SAAEA,GAAaQ,EACxBG,EAAO,CAAEC,MAAO,EAAGC,cAAe,EAAGC,MAAO,IAE3CC,EAAIC,EAAIC,GApCO,EAACb,EAAGC,EAAGC,KAC7B,IAAKY,SAASZ,GACV,OAAKY,SAASb,GAiBP,CAJKc,IACR,MAAMC,EAAmB,GAAK,EAAID,GAClC,OAAOf,EAAEC,EAAIc,EAAIC,GAAoBA,EAAmBA,GAEhD,EAAG,GAPJ,CARKD,IACR,MAAME,EAAWF,EAAIA,EACfG,EAA0B,GAAK,EAAID,GACzC,OAAQjB,EAAEe,EAAIG,IACT,EAAID,GACLC,EACAA,IAEK,EAAG,GASxB,IAAKJ,SAASb,GAKV,MAAO,CAHKc,GACDf,EAAEE,GAAK,EAAIa,GAAKA,IAAMA,EAAIA,GAEzB,EAAG,GAEnB,MAA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AEmC,EAASO,GACX1C,EAAEmC,EAASO,IACLC,EAAmBY,EACpCX,GAAoBc,EAAWC,GAC/Bd,GAAoBiB,EAAWC,GAC/BjB,GAAoBoB,EAAWC,KC7FjCC,EAAoB,wGAUN,CAACpE,EAAGqE,EAAOlE,EAAU,MAErC,IAAKmE,MAAMC,QAAQF,GACf,MAAM,IAAIG,WAAWJ,GAEzB,GAAqB,IAAjBC,EAAMI,OAAc,CAEpB,MAAOxE,EAAGC,GAAKmE,EACf,OAAOvE,EAAWC,EAAiBC,EAAGC,EAAGC,EAAGC,GAEhD,GAAIkE,EAAMI,OAAS,EAEf,MAAM,IAAID,WAAWJ,GAGzB,IAAIhD,EAAS,EACb,MACMb,EAAO,CACTC,MAAO,EACPC,cAAe,EACfiE,OAJW,GAKXhE,MAAO,GAEX,IAAK,IAAIiE,EAAI,EAAGA,EAAIN,EAAMI,OAAS,IAAKE,EAAG,CACvC,MAAMC,EAAS9E,EAAWC,EAAiBC,EAAGqE,EAAMM,GAAIN,EAAMM,EAAI,GAAIxE,GACtEI,EAAKmE,OAAOG,KAAKD,GAEjBxD,GAAUwD,EAAO,GAEjBrE,EAAKC,OAASoE,EAAO,GAAGpE,MACxBD,EAAKE,eAAiBmE,EAAO,GAAGnE,cAChCF,EAAKG,MAAQa,KAAKuD,IAAIvE,EAAKG,MAAOkE,EAAO,GAAGlE,OAEhD,MAAO,CAACU,EAAQb,qCC7CG"} |
+2
-2
@@ -1,2 +0,2 @@ | ||
| export const version = '1.1.0'; | ||
| export * as integrate from './integrate/index.js'; | ||
| export const version = '1.2.0'; | ||
| export * as integrate from './integrate.js'; |
+3
-4
| { | ||
| "name": "@rec-math/math", | ||
| "version": "1.1.0", | ||
| "version": "1.2.0", | ||
| "description": "Mathematics for the browser (and TypeScript, JavaScript).", | ||
| "main": "esm/index.js", | ||
| "browser": "dist/rec-math.min.js", | ||
| "module": "esm", | ||
| "module": "esm/index.js", | ||
| "type": "module", | ||
@@ -19,3 +18,3 @@ "sideEffects": false, | ||
| "build:esm": "tsc --project tsconfig.types.json && tsc --project tsconfig.build.json", | ||
| "ci:test": "npm run lint && npm run test:unit && npm run build", | ||
| "ci:build": "npm run lint && npm run test:unit && npm run build", | ||
| "lint": "eslint . && prettier . --check", | ||
@@ -22,0 +21,0 @@ "lint:fix": "eslint . --fix && prettier . --write", |
+7
-7
| declare module "integrate/quad/adaptive-quadrature" { | ||
| import type { IntegrandCallback, IntegrationStep, QuadratureInfo, QuadratureOptions } from "integrate/quad/index"; | ||
| import type { IntegrandCallback, IntegrationStep, QuadratureInfo, QuadratureOptions } from "integrate/quad"; | ||
| export { quadrature }; | ||
@@ -7,3 +7,3 @@ const quadrature: (integrationStep: IntegrationStep, f: IntegrandCallback, a: number, b: number, options?: QuadratureOptions) => [r: number, i: QuadratureInfo]; | ||
| declare module "integrate/quad/gauss-kronrod-g7k15" { | ||
| import type { IntegrationStep } from "integrate/quad/index"; | ||
| import type { IntegrationStep } from "integrate/quad"; | ||
| export { integrationStep }; | ||
@@ -20,3 +20,3 @@ /** | ||
| } | ||
| declare module "integrate/quad/index" { | ||
| declare module "integrate/quad" { | ||
| export type IntegrandCallback = (a: number) => number; | ||
@@ -62,9 +62,9 @@ export interface QuadratureInfo { | ||
| } | ||
| declare module "integrate/index" { | ||
| export { quad } from "integrate/quad/index"; | ||
| declare module "integrate" { | ||
| export { quad } from "integrate/quad"; | ||
| } | ||
| declare module "index" { | ||
| export const version = "1.1.0"; | ||
| export * as integrate from "integrate/index"; | ||
| export const version = "1.2.0"; | ||
| export * as integrate from "integrate"; | ||
| } | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/integrate/quad/adaptive-quadrature.ts","../src/integrate/quad/gauss-kronrod-g7k15.ts","../src/integrate/quad/index.ts","../src/integrate/index.ts","../src/index.ts"],"names":[],"mappings":";IAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,c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,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,CA8C/B,CAAC;;;ICnGF,OAAO,EAAE,IAAI,EAAE,6BAAwB;;;ICDvC,MAAM,CAAC,MAAM,OAAO,UAAU,CAAC;IAE/B,OAAO,KAAK,SAAS,wBAA6B"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/integrate/quad/adaptive-quadrature.ts","../src/integrate/quad/gauss-kronrod-g7k15.ts","../src/integrate/quad.ts","../src/integrate.ts","../src/index.ts"],"names":[],"mappings":";IAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,iBAAiB,EAClB,uBAAgB;IAGjB,OAAO,EAAE,UAAU,EAAE,CAAC;IAsDtB,MAAM,UAAU,oBACG,eAAe,KAC7B,iBAAiB,KACjB,MAAM,KACN,MAAM,YACA,iBAAiB,KACzB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,CAqC/B,CAAC;;;ICzGF,OAAO,KAAK,EAAqB,eAAe,EAAE,uBAAgB;IAGlE,OAAO,EAAE,eAAe,EAAE,CAAC;IAgD3B;;;;;;;OAOG;IACH,MAAM,eAAe,EAAE,eAqEtB,CAAC;;;IC7HF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAEtD,MAAM,WAAW,cAAc;QAC7B,iDAAiD;QACjD,KAAK,EAAE,MAAM,CAAC;QACd,oCAAoC;QACpC,aAAa,EAAE,MAAM,CAAC;QACtB;;;WAGG;QACH,YAAY,CAAC,EAAE,IAAI,CAAC;QACpB;;;WAGG;QACH,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,CAAC,EAAE,CAAC;QAC1C,8BAA8B;QAC9B,KAAK,EAAE,MAAM,CAAC;KACf;IAED,MAAM,WAAW,iBAAiB;QAChC,oCAAoC;QACpC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,qDAAqD;QACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IAED,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB;IACrB,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EACxB,CAAC,EAAE,MAAM,EAAE,eAAe;IAC1B,CAAC,EAAE,MAAM,KACN,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IAK5B;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,IAAI,MACZ,iBAAiB,SACb,MAAM,EAAE,YACN,iBAAiB,KACzB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,CA8C/B,CAAC;;;ICnGF,OAAO,EAAE,IAAI,EAAE,uBAA4B;;;ICD3C,MAAM,CAAC,MAAM,OAAO,UAAU,CAAC;IAE/B,OAAO,KAAK,SAAS,kBAAuB"} |
| // Export the default method. | ||
| export { quad } from './quad/index.js'; |
| import { quadrature } from './adaptive-quadrature.js'; | ||
| import { integrationStep } from './gauss-kronrod-g7k15.js'; | ||
| const rangeErrorMessage = 'integration range must be an array of at least two endpoints'; | ||
| /** | ||
| * Numerically compute a definite integral. | ||
| * | ||
| * @param f Callback returning value of integrand. | ||
| * @param range A range of at least 2 endpoints. | ||
| * @param options Options for the computation. | ||
| * | ||
| * @returns The results of the computation. | ||
| */ | ||
| export const quad = (f, range, options = {}) => { | ||
| // Interpret the range. | ||
| if (!Array.isArray(range)) { | ||
| throw new RangeError(rangeErrorMessage); | ||
| } | ||
| if (range.length === 2) { | ||
| // Integrate over a single range. | ||
| const [a, b] = range; | ||
| return quadrature(integrationStep, f, a, b, options); | ||
| } | ||
| if (range.length < 2) { | ||
| // Can't integrate at a point! | ||
| throw new RangeError(rangeErrorMessage); | ||
| } | ||
| // Integrate over multiple ranges. | ||
| let result = 0; | ||
| const points = []; | ||
| const info = { | ||
| steps: 0, | ||
| errorEstimate: 0, | ||
| points, | ||
| depth: 0, | ||
| }; | ||
| for (let i = 0; i < range.length - 1; ++i) { | ||
| const single = quadrature(integrationStep, f, range[i], range[i + 1], options); | ||
| info.points.push(single); | ||
| // Update the result. | ||
| result += single[0]; | ||
| // Update the cumulative statistics. | ||
| info.steps += single[1].steps; | ||
| info.errorEstimate += single[1].errorEstimate; | ||
| info.depth = Math.max(info.depth, single[1].depth); | ||
| } | ||
| return [result, info]; | ||
| }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
-100%38967
-0.14%