diff --git a/src/DataTree.cc b/src/DataTree.cc
index a74ea03cc2ec378af842c8590c10ad11108b151e..afa5288017a6964b809186189a34b024de0d1052 100644
--- a/src/DataTree.cc
+++ b/src/DataTree.cc
@@ -27,6 +27,8 @@
 
 #include "DataTree.hh"
 
+bool DataTree::no_commutativity = false;
+
 void
 DataTree::initConstants()
 {
@@ -205,7 +207,7 @@ DataTree::AddPlus(expr_t iArg1, expr_t iArg2)
 
   // To treat commutativity of "+"
   // Nodes iArg1 and iArg2 are sorted by index
-  if (iArg1->idx > iArg2->idx)
+  if (iArg1->idx > iArg2->idx && !no_commutativity)
     swap(iArg1, iArg2);
   return AddBinaryOp(iArg1, BinaryOpcode::plus, iArg2);
 }
@@ -284,7 +286,7 @@ DataTree::AddTimes(expr_t iArg1, expr_t iArg2)
 
   // To treat commutativity of "*"
   // Nodes iArg1 and iArg2 are sorted by index
-  if (iArg1->idx > iArg2->idx)
+  if (iArg1->idx > iArg2->idx && !no_commutativity)
     swap(iArg1, iArg2);
   return AddBinaryOp(iArg1, BinaryOpcode::times, iArg2);
 }
diff --git a/src/DataTree.hh b/src/DataTree.hh
index 39d7ff312a4b106e143c6baf4b230d490e6d9469..11bd2278bbb331e48e609d4afe5c1f98408c6c64 100644
--- a/src/DataTree.hh
+++ b/src/DataTree.hh
@@ -89,6 +89,9 @@ private:
   using second_deriv_external_function_node_map_t = map<tuple<vector<expr_t>, int, int, int>, SecondDerivExternalFunctionNode *>;
   second_deriv_external_function_node_map_t second_deriv_external_function_node_map;
 
+  // Flag to disable simplifications related to commutativity of addition and multiplication
+  static bool no_commutativity;
+
 protected:
   //! Stores local variables value (maps symbol ID to corresponding node)
   map<int, expr_t> local_variables_table;
@@ -340,6 +343,12 @@ public:
 
     return it->second;
   }
+
+  static void
+  setNoCommutativity()
+  {
+    no_commutativity = true;
+  }
 };
 
 inline expr_t
diff --git a/src/DynareMain.cc b/src/DynareMain.cc
index 7ab8d785f87f0451815e2dad60caa3786d63c457..723d948a437862d4ae020c212b28b625e4f59e5f 100644
--- a/src/DynareMain.cc
+++ b/src/DynareMain.cc
@@ -53,7 +53,7 @@ usage()
        << " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=second|third] [language=matlab|julia]"
        << " [params_derivs_order=0|1|2] [transform_unary_ops] [exclude_eqs=<equation_tag_list_or_file>] [include_eqs=<equation_tag_list_or_file>]"
        << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange] [nopreprocessoroutput]"
-       << " [mexext=<extension>] [matlabroot=<path>] [onlymodel] [notime] [use_dll]"
+       << " [mexext=<extension>] [matlabroot=<path>] [onlymodel] [notime] [use_dll] [nocommutativity]"
        << endl;
   exit(EXIT_FAILURE);
 }
@@ -415,6 +415,8 @@ main(int argc, char **argv)
         gui = true;
       else if (s == "use_dll")
         use_dll = true;
+      else if (s == "nocommutativity")
+        DataTree::setNoCommutativity();
       else
         {
           cerr << "Unknown option: " << s << endl;