fix linear substitution for polynomials

This commit is contained in:
Val Erastov (xibyte) 2020-03-15 03:06:00 -07:00
parent 9548c3908d
commit 10adf51426
2 changed files with 13 additions and 14 deletions

View file

@ -207,6 +207,7 @@ export class AlgNumSubSystem {
}
this.polynomials[i] = null;
} else if (polynomial.isLinear && polynomial.monomials.length === 1) {
this.polynomials[i] = null;
const monomial = polynomial.monomials[0];
const terms = monomial.terms;
if (terms.length === 1) {
@ -218,9 +219,9 @@ export class AlgNumSubSystem {
this.eliminatedParams.set(p, val);
for (let polynomial of this.polynomials) {
if (polynomial) {
polynomial.eliminate(p, val);
for (let otherPolynomial of this.polynomials) {
if (otherPolynomial) {
otherPolynomial.eliminate(p, val);
}
}
@ -228,7 +229,6 @@ export class AlgNumSubSystem {
}
}
this.polynomials[i] = null;
} else if (polynomial.monomials.length === 2 && polynomial.isLinear) {
let [m1, m2] = polynomial.monomials;
@ -244,22 +244,21 @@ export class AlgNumSubSystem {
const constant = - m2.constant / m1.constant;
if (eqEps(polynomial.constant, 0)) {
for (let polynomial of this.polynomials) {
if (polynomial) {
polynomial.substitute(p1, p2, constant);
this.polynomials[i] = null;
this.substitute(p1, new Polynomial().monomial(constant).term(p2, POW_1_FN));
for (let otherPolynomial of this.polynomials) {
if (otherPolynomial) {
otherPolynomial.substitute(p1, p2, constant);
}
}
this.substitute(p1, new Polynomial().monomial(constant).term(p2, POW_1_FN));
this.polynomials[i] = null;
requirePass = true;
} else {
const b = - polynomial.constant / m1.constant;
let transaction = compositeFn();
for (let polynomial of this.polynomials) {
if (polynomial) {
const polyTransaction = polynomial.linearSubstitution(p1, p2, constant, b);
for (let otherPolynomial of this.polynomials) {
if (otherPolynomial && otherPolynomial !== polynomial) {
const polyTransaction = otherPolynomial.linearSubstitution(p1, p2, constant, b);
if (!polyTransaction) {
transaction = null;
break;

View file

@ -363,7 +363,7 @@ export class ToThePowerFunction {
if (this.degree === 1) {
return new Polynomial(b).monomial(k).term(x, POW_1_FN);
} else if (this.degree === 2) {
return new Polynomial(b*b).monomial(k*k).term(x, POW_2_FN).monomial(2*k).term(x, POW_1_FN);
return new Polynomial(b*b).monomial(k*k).term(x, POW_2_FN).monomial(2*k*b).term(x, POW_1_FN);
} else {
return null;
}