nerdamer 1.1.9 → 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 +2061 -1850
- package/Calculus.js +761 -680
- package/Extra.js +148 -117
- package/README.md +30 -1
- package/Solve.js +476 -332
- package/all.min.js +1 -0
- package/gulpfile.js +16 -0
- package/index.d.ts +150 -13
- package/nerdamer.core.js +2166 -1901
- package/package.json +57 -52
- package/spec/LaTeX.spec.js +14 -44
- package/spec/TeXConvert.spec.js +3 -2
- package/spec/algebra.spec.js +181 -732
- package/spec/calculus.spec.js +160 -673
- package/spec/core.spec.js +35 -8
- package/spec/extra.spec.js +39 -171
- package/spec/solve.spec.js +89 -305
package/spec/solve.spec.js
CHANGED
|
@@ -7,326 +7,103 @@ require('../Solve');
|
|
|
7
7
|
|
|
8
8
|
describe('Solve', function () {
|
|
9
9
|
it('should solve correctly', function () {
|
|
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
|
-
given: 'solve(a*x^2+b*x+c, x)',
|
|
78
|
-
expected: '[(1/2)*(-b+sqrt(-4*a*c+b^2))*a^(-1),(1/2)*(-b-sqrt(-4*a*c+b^2))*a^(-1)]'
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
//NOTE: this test has duplicates
|
|
82
|
-
given: 'solve(sqrt(x^3)+sqrt(x^2)-sqrt(x)=0,x)',
|
|
83
|
-
expected: '[0,78202389238903801/240831735646702201]'
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
given: 'solve(x^3-10x^2+31x-30,x)',
|
|
87
|
-
expected: '[3,5,2]'
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
given: 'solve(sqrt(x)+sqrt(2x+1)=5,x)',
|
|
91
|
-
expected: '[4]'
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
given: 'solve(x=2/(3-x),x)',
|
|
95
|
-
expected: '[1,2]'
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
given: 'solve(1/x=a,x)',
|
|
99
|
-
expected: '[a^(-1)]'
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
given: 'solve(sqrt(x^2-1),x)',
|
|
103
|
-
expected: '[1,-1]'
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
given: 'solve(m*x^9+n,x)',
|
|
107
|
-
expected: '[2*m^(-1/9)*n^(1/9),2*e^((2/9)*i*pi)*m^(-1/9)*n^(1/9),2*e^((4/9)*i*pi)*m^(-1/9)*n^(1/9),'+
|
|
108
|
-
'2*e^((2/3)*i*pi)*m^(-1/9)*n^(1/9),2*e^((8/9)*i*pi)*m^(-1/9)*n^(1/9),2*e^((10/9)*i*pi)*m^(-1/9)*n^(1/9),'+
|
|
109
|
-
'2*e^((4/3)*i*pi)*m^(-1/9)*n^(1/9),2*e^((14/9)*i*pi)*m^(-1/9)*n^(1/9),2*e^((16/9)*i*pi)*m^(-1/9)*n^(1/9)]'
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
given: 'solve(sqrt(97)x^2-sqrt(13)x+sqrt(14)x+sqrt(43)x^2+sqrt(3)*sqrt(101)=0,x)',
|
|
113
|
-
expected: '[(-1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(14)+(1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt((-sqrt(13)+sqrt(14))^2-'+
|
|
114
|
-
'4*(sqrt(43)+sqrt(97))*sqrt(101)*sqrt(3))+(1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(13),'+
|
|
115
|
-
'(-1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt((-sqrt(13)+sqrt(14))^2-4*(sqrt(43)+sqrt(97))*sqrt(101)*sqrt(3))+'+
|
|
116
|
-
'(-1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(14)+(1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(13)]'
|
|
117
|
-
},
|
|
118
|
-
//The tests below were disabled. Too long and extremely difficult to verify.
|
|
119
|
-
/*
|
|
120
|
-
{
|
|
121
|
-
given: 'solve(cos(x), x)',
|
|
122
|
-
expected: '[(-1/2)*pi,(-3/2)*pi,(-9/2)*pi,(1/2)*pi,(3/2)*pi,-1352180071/26085593,-1908340923/110444324,-2517548877/94277729,'+
|
|
123
|
-
'-411557987/20154304,-529064097/48116095,-571845701/72809656,-742972117/31532716,-988823039/7771658,1100909798/10157405,'+
|
|
124
|
-
'1186473006/3058025,2330164408/10230543,363357032/2541981,3842632193/22862576,486282493/4127694,486282493/6879490,'+
|
|
125
|
-
'529064097/48116095,571845701/72809656,694771162/3482717,700190513/17830205,742972117/31532716,8001566871/92617376,828535325/15070342,871316929/8533809]'
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
{
|
|
129
|
-
given: 'solve(cos(x)*x+1-cos(x), x)',
|
|
130
|
-
expected: '[-157611237/7736072,-2656223529/19001015,-299590117/27042575,-302136356/39039211,-308954356/17824291,-36091008/7390861,'+
|
|
131
|
-
'-414635924/29467903,-617639565/11230682,-88830662/83379401,0,1015553327/14364225,1055263167/12216227,'+
|
|
132
|
-
'1168204159/10777362,150965503/34192001,1887835580/8523467,193836127/24237444,2053282505/45052302,332594509/8463821,'+
|
|
133
|
-
'3498970568/8735403,392182006/35998715,406482779/5074820,412628401/2886817,467039565/19859218,651649517/11856939,738326717/6103909,961315151/5614415]'
|
|
10
|
+
expect(nerdamer('solve(x=y/3416.3333333333344, y)').toString()).toEqual('[(1073228064103962/314146179365)*x]');
|
|
11
|
+
expect(nerdamer('solve(x, x)').toString()).toEqual('[0]');
|
|
12
|
+
expect(nerdamer('solve(5*y^x=8, x)').toString()).toEqual('[log(8/5)*log(y)^(-1)]');
|
|
13
|
+
expect(nerdamer('solve(x^y+8=a*b, x)').toString()).toEqual('[(-8+a*b)^y^(-1)]');
|
|
14
|
+
expect(nerdamer('solve(x^2, x)').toString()).toEqual('[0]');
|
|
15
|
+
expect(nerdamer('solve(x^3, x)').toString()).toEqual('[0]');
|
|
16
|
+
expect(nerdamer('solve(x+1, x)').toString()).toEqual('[-1]');
|
|
17
|
+
expect(nerdamer('solve(x^2+1, x)').toString()).toEqual('[i,-i]');
|
|
18
|
+
expect(nerdamer('solve(2*x^2+1, x)').toString()).toEqual('[(1/2)*i*sqrt(2),(-1/2)*i*sqrt(2)]');
|
|
19
|
+
expect(nerdamer('solve(3*(x+5)*(x-4), x)').toString()).toEqual('[-5,4]');
|
|
20
|
+
expect(nerdamer('solve(3*(x+a)*(x-b), x)').toString()).toEqual('[-a,b]');
|
|
21
|
+
expect(nerdamer('solve(a*x^2+b, x)').toString()).toEqual('[a^(-1)*i*sqrt(a)*sqrt(b),-a^(-1)*i*sqrt(a)*sqrt(b)]');
|
|
22
|
+
expect(nerdamer('solve(x^2+2*x+1, x)').toString()).toEqual('[-1]');
|
|
23
|
+
expect(nerdamer('solve(-5 sqrt(14)x-14x^2 sqrt(83)-10=0,x)').toString()).toEqual('[(-1/28)*sqrt(-560*sqrt(83)+350)*sqrt(83)^(-1)+(-5/28)*sqrt(14)*sqrt(83)^(-1),(-5/28)*sqrt(14)*sqrt(83)^(-1)+(1/28)*sqrt(-560*sqrt(83)+350)*sqrt(83)^(-1)]');
|
|
24
|
+
expect(nerdamer('solve(-5*sqrt(14)x-14x^2*sqrt(83)-10x=0,x)').toString()).toEqual('[(-5/14)*(2+sqrt(14))*sqrt(83)^(-1),0]');
|
|
25
|
+
expect(nerdamer('solve(8*x^3-26x^2+3x+9,x)').toString()).toEqual('[3/4,-1/2,3]');
|
|
26
|
+
expect(nerdamer('solve(a*x^2+b*x+c, x)').toString()).toEqual('[(1/2)*(-b+sqrt(-4*a*c+b^2))*a^(-1),(1/2)*(-b-sqrt(-4*a*c+b^2))*a^(-1)]');
|
|
27
|
+
expect(nerdamer('solve(sqrt(x^3)+sqrt(x^2)-sqrt(x)=0,x)').toString()).toEqual('[0,78202389238903801/240831735646702201]');
|
|
28
|
+
expect(nerdamer('solve(x^3-10x^2+31x-30,x)').toString()).toEqual('[3,5,2]');
|
|
29
|
+
expect(nerdamer('solve(sqrt(x)+sqrt(2x+1)=5,x)').toString()).toEqual('[4]');
|
|
30
|
+
expect(nerdamer('solve(x=2/(3-x),x)').toString()).toEqual('[1,2]');
|
|
31
|
+
expect(nerdamer('solve(1/x=a,x)').toString()).toEqual('[a^(-1)]');
|
|
32
|
+
expect(nerdamer('solve(sqrt(x^2-1),x)').toString()).toEqual('[1,-1]');
|
|
33
|
+
expect(nerdamer('solve(m*x^9+n,x)').toString()).toEqual('[2*m^(-1/9)*n^(1/9),2*e^((2/9)*i*pi)*m^(-1/9)*n^(1/9),2*e^((4/9)*i*pi)*m^(-1/9)*n^(1/9),2*e^((2/3)*i*pi)*m^(-1/9)*n^(1/9),2*e^((8/9)*i*pi)*m^(-1/9)*n^(1/9),2*e^((10/9)*i*pi)*m^(-1/9)*n^(1/9),2*e^((4/3)*i*pi)*m^(-1/9)*n^(1/9),2*e^((14/9)*i*pi)*m^(-1/9)*n^(1/9),2*e^((16/9)*i*pi)*m^(-1/9)*n^(1/9)]');
|
|
34
|
+
expect(nerdamer('solve(sqrt(97)x^2-sqrt(13)x+sqrt(14)x+sqrt(43)x^2+sqrt(3)*sqrt(101)=0,x)').toString()).toEqual('[(-1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(14)+(1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(-2*sqrt(13)*sqrt(14)-4*sqrt(101)*sqrt(3)*sqrt(43)-4*sqrt(101)*sqrt(3)*sqrt(97)+27)+(1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(13),(-1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(-2*sqrt(13)*sqrt(14)-4*sqrt(101)*sqrt(3)*sqrt(43)-4*sqrt(101)*sqrt(3)*sqrt(97)+27)+(-1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(14)+(1/2)*(sqrt(43)+sqrt(97))^(-1)*sqrt(13)]');
|
|
35
|
+
expect(nerdamer('solve(a*y^2*x^3-1, x)').toString()).toEqual('[((-1/2)*abs(a^(-1)*y^(-2))+(1/2)*a^(-1)*y^(-2))^(1/3)+((1/2)*a^(-1)*y^(-2)+(1/2)*abs(a^(-1)*y^(-2)))^(1/3),(((-1/2)*abs(a^(-1)*y^(-2))+(1/2)*a^(-1)*y^(-2))^(1/3)+((1/2)*a^(-1)*y^(-2)+(1/2)*abs(a^(-1)*y^(-2)))^(1/3))*((1/2)*i*sqrt(3)+1/2),(((-1/2)*abs(a^(-1)*y^(-2))+(1/2)*a^(-1)*y^(-2))^(1/3)+((1/2)*a^(-1)*y^(-2)+(1/2)*abs(a^(-1)*y^(-2)))^(1/3))*((1/2)*i*sqrt(3)+1/2)^2]');
|
|
36
|
+
expect(nerdamer('solve((1/2)*sqrt(-4*x+4*y)-2+y, y)').toString()).toEqual('[(-1/2)*(-5+sqrt(-4*x+9)),(-1/2)*(-5-sqrt(-4*x+9))]');
|
|
37
|
+
expect(nerdamer('solve(log(a*x-c)-b=21, x)').toString()).toEqual('[-(-c-e^(21+b))*a^(-1)]');
|
|
38
|
+
expect(nerdamer('solve(x/(x-a)+4,x)').toString()).toEqual('[(4/5)*a]');
|
|
39
|
+
expect(nerdamer('solve(3*sin(a^2*x-b)-4,x)').toString()).toEqual('[a^(-2)*asin(4/3)]');
|
|
40
|
+
expect(nerdamer('solve(a*log(x^2-4)-4,x)').toString()).toEqual('[(1/2)*sqrt(16+4*e^(4*a^(-1))),(-1/2)*sqrt(16+4*e^(4*a^(-1)))]');
|
|
41
|
+
expect(nerdamer('solve(x/(x^2+2*x+1)+4,x)').toString()).toEqual('[(1/8)*sqrt(17)-9/8,(-1/8)*sqrt(17)-9/8]');
|
|
42
|
+
expect(nerdamer('solve((a*x^2+1),x)').toString()).toEqual('[a^(-1)*sqrt(-a),-a^(-1)*sqrt(-a)]');
|
|
43
|
+
expect(nerdamer('solve(sqrt(x)-2x+x^2,x)').toString()).toEqual('[(-1/2)*sqrt(5)+3/2,0,1,832040/2178309]');
|
|
44
|
+
expect(nerdamer('solve((2x+x^2)^2-x,x)').toString()).toEqual('[0,((-1/6)*sqrt(3)^(-1)*sqrt(59)+43/54)^(1/3)+((1/6)*sqrt(3)^(-1)*sqrt(59)+43/54)^(1/3)-4/3,(((-1/6)*sqrt(3)^(-1)*sqrt(59)+43/54)^(1/3)+((1/6)*sqrt(3)^(-1)*sqrt(59)+43/54)^(1/3)-4/3)*((1/2)*i*sqrt(3)+1/2),(((-1/6)*sqrt(3)^(-1)*sqrt(59)+43/54)^(1/3)+((1/6)*sqrt(3)^(-1)*sqrt(59)+43/54)^(1/3)-4/3)*((1/2)*i*sqrt(3)+1/2)^2]');
|
|
45
|
+
expect(nerdamer('solve((5*x^4-2)/(x+1)/(x^2-1),x)').toString()).toEqual('[72425485/91070226,-72425485/91070226,(316684236/398209345)*i,(-316684236/398209345)*i]');
|
|
46
|
+
expect(nerdamer('solve(0=(x^(2)-2)/(e^(x)-1), x)').toString()).toEqual('[sqrt(2),-sqrt(2)]');
|
|
47
|
+
expect(nerdamer('solve(4/y^2=x^2+1,y)').toString()).toEqual('[(1/2)*(-1-x^2)^(-1)*sqrt(16+16*x^2),(-1/2)*(-1-x^2)^(-1)*sqrt(16+16*x^2)]');
|
|
48
|
+
expect(nerdamer('solve(1/(x+x^2), x)').toString()).toEqual('[]');
|
|
49
|
+
expect(nerdamer('solve(1/(x+x^2-1), x)').toString()).toEqual('[]');
|
|
50
|
+
expect(nerdamer('solve(-1+11000*(-100*(10+x)^(-1)+20)^(-2)*(10+x)^(-2), x)').toString()).toEqual('[(-1/2)*sqrt(110)-5,(1/2)*sqrt(110)-5]');
|
|
51
|
+
expect(nerdamer('solve(x^3+y^3=3, x)').toString()).toEqual('[((-1/2)*y^3+3/2+abs((-1/2)*y^3+3/2))^(1/3)+((-1/2)*y^3-abs((-1/2)*y^3+3/2)+3/2)^(1/3),(((-1/2)*y^3+3/2+abs((-1/2)*y^3+3/2))^(1/3)+((-1/2)*y^3-abs((-1/2)*y^3+3/2)+3/2)^(1/3))*((1/2)*i*sqrt(3)+1/2),(((-1/2)*y^3+3/2+abs((-1/2)*y^3+3/2))^(1/3)+((-1/2)*y^3-abs((-1/2)*y^3+3/2)+3/2)^(1/3))*((1/2)*i*sqrt(3)+1/2)^2]');
|
|
52
|
+
expect(nerdamer('solve(sqrt(10x+186)=x+9,x)').toString()).toEqual('[7]');
|
|
53
|
+
expect(nerdamer('solve(x^3+8=x^2+6,x)').toString()).toEqual('[-1,1+i,-i+1]');
|
|
54
|
+
expect(nerdamer('solve(x^3-10x^2+31x-30,x)').toString()).toEqual('[3,5,2]');
|
|
55
|
+
expect(nerdamer('solve(8x^3-26x^2+3x+9,x)').toString()).toEqual('[3/4,-1/2,3]');
|
|
56
|
+
expect(nerdamer('solve(x^3-1/2x^2-13/2x-3,x)').toString()).toEqual('[-2,3,-1/2]');
|
|
57
|
+
expect(nerdamer('solve(x^3+2x^2+3x-4=0,x)').evaluate().text()).toEqual('[0.776045435028538,0.388022717514269+0.6720750612256601*i,-0.388022717514269+0.6720750612256599*i]');
|
|
58
|
+
expect(nerdamer('solve(x*log(x),x)').toString()).toEqual('[1]');
|
|
59
|
+
expect(nerdamer('solve((9x+x^2)^3+10800x+40x^4+4440x^2+720x^3+20(9*x+x^2)^2+8000,x) ').toString()).toEqual('[-5,-4]');
|
|
60
|
+
expect(nerdamer('solve((x^3-4)/(x^3+7x-11),x)').evaluate().text()).toEqual('[1.587401051968199,0.7937005259840910+1.3747296369986024*i,-0.793700525984099+1.374729636998602*i]');
|
|
61
|
+
expect(nerdamer('solve((93222358/131836323)*(-2*y+549964829/38888386)=10, y)').toString()).toEqual('[1/3625267041734188]');
|
|
62
|
+
expect(nerdamer('solve(sqrt(x)+sqrt(2x+1)=5,x) ').toString()).toEqual('[4]');
|
|
63
|
+
expect(nerdamer('solve(sqrt(x)-1,x) ').toString()).toEqual('[1]');
|
|
64
|
+
expect(nerdamer('solve(sqrt(x)+1,x)').toString()).toEqual('[]');
|
|
65
|
+
expect(nerdamer('solve((x-1)*(x+1)*x=3x,x)').toString()).toEqual('[0,2,-2]');
|
|
66
|
+
expect(nerdamer('solve(sqrt(x^2+1),x)').toString()).toEqual('[i,-i]');
|
|
67
|
+
expect(nerdamer('solve(sqrt(x^2-1),x)').toString()).toEqual('[1,-1]');
|
|
68
|
+
expect(nerdamer('solve(((x+1)*((x+1)+1))/2=n,x)').toString()).toEqual('[-3/2+sqrt(1/4+2*n),-3/2-sqrt(1/4+2*n)]');
|
|
69
|
+
expect(nerdamer('solve(sqrt(10x+186)=x+9,x)').toString()).toEqual('[7]');
|
|
70
|
+
expect(nerdamer('solve(x^3+8=x^2+6,x)').toString()).toEqual('[-1,1+i,-i+1]');
|
|
71
|
+
expect(nerdamer('solve(x^2=x^-2,x)').toString()).toEqual('[1,-1,i,-i]');
|
|
72
|
+
expect(nerdamer('solve((x+1)(x+1)x=3x,x)').toString()).toEqual('[0,-1+sqrt(3),-1-sqrt(3)]');
|
|
73
|
+
expect(nerdamer('solve(log(y) = -t, y)').toString() ).toEqual('[e^(-t)]');
|
|
74
|
+
expect(nerdamer('solve(y=exp(4x),x)').toString() ).toEqual('[(1/4)*log(y)]');
|
|
134
75
|
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
given: 'solve(a*x^3+b*x+c, x)',
|
|
138
|
-
expected: '[(-1/3)*(27*a^2*c+sqrt(108*a^3*b^3+729*a^4*c^2))^(1/3)*2^(-1/3)*a^(-1)'+
|
|
139
|
-
'+(27*a^2*c+sqrt(108*a^3*b^3+729*a^4*c^2))^(-1/3)*2^(1/3)*b,(-1/2)*(-i*sqrt(3)+1)'+
|
|
140
|
-
'*(27*a^2*c+sqrt(108*a^3*b^3+729*a^4*c^2))^(-1/3)*2^(1/3)*a*b*a^(-1)+(1/6)*'+
|
|
141
|
-
'(1+i*sqrt(3))*(27*a^2*c+sqrt(108*a^3*b^3+729*a^4*c^2))^(1/3)*2^(-1/3)*a^(-1),'+
|
|
142
|
-
'(-1/2)*(1+i*sqrt(3))*(27*a^2*c+sqrt(108*a^3*b^3+729*a^4*c^2))^(-1/3)*2^(1/3)*'+
|
|
143
|
-
'a*b*a^(-1)+(1/6)*(-i*sqrt(3)+1)*(27*a^2*c+sqrt(108*a^3*b^3+729*a^4*c^2))^(1/3)*2^(-1/3)*a^(-1)]'
|
|
144
|
-
},
|
|
145
|
-
*/
|
|
146
|
-
{
|
|
147
|
-
given: 'solve(a*y^2*x^3-1, x)',
|
|
148
|
-
expected: '[((-1/2)*abs(a^(-1)*y^(-2))+(1/2)*a^(-1)*y^(-2))^(1/3)+((1/2)*a^(-1)*y^(-2)+(1/2)*abs(a^(-1)*y^(-2)))^(1/3),(((-1/2)*abs(a^(-1)*y^(-2))+(1/2)*a^(-1)*y^(-2))^(1/3)+((1/2)*a^(-1)*y^(-2)+(1/2)*abs(a^(-1)*y^(-2)))^(1/3))*((1/2)*i*sqrt(3)+1/2),(((-1/2)*abs(a^(-1)*y^(-2))+(1/2)*a^(-1)*y^(-2))^(1/3)+((1/2)*a^(-1)*y^(-2)+(1/2)*abs(a^(-1)*y^(-2)))^(1/3))*((1/2)*i*sqrt(3)+1/2)^2]'
|
|
149
|
-
},
|
|
150
|
-
//The tests below are incorrect and have no solutions
|
|
151
|
-
/*
|
|
152
|
-
{
|
|
153
|
-
given: 'solve(log(x,2)+log(x,3)=log(x,5), x)',
|
|
154
|
-
expected: '[1]'
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
given: 'solve(log(x)-log(x,0.5)=log(x,-3), x)',
|
|
158
|
-
expected: '[1]'
|
|
159
|
-
},
|
|
160
|
-
*/
|
|
161
|
-
{
|
|
162
|
-
given: 'solve((1/2)*sqrt(-4*x+4*y)-2+y, y)',
|
|
163
|
-
expected: '[(-1/2)*(-5+sqrt(-4*x+9)),(-1/2)*(-5-sqrt(-4*x+9))]'
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
given: 'solve(log(a*x-c)-b=21, x)',
|
|
167
|
-
expected: '[-(-c-e^(21+b))*a^(-1)]'
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
given: 'solve(x/(x-a)+4,x)',
|
|
171
|
-
expected: '[(4/5)*a]'
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
given: 'solve(3*sin(a^2*x-b)-4,x)',
|
|
175
|
-
expected: '[a^(-2)*asin(4/3)]'
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
given: 'solve(a*log(x^2-4)-4,x)',
|
|
179
|
-
expected: '[(1/2)*sqrt(16+4*e^(4*a^(-1))),(-1/2)*sqrt(16+4*e^(4*a^(-1)))]'
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
given: 'solve(x/(x^2+2*x+1)+4,x)',
|
|
183
|
-
expected: '[(1/8)*sqrt(17)-9/8,(-1/8)*sqrt(17)-9/8]'
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
given: 'solve((a*x^2+1),x)',
|
|
187
|
-
expected: '[a^(-1)*sqrt(-a),-a^(-1)*sqrt(-a)]'
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
//NOTE: 4503599627370497/4503599627370496 result can be safely removed since it has rounding errors
|
|
191
|
-
//NOTE: this test has duplicate solutions. The last two are duplicates of the first but have rounding errors
|
|
192
|
-
given: 'solve(sqrt(x)-2x+x^2,x)',
|
|
193
|
-
expected: '[(-1/2)*sqrt(5)+3/2,0,1,832040/2178309]'
|
|
194
|
-
},
|
|
195
|
-
// {
|
|
196
|
-
// given: 'solve((2x+x^2)^2-x,x)',
|
|
197
|
-
// expected: '[0,1097^(1/3)*729^(-1/3)+4*(-1)^(1/3)*729^(-1/3)+4/3,((1/2)*i*sqrt(3)+1/2)*(1097^(1/3)*729^(-1/3)+4*(-1)^(1/3)*729^(-1/3)+4/3),((1/2)*i*sqrt(3)+1/2)^2*(1097^(1/3)*729^(-1/3)+4*(-1)^(1/3)*729^(-1/3)+4/3)]'
|
|
198
|
-
// },
|
|
199
|
-
{
|
|
200
|
-
given: 'solve((5*x^4-2)/(x+1)/(x^2-1),x)',
|
|
201
|
-
expected: '[72425485/91070226,-72425485/91070226,(316684236/398209345)*i,(-316684236/398209345)*i]'
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
given: 'solve(0=(x^(2)-2)/(e^(x)-1), x)',
|
|
205
|
-
expected: '[sqrt(2),-sqrt(2)]'
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
given: 'solve(4/y^2=x^2+1,y)',
|
|
209
|
-
expected: '[(1/2)*(-1-x^2)^(-1)*sqrt(16+16*x^2),(-1/2)*(-1-x^2)^(-1)*sqrt(16+16*x^2)]'
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
given: 'solve(1/(x+x^2), x)',
|
|
213
|
-
expected: '[]'
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
given: 'solve(1/(x+x^2-1), x)',
|
|
217
|
-
expected: '[]'
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
given: 'solve(-1+11000*(-100*(10+x)^(-1)+20)^(-2)*(10+x)^(-2), x)',
|
|
221
|
-
expected: '[(-1/2)*sqrt(110)-5,(1/2)*sqrt(110)-5]'
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
given: 'solve(x^3+y^3=3, x)',
|
|
225
|
-
expected: '[((-1/2)*y^3+3/2+abs((-1/2)*y^3+3/2))^(1/3)+((-1/2)*y^3-abs((-1/2)*y^3+3/2)+3/2)^(1/3),(((-1/2)*y^3+3/2+abs((-1/2)*y^3+3/2))^(1/3)+((-1/2)*y^3-abs((-1/2)*y^3+3/2)+3/2)^(1/3))*((1/2)*i*sqrt(3)+1/2),(((-1/2)*y^3+3/2+abs((-1/2)*y^3+3/2))^(1/3)+((-1/2)*y^3-abs((-1/2)*y^3+3/2)+3/2)^(1/3))*((1/2)*i*sqrt(3)+1/2)^2]'
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
given: 'solve(sqrt(10x+186)=x+9,x)',
|
|
229
|
-
expected: '[7]'
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
given: 'solve(x^3+8=x^2+6,x)',
|
|
233
|
-
expected: '[-1,1+i,-i+1]'
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
given: 'solve(x^3-10x^2+31x-30,x)',
|
|
237
|
-
expected: '[3,5,2]'
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
given: 'solve(8x^3-26x^2+3x+9,x)',
|
|
241
|
-
expected: '[3/4,-1/2,3]'
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
given: 'solve(x^3-1/2x^2-13/2x-3,x)',
|
|
245
|
-
expected: '[-2,3,-1/2]'
|
|
246
|
-
},
|
|
247
|
-
// {
|
|
248
|
-
// given: '',
|
|
249
|
-
// expected: ''
|
|
250
|
-
// },
|
|
251
|
-
// {
|
|
252
|
-
// given: '',
|
|
253
|
-
// expected: ''
|
|
254
|
-
// },
|
|
255
|
-
];
|
|
256
|
-
|
|
257
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
258
|
-
// when
|
|
259
|
-
var parsed = nerdamer(testCases[i].given);
|
|
260
|
-
|
|
261
|
-
// then
|
|
262
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
263
|
-
}
|
|
264
76
|
});
|
|
265
77
|
it('should solve system of equations correctly', function () {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
{
|
|
278
|
-
given: ['x-2*y=-3', 'x+y-z+2*d=8', '5*d-1=19', 'z+d=7'],
|
|
279
|
-
expected: 'd,4,x,1,y,2,z,3'
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
given: 'x^2+4=x-y',
|
|
283
|
-
expected: '(1/2)*(1+sqrt(-15-4*y)),(1/2)*(-sqrt(-15-4*y)+1)'
|
|
284
|
-
},
|
|
285
|
-
//non-linear systems
|
|
286
|
-
{
|
|
287
|
-
given: ['x+y=3','y^3-x=7'],
|
|
288
|
-
expected: 'x,1,y,2'
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
given: ['x^2+y=3','x+y+z=6', 'z^2-y=7'],
|
|
292
|
-
expected: 'x,1,y,2,z,3'
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
given: ['x*y-cos(z)=-3', '3*z^3-y^2+1=12', '3*sin(x)*cos(y)-x^3=-4'],
|
|
296
|
-
expected: 'x,1.10523895006979,y,-2.98980336936266,z,1.88015428627437'
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
];
|
|
300
|
-
|
|
301
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
302
|
-
// when
|
|
303
|
-
var testCase = testCases[i],
|
|
304
|
-
parsed;
|
|
305
|
-
if (testCase.variables)
|
|
306
|
-
parsed = nerdamer.solveEquations(testCase.given, testCase.variables);
|
|
307
|
-
else
|
|
308
|
-
parsed = nerdamer.solveEquations(testCase.given);
|
|
309
|
-
// then
|
|
310
|
-
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
311
|
-
}
|
|
78
|
+
expect(nerdamer.solveEquations(['x+y=1', '2*x=6', '4*z+y=6']).toString()).toEqual('x,3,y,-2,z,2');
|
|
79
|
+
expect(nerdamer.solveEquations(['x+y=a', 'x-y=b', 'z+y=c'], ['x', 'y', 'z']).toString()).toEqual('x,0.5*a+0.5*b,y,-0.5*b+0.5*a,z,-0.5*a+0.5*b+c');
|
|
80
|
+
expect(nerdamer.solveEquations(['x-2*y=-3', 'x+y-z+2*d=8', '5*d-1=19', 'z+d=7']).toString()).toEqual('d,4,x,1,y,2,z,3');
|
|
81
|
+
expect(nerdamer.solveEquations('x^2+4=x-y').toString()).toEqual('(1/2)*(1+sqrt(-15-4*y)),(1/2)*(-sqrt(-15-4*y)+1)');
|
|
82
|
+
expect(nerdamer.solveEquations(['x+y=3', 'y^3-x=7']).toString()).toEqual('x,1,y,2');
|
|
83
|
+
expect(nerdamer.solveEquations(['x^2+y=3', 'x+y+z=6', 'z^2-y=7']).toString()).toEqual('x,1,y,2,z,3');
|
|
84
|
+
expect(nerdamer.solveEquations(['x*y-cos(z)=-3', '3*z^3-y^2+1=12', '3*sin(x)*cos(y)-x^3=-4']).toString()).toEqual('x,1.10523895006979,y,-2.98980336936266,z,1.88015428627437');
|
|
85
|
+
expect(nerdamer.solveEquations(['x=i','x+y=3']).toString()).toEqual('x,i,y,-i+3');
|
|
86
|
+
expect(nerdamer.solveEquations(["x/(45909438.9 + 0 + x)=0", "45909438.9+0+x=45909438.9"]).toString()).toEqual('x,0');
|
|
87
|
+
expect(nerdamer.solveEquations(["a=1"]).toString()).toEqual('a,1');
|
|
88
|
+
expect(nerdamer.solveEquations(["x=5", "0.6=1-(x/(10+y))"]).toString()).toEqual('x,5,y,2.5');
|
|
312
89
|
});
|
|
313
90
|
/** #55: nerdamer.solveEquation quits working */
|
|
314
91
|
it('should handle text("fractions") without later impact', function () {
|
|
315
92
|
expect(nerdamer.solveEquations("x+1=2", "x").toString()).toEqual('1');
|
|
316
93
|
expect(nerdamer('x=1').text("fractions")).toEqual('x=1');
|
|
317
94
|
expect(nerdamer.solveEquations("x+1=2", "x").toString()).toEqual('1');
|
|
318
|
-
});
|
|
95
|
+
});
|
|
319
96
|
it('should parse equations correctly', function () {
|
|
320
97
|
expect(nerdamer("-(a+1)=(a+3)^2").toString()).toEqual('-1-a=(3+a)^2');
|
|
321
98
|
});
|
|
322
99
|
//NOTE: contains duplicates
|
|
323
|
-
it('should solve functions with factorials', function() {
|
|
100
|
+
it('should solve functions with factorials', function () {
|
|
324
101
|
expect(nerdamer('solve(x!-x^2,x)').text('decimals', 20)).toEqual('[-2.200391782610595,-4.010232827899529,-2.938361683501947,1,1.000000000000001,3.562382285390900,3.562382285390896,0.9999999999999910,1.000000000000000]');
|
|
325
|
-
});
|
|
326
|
-
it('should solve for variables other than x', function() {
|
|
102
|
+
});
|
|
103
|
+
it('should solve for variables other than x', function () {
|
|
327
104
|
expect(nerdamer('solve(2*a^(2)+4*a*6=128, a)').toString()).toEqual('[4,-16]');
|
|
328
105
|
});
|
|
329
|
-
it('should solve nonlinear system of equations with multiple parameter functions', function() {
|
|
106
|
+
it('should solve nonlinear system of equations with multiple parameter functions', function () {
|
|
330
107
|
var ans = nerdamer.solveEquations([
|
|
331
108
|
`y=x * 2`,
|
|
332
109
|
`z=y + max (y * 0.1, 23)`,
|
|
@@ -336,7 +113,14 @@ describe('Solve', function () {
|
|
|
336
113
|
expect(ans.toString()).toEqual('j,2935.601831019821,x,1334.3644686453729,y,2668.7289372907458,z,2935.601831019821');
|
|
337
114
|
});
|
|
338
115
|
|
|
339
|
-
|
|
116
|
+
it('should solve factors', function () {
|
|
340
117
|
expect(nerdamer('solve((x-1)*(-a*c-a*x+c*x+x^2),x)').text()).toEqual('[1,-c,a]');
|
|
341
118
|
});
|
|
119
|
+
|
|
120
|
+
it('should solve circle equations', function() {
|
|
121
|
+
var eq1 ="x^2+y^2=1";
|
|
122
|
+
var eq2 ="x+y=1";
|
|
123
|
+
var sol = nerdamer.solveEquations([eq1, eq2]);
|
|
124
|
+
expect(sol.toString()).toEqual('x,1,0,y,0,1');
|
|
125
|
+
});
|
|
342
126
|
});
|