test_leiden_oefenopgave_v12.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # This file is part of TRS (http://math.kompiler.org)
  2. #
  3. # TRS is free software: you can redistribute it and/or modify it under the
  4. # terms of the GNU Affero General Public License as published by the Free
  5. # Software Foundation, either version 3 of the License, or (at your option) any
  6. # later version.
  7. #
  8. # TRS is distributed in the hope that it will be useful, but WITHOUT ANY
  9. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  10. # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  11. # details.
  12. #
  13. # You should have received a copy of the GNU Affero General Public License
  14. # along with TRS. If not, see <http://www.gnu.org/licenses/>.
  15. from tests.rulestestcase import RulesTestCase as TestCase
  16. class TestLeidenOefenopgaveV12(TestCase):
  17. def test_1_d(self):
  18. self.assertRewrite([
  19. '(2x + x)x',
  20. '(2 + 1)x * x',
  21. '3x * x',
  22. '3x ^ (1 + 1)',
  23. '3x ^ 2',
  24. ])
  25. def test_1_e(self):
  26. self.assertRewrite([
  27. '-2(6x - 4) ^ 2x',
  28. '-2(6x - 4)(6x - 4)x',
  29. '-(2 * 6x + 2 * -4)(6x - 4)x',
  30. '-(12x + 2 * -4)(6x - 4)x',
  31. '-(12x - 8)(6x - 4)x',
  32. '-(12x - 8)(6x * x + (-4)x)',
  33. '-(12x - 8)(6x * x - 4x)',
  34. '-(12x - 8)(6x ^ (1 + 1) - 4x)',
  35. '-(12x - 8)(6x ^ 2 - 4x)',
  36. '-(12x * 6x ^ 2 + 12x * -4x + (-8)6x ^ 2 + (-8) * -4x)',
  37. '-(72x * x ^ 2 + 12x * -4x + (-8)6x ^ 2 + (-8) * -4x)',
  38. '-(72x * x ^ 2 + (-48)x * x + (-8)6x ^ 2 + (-8) * -4x)',
  39. '-(72x * x ^ 2 + (-48)x * x + (-48)x ^ 2 + (-8) * -4x)',
  40. '-(72x * x ^ 2 + (-48)x * x + (-48)x ^ 2 + (--32)x)',
  41. '-(72x * x ^ 2 + (-48)x * x + (-48)x ^ 2 + 32x)',
  42. '-(72x * x ^ 2 - 48x * x + (-48)x ^ 2 + 32x)',
  43. '-(72x * x ^ 2 - 48x * x - 48x ^ 2 + 32x)',
  44. '-(72x ^ (1 + 2) - 48x * x - 48x ^ 2 + 32x)',
  45. '-(72x ^ 3 - 48x * x - 48x ^ 2 + 32x)',
  46. '-(72x ^ 3 - 48x ^ (1 + 1) - 48x ^ 2 + 32x)',
  47. '-(72x ^ 3 - 48x ^ 2 - 48x ^ 2 + 32x)',
  48. '-(72x ^ 3 + (1 + 1) * -48x ^ 2 + 32x)',
  49. '-(72x ^ 3 + 2 * -48x ^ 2 + 32x)',
  50. '-(72x ^ 3 + (-96)x ^ 2 + 32x)',
  51. '-(72x ^ 3 - 96x ^ 2 + 32x)',
  52. '-72x ^ 3 - -96x ^ 2 - 32x',
  53. '-72x ^ 3 + 96x ^ 2 - 32x',
  54. ])
  55. def test_2_a(self):
  56. self.assertRewrite([
  57. '(a ^ 2 * b ^ -1) ^ 3 * a b ^ 2',
  58. '(a ^ 2 * 1 / b ^ 1) ^ 3 * a b ^ 2',
  59. '(a ^ 2 * 1 / b) ^ 3 * a b ^ 2',
  60. '((a ^ 2 * 1) / b) ^ 3 * a b ^ 2',
  61. '(a ^ 2 / b) ^ 3 * a b ^ 2',
  62. '(a ^ 2) ^ 3 / b ^ 3 * a b ^ 2',
  63. 'a ^ (2 * 3) / b ^ 3 * a b ^ 2',
  64. 'a ^ 6 / b ^ 3 * a b ^ 2',
  65. '(a ^ 6 * a) / b ^ 3 * b ^ 2',
  66. 'a ^ (6 + 1) / b ^ 3 * b ^ 2',
  67. 'a ^ 7 / b ^ 3 * b ^ 2',
  68. '(a ^ 7 * b ^ 2) / b ^ 3',
  69. 'b ^ 2 / b ^ 3 * a ^ 7 / 1',
  70. 'b ^ 2 / b ^ 3 * a ^ 7',
  71. 'b ^ (2 - 3)a ^ 7',
  72. 'b ^ -1 * a ^ 7',
  73. '1 / b ^ 1 * a ^ 7',
  74. '1 / b * a ^ 7',
  75. '(1a ^ 7) / b',
  76. 'a ^ 7 / b',
  77. ])
  78. def test_2_b(self):
  79. self.assertRewrite([
  80. 'a^3b^2a^3',
  81. 'a ^ (3 + 3)b ^ 2',
  82. 'a ^ 6 * b ^ 2',
  83. ])
  84. #def test_2_c(self):
  85. # self.assertRewrite([
  86. # 'a^5+a^3',
  87. # 'a ^ 5 + a ^ 3',
  88. # ])
  89. def test_2_d(self):
  90. self.assertRewrite([
  91. 'a^2+a^2',
  92. '(1 + 1)a ^ 2',
  93. '2a ^ 2',
  94. ])
  95. def test_2_e(self):
  96. self.assertRewrite([
  97. '4b^-2',
  98. '4 * 1 / b ^ 2',
  99. '(4 * 1) / b ^ 2',
  100. '4 / b ^ 2',
  101. ])
  102. def test_2_f(self):
  103. self.assertRewrite([
  104. '(4b) ^ -2',
  105. '4 ^ -2 * b ^ -2',
  106. '1 / 4 ^ 2 * b ^ -2',
  107. '1 / 16 * b ^ -2',
  108. '1 / 16 * 1 / b ^ 2',
  109. '(1 * 1) / (16b ^ 2)',
  110. '1 / (16b ^ 2)',
  111. ])