semantic-math / math-rules

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

provide a way to generate the inverse of a rule #8

Open kevinbarabash opened 7 years ago

kevinbarabash commented 7 years ago
const rule = defineRuleString('1 * #a', '#a')
const inverse = rule.inverse()  // equivalent to defineRuleString('#a', '1 * #a')
aliang8 commented 7 years ago

Not every rule has an inverse (e.g 0 / 1 or 2 - -3). So we can limit the inverses to only rules on addition and multiplication. One solution would just be to reverse the arguments (assuming that there are only two, e.g #a + 0 -> 0 + #a). Or, since we don't have too many rules right now we can hard code it. But that wouldn't be too ideal considering we would probably want to find inverse of other operations. What do you think?

kevinbarabash commented 7 years ago

It may be simpler to just write the reverse rules we want by hand.