فهرست منبع

Made combine_groups a high-priority rule.

Taddeus Kroes 13 سال پیش
والد
کامیت
fa97ae38ed
2فایلهای تغییر یافته به همراه27 افزوده شده و 23 حذف شده
  1. 5 1
      src/rules/precedences.py
  2. 22 22
      tests/test_leiden_oefenopgave.py

+ 5 - 1
src/rules/precedences.py

@@ -48,6 +48,10 @@ HIGH = [
         add_numerics,
         multiply_numerics,
         negated_factor,
+
+        # Combine occurences before doing other stuff to prevent duplicate
+        # calculations
+        combine_groups,
         ]
 
 
@@ -74,7 +78,7 @@ RELATIVE = [
 
         # Combine groups before expanding them
         # Expand 'single' before 'double' to avoid unnessecary complexity
-        (combine_groups, expand_single, expand_double),
+        (expand_single, expand_double),
 
         (factor_out_exponent_important, raise_numerics),
 

+ 22 - 22
tests/test_leiden_oefenopgave.py

@@ -46,22 +46,22 @@ class TestLeidenOefenopgave(TestCase):
             '(xx + x + 1x + 1 * 1)(x + 1)',
             '(xx + x + x + 1 * 1)(x + 1)',
             '(xx + x + x + 1)(x + 1)',
-            '(x ^ (1 + 1) + x + x + 1)(x + 1)',
-            '(x ^ 2 + x + x + 1)(x + 1)',
-            '(x ^ 2 + (1 + 1)x + 1)(x + 1)',
+            '(xx + (1 + 1)x + 1)(x + 1)',
+            '(xx + 2x + 1)(x + 1)',
+            '(x ^ (1 + 1) + 2x + 1)(x + 1)',
             '(x ^ 2 + 2x + 1)(x + 1)',
             'x ^ 2 * x + x ^ 2 * 1 + 2xx + 2x * 1 + 1x + 1 * 1',
             'x ^ 2 * x + x ^ 2 + 2xx + 2x * 1 + 1x + 1 * 1',
             'x ^ 2 * x + x ^ 2 + 2xx + 2x + 1x + 1 * 1',
             'x ^ 2 * x + x ^ 2 + 2xx + 2x + x + 1 * 1',
             'x ^ 2 * x + x ^ 2 + 2xx + 2x + x + 1',
-            'x ^ (2 + 1) + x ^ 2 + 2xx + 2x + x + 1',
-            'x ^ 3 + x ^ 2 + 2xx + 2x + x + 1',
-            'x ^ 3 + x ^ 2 + 2x ^ (1 + 1) + 2x + x + 1',
-            'x ^ 3 + x ^ 2 + 2x ^ 2 + 2x + x + 1',
-            'x ^ 3 + (1 + 2)x ^ 2 + 2x + x + 1',
-            'x ^ 3 + 3x ^ 2 + 2x + x + 1',
-            'x ^ 3 + 3x ^ 2 + (2 + 1)x + 1',
+            'x ^ 2 * x + x ^ 2 + 2xx + (2 + 1)x + 1',
+            'x ^ 2 * x + x ^ 2 + 2xx + 3x + 1',
+            'x ^ (2 + 1) + x ^ 2 + 2xx + 3x + 1',
+            'x ^ 3 + x ^ 2 + 2xx + 3x + 1',
+            'x ^ 3 + x ^ 2 + 2x ^ (1 + 1) + 3x + 1',
+            'x ^ 3 + x ^ 2 + 2x ^ 2 + 3x + 1',
+            'x ^ 3 + (1 + 2)x ^ 2 + 3x + 1',
             'x ^ 3 + 3x ^ 2 + 3x + 1',
         ])
 
@@ -74,9 +74,9 @@ class TestLeidenOefenopgave(TestCase):
             'xx + x + 1x + 1 * 1',
             'xx + x + x + 1 * 1',
             'xx + x + x + 1',
-            'x ^ (1 + 1) + x + x + 1',
-            'x ^ 2 + x + x + 1',
-            'x ^ 2 + (1 + 1)x + 1',
+            'xx + (1 + 1)x + 1',
+            'xx + 2x + 1',
+            'x ^ (1 + 1) + 2x + 1',
             'x ^ 2 + 2x + 1',
         ])
 
@@ -92,10 +92,10 @@ class TestLeidenOefenopgave(TestCase):
             'xx - x + (-1)x + 1',
             'xx - x - 1x + 1',
             'xx - x - x + 1',
-            'x ^ (1 + 1) - x - x + 1',
-            'x ^ 2 - x - x + 1',
-            'x ^ 2 + (1 + 1) * -x + 1',
-            'x ^ 2 + 2 * -x + 1',
+            'xx + (1 + 1) * -x + 1',
+            'xx + 2 * -x + 1',
+            'xx - 2x + 1',
+            'x ^ (1 + 1) - 2x + 1',
             'x ^ 2 - 2x + 1',
         ])
 
@@ -153,11 +153,11 @@ class TestLeidenOefenopgave(TestCase):
             '-(20x + (-16)xx + 25 + (-20)x)',
             '-(20x - 16xx + 25 + (-20)x)',
             '-(20x - 16xx + 25 - 20x)',
-            '-(20x - 16x ^ (1 + 1) + 25 - 20x)',
-            '-(20x - 16x ^ 2 + 25 - 20x)',
-            '-((1 - 1)20x - 16x ^ 2 + 25)',
-            '-(0 * 20x - 16x ^ 2 + 25)',
-            '-(0 - 16x ^ 2 + 25)',
+            '-((1 - 1)20x - 16xx + 25)',
+            '-(0 * 20x - 16xx + 25)',
+            '-(0 - 16xx + 25)',
+            '-(-16xx + 25)',
+            '-(-16x ^ (1 + 1) + 25)',
             '-(-16x ^ 2 + 25)',
             '--16x ^ 2 - 25',
             '16x ^ 2 - 25',