FloPoly
所属分类:TypeScript编程
开发工具:TypeScript
文件大小:0KB
下载次数:0
上传日期:2023-08-05 01:58:59
上 传 者:
sh-1993
说明: 一个实用的、以根为中心的JavaScript多项式实用程序库。,
(A practical, root-focused JavaScript polynomial utility library.,)
文件列表:
.eslintrc.cjs (2178, 2023-08-06)
.mocharc.cjs (240, 2023-08-06)
.quokka (46, 2023-08-06)
.vscode/ (0, 2023-08-06)
.vscode/launch.json (639, 2023-08-06)
browser/ (0, 2023-08-06)
browser/index.js (387768, 2023-08-06)
browser/index.min.js (45810, 2023-08-06)
docs/ (0, 2023-08-06)
docs/.nojekyll (0, 2023-08-06)
docs/00fa1eaa.0d46f381.js (8652, 2023-08-06)
docs/00fa1eaa.acaa075e.js (8643, 2023-08-06)
docs/00fa1eaa.d990e3cc.js (8628, 2023-08-06)
docs/01715e52.498c5627.js (10444, 2023-08-06)
docs/01715e52.a8789f63.js (10453, 2023-08-06)
docs/01715e52.c0ef2b84.js (10429, 2023-08-06)
docs/01a85c17.1d6ecba7.js (1589, 2023-08-06)
docs/0268e157.1a88a223.js (4735, 2023-08-06)
docs/0268e157.e4fbe93a.js (4744, 2023-08-06)
docs/0268e157.f18287bf.js (4720, 2023-08-06)
docs/043b548b.803959ee.js (4936, 2023-08-06)
docs/043b548b.c0a345c1.js (4945, 2023-08-06)
docs/043b548b.dd639bbd.js (4921, 2023-08-06)
docs/0565b9f3.29dc50bd.js (5541, 2023-08-06)
docs/0565b9f3.58b0b30f.js (5526, 2023-08-06)
docs/0565b9f3.fc78355a.js (5550, 2023-08-06)
docs/06056503.5a28f421.js (4608, 2023-08-06)
docs/06056503.9d8f4722.js (4599, 2023-08-06)
docs/06056503.bea350d3.js (4584, 2023-08-06)
docs/086ece82.598ab107.js (6492, 2023-08-06)
docs/086ece82.7181327c.js (6468, 2023-08-06)
docs/086ece82.d685f703.js (6483, 2023-08-06)
docs/086ef06c.4556d68e.js (5273, 2023-08-06)
docs/086ef06c.8c089293.js (5264, 2023-08-06)
docs/086ef06c.c7af9607.js (5249, 2023-08-06)
docs/0a4cdd6a.13b8e115.js (5310, 2023-08-06)
docs/0a4cdd6a.282ca8dc.js (5319, 2023-08-06)
... ...
[![Coverage Status](https://coveralls.io/repos/github/FlorisSteenkamp/FloPoly/badge.svg?branch=master)](https://coveralls.io/github/FlorisSteenkamp/FloPoly?branch=master)
[![Build Status](https://travis-ci.org/FlorisSteenkamp/FloPoly.svg?branch=master)](https://travis-ci.org/FlorisSteenkamp/FloPoly)
# Overview
The focus is to find real roots of real coefficient polynomials from degree 1 up to about degree 20 as
accurately and as fast as possible, e.g.
```typescript
// some polynomial with double precision coefficients, i.e. x^6 - 21x^5 + 175x^4 - 735x^3 + 1624x^2 - 1764 + 720
const p = [1, -21, 175, -735, 1624, -1764, 720];
allRoots(p); //=> [0.9999999999999997, 2.0000000000000013, 2.9999999999999316, 4.00000000000096, 5.000000000000012, 6.00000000000028]
```
However, the above function, `allRoots`, does not take error bounds into account and
can thus be inaccurate if the roots have high condition numbers.
For extremely accurate (no matter how high the condition number) certified results use e.g.:
```typescript
const p = [1, -21, 175, -735, 1624, -1764, 720]; // some polynomial with double precision coefficients
allRootsCertifiedSimplified(p);
```
or for a more flexible function that takes the input polynomial coefficients
as double-double precision and the ability to specify error bounds on the coefficients
in addition to a fallback function to specify exact coefficients
(in the form of [Shewchuk expansions](https://people.eecs.berkeley.edu/~jrs/papers/robustr.pdf))
use `allRootsCertified`.
Though the focus is on root finding, the library include numerous useful operators
on polynomials with `double`, `double-double`, `Shewchuk expansion` and `bigint` coefficients, e.g
```typescript
add([1,2,3], [3,4]); //=> [1,5,7]
```
## Why only up to about degree 20?
This isn't a hard limit. Roughly speaking, since the roots are found
using [Rolle's Theorem](https://en.wikipedia.org/wiki/Rolle%27s_theorem)
it becomes asymptotically slower (compared to [Descartes Methods](https://en.wikipedia.org/wiki/Descartes%27_rule_of_signs)), i.e.
roughly `O(n)` vs `O(n)` the higher the polynomial degree, `n`.
Another reason is that evaluation of the polynomial at `x` when `|x| >> 1` can result in
overflow when the result is larger than about `1.8 x 10^308` (the max value a double precision floating point value can be).
# Documentation
For more in-depth documentation please [read the docs!](https://florissteenkamp.github.io/FloPoly).
# Installation
```cli
npm install flo-poly
```
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
and can be used in `Node.js` (or in a browser when bundled using e.g. Webpack).
Additionally, self-contained `ECMAScript Module` (ESM) files `index.js` and
`index.min.js` in the `./browser` folder is provided.
# Usage
### Node.js
```JavaScript
import { allRoots } from 'flo-poly';
// some polynomial with double precision coefficients, i.e. x^6 - 21x^5 + 175x^4 - 735x^3 + 1624x^2 - 1764 + 720
const p = [1, -21, 175, -735, 1624, -1764, 720];
const roots = allRoots(p);
if (roots.length === 6) {
console.log('success! '); // we should get to here!
} else {
console.log('failure! '); // ...and not here
}
```
### Browsers - directly, without a bundler, using the pre-bundled minified .js file
Please note that no tree shaking will take place in this case.
```html
Check the console.
```
### Bundlers (Webpack, Rollup, ...)
Webpack will be taken as an example here.
Since your webpack config file might still use `CommonJS` you must rename
`webpack.config.js` to `webpack.config.cjs`.
If you are using TypeScript:
Since this is an [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
library you must use [resolve-typescript-plugin](https://www.npmjs.com/package/resolve-typescript-plugin)
(at least until webpack catches up with ESM?) in your `webpack.config.cjs` file.
```cli
npm install --save-dev resolve-typescript-plugin
```
and follow the instructions given at [resolve-typescript-plugin](https://www.npmjs.com/package/resolve-typescript-plugin).
Additionally, follow this [guide](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm).
近期下载者:
相关文件:
收藏者: