-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some additional helper functions #7
base: master
Are you sure you want to change the base?
Changes from 1 commit
3dceb6e
b862d6f
c72cb3d
f1d1e81
9ccc904
4f769a2
fc21cc9
7a26bad
cbc3bb9
b14fdeb
2ecf06c
623f926
e94f341
0c40e27
b21ee85
29938d4
c669902
2b31dfd
62f8a0d
acde4be
8c5671b
caf9282
5df8e66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,10 +212,10 @@ export const sortVariables = (variables) => | |
export const getCoefficientsAndConstants = (node, coefficientMap = {}, constants = [], others = []) => { | ||
if (isNumber(node) || isConstantFraction(node)) { | ||
constants.push(node) | ||
} else if (isFunction(node)) { | ||
} else if (isFunction(node) || hasConstantBase(node)) { | ||
// cos, sin, f(a), etc | ||
others.push(node) | ||
} else if (isPolynomialTerm(node) && !hasConstantBase(node)) { | ||
} else if (isPolynomialTerm(node)) { | ||
// x^2, 3x^2 | ||
|
||
// sort the variables first (2yzx -> 2xyz) | ||
|
@@ -232,7 +232,7 @@ export const getCoefficientsAndConstants = (node, coefficientMap = {}, constants | |
} else { | ||
coefficientMap[key].push(coefficient) | ||
} | ||
} else if(isPolynomial(node) || isApply(node)) { | ||
} else if(isPolynomial(node) || isAdd(node) || (isMul(node) && node.args.every(isPolynomialTerm))) { | ||
// 2x^2 + 3x + 1, 3x^2 * 2x^2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the comment, shouldn't checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so; it leaves out non-polynomial expressions such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. Can you update the comment with that example? |
||
node.args.forEach(function(arg) { | ||
getCoefficientsAndConstants(arg, coefficientMap, constants, others) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these two lines should be reverted.