FloPoly Polynomial Utility

7.0.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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. 😥');
}

view raw JSON →