nerdamer 1.1.12 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Algebra.js +23 -8
- package/Calculus.js +5 -1
- package/Extra.js +1 -1
- package/README.md +30 -1
- package/Solve.js +52 -3
- package/all.min.js +1 -1
- package/gulpfile.js +15 -15
- package/index.d.ts +6 -0
- package/nerdamer.core.js +50 -153
- package/package.json +1 -1
- package/spec/algebra.spec.js +179 -731
- package/spec/calculus.spec.js +1 -0
- package/spec/solve.spec.js +7 -1
package/spec/algebra.spec.js
CHANGED
|
@@ -6,224 +6,81 @@ var nerdamer = require('../nerdamer.core.js');
|
|
|
6
6
|
require('../Algebra.js');
|
|
7
7
|
|
|
8
8
|
describe('Algebra', function () {
|
|
9
|
-
it('should perform gcd
|
|
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
|
-
given:'5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x,x',
|
|
70
|
-
expected_gcd: 'x',
|
|
71
|
-
expected_lcm: '(1375*x^9+1430*x^8+1872*x^6+37550*x^7+47075*x^5+7150*x^12+7510*x^3+9360*x+9360*x^10)*(361*x^7+473*x^5+5*x^11+72*x^3+90*x^9+91*x)*(5*x^6+x^2)^(-1)*x'
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
given:'x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3), 3+x^3',
|
|
75
|
-
expected_gcd: '3+x^3',
|
|
76
|
-
expected_lcm: '(12*x^3+12*x^4+3*x^5+4*x^6+4*x^7+x^8)*(3+x^3)^2*(6*x^3+x^6+9)^(-1)'
|
|
77
|
-
},
|
|
78
|
-
//End TODO
|
|
79
|
-
{
|
|
80
|
-
given:'a, b, c',
|
|
81
|
-
expected_gcd: 'gcd(a,b,c)',
|
|
82
|
-
expected_lcm: 'a*b*c*gcd(a*b,a*c,b*c)^(-1)'
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
given:'18,12, 6',
|
|
86
|
-
expected_gcd: '6',
|
|
87
|
-
expected_lcm: '36'
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
given:'3, 5, 7',
|
|
91
|
-
expected_gcd: '1',
|
|
92
|
-
expected_lcm: '105'
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
given:'1/2, 1/3, 1/4',
|
|
96
|
-
expected_gcd: '1/12',
|
|
97
|
-
expected_lcm: '1'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
given:'5%, 15%, 25%',
|
|
101
|
-
expected_gcd: '1/20',
|
|
102
|
-
expected_lcm: '3/4'
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
given:'1/a, 1/b, 1/c',
|
|
106
|
-
expected_gcd: 'gcd(a^(-1),b^(-1),c^(-1))',
|
|
107
|
-
expected_lcm: '1'
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
given:'2^x, 6^x',
|
|
111
|
-
expected_gcd: '2^x',
|
|
112
|
-
expected_lcm: '6^x'
|
|
113
|
-
},
|
|
114
|
-
{ //TODO: fix expected_lcm
|
|
115
|
-
given:'a, b, c, gcd(x, y, z, gcd(f,gcd(g,h)))',
|
|
116
|
-
expected_gcd: 'gcd(a,b,c,x,y,z,f,g,h)',
|
|
117
|
-
expected_lcm: 'a*b*c*gcd(x,y,z,f,g,h)'
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
given:'2^x, 6^x',
|
|
121
|
-
expected_gcd: '2^x',
|
|
122
|
-
expected_lcm: '6^x'
|
|
123
|
-
},
|
|
124
|
-
{ //TODO: remove duplicates
|
|
125
|
-
given:'a,a,b,b,gcd(c,c)',
|
|
126
|
-
expected_gcd: '1',
|
|
127
|
-
expected_lcm: 'a^2*b^2*c*gcd(a^2*b^2,a^2*b*c,a^2*b*c,a*b^2*c,a*b^2*c)^(-1)'
|
|
128
|
-
},
|
|
129
|
-
{ //TODO: remove duplicates
|
|
130
|
-
given:'a,a',
|
|
131
|
-
expected_gcd: 'a',
|
|
132
|
-
expected_lcm: 'a^2*gcd(a,a)^(-1)'
|
|
133
|
-
},
|
|
134
|
-
{ //TODO: fix expected_lcm, should be a^(b+c)
|
|
135
|
-
given:'a^b,a^c',
|
|
136
|
-
expected_gcd: 'a',
|
|
137
|
-
expected_lcm: 'a^(-1+b+c)'
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
given:'a^c,b^c',
|
|
141
|
-
expected_gcd: '1',
|
|
142
|
-
expected_lcm: 'a^c*b^c'
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
given:'a^a,a^a',
|
|
146
|
-
expected_gcd: 'a^a',
|
|
147
|
-
expected_lcm: 'a^a'
|
|
148
|
-
}
|
|
149
|
-
];
|
|
150
|
-
|
|
151
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
152
|
-
// when
|
|
153
|
-
var result_gcd = nerdamer("gcd(" + testCases[i].given + ")");
|
|
154
|
-
var result_lcm = nerdamer("lcm(" + testCases[i].given + ")");
|
|
155
|
-
|
|
156
|
-
// then
|
|
157
|
-
expect(result_gcd.toString()).toEqual(testCases[i].expected_gcd);
|
|
158
|
-
expect(result_lcm.toString()).toEqual(testCases[i].expected_lcm);
|
|
159
|
-
}
|
|
9
|
+
it('should perform gcd operations correctly', function () {
|
|
10
|
+
expect(nerdamer('gcd(5*x^6+5*x^5+27*x^4+27*x^3+28*x^2+28*x, 5*x^3+7*x)').toString()).toEqual('5*x^3+7*x');
|
|
11
|
+
expect(nerdamer('gcd(-20+16*i,-10+8*i)').toString()).toEqual('-10+8*i');
|
|
12
|
+
expect(nerdamer('gcd(2*x^2+2*x+1,x+1)').toString()).toEqual('1');
|
|
13
|
+
expect(nerdamer('gcd(x^2+2*x+1,x+1)').toString()).toEqual('1+x');
|
|
14
|
+
expect(nerdamer('gcd(6*x^9+24*x^8+15*x^7+6*x^2+24*x+15, (2*x^2+8*x+5))').toString()).toEqual('2*x^2+8*x+5');
|
|
15
|
+
expect(nerdamer('gcd(x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3))').toString()).toEqual('3+x^3');
|
|
16
|
+
expect(nerdamer('gcd(6*x^9+24*x^8+15*x^7+6*x^2+24*x+15, x^7+1)').toString()).toEqual('1+x^7');
|
|
17
|
+
expect(nerdamer('gcd(1+x^2,2*x)').toString()).toEqual('1');
|
|
18
|
+
expect(nerdamer('gcd(84*x^4+147*x^3+16*x^2+28*x, 44*x^5+77*x^4+16*x^3+28*x^2+12*x+21)').toString()).toEqual('4*x+7');
|
|
19
|
+
expect(nerdamer('gcd(5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x)').toString()).toEqual('5*x^5+x');
|
|
20
|
+
expect(nerdamer('gcd(7*x^4+7*x^3+4*x^2+5*x+1, 21*x^6+47*x^4+80*x^3+20*x^2+49*x+11)').toString()).toEqual('1+4*x+7*x^3');
|
|
21
|
+
expect(nerdamer('gcd(5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x,x)').toString()).toEqual('x');
|
|
22
|
+
expect(nerdamer('gcd(x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3), 3+x^3)').toString()).toEqual('3+x^3');
|
|
23
|
+
expect(nerdamer('gcd(a, b, c)').toString()).toEqual('gcd(a,b,c)');
|
|
24
|
+
expect(nerdamer('gcd(18,12, 6)').toString()).toEqual('6');
|
|
25
|
+
expect(nerdamer('gcd(3, 5, 7)').toString()).toEqual('1');
|
|
26
|
+
expect(nerdamer('gcd(1/2, 1/3, 1/4)').toString()).toEqual('1/12');
|
|
27
|
+
expect(nerdamer('gcd(5%, 15%, 25%)').toString()).toEqual('1/20');
|
|
28
|
+
expect(nerdamer('gcd(1/a, 1/b, 1/c)').toString()).toEqual('gcd(a^(-1),b^(-1),c^(-1))');
|
|
29
|
+
expect(nerdamer('gcd(2^x, 6^x)').toString()).toEqual('2^x');
|
|
30
|
+
expect(nerdamer('gcd(a, b, c, gcd(x, y, z, gcd(f,gcd(g,h))))').toString()).toEqual('gcd(a,b,c,x,y,z,f,g,h)');
|
|
31
|
+
expect(nerdamer('gcd(2^x, 6^x)').toString()).toEqual('2^x');
|
|
32
|
+
expect(nerdamer('gcd(a,a,b,b,gcd(c,c))').toString()).toEqual('1');
|
|
33
|
+
expect(nerdamer('gcd(a,a)').toString()).toEqual('a');
|
|
34
|
+
expect(nerdamer('gcd(a^b,a^c)').toString()).toEqual('a');
|
|
35
|
+
expect(nerdamer('gcd(a^c,b^c)').toString()).toEqual('1');
|
|
36
|
+
expect(nerdamer('gcd(a^a,a^a)').toString()).toEqual('a^a');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should perform lcm operations correctly', function () {
|
|
40
|
+
expect(nerdamer('lcm(5*x^6+5*x^5+27*x^4+27*x^3+28*x^2+28*x, 5*x^3+7*x)').toString()).toEqual('27*x^3+27*x^4+28*x+28*x^2+5*x^5+5*x^6');
|
|
41
|
+
expect(nerdamer('lcm(-20+16*i,-10+8*i)').toString()).toEqual('-10+8*i');
|
|
42
|
+
expect(nerdamer('lcm(2*x^2+2*x+1,x+1)').toString()).toEqual('(1+2*x+2*x^2)*(1+x)');
|
|
43
|
+
expect(nerdamer('lcm(x^2+2*x+1,x+1)').toString()).toEqual('1+2*x+x^2');
|
|
44
|
+
expect(nerdamer('lcm(6*x^9+24*x^8+15*x^7+6*x^2+24*x+15, (2*x^2+8*x+5))').toString()).toEqual('15+15*x^7+24*x+24*x^8+6*x^2+6*x^9');
|
|
45
|
+
expect(nerdamer('lcm(x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3))').toString()).toEqual('12*x^3+12*x^4+3*x^5+4*x^6+4*x^7+x^8');
|
|
46
|
+
expect(nerdamer('lcm(6*x^9+24*x^8+15*x^7+6*x^2+24*x+15, x^7+1)').toString()).toEqual('15+15*x^7+24*x+24*x^8+6*x^2+6*x^9');
|
|
47
|
+
expect(nerdamer('lcm(1+x^2,2*x)').toString()).toEqual('2*(1+x^2)*x');
|
|
48
|
+
expect(nerdamer('lcm(84*x^4+147*x^3+16*x^2+28*x, 44*x^5+77*x^4+16*x^3+28*x^2+12*x+21)').toString()).toEqual('(12*x+16*x^3+28*x^2+44*x^5+77*x^4+21)*(147*x^3+16*x^2+28*x+84*x^4)*(4*x+7)^(-1)');
|
|
49
|
+
expect(nerdamer('lcm(5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x)').toString()).toEqual('(1375*x^9+1430*x^8+1872*x^6+37550*x^7+47075*x^5+7150*x^12+7510*x^3+9360*x+9360*x^10)*(361*x^7+473*x^5+5*x^11+72*x^3+90*x^9+91*x)*(5*x^5+x)^(-1)');
|
|
50
|
+
expect(nerdamer('lcm(7*x^4+7*x^3+4*x^2+5*x+1, 21*x^6+47*x^4+80*x^3+20*x^2+49*x+11)').toString()).toEqual('(1+4*x+7*x^3)^(-1)*(1+4*x^2+5*x+7*x^3+7*x^4)*(11+20*x^2+21*x^6+47*x^4+49*x+80*x^3)');
|
|
51
|
+
expect(nerdamer('lcm(5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x,x)').toString()).toEqual('(1375*x^9+1430*x^8+1872*x^6+37550*x^7+47075*x^5+7150*x^12+7510*x^3+9360*x+9360*x^10)*(361*x^7+473*x^5+5*x^11+72*x^3+90*x^9+91*x)*(5*x^6+x^2)^(-1)*x');
|
|
52
|
+
expect(nerdamer('lcm(x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3), 3+x^3)').toString()).toEqual('(12*x^3+12*x^4+3*x^5+4*x^6+4*x^7+x^8)*(3+x^3)^2*(6*x^3+x^6+9)^(-1)');
|
|
53
|
+
expect(nerdamer('lcm(a, b, c)').toString()).toEqual('a*b*c*gcd(a*b,a*c,b*c)^(-1)');
|
|
54
|
+
expect(nerdamer('lcm(18,12, 6)').toString()).toEqual('36');
|
|
55
|
+
expect(nerdamer('lcm(3, 5, 7)').toString()).toEqual('105');
|
|
56
|
+
expect(nerdamer('lcm(1/2, 1/3, 1/4)').toString()).toEqual('1');
|
|
57
|
+
expect(nerdamer('lcm(5%, 15%, 25%)').toString()).toEqual('3/4');
|
|
58
|
+
expect(nerdamer('lcm(1/a, 1/b, 1/c)').toString()).toEqual('1');
|
|
59
|
+
expect(nerdamer('lcm(2^x, 6^x)').toString()).toEqual('6^x');
|
|
60
|
+
expect(nerdamer('lcm(a, b, c, gcd(x, y, z, gcd(f,gcd(g,h))))').toString()).toEqual('a*b*c*gcd(x,y,z,f,g,h)');
|
|
61
|
+
expect(nerdamer('lcm(2^x, 6^x)').toString()).toEqual('6^x');
|
|
62
|
+
expect(nerdamer('lcm(a,a,b,b,gcd(c,c))').toString()).toEqual('a^2*b^2*c*gcd(a^2*b^2,a^2*b*c,a^2*b*c,a*b^2*c,a*b^2*c)^(-1)');
|
|
63
|
+
expect(nerdamer('lcm(a,a)').toString()).toEqual('a^2*gcd(a,a)^(-1)');
|
|
64
|
+
expect(nerdamer('lcm(a^b,a^c)').toString()).toEqual('a^(-1+b+c)');
|
|
65
|
+
expect(nerdamer('lcm(a^c,b^c)').toString()).toEqual('a^c*b^c');
|
|
66
|
+
expect(nerdamer('lcm(a^a,a^a)').toString()).toEqual('a^a');
|
|
160
67
|
});
|
|
161
68
|
|
|
162
69
|
describe('isPoly', function () {
|
|
163
70
|
it('should detect polynomials', function () {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
given: 'x^2+1/x',
|
|
180
|
-
expected: false
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
given: 'y*x^2+1/x',
|
|
184
|
-
expected: false
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
given: 'y*x^2+x',
|
|
188
|
-
expected: true
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
given: '7*y*x^2+z*x+4',
|
|
192
|
-
expected: true
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
given: '7*y*x^2+z*x^-1+4',
|
|
196
|
-
expected: false
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
given: 'sqrt(5*x)+7',
|
|
200
|
-
expected: false
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
given: 'abs(5*x^3)-x+7',
|
|
204
|
-
expected: false
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
given: 'cos(x)^2+cos(x)+1',
|
|
208
|
-
expected: false
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
given: 'sqrt(97)x^2-sqrt(13)x+sqrt(14)x+sqrt(43)x^2+sqrt(3)*sqrt(101)',
|
|
212
|
-
expected: true
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
given: '-5 sqrt(14)x-14x^2 sqrt(83)',
|
|
216
|
-
expected: true
|
|
217
|
-
},
|
|
218
|
-
];
|
|
219
|
-
|
|
220
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
221
|
-
// when
|
|
222
|
-
var result = nerdamer(testCases[i].given);
|
|
223
|
-
|
|
224
|
-
// then
|
|
225
|
-
expect(result.symbol.isPoly(true)).toEqual(testCases[i].expected);
|
|
226
|
-
}
|
|
71
|
+
expect(nerdamer('51').symbol.isPoly(true)).toEqual(true);
|
|
72
|
+
expect(nerdamer('x^2+1').symbol.isPoly(true)).toEqual(true);
|
|
73
|
+
expect(nerdamer('51/x').symbol.isPoly(true)).toEqual(false);
|
|
74
|
+
expect(nerdamer('x^2+1/x').symbol.isPoly(true)).toEqual(false);
|
|
75
|
+
expect(nerdamer('y*x^2+1/x').symbol.isPoly(true)).toEqual(false);
|
|
76
|
+
expect(nerdamer('y*x^2+x').symbol.isPoly(true)).toEqual(true);
|
|
77
|
+
expect(nerdamer('7*y*x^2+z*x+4').symbol.isPoly(true)).toEqual(true);
|
|
78
|
+
expect(nerdamer('7*y*x^2+z*x^-1+4').symbol.isPoly(true)).toEqual(false);
|
|
79
|
+
expect(nerdamer('sqrt(5*x)+7').symbol.isPoly(true)).toEqual(false);
|
|
80
|
+
expect(nerdamer('abs(5*x^3)-x+7').symbol.isPoly(true)).toEqual(false);
|
|
81
|
+
expect(nerdamer('cos(x)^2+cos(x)+1').symbol.isPoly(true)).toEqual(false);
|
|
82
|
+
expect(nerdamer('sqrt(97)x^2-sqrt(13)x+sqrt(14)x+sqrt(43)x^2+sqrt(3)*sqrt(101)').symbol.isPoly(true)).toEqual(true);
|
|
83
|
+
expect(nerdamer('-5 sqrt(14)x-14x^2 sqrt(83)').symbol.isPoly(true)).toEqual(true);
|
|
227
84
|
});
|
|
228
85
|
|
|
229
86
|
it('should evaluate abs() directly', function () {
|
|
@@ -239,137 +96,38 @@ describe('Algebra', function () {
|
|
|
239
96
|
});
|
|
240
97
|
|
|
241
98
|
it('should perform divisions', function () {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}, {
|
|
275
|
-
given: 'div(sin(x)^2*tan(x)-4*cos(x)*tan(x)+cos(x)*sin(x)^2-4*cos(x)^2, sin(x)^2-4*cos(x)^2)',
|
|
276
|
-
expected: '[cos(x)+tan(x),-4*cos(x)*tan(x)-4*cos(x)^2+4*cos(x)^3+4*cos(x)^2*tan(x)]'
|
|
277
|
-
}, {
|
|
278
|
-
given: 'div(y^2*z-4*x*z+x*y^2-4*x^2, y^2-4*x^2)',
|
|
279
|
-
expected: '[x+z,-4*x*z-4*x^2+4*x^3+4*x^2*z]'
|
|
280
|
-
}, {
|
|
281
|
-
given: 'div(-5*y^2+16*a*y+5*x^4+14*a*x^2-3*a^2, 3*a-y+x^2)',
|
|
282
|
-
expected: '[-a+5*x^2+5*y,0]'
|
|
283
|
-
}, {
|
|
284
|
-
given: 'div(y^2+2*x*y+x^2,x+y)',
|
|
285
|
-
expected: '[x+y,0]'
|
|
286
|
-
}, {
|
|
287
|
-
given: 'div(x*y^2+x^2*y-y-x, x*y-1)',
|
|
288
|
-
expected: '[x+y,0]'
|
|
289
|
-
}, {
|
|
290
|
-
given: 'div(y^2*z-4*x*z+x*y^2-4*x^2+x^2, y^2-4*x^2)',
|
|
291
|
-
expected: '[x+z,-3*x^2+4*x^3-4*x*z+4*x^2*z]'
|
|
292
|
-
}, {
|
|
293
|
-
given: 'div(7*x^6*z-a*x*z+28*a*x^6*y^3-4*a^2*x*y^3+7*b*x^6-a*b*x, 4*y^3*a+z+b)',
|
|
294
|
-
expected: '[-a*x+7*x^6,0]'
|
|
295
|
-
}, {
|
|
296
|
-
given: 'div(x^2+5, cos(x)-1)',
|
|
297
|
-
expected: '[0,5+x^2]'
|
|
298
|
-
}, {
|
|
299
|
-
given: 'div((1+z), t*x+7)',
|
|
300
|
-
expected: '[0,1+z]'
|
|
301
|
-
}, {
|
|
302
|
-
given: 'div(-x^2*y-y+4*a*x^2+t+4*a+6*b, x^2+1)',
|
|
303
|
-
expected: '[-y+4*a,6*b+t]'
|
|
304
|
-
}, {
|
|
305
|
-
given: 'div(15*x^9-25*x^7-35*x^6+6*x^5+3*x^4-10*x^3-19*x^2-7*x+y, 3*x^3-5*x-7)',
|
|
306
|
-
expected: '[2*x^2+5*x^6+x,y]'
|
|
307
|
-
},
|
|
308
|
-
/*{
|
|
309
|
-
given: 'div(25*x^6*y+10*x^5*y, 5*x^2*y+3-17*x^5)',
|
|
310
|
-
expected: '[2*x^3+5*x^4,-15*x^4-6*x^3+34*x^8+85*x^9]'
|
|
311
|
-
},*/
|
|
312
|
-
{
|
|
313
|
-
given: 'div(x^2+2*x+1+u, x+1)',
|
|
314
|
-
expected: '[1+x,u]'
|
|
315
|
-
}, {
|
|
316
|
-
given: 'div(y^3+x*y^2+x^2*y+x^3+x, x+y)',
|
|
317
|
-
expected: '[x^2+y^2,x]'
|
|
318
|
-
}, {
|
|
319
|
-
given: 'div(b*y*z+7*x^6*z-a*x*z-7*z+4*a*b*y^4+28*a*x^6*y^3-4*a^2*x*y^3-28*a*y^3+b^2*y+7*b*x^6-a*b*x-7*b, 4*y^3*a+z+b)',
|
|
320
|
-
expected: '[-7-a*x+7*x^6+b*y,0]'
|
|
321
|
-
}, {
|
|
322
|
-
given: 'div(b*y*z-a*x*z+4*a*b*y^4-4*a^2*x*y^3+b^2*y-a*b*x, 4*y^3*a+z+b)',
|
|
323
|
-
expected: '[-a*x+b*y,0]'
|
|
324
|
-
}, {
|
|
325
|
-
given: 'div(17*x^3*y+3*x^2*y+34*x+6, x^2*y+2)',
|
|
326
|
-
expected: '[17*x+3,0]'
|
|
327
|
-
},
|
|
328
|
-
/* {
|
|
329
|
-
given: 'div(3*(x^2*y)+5,6*x^2*y+3*x*y+7)',
|
|
330
|
-
expected: '[(1+2*x)^(-1)*x,(1+2*x)^(-1)*(3*x+5)]'
|
|
331
|
-
},
|
|
332
|
-
/* {
|
|
333
|
-
given: 'div(-5*x^2+17*x^2*y+4+3*x*y, 2*x^2*y+4)',
|
|
334
|
-
expected: '[(3/2)*x^(-1)+17/2,-30-5*x^2-6*x^(-1)]'
|
|
335
|
-
}, */
|
|
336
|
-
/* {
|
|
337
|
-
given: 'div(25*x^6*y+10*x^5*y, 5*x^2*y+3-17*x^5)',
|
|
338
|
-
expected: '[2*x^3+5*x^4,-15*x^4-6*x^3+34*x^8+85*x^9]'
|
|
339
|
-
}, */
|
|
340
|
-
{
|
|
341
|
-
given: 'div(b^2*y^2+2*a*b*y^2+a^2*y^2+2*b^2*x*y+4*a*b*x*y+2*a^2*x*y+b^2*x^2+2*a*b*x^2+a^2*x^2, 2*b*y^2+2*a*y^2+4*b*x*y+4*a*x*y+2*b*x^2+2*a*x^2)',
|
|
342
|
-
expected: '[(1/2)*a+(1/2)*b,0]'
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
given: 'div(2*a*b*x+2*a*b*y+a^2*x+a^2*y+b^2*x+b^2*y, x+y)',
|
|
346
|
-
expected: '[2*a*b+a^2+b^2,0]'
|
|
347
|
-
},
|
|
348
|
-
{
|
|
349
|
-
given: 'div((2x-1)(3x^2+5x-2)-7x-14,x^2+1)',
|
|
350
|
-
expected: '[6*x+7,-19-22*x]'
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
given: 'div(2(x+1)^5+1,x+2)',
|
|
354
|
-
expected: '[2+2*x^4+4*x+6*x^3+8*x^2,-1]'
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
given: 'divide(a*b^(-1)+b^(-1)*c,a+c)',
|
|
358
|
-
expected: 'b^(-1)'
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
given: 'divide(-20+16*i,-10+8*i)',
|
|
362
|
-
expected: '2'
|
|
363
|
-
}
|
|
364
|
-
];
|
|
365
|
-
|
|
366
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
367
|
-
// when
|
|
368
|
-
var result = nerdamer(testCases[i].given);
|
|
369
|
-
|
|
370
|
-
// then
|
|
371
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
372
|
-
}
|
|
99
|
+
expect(nerdamer('div(x^2*y^3+b*y^2+3*a*x^2*y+3*a*b, y^2+3*a)').toString()).toEqual('[b+x^2*y,0]');
|
|
100
|
+
expect(nerdamer('div(x^2, x^3)').toString()).toEqual('[0,x^2]');
|
|
101
|
+
expect(nerdamer('div(cos(x^2)^2+2*cos(x^2)+1, cos(x^2)+1)').toString()).toEqual('[1+cos(x^2),0]');
|
|
102
|
+
expect(nerdamer('div(2*x^2+2*x+1, x+1)').toString()).toEqual('[2*x,1]');
|
|
103
|
+
expect(nerdamer('div(7*x,2*x)').toString()).toEqual('[7/2,0]');
|
|
104
|
+
expect(nerdamer('div(7*b*z^2+14*y*z+14*a*x^2*z-b*t*z-2*t*y-2*a*t*x^2, 7*z-t)').toString()).toEqual('[2*a*x^2+2*y+b*z,0]');
|
|
105
|
+
expect(nerdamer('div(x^2+5, y-1)').toString()).toEqual('[0,5+x^2]');
|
|
106
|
+
expect(nerdamer('div(4*a*x^2*y^2+4*a*y^2+b*x^2+a*x^2+b+a, x^2+1)').toString()).toEqual('[4*a*y^2+a+b,0]');
|
|
107
|
+
expect(nerdamer('div(4*a*x^2*y^2+4*a*y^2+b*x^2+a*x^2+b+a+u^6+1, x^2+1)').toString()).toEqual('[4*a*y^2+a+b,1+u^6]');
|
|
108
|
+
expect(nerdamer('div(15*x^9-25*x^7-35*x^6+6*x^5+3*x^4-10*x^3-19*x^2-7*x, 3*x^3-5*x-7)').toString()).toEqual('[2*x^2+5*x^6+x,0]');
|
|
109
|
+
expect(nerdamer('div(sin(x)^2*tan(x)-4*cos(x)*tan(x)+cos(x)*sin(x)^2-4*cos(x)^2, sin(x)^2-4*cos(x)^2)').toString()).toEqual('[cos(x)+tan(x),-4*cos(x)*tan(x)-4*cos(x)^2+4*cos(x)^3+4*cos(x)^2*tan(x)]');
|
|
110
|
+
expect(nerdamer('div(y^2*z-4*x*z+x*y^2-4*x^2, y^2-4*x^2)').toString()).toEqual('[x+z,-4*x*z-4*x^2+4*x^3+4*x^2*z]');
|
|
111
|
+
expect(nerdamer('div(-5*y^2+16*a*y+5*x^4+14*a*x^2-3*a^2, 3*a-y+x^2)').toString()).toEqual('[-a+5*x^2+5*y,0]');
|
|
112
|
+
expect(nerdamer('div(y^2+2*x*y+x^2,x+y)').toString()).toEqual('[x+y,0]');
|
|
113
|
+
expect(nerdamer('div(x*y^2+x^2*y-y-x, x*y-1)').toString()).toEqual('[x+y,0]');
|
|
114
|
+
expect(nerdamer('div(y^2*z-4*x*z+x*y^2-4*x^2+x^2, y^2-4*x^2)').toString()).toEqual('[x+z,-3*x^2+4*x^3-4*x*z+4*x^2*z]');
|
|
115
|
+
expect(nerdamer('div(7*x^6*z-a*x*z+28*a*x^6*y^3-4*a^2*x*y^3+7*b*x^6-a*b*x, 4*y^3*a+z+b)').toString()).toEqual('[-a*x+7*x^6,0]');
|
|
116
|
+
expect(nerdamer('div(x^2+5, cos(x)-1)').toString()).toEqual('[0,5+x^2]');
|
|
117
|
+
expect(nerdamer('div((1+z), t*x+7)').toString()).toEqual('[0,1+z]');
|
|
118
|
+
expect(nerdamer('div(-x^2*y-y+4*a*x^2+t+4*a+6*b, x^2+1)').toString()).toEqual('[-y+4*a,6*b+t]');
|
|
119
|
+
expect(nerdamer('div(15*x^9-25*x^7-35*x^6+6*x^5+3*x^4-10*x^3-19*x^2-7*x+y, 3*x^3-5*x-7)').toString()).toEqual('[2*x^2+5*x^6+x,y]');
|
|
120
|
+
expect(nerdamer('div(x^2+2*x+1+u, x+1)').toString()).toEqual('[1+x,u]');
|
|
121
|
+
expect(nerdamer('div(y^3+x*y^2+x^2*y+x^3+x, x+y)').toString()).toEqual('[x^2+y^2,x]');
|
|
122
|
+
expect(nerdamer('div(b*y*z+7*x^6*z-a*x*z-7*z+4*a*b*y^4+28*a*x^6*y^3-4*a^2*x*y^3-28*a*y^3+b^2*y+7*b*x^6-a*b*x-7*b, 4*y^3*a+z+b)').toString()).toEqual('[-7-a*x+7*x^6+b*y,0]');
|
|
123
|
+
expect(nerdamer('div(b*y*z-a*x*z+4*a*b*y^4-4*a^2*x*y^3+b^2*y-a*b*x, 4*y^3*a+z+b)').toString()).toEqual('[-a*x+b*y,0]');
|
|
124
|
+
expect(nerdamer('div(17*x^3*y+3*x^2*y+34*x+6, x^2*y+2)').toString()).toEqual('[17*x+3,0]');
|
|
125
|
+
expect(nerdamer('div(b^2*y^2+2*a*b*y^2+a^2*y^2+2*b^2*x*y+4*a*b*x*y+2*a^2*x*y+b^2*x^2+2*a*b*x^2+a^2*x^2, 2*b*y^2+2*a*y^2+4*b*x*y+4*a*x*y+2*b*x^2+2*a*x^2)').toString()).toEqual('[(1/2)*a+(1/2)*b,0]');
|
|
126
|
+
expect(nerdamer('div(2*a*b*x+2*a*b*y+a^2*x+a^2*y+b^2*x+b^2*y, x+y)').toString()).toEqual('[2*a*b+a^2+b^2,0]');
|
|
127
|
+
expect(nerdamer('div((2x-1)(3x^2+5x-2)-7x-14,x^2+1)').toString()).toEqual('[6*x+7,-19-22*x]');
|
|
128
|
+
expect(nerdamer('div(2(x+1)^5+1,x+2)').toString()).toEqual('[2+2*x^4+4*x+6*x^3+8*x^2,-1]');
|
|
129
|
+
expect(nerdamer('divide(a*b^(-1)+b^(-1)*c,a+c)').toString()).toEqual('b^(-1)');
|
|
130
|
+
expect(nerdamer('divide(-20+16*i,-10+8*i)').toString()).toEqual('2');
|
|
373
131
|
});
|
|
374
132
|
/** #3: "(a-b)^2 - (b-a)^2" not simplifying. */
|
|
375
133
|
it('should simplify to 0', function () {
|
|
@@ -406,412 +164,102 @@ describe('Algebra', function () {
|
|
|
406
164
|
expect(result).toBe('-15+2*x');
|
|
407
165
|
});
|
|
408
166
|
it('should factor correctly', function () {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
},
|
|
435
|
-
{
|
|
436
|
-
given: 'factor(c^6+3*b^2*c^4+3*a^2*c^4+3*b^4*c^2+6*a^2*b^2*c^2+3*a^4*c^2+b^6+3*a^2*b^4+3*a^4*b^2+a^6)',
|
|
437
|
-
expected: '(a^2+b^2+c^2)^3'
|
|
438
|
-
},
|
|
439
|
-
{
|
|
440
|
-
given: 'factor(x^4+25*x^3+234*x^2+972*x+1512)',
|
|
441
|
-
expected: '(6+x)^3*(7+x)'
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
given: 'factor(x^5+32*x^4+288*x^3-418*x^2-16577*x-55902)',
|
|
445
|
-
expected: '(-7+x)*(11+x)^3*(6+x)'
|
|
446
|
-
},
|
|
447
|
-
{
|
|
448
|
-
given: 'factor(x^2*y*z+x*z+t*x^2*y+t*x)',
|
|
449
|
-
expected: '(1+x*y)*(t+z)*x'
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
given: 'factor(x^2*y+x^2)',
|
|
453
|
-
expected: '(1+y)*x^2'
|
|
454
|
-
},
|
|
455
|
-
{
|
|
456
|
-
given: 'factor(sqrt(4*x^2*y+4*x^2))',
|
|
457
|
-
expected: '2*abs(x)*sqrt(1+y)'
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
given: 'factor(x^3-1/2x^2-13/2x-3)',
|
|
461
|
-
expected: '(1/2)*(-3+x)*(1+2*x)*(2+x)'
|
|
462
|
-
},
|
|
463
|
-
{
|
|
464
|
-
given: 'factor(x^16-1)',
|
|
465
|
-
expected: '(-1+x)*(1+x)*(1+x^2)*(1+x^4)*(1+x^8)'
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
given: 'factor(-1866240-311040*x^2-3265920*x+1120*x^8+150080*x^6+17610*x^7+2026080*x^4+2509920*x^3+30*x^9+738360*x^5)',
|
|
469
|
-
expected: '10*(-1+x)*(1+x)*(3*x+4)*(6+x)^6'
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
given: 'factor((7x^3+4x^2+x)/(12x^3+6x^2-2x))',
|
|
473
|
-
expected: '(1/2)*(-1+3*x+6*x^2)^(-1)*(1+4*x+7*x^2)'
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
given: 'factor((-2x-2x^2-2))',
|
|
477
|
-
expected: '-2*(1+x+x^2)'
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
given: 'factor(1331*x^3*y^3+216*z^6)',
|
|
481
|
-
expected: '(-66*x*y*z^2+121*x^2*y^2+36*z^4)*(11*x*y+6*z^2)'
|
|
482
|
-
},
|
|
483
|
-
{
|
|
484
|
-
given: 'factor(1331*x^3*y^3-216*z^6)',
|
|
485
|
-
expected: '(-6*z^2+11*x*y)*(121*x^2*y^2+36*z^4+66*x*y*z^2)'
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
given: 'factor(64a^3-27b^3)',
|
|
489
|
-
expected: '(-3*b+4*a)*(12*a*b+16*a^2+9*b^2)'
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
given: 'factor(64*x^3+125)',
|
|
493
|
-
expected: '(-20*x+16*x^2+25)*(4*x+5)'
|
|
494
|
-
},
|
|
495
|
-
{
|
|
496
|
-
given: 'factor((-5*K+32)^2)',
|
|
497
|
-
expected: '(-32+5*K)^2'
|
|
498
|
-
},
|
|
499
|
-
{
|
|
500
|
-
given: 'factor(100)',
|
|
501
|
-
expected: '2^2*5^2'
|
|
502
|
-
},
|
|
503
|
-
{
|
|
504
|
-
given: 'factor(100*x)',
|
|
505
|
-
expected: '100*x'
|
|
506
|
-
}
|
|
507
|
-
];
|
|
508
|
-
|
|
509
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
510
|
-
// when
|
|
511
|
-
var result = nerdamer(testCases[i].given);
|
|
512
|
-
|
|
513
|
-
// then
|
|
514
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
515
|
-
}
|
|
167
|
+
expect(nerdamer('factor(x^2+2*x+1)').toString()).toEqual('(1+x)^2');
|
|
168
|
+
expect(nerdamer('factor(x^2-y^2)').toString()).toEqual('(-y+x)*(x+y)');
|
|
169
|
+
expect(nerdamer('factor(a^2*x^2-b^2*y^2)').toString()).toEqual('(-b*y+a*x)*(a*x+b*y)');
|
|
170
|
+
expect(nerdamer('factor(x^2-6*x+9-4*y^2)').toString()).toEqual('(-2*y-3+x)*(-3+2*y+x)');
|
|
171
|
+
expect(nerdamer('factor(b^6+3*a^2*b^4+3*a^4*b^2+a^6)').toString()).toEqual('(a^2+b^2)^3');
|
|
172
|
+
expect(nerdamer('factor(b^6+12*a^2*b^4+48*a^4*b^2+64*a^6)').toString()).toEqual('((9007199254740996/2251799813685249)*a^2+b^2)^3');
|
|
173
|
+
expect(nerdamer('factor(c^6+3*b^2*c^4+3*a^2*c^4+3*b^4*c^2+6*a^2*b^2*c^2+3*a^4*c^2+b^6+3*a^2*b^4+3*a^4*b^2+a^6)').toString()).toEqual('(a^2+b^2+c^2)^3');
|
|
174
|
+
expect(nerdamer('factor(x^4+25*x^3+234*x^2+972*x+1512)').toString()).toEqual('(6+x)^3*(7+x)');
|
|
175
|
+
expect(nerdamer('factor(x^5+32*x^4+288*x^3-418*x^2-16577*x-55902)').toString()).toEqual('(-7+x)*(11+x)^3*(6+x)');
|
|
176
|
+
expect(nerdamer('factor(x^2*y*z+x*z+t*x^2*y+t*x)').toString()).toEqual('(1+x*y)*(t+z)*x');
|
|
177
|
+
expect(nerdamer('factor(x^2*y+x^2)').toString()).toEqual('(1+y)*x^2');
|
|
178
|
+
expect(nerdamer('factor(sqrt(4*x^2*y+4*x^2))').toString()).toEqual('2*abs(x)*sqrt(1+y)');
|
|
179
|
+
expect(nerdamer('factor(x^3-1/2x^2-13/2x-3)').toString()).toEqual('(1/2)*(-3+x)*(1+2*x)*(2+x)');
|
|
180
|
+
expect(nerdamer('factor(x^16-1)').toString()).toEqual('(-1+x)*(1+x)*(1+x^2)*(1+x^4)*(1+x^8)');
|
|
181
|
+
expect(nerdamer('factor(-1866240-311040*x^2-3265920*x+1120*x^8+150080*x^6+17610*x^7+2026080*x^4+2509920*x^3+30*x^9+738360*x^5)').toString()).toEqual('10*(-1+x)*(1+x)*(3*x+4)*(6+x)^6');
|
|
182
|
+
expect(nerdamer('factor((7x^3+4x^2+x)/(12x^3+6x^2-2x))').toString()).toEqual('(1/2)*(-1+3*x+6*x^2)^(-1)*(1+4*x+7*x^2)');
|
|
183
|
+
expect(nerdamer('factor((-2x-2x^2-2))').toString()).toEqual('-2*(1+x+x^2)');
|
|
184
|
+
expect(nerdamer('factor(1331*x^3*y^3+216*z^6)').toString()).toEqual('(-66*x*y*z^2+121*x^2*y^2+36*z^4)*(11*x*y+6*z^2)');
|
|
185
|
+
expect(nerdamer('factor(1331*x^3*y^3-216*z^6)').toString()).toEqual('(-6*z^2+11*x*y)*(121*x^2*y^2+36*z^4+66*x*y*z^2)');
|
|
186
|
+
expect(nerdamer('factor(64a^3-27b^3)').toString()).toEqual('(-3*b+4*a)*(12*a*b+16*a^2+9*b^2)');
|
|
187
|
+
expect(nerdamer('factor(64*x^3+125)').toString()).toEqual('(-20*x+16*x^2+25)*(4*x+5)');
|
|
188
|
+
expect(nerdamer('factor((-5*K+32)^2)').toString()).toEqual('(-32+5*K)^2');
|
|
189
|
+
expect(nerdamer('factor(100)').toString()).toEqual('2^2*5^2');
|
|
190
|
+
expect(nerdamer('factor(100*x)').toString()).toEqual('100*x');
|
|
191
|
+
expect(nerdamer('(2*y+p)^2').toString()).toEqual('(2*y+p)^2');
|
|
516
192
|
});
|
|
517
193
|
it('should not have any regression to factor', function() {
|
|
518
194
|
//this test will absolutely break as factor improves enough to factor this expression. For now it just serves as a safeguard
|
|
519
195
|
expect(nerdamer('factor(x^a+2x^(a-1)+1x^(a-2))').toString()).toEqual('2*x^(-1+a)+x^(-2+a)+x^a');
|
|
520
196
|
});
|
|
521
197
|
it('should correctly determine the polynomial degree', function () {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
},
|
|
528
|
-
{
|
|
529
|
-
given: 'deg(x^2+2*x+x^x)',
|
|
530
|
-
expected: 'max(2,x)'
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
given: 'deg(x^2+2*x+cos(x))',
|
|
534
|
-
expected: '2'
|
|
535
|
-
},
|
|
536
|
-
{
|
|
537
|
-
given: 'deg(x^a+x^b+x^c,x)',
|
|
538
|
-
expected: 'max(a,b,c)'
|
|
539
|
-
},
|
|
540
|
-
{
|
|
541
|
-
given: 'deg(a*x^2+b*x+c,x)',
|
|
542
|
-
expected: '2'
|
|
543
|
-
}
|
|
544
|
-
];
|
|
545
|
-
|
|
546
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
547
|
-
// when
|
|
548
|
-
var result = nerdamer(testCases[i].given);
|
|
549
|
-
|
|
550
|
-
// then
|
|
551
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
552
|
-
}
|
|
198
|
+
expect(nerdamer('deg(x^2+2*x+x^5)').toString()).toEqual('5');
|
|
199
|
+
expect(nerdamer('deg(x^2+2*x+x^x)').toString()).toEqual('max(2,x)');
|
|
200
|
+
expect(nerdamer('deg(x^2+2*x+cos(x))').toString()).toEqual('2');
|
|
201
|
+
expect(nerdamer('deg(x^a+x^b+x^c,x)').toString()).toEqual('max(a,b,c)');
|
|
202
|
+
expect(nerdamer('deg(a*x^2+b*x+c,x)').toString()).toEqual('2');
|
|
553
203
|
});
|
|
554
204
|
it('should correctly peform partial fraction decomposition', function () {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
expected: '13*(3+x)^(-1)+4*(-5+x)^(-1)'
|
|
565
|
-
},
|
|
566
|
-
{
|
|
567
|
-
given: 'partfrac((x^3+2)/(x+1)^2,x)',
|
|
568
|
-
expected: '(1+x)^(-2)+3*(1+x)^(-1)-2+x'
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
given: 'partfrac(x/(x-1)^2, x)',
|
|
572
|
-
expected: '(-1+x)^(-1)+(-1+x)^(-2)'
|
|
573
|
-
},
|
|
574
|
-
{
|
|
575
|
-
given: 'partfrac((x^2+1)/(x*(x-1)^3), x)',
|
|
576
|
-
expected: '(-1+x)^(-1)+2*(-1+x)^(-3)-x^(-1)'
|
|
577
|
-
},
|
|
578
|
-
{
|
|
579
|
-
given: 'partfrac((17-53)/(x^2-2*x-15), x)',
|
|
580
|
-
expected: '(-9/2)*(-5+x)^(-1)+(9/2)*(3+x)^(-1)'
|
|
581
|
-
},
|
|
582
|
-
{
|
|
583
|
-
given: 'partfrac(1/(x^6-1),x)',
|
|
584
|
-
//this result is in expanded form and future versions should avoid this.
|
|
585
|
-
expected: '(-1/3)*(-x+x^2+1)^(-1)+(-1/3)*(1+x+x^2)^(-1)+(-1/6)*(1+x)^(-1)+(-1/6)*(1+x+x^2)^(-1)*x+(1/6)*(-1+x)^(-1)+(1/6)*(-x+x^2+1)^(-1)*x'
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
given: 'partfrac((3*x^2-3*x-8)/((x-5)*(x^2+x-4)),x)',
|
|
589
|
-
expected: '(-4+x+x^2)^(-1)*x+2*(-5+x)^(-1)'
|
|
590
|
-
},
|
|
591
|
-
{
|
|
592
|
-
given: 'partfrac(15*(9+s^2)^(-1)*cos(1)+5*(9+s^2)^(-1)*s*sin(1),s)',
|
|
593
|
-
expected: '(15*cos(1)+5*s*sin(1))*(9+s^2)^(-1)'
|
|
594
|
-
},
|
|
595
|
-
];
|
|
596
|
-
|
|
597
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
598
|
-
// when
|
|
599
|
-
var result = nerdamer(testCases[i].given);
|
|
600
|
-
|
|
601
|
-
// then
|
|
602
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
603
|
-
}
|
|
205
|
+
expect(nerdamer('partfrac((3*x+2)/(x^2+x), x)').toString()).toEqual('(1+x)^(-1)+2*x^(-1)');
|
|
206
|
+
expect(nerdamer('partfrac((17*x-53)/(x^2-2*x-15), x)').toString()).toEqual('13*(3+x)^(-1)+4*(-5+x)^(-1)');
|
|
207
|
+
expect(nerdamer('partfrac((x^3+2)/(x+1)^2,x)').toString()).toEqual('(1+x)^(-2)+3*(1+x)^(-1)-2+x');
|
|
208
|
+
expect(nerdamer('partfrac(x/(x-1)^2, x)').toString()).toEqual('(-1+x)^(-1)+(-1+x)^(-2)');
|
|
209
|
+
expect(nerdamer('partfrac((x^2+1)/(x*(x-1)^3), x)').toString()).toEqual('(-1+x)^(-1)+2*(-1+x)^(-3)-x^(-1)');
|
|
210
|
+
expect(nerdamer('partfrac((17-53)/(x^2-2*x-15), x)').toString()).toEqual('(-9/2)*(-5+x)^(-1)+(9/2)*(3+x)^(-1)');
|
|
211
|
+
expect(nerdamer('partfrac(1/(x^6-1),x)').toString()).toEqual('(-1/3)*(-x+x^2+1)^(-1)+(-1/3)*(1+x+x^2)^(-1)+(-1/6)*(1+x)^(-1)+(-1/6)*(1+x+x^2)^(-1)*x+(1/6)*(-1+x)^(-1)+(1/6)*(-x+x^2+1)^(-1)*x');
|
|
212
|
+
expect(nerdamer('partfrac((3*x^2-3*x-8)/((x-5)*(x^2+x-4)),x)').toString()).toEqual('(-4+x+x^2)^(-1)*x+2*(-5+x)^(-1)');
|
|
213
|
+
expect(nerdamer('partfrac(15*(9+s^2)^(-1)*cos(1)+5*(9+s^2)^(-1)*s*sin(1),s)').toString()).toEqual('(15*cos(1)+5*s*sin(1))*(9+s^2)^(-1)');
|
|
604
214
|
});
|
|
605
215
|
it('should prime factor correctly', function () {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
expected: '(2^3)'
|
|
619
|
-
},
|
|
620
|
-
{
|
|
621
|
-
given: 'pfactor(999999999999)',
|
|
622
|
-
expected: '(101)*(11)*(13)*(37)*(3^3)*(7)*(9901)'
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
given: 'pfactor(1000000005721)',
|
|
626
|
-
expected: '(1000000005721)'
|
|
627
|
-
},
|
|
628
|
-
{
|
|
629
|
-
given: 'pfactor(1000000005721092)',
|
|
630
|
-
expected: '(131)*(212044106387)*(2^2)*(3^2)'
|
|
631
|
-
},
|
|
632
|
-
{
|
|
633
|
-
given: 'pfactor(-10000000114421840327308)',
|
|
634
|
-
expected: '(-2^2)*(480827)*(7)*(8345706745687)*(89)'
|
|
635
|
-
},
|
|
636
|
-
{
|
|
637
|
-
given: 'pfactor(-7877474663)',
|
|
638
|
-
expected: '(-97)*(180871)*(449)'
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
given: 'pfactor(15!+1)',
|
|
642
|
-
expected: '(46271341)*(479)*(59)'
|
|
643
|
-
},
|
|
644
|
-
{
|
|
645
|
-
given: 'pfactor(15!+11!)',
|
|
646
|
-
expected: '(11)*(181^2)*(2^8)*(3^4)*(5^2)*(7)'
|
|
647
|
-
},
|
|
648
|
-
{
|
|
649
|
-
given: 'pfactor(product(n!,n,1,10))',
|
|
650
|
-
expected: '(2^38)*(3^17)*(5^7)*(7^4)'
|
|
651
|
-
},
|
|
652
|
-
{
|
|
653
|
-
given: 'pfactor(4677271)',
|
|
654
|
-
expected: '(2089)*(2239)'
|
|
655
|
-
}
|
|
656
|
-
];
|
|
657
|
-
|
|
658
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
659
|
-
// when
|
|
660
|
-
var result = nerdamer(testCases[i].given);
|
|
661
|
-
|
|
662
|
-
// then
|
|
663
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
664
|
-
}
|
|
216
|
+
expect(nerdamer('pfactor(100!)').toString()).toEqual('(11^9)*(13^7)*(17^5)*(19^5)*(23^4)*(29^3)*(2^97)*(31^3)*(37^2)*(3^48)*(41^2)*(43^2)*(47^2)*(53)*(59)*(5^24)*(61)*(67)*(71)*(73)*(79)*(7^16)*(83)*(89)*(97)');
|
|
217
|
+
expect(nerdamer('pfactor(100)').toString()).toEqual('(2^2)*(5^2)');
|
|
218
|
+
expect(nerdamer('pfactor(8)').toString()).toEqual('(2^3)');
|
|
219
|
+
expect(nerdamer('pfactor(999999999999)').toString()).toEqual('(101)*(11)*(13)*(37)*(3^3)*(7)*(9901)');
|
|
220
|
+
expect(nerdamer('pfactor(1000000005721)').toString()).toEqual('(1000000005721)');
|
|
221
|
+
expect(nerdamer('pfactor(1000000005721092)').toString()).toEqual('(131)*(212044106387)*(2^2)*(3^2)');
|
|
222
|
+
expect(nerdamer('pfactor(-10000000114421840327308)').toString()).toEqual('(-2^2)*(480827)*(7)*(8345706745687)*(89)');
|
|
223
|
+
expect(nerdamer('pfactor(-7877474663)').toString()).toEqual('(-97)*(180871)*(449)');
|
|
224
|
+
expect(nerdamer('pfactor(15!+1)').toString()).toEqual('(46271341)*(479)*(59)');
|
|
225
|
+
expect(nerdamer('pfactor(15!+11!)').toString()).toEqual('(11)*(181^2)*(2^8)*(3^4)*(5^2)*(7)');
|
|
226
|
+
expect(nerdamer('pfactor(product(n!,n,1,10))').toString()).toEqual('(2^38)*(3^17)*(5^7)*(7^4)');
|
|
227
|
+
expect(nerdamer('pfactor(4677271)').toString()).toEqual('(2089)*(2239)');
|
|
665
228
|
});
|
|
666
229
|
it('should get coeffs', function () {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
},
|
|
673
|
-
{
|
|
674
|
-
given: 'coeffs(a*b*x^2+c*x+d, x)',
|
|
675
|
-
expected: '[d,c,a*b]'
|
|
676
|
-
},
|
|
677
|
-
{
|
|
678
|
-
given: 'coeffs(t*x, x)',
|
|
679
|
-
expected: '[0,t]'
|
|
680
|
-
},
|
|
681
|
-
{
|
|
682
|
-
given: 'coeffs(b*(t*x-5), x)',
|
|
683
|
-
expected: '[-5*b,b*t]'
|
|
684
|
-
},
|
|
685
|
-
{
|
|
686
|
-
given: 'coeffs(a*x^2+b*x+c+x, x)',
|
|
687
|
-
expected: '[c,1+b,a]'
|
|
688
|
-
}
|
|
689
|
-
];
|
|
690
|
-
|
|
691
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
692
|
-
// when
|
|
693
|
-
var result = nerdamer(testCases[i].given);
|
|
694
|
-
|
|
695
|
-
// then
|
|
696
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
697
|
-
}
|
|
230
|
+
expect(nerdamer('coeffs(x^2+2*x+1, x)').toString()).toEqual('[1,2,1]');
|
|
231
|
+
expect(nerdamer('coeffs(a*b*x^2+c*x+d, x)').toString()).toEqual('[d,c,a*b]');
|
|
232
|
+
expect(nerdamer('coeffs(t*x, x)').toString()).toEqual('[0,t]');
|
|
233
|
+
expect(nerdamer('coeffs(b*(t*x-5), x)').toString()).toEqual('[-5*b,b*t]');
|
|
234
|
+
expect(nerdamer('coeffs(a*x^2+b*x+c+x, x)').toString()).toEqual('[c,1+b,a]');
|
|
698
235
|
});
|
|
699
236
|
it('should get all coeffs', function () {
|
|
700
237
|
expect(nerdamer('coeffs(x+A+1,x)').toString()).toEqual('[1+A,1]');
|
|
701
238
|
expect(nerdamer.coeffs('2x+i*x+5', 'x').toString()).toEqual('[5,2+i]');
|
|
702
239
|
});
|
|
703
240
|
it('should calculate the line function', function () {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
{
|
|
707
|
-
given: 'line([1,2], [3,4])',
|
|
708
|
-
expected: '1+x'
|
|
709
|
-
},
|
|
710
|
-
{
|
|
711
|
-
given: 'line([a1,b1], [a2,b2], t)',
|
|
712
|
-
expected: '(-a1+a2)^(-1)*(-b1+b2)*t-(-a1+a2)^(-1)*(-b1+b2)*a1+b1'
|
|
713
|
-
},
|
|
714
|
-
|
|
715
|
-
];
|
|
716
|
-
|
|
717
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
718
|
-
// when
|
|
719
|
-
var result = nerdamer(testCases[i].given);
|
|
720
|
-
|
|
721
|
-
// then
|
|
722
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
723
|
-
}
|
|
241
|
+
expect(nerdamer('line([1,2], [3,4])').toString()).toEqual('1+x');
|
|
242
|
+
expect(nerdamer('line([a1,b1], [a2,b2], t)').toString()).toEqual('(-a1+a2)^(-1)*(-b1+b2)*t-(-a1+a2)^(-1)*(-b1+b2)*a1+b1');
|
|
724
243
|
});
|
|
725
244
|
it('should simplify correctly', function () {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
{
|
|
745
|
-
given: 'simplify((x^2+4*x-45)/(x^2+x-30))',
|
|
746
|
-
expected: '(6+x)^(-1)*(9+x)'
|
|
747
|
-
},
|
|
748
|
-
{
|
|
749
|
-
given: 'simplify(1/(x-1)+1/(1-x))',
|
|
750
|
-
expected: '0'
|
|
751
|
-
},
|
|
752
|
-
{
|
|
753
|
-
given: 'simplify((x-1)/(1-x))',
|
|
754
|
-
expected: '-1'
|
|
755
|
-
},
|
|
756
|
-
{
|
|
757
|
-
given: 'simplify((x^2+2*x+1)/(x+1))',
|
|
758
|
-
expected: '1+x'
|
|
759
|
-
},
|
|
760
|
-
{
|
|
761
|
-
given: 'simplify((- x + x^2 + 1)/(x - x^2 - 1))',
|
|
762
|
-
expected: '-1'
|
|
763
|
-
},
|
|
764
|
-
{
|
|
765
|
-
given: 'simplify(n!/(n+1)!)',
|
|
766
|
-
expected: '(1+n)^(-1)'
|
|
767
|
-
},
|
|
768
|
-
//imaginary number
|
|
769
|
-
{
|
|
770
|
-
given: 'simplify((17/2)*(-10+8*i)^(-1)-5*(-10+8*i)^(-1)*i)',
|
|
771
|
-
expected: '(-9/82)*i-125/164'
|
|
772
|
-
},
|
|
773
|
-
{
|
|
774
|
-
given: 'simplify((-2*i+7)^(-1)*(3*i+4))',
|
|
775
|
-
expected: '(29/53)*i+22/53'
|
|
776
|
-
},
|
|
777
|
-
{
|
|
778
|
-
given: 'simplify(((17/2)*(-5*K+32)^(-1)*K^2+(5/2)*K-125*(-5*K+32)^(-1)*K-16+400*(-5*K+32)^(-1))*(-17*(-5*K+32)^(-1)*K+80*(-5*K+32)^(-1))^(-1))',
|
|
779
|
-
expected: '(-35*K+4*K^2+112)*(-80+17*K)^(-1)'
|
|
780
|
-
},
|
|
781
|
-
{
|
|
782
|
-
given: 'simplify(((a+b)^2)/c)',
|
|
783
|
-
expected: '(a+b)^2*c^(-1)'
|
|
784
|
-
},
|
|
785
|
-
// TODO: Disabling for now since sqrt simplify contains bug
|
|
786
|
-
// {
|
|
787
|
-
// given: 'simplify((-1/2)*(1+x^2)^(-1)*sqrt(16+16*x^2))',
|
|
788
|
-
// expected: '-2*sqrt(1+x^2)^(-1)'
|
|
789
|
-
// },
|
|
790
|
-
// {
|
|
791
|
-
// given: 'simplify((1/2)*sqrt(-4*x^2+16)*x)',
|
|
792
|
-
// expected: 'sqrt(-x^2+4)*x'
|
|
793
|
-
// },
|
|
794
|
-
// {
|
|
795
|
-
// given: 'simplify((-1/2)*(1+x^2)^(-1)*sqrt(16+16*x^2))',
|
|
796
|
-
// expected: '-2*sqrt(1+x^2)^(-1)'
|
|
797
|
-
// },
|
|
798
|
-
{
|
|
799
|
-
given: 'simplify(-(-5*x - 9 + 2*y))',
|
|
800
|
-
expected: '-2*y+5*x+9'
|
|
801
|
-
},
|
|
802
|
-
{
|
|
803
|
-
given: 'simplify(a/b+b/a)',
|
|
804
|
-
expected: '(a*b)^(-1)*(a^2+b^2)'
|
|
805
|
-
}
|
|
806
|
-
];
|
|
807
|
-
|
|
808
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
809
|
-
// when
|
|
810
|
-
var result = nerdamer(testCases[i].given);
|
|
811
|
-
|
|
812
|
-
// then
|
|
813
|
-
expect(result.toString()).toEqual(testCases[i].expected);
|
|
814
|
-
}
|
|
245
|
+
expect(nerdamer('simplify(sin(x)^2+cos(x)^2)').toString()).toEqual('1');
|
|
246
|
+
expect(nerdamer('simplify(1/2*sin(x^2)^2+cos(x^2)^2)').toString()).toEqual('(1/4)*(3+cos(2*x^2))');
|
|
247
|
+
expect(nerdamer('simplify(0.75*sin(x^2)^2+cos(x^2)^2)').toString()).toEqual('(1/8)*(7+cos(2*x^2))');
|
|
248
|
+
expect(nerdamer('simplify(cos(x)^2+sin(x)^2+cos(x)-tan(x)-1+sin(x^2)^2+cos(x^2)^2)').toString()).toEqual('-tan(x)+1+cos(x)');
|
|
249
|
+
expect(nerdamer('simplify((x^2+4*x-45)/(x^2+x-30))').toString()).toEqual('(6+x)^(-1)*(9+x)');
|
|
250
|
+
expect(nerdamer('simplify(1/(x-1)+1/(1-x))').toString()).toEqual('0');
|
|
251
|
+
expect(nerdamer('simplify((x-1)/(1-x))').toString()).toEqual('-1');
|
|
252
|
+
expect(nerdamer('simplify((x^2+2*x+1)/(x+1))').toString()).toEqual('1+x');
|
|
253
|
+
expect(nerdamer('simplify((- x + x^2 + 1)/(x - x^2 - 1))').toString()).toEqual('-1');
|
|
254
|
+
expect(nerdamer('simplify(n!/(n+1)!)').toString()).toEqual('(1+n)^(-1)');
|
|
255
|
+
expect(nerdamer('simplify((17/2)*(-10+8*i)^(-1)-5*(-10+8*i)^(-1)*i)').toString()).toEqual('(-9/82)*i-125/164');
|
|
256
|
+
expect(nerdamer('simplify((-2*i+7)^(-1)*(3*i+4))').toString()).toEqual('(29/53)*i+22/53');
|
|
257
|
+
expect(nerdamer('simplify(((17/2)*(-5*K+32)^(-1)*K^2+(5/2)*K-125*(-5*K+32)^(-1)*K-16+400*(-5*K+32)^(-1))*(-17*(-5*K+32)^(-1)*K+80*(-5*K+32)^(-1))^(-1))').toString()).toEqual('(-35*K+4*K^2+112)*(-80+17*K)^(-1)');
|
|
258
|
+
expect(nerdamer('simplify(((a+b)^2)/c)').toString()).toEqual('(a+b)^2*c^(-1)');
|
|
259
|
+
expect(nerdamer('simplify(-(-5*x - 9 + 2*y))').toString()).toEqual('-2*y+5*x+9');
|
|
260
|
+
expect(nerdamer('simplify(a/b+b/a)').toString()).toEqual('(a*b)^(-1)*(a^2+b^2)');
|
|
261
|
+
expect(nerdamer('simplify(((2*e^t)/(e^t))+(1/(e^t)))').toString()).toEqual('(1+2*e^t)*e^(-t)');
|
|
262
|
+
expect(nerdamer('simplify((-3/2)x+(1/3)y+2+z)').toString()).toEqual('(1/6)*(-9*x+12+2*y+6*z)');
|
|
815
263
|
});
|
|
816
264
|
it('should also simplify', function() {
|
|
817
265
|
//expect(nerdamer('6/sqrt(3)')).toEqual();
|