semantic-math / math-rules

Manipulate math-ast ASTs based on algebraic rules
MIT License
4 stars 1 forks source link

Adding Numerator rule does not recognize subtraction #29

Closed aliang8 closed 7 years ago

aliang8 commented 7 years ago
export const ADD_NUMERATORS =
    defineRuleString('#a_0 / #b + ...', '(#a_0 + ...) / #b')

Example: ['2/3 - 2/3', '(2 - 2) / 3'] ['2/4 - 4/4 - 6/4', '(2 - 4 - 6) / 4']

TypeError: Cannot read property 'node' of null because it cannot find the matchPattern

[UPDATE] Also fails for REMOVE_ADDITION_OF_ZERO

E.g 2 - 0 => 2 , same error

kevinbarabash commented 7 years ago

This is not cool. The reason why we're not matching fractions when there's a minus is b/c the minus is a neg node wrapping the division so it doesn't look like division to the matcher. We can unwrap neg nodes to check if there's a fraction, but it's unclear to me how to communicate information about signs to the rewrite pattern.

kevinbarabash commented 7 years ago

I'm going to fix this for variable length patterns such as ADD_NUMERATORS, but not for fix length patterns such as REMOVE_ADDITION_OF_ZERO. This is to save time, but also to isolate any weird side effects there may be of making this change.