test_leiden_oefenopgave_v12.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_a(self):
  18. self.assertRewrite([
  19. '-5(x^2 - 3x + 6)',
  20. '-(5x ^ 2 + 5(-3x) + 5 * 6)',
  21. '-(5x ^ 2 - 5 * 3x + 5 * 6)',
  22. '-(5x ^ 2 - 15x + 5 * 6)',
  23. '-(5x ^ 2 - 15x + 30)',
  24. '-5x ^ 2 - -15x - 30',
  25. '-5x ^ 2 + 15x - 30',
  26. ])
  27. def test_1_d(self):
  28. self.assertRewrite([
  29. '(2x + x)x',
  30. '(2 + 1)xx',
  31. '3xx',
  32. '3x ^ (1 + 1)',
  33. '3x ^ 2',
  34. ])
  35. def test_1_e(self):
  36. self.assertRewrite([
  37. '-2(6x - 4) ^ 2x',
  38. '-2(6x - 4)(6x - 4)x',
  39. '-(2 * 6x + 2(-4))(6x - 4)x',
  40. '-(12x + 2(-4))(6x - 4)x',
  41. '-(12x - 8)(6x - 4)x',
  42. '-(12x - 8)(6xx + (-4)x)',
  43. '-(12x - 8)(6x ^ (1 + 1) + (-4)x)',
  44. '-(12x - 8)(6x ^ 2 + (-4)x)',
  45. '-(12x - 8)(6x ^ 2 - 4x)',
  46. '-(12x * 6x ^ 2 + 12x(-4x) + (-8)6x ^ 2 + (-8)(-4x))',
  47. '-(72xx ^ 2 + 12x(-4x) + (-8)6x ^ 2 + (-8)(-4x))',
  48. '-(72x ^ (1 + 2) + 12x(-4x) + (-8)6x ^ 2 + (-8)(-4x))',
  49. '-(72x ^ 3 + 12x(-4x) + (-8)6x ^ 2 + (-8)(-4x))',
  50. '-(72x ^ 3 - 12x * 4x + (-8)6x ^ 2 + (-8)(-4x))',
  51. '-(72x ^ 3 - 48xx + (-8)6x ^ 2 + (-8)(-4x))',
  52. '-(72x ^ 3 - 48x ^ (1 + 1) + (-8)6x ^ 2 + (-8)(-4x))',
  53. '-(72x ^ 3 - 48x ^ 2 + (-8)6x ^ 2 + (-8)(-4x))',
  54. '-(72x ^ 3 - 48x ^ 2 + (-48)x ^ 2 + (-8)(-4x))',
  55. '-(72x ^ 3 - 48x ^ 2 - 48x ^ 2 + (-8)(-4x))',
  56. '-(72x ^ 3 - 48x ^ 2 - 48x ^ 2 - 8(-4x))',
  57. '-(72x ^ 3 - 48x ^ 2 - 48x ^ 2 - -8 * 4x)',
  58. '-(72x ^ 3 - 48x ^ 2 - 48x ^ 2 - -32x)',
  59. '-(72x ^ 3 - 48x ^ 2 - 48x ^ 2 + 32x)',
  60. '-(72x ^ 3 + (1 + 1)(-48x ^ 2) + 32x)',
  61. '-(72x ^ 3 + 2(-48x ^ 2) + 32x)',
  62. '-(72x ^ 3 - 2 * 48x ^ 2 + 32x)',
  63. '-(72x ^ 3 - 96x ^ 2 + 32x)',
  64. '-72x ^ 3 - -96x ^ 2 - 32x',
  65. '-72x ^ 3 + 96x ^ 2 - 32x',
  66. ])
  67. def test_2_a(self):
  68. self.assertRewrite([
  69. '(a ^ 2 * b ^ -1) ^ 3(ab ^ 2)',
  70. '(a ^ 2 * 1 / b ^ 1) ^ 3 * ab ^ 2',
  71. '(a ^ 2 * 1 / b) ^ 3 * ab ^ 2',
  72. '((a ^ 2 * 1) / b) ^ 3 * ab ^ 2',
  73. '(a ^ 2 / b) ^ 3 * ab ^ 2',
  74. '(a ^ 2) ^ 3 / b ^ 3 * ab ^ 2',
  75. 'a ^ (2 * 3) / b ^ 3 * ab ^ 2',
  76. 'a ^ 6 / b ^ 3 * ab ^ 2',
  77. '(a ^ 6 * a) / b ^ 3 * b ^ 2',
  78. 'a ^ (6 + 1) / b ^ 3 * b ^ 2',
  79. 'a ^ 7 / b ^ 3 * b ^ 2',
  80. '(a ^ 7 * b ^ 2) / b ^ 3',
  81. 'b ^ 2 / b ^ 3 * a ^ 7 / 1',
  82. 'b ^ (2 - 3)a ^ 7 / 1',
  83. 'b ^ (-1)a ^ 7 / 1',
  84. '1 / b ^ 1 * a ^ 7 / 1',
  85. '1 / b * a ^ 7 / 1',
  86. '1 / b * a ^ 7',
  87. '(1a ^ 7) / b',
  88. 'a ^ 7 / b',
  89. ])
  90. def test_2_b(self):
  91. self.assertRewrite([
  92. 'a^3b^2a^3',
  93. 'a ^ (3 + 3)b ^ 2',
  94. 'a ^ 6 * b ^ 2',
  95. ])
  96. #def test_2_c(self):
  97. # self.assertRewrite([
  98. # 'a^5+a^3',
  99. # 'a ^ 5 + a ^ 3',
  100. # ])
  101. def test_2_d(self):
  102. self.assertRewrite([
  103. 'a^2+a^2',
  104. '(1 + 1)a ^ 2',
  105. '2a ^ 2',
  106. ])
  107. def test_2_e(self):
  108. self.assertRewrite([
  109. '4b^-2',
  110. '4 * 1 / b ^ 2',
  111. '(4 * 1) / b ^ 2',
  112. '4 / b ^ 2',
  113. ])
  114. def test_2_f(self):
  115. self.assertRewrite([
  116. '(4b) ^ -2',
  117. '4 ^ (-2)b ^ (-2)',
  118. '1 / 4 ^ 2 * b ^ (-2)',
  119. '1 / 16 * b ^ (-2)',
  120. '1 / 16 * 1 / b ^ 2',
  121. '(1 * 1) / (16b ^ 2)',
  122. '1 / (16b ^ 2)',
  123. ])