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