Registry / ai-ml / flo-poly

flo-poly

JSON →
library7.0.1jsnpmunverified

FloPoly is a JavaScript/TypeScript utility library focused on efficient and accurate real root-finding for real-coefficient polynomials. Currently at version 7.0.1, it supports Node.js (>=12.20.0) and browser environments, distributed as an ECMAScript Module (ESM). The library excels in root-finding for polynomials up to approximately degree 20, employing Rolle's Theorem. It offers advanced capabilities like 'certified' root-finding, which are robust against high condition numbers, and supports various coefficient precisions including `double`, `double-double`, `Shewchuk expansions`, and `bigint`. Beyond root-finding, FloPoly provides a suite of polynomial operators. Its ESM-only distribution simplifies its use in modern JavaScript projects, though it marks a breaking change for older CommonJS environments. While a precise release cadence is not specified, the version jumps suggest significant, though not frequent, updates.

npm install flo-poly
INSTALL
IMPORT
SIG · FLO-POLY
F
flo-poly
ai-mljavascriptv7.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

allRoots
import { allRoots } from 'flo-poly';
const { allRoots } = require('flo-poly');
FloPoly is ESM-only. CommonJS `require` is not supported. Use named ESM imports.
allRootsCertifiedSimplified
import { allRootsCertifiedSimplified } from 'flo-poly';
import allRootsCertifiedSimplified from 'flo-poly';
This is a named export, not a default export. Ensure you destructure it correctly.
add
import { add } from 'flo-poly';
Used for polynomial addition; demonstrates a general polynomial operator import.
allRoots (browser)
import { allRoots } from './node_modules/flo-poly/browser/index.min.js';
import { allRoots } from 'flo-poly';
When using directly in browsers without a bundler, you must import from the pre-bundled path. The bare specifier `flo-poly` only works with bundlers or Node.js module resolution.

Demonstrates basic root finding with `allRoots`, highly accurate certified root finding with `allRootsCertifiedSimplified`, and a simple polynomial addition operation.

import { allRoots, allRootsCertifiedSimplified, add } from 'flo-poly'; // Example 1: Finding roots of a double-precision polynomial const p1 = [1, -21, 175, -735, 1624, -1764, 720]; // x^6 - 21x^5 + ... + 720 const roots1 = allRoots(p1); console.log('Roots (approximate):', roots1); // Example 2: Certified root finding for high accuracy const p2 = [1, -21, 175, -735, 1624, -1764, 720]; const certifiedRoots = allRootsCertifiedSimplified(p2); console.log('Roots (certified simplified):', certifiedRoots); // Example 3: Polynomial addition const polyA = [1, 2, 3]; // 1x^2 + 2x + 3 const polyB = [3, 4]; // 3x + 4 const sumPoly = add(polyA, polyB); console.log('Polynomial sum (1x^2 + 2x + 3) + (3x + 4):', sumPoly); // Expected: [1, 5, 7] if (roots1.length === 6 && sumPoly.length === 3) { console.log('FloPoly functions executed successfully! 😁'); } else { console.log('Something went wrong. 😥'); }
Debug
Known issues
breakingFloPoly is an ESM-only package since version 1.0.0 (or possibly earlier, certainly by 7.x.x). This means it cannot be `require()`-d in CommonJS environments without a transpilation step or a dynamic `import()` call, which may be slower.
fix
Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`) and use `import` statements. If using bundlers like Webpack with TypeScript, specific configurations like `resolve-typescript-plugin` might be necessary.
affects: >=1.0.0
gotchaThe `allRoots` function does not account for error bounds and can yield inaccurate results for polynomials with high condition numbers.
fix
For highly accurate and certified results, especially with ill-conditioned polynomials, use `allRootsCertifiedSimplified` or the more flexible `allRootsCertified` which supports `double-double` and `Shewchuk expansion` coefficients.
affects: >=0.1.0
gotchaThe library's performance using Rolle's Theorem for root finding becomes asymptotically slower (`O(n²)`) for higher polynomial degrees, typically beyond degree 20, compared to `O(n)` methods like Descartes' Rule of Signs.
fix
Consider the degree of polynomials when choosing FloPoly for performance-critical applications, or evaluate alternative libraries if consistently dealing with very high-degree polynomials where `O(n)` methods are critical.
affects: >=0.1.0
gotchaEvaluating polynomials with large `|x|` values can lead to floating-point overflow, as standard double-precision numbers have a maximum value of approximately `1.8 x 10^308`.
fix
If dealing with extremely large root magnitudes or coefficient values, utilize functions that support arbitrary-precision types like `bigint` or `double-double` where available within the library, or implement scaling pre-processing.
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` to import `flo-poly` in an ESM-only Node.js environment or a browser.
fix
Ensure your project is set up for ESM by adding `"type": "module"` to your `package.json` and using `import { ... } from 'flo-poly';`. If in a browser without a bundler, import from the explicit browser path: `import { ... } from './node_modules/flo-poly/browser/index.min.js';`
TypeError: (0 , flo_poly__WEBPACK_IMPORTED_MODULE_0__.allRoots) is not a function
This error typically occurs in a bundled environment (e.g., Webpack) when a CommonJS default export is incorrectly imported as a named ESM export, or vice-versa. Although FloPoly is ESM-only, incorrect import syntax can trigger similar errors. It could also happen if a module is incorrectly interpreted as having a default export when it only has named exports.
fix
Verify that `allRoots` is correctly imported as a named export: `import { allRoots } from 'flo-poly';`. FloPoly primarily uses named exports. If the issue persists with a bundler, ensure your bundler configuration correctly handles ESM imports, particularly for TypeScript projects where `resolve-typescript-plugin` might be needed.
Uncaught SyntaxError: Cannot use import statement outside a module
Attempting to use `import` syntax in a browser `<script>` tag without `type="module"` or in a Node.js environment that is configured for CommonJS.
fix
For browsers, ensure your script tag is `<script type="module">`. For Node.js, ensure your `package.json` includes `"type": "module"` to enable ESM globally, or run with `node --input-type=module` for single files.
Upgrade
Version history
7.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources