Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Better handling of Unnecessary Parentheses #252

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/Symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ Symbols.getLastSymbolTerm = function(node, symbolName) {
}
}
}
else if (Node.Type.isParenthesis(node)) {
return Symbols.getLastSymbolTerm(node.content, symbolName);
}

return null;
};

Expand Down
10 changes: 2 additions & 8 deletions lib/solveEquation/EquationOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,10 @@ EquationOperations.removeSymbolFromRightSide = function(equation, symbolName) {
// or dividing all other symbols and constants from both sides appropriately
// TODO: support inverting functions e.g. sqrt, ^, log etc.
EquationOperations.isolateSymbolOnLeftSide = function(equation, symbolName) {
let leftNode = equation.leftNode;

if (Node.Type.isParenthesis(leftNode)) {
// if entire left node is a parenthesis, we can ignore the parenthesis
leftNode = leftNode.content;
}

const leftNode = equation.leftNode;
let nonSymbolTerm = Symbols.getLastNonSymbolTerm(leftNode, symbolName);
let inverseOp, inverseTerm, changeType;

let inverseOp, inverseTerm, changeType;
if (!nonSymbolTerm) {
return EquationStatus.noChange(equation);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/solveEquation/stepThrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function stepThrough(leftNode, rightNode, comparator, debug=false) {
// If we have roots, we return early and do not go through simplification,
// so we can't rely on that flow for parentheses removal
// e.g. x^(2) = 0 -> x^2 = 0
equation.leftNode = removeUnnecessaryParens(equation.leftNode);
equation.rightNode = removeUnnecessaryParens(equation.rightNode);
equation.leftNode = removeUnnecessaryParens(equation.leftNode, true);
equation.rightNode = removeUnnecessaryParens(equation.rightNode, true);

// Checks if there are roots in the original equation before we
// do any simplification.
Expand Down
3 changes: 2 additions & 1 deletion test/solveEquation/solveEquation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ describe('solveEquation for =', function () {
['(3 + x) / (x^2 + 3) = 1', 'x = [0, 1]'],
['6/x + 8/(2x) = 10', 'x = 1'],
['(x+1)=4', 'x = 3'],
['((x)/(4))=4', 'x = 16']
['((x)/(4))=4', 'x = 16'],
['(2x-12)=(x+4)', 'x = 16']
// TODO: fix these cases, fail because lack of factoring support, for complex #s,
// for taking the sqrt of both sides, etc
// ['(x + y) (y + 2) = 0', 'y = -y'],
Expand Down