diff --git a/poincare/src/simplification/rulegen/node.cpp b/poincare/src/simplification/rulegen/node.cpp index f47724f15..c1bfc8cb6 100644 --- a/poincare/src/simplification/rulegen/node.cpp +++ b/poincare/src/simplification/rulegen/node.cpp @@ -186,6 +186,9 @@ void Node::sort() { for (Node * child : *m_children) { child->sort(); } + if (!isCommutative()) { + return; + } for (int i = m_children->size()-1; i > 0; i--) { bool isSorted = true; for (int j = 0; j < m_children->size()-1; j++) { @@ -200,6 +203,13 @@ void Node::sort() { } } +bool Node::isCommutative() { + if (m_name->compare("Addition") == 0 || m_name->compare("Multiplication") == 0) { + return true; + } + return false; +} + #if 0 std::string Node::generateSelectorConstructor(Rule * context) { diff --git a/poincare/src/simplification/rulegen/node.h b/poincare/src/simplification/rulegen/node.h index 1f106f324..0d8cbd056 100644 --- a/poincare/src/simplification/rulegen/node.h +++ b/poincare/src/simplification/rulegen/node.h @@ -30,7 +30,7 @@ public: private: int selectorCaptureIndexInRule(Rule * rule); int selectorIndexInRule(Rule * rule); - + bool isCommutative(); /* int generateTree(bool selector, Rule * context, int index, int indentationLevel); std::string generateSelectorConstructor(Rule * context);