Skip to content

Commit c6e5950

Browse files
authored
Merge pull request #70 from pie-framework/feat/PD-4890
feat: update demo page PD-4890
2 parents 7d6f52a + 0bcb192 commit c6e5950

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

docs/js/demo.js

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39770,14 +39770,50 @@ const expressionsCanBeCompared = (
3977039770
});
3977139771
return noFunctionOrArray && symbolNode && !seriesNode;
3977239772
};
39773+
const hasSymbolicExponent = (node) => {
39774+
let found = false;
39775+
node.traverse((n) => {
39776+
if (
39777+
n.isOperatorNode &&
39778+
n.op === "^" &&
39779+
!_optionalChain$2([n, 'access', _ => _.args, 'access', _2 => _2[1], 'optionalAccess', _3 => _3.isConstantNode])
39780+
) {
39781+
found = true;
39782+
}
39783+
});
39784+
return found;
39785+
};
39786+
const areNumericallyEquivalent = (
39787+
exprA,
39788+
exprB,
39789+
variables,
39790+
tolerance = 1e-10
39791+
) => {
39792+
const compiledA = m$4.compile(exprA.toString());
39793+
const compiledB = m$4.compile(exprB.toString());
39794+
const testValues = [1, 2, 3, 4, 5];
39795+
return testValues.every((val) => {
39796+
const scope = variables.reduce((acc, v) => {
39797+
acc[v] = val;
39798+
return acc;
39799+
}, {} );
39800+
try {
39801+
const resultA = compiledA.evaluate(scope);
39802+
const resultB = compiledB.evaluate(scope);
39803+
return Math.abs(resultA - resultB) < tolerance;
39804+
} catch (e2) {
39805+
return false;
39806+
}
39807+
});
39808+
};
3977339809
const transformEqualityInExpression = (equality) =>
3977439810
simplify$1(new m$4.OperatorNode("-", "subtract", equality.args));
3977539811
const getVariables = (equation) => {
3977639812
let variableNames = [];
3977739813
equation.traverse(function (node, path, parent) {
3977839814
if (
3977939815
node.isSymbolNode &&
39780-
_optionalChain$2([node, 'optionalAccess', _ => _.name, 'access', _2 => _2.length]) === 1 &&
39816+
_optionalChain$2([node, 'optionalAccess', _4 => _4.name, 'access', _5 => _5.length]) === 1 &&
3978139817
!variableNames.includes(node.name)
3978239818
) {
3978339819
variableNames.push(node.name);
@@ -39823,14 +39859,14 @@ const solveQuadraticEquation = (coefficients) => {
3982339859
addDiscriminant = m$4.compile(
3982439860
m$4.fraction(-b + m$4.sqrt(discriminant)) / (2 * a)
3982539861
);
39826-
} catch (e2) {
39862+
} catch (e3) {
3982739863
addDiscriminant = m$4.compile("(-b+sqrt(discriminant))/(2*a)");
3982839864
}
3982939865
try {
3983039866
subtractDiscriminant = m$4.compile(
3983139867
m$4.fraction(-b - m$4.sqrt(discriminant)) / (2 * a)
3983239868
);
39833-
} catch (e3) {
39869+
} catch (e4) {
3983439870
subtractDiscriminant = m$4.compile("(-b-sqrt(discriminant))/(2*a)");
3983539871
}
3983639872
let firstRoot = addDiscriminant.evaluate({
@@ -39925,6 +39961,17 @@ const compareEquations = (
3992539961
}
3992639962
let firstEquationCoefficients;
3992739963
let secondEquationCoefficients;
39964+
if (
39965+
hasSymbolicExponent(firstExpression) ||
39966+
hasSymbolicExponent(secondExpression)
39967+
) {
39968+
const isEquivalent = areNumericallyEquivalent(
39969+
firstExpression,
39970+
secondExpression,
39971+
firstEquationVariablesName
39972+
);
39973+
return isEquivalent;
39974+
}
3992839975
if (firstEquationVariablesName.length === 1) {
3992939976
firstEquationCoefficients = getCoefficients(
3993039977
firstExpression,

0 commit comments

Comments
 (0)