Skip to content

Instantly share code, notes, and snippets.

View grossvogel's full-sized avatar
🐢

Jason Pollentier grossvogel

🐢
  • Revelry Labs
  • New Orleans, LA
View GitHub Profile
const polynomial = new Polynomial([1,2,3]); // 3x^2 + 2x + 1
const y1 = polynomial.evaluate(1); // 6
describe('newton\'s method', () => {
it('solves polynomial functions from a guess within 0.5', () => {
const solverTest = (polynomial, x) => {
if (polynomial.degree <= 0) {
return true; // no fun solving constant functions
};
// polynomial(x) = y, so we make a new polynomial
// polynomialWithZero such that polynomialWithZero(x) = 0
const y = polynomial.evaluate(x);
const shrink = polynomial => {
const arrayShrinker = jsc.shrink.array;
const arrayIntShrinker = arrayShrinker(jsc.integer.shrink);
const coefficientSets = arrayIntShrinker(polynomial.coefficients);
return coefficientSets.map(Polynomial.create);
};