From d4e5f60b5cb0d0e380bd26a9a0ec520c12fc9eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 2 Oct 2017 14:14:16 +0200 Subject: [PATCH] [poincare] In rulegen, do not sort children of non-commutative nodes!! Change-Id: Ibe228f400e688a17aeff4721fe6e77ab4bca1373 --- poincare/src/simplification/rulegen/node.cpp | 10 ++++++++++ poincare/src/simplification/rulegen/node.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) 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);