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/core.spec.js
CHANGED
|
@@ -9,6 +9,7 @@ var _ = utils.toFixed;
|
|
|
9
9
|
var run = utils.run;
|
|
10
10
|
var core = nerdamer.getCore();
|
|
11
11
|
var round = core.Utils.round;
|
|
12
|
+
var block = core.Utils.block;
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
//, x=2.1, y=3.3, z=1, a=7.42
|
|
@@ -918,6 +919,11 @@ describe('Nerdamer core', function () {
|
|
|
918
919
|
given: 'sqrt(2/x)',
|
|
919
920
|
expected: 'sqrt(2)*sqrt(x)^(-1)',
|
|
920
921
|
expectedValue: '0.9759000729485331'
|
|
922
|
+
},
|
|
923
|
+
{
|
|
924
|
+
given: 'sqrt(3^x)',
|
|
925
|
+
expected: 'sqrt(3^x)',
|
|
926
|
+
expectedValue: '3.169401925649'
|
|
921
927
|
}
|
|
922
928
|
];
|
|
923
929
|
|
|
@@ -1881,7 +1887,15 @@ describe('Nerdamer core', function () {
|
|
|
1881
1887
|
});
|
|
1882
1888
|
it('should recognize the mod and percent operator', function() {
|
|
1883
1889
|
expect(nerdamer('3*(a%%b%)').toString()).toEqual('3*mod((1/100)*a,(1/100)*b)')
|
|
1884
|
-
})
|
|
1890
|
+
});
|
|
1891
|
+
it('should rewrite e as exp', function() {
|
|
1892
|
+
block('E_TO_EXP', function() {
|
|
1893
|
+
expect(nerdamer('(3*e^(e^(x))+tan(-e^x))+a').toString()).toEqual('3*exp(exp(x))+a+tan(-exp(x))');
|
|
1894
|
+
});
|
|
1895
|
+
});
|
|
1896
|
+
it('should unwrap even abs', function() {
|
|
1897
|
+
expect(nerdamer('(3*abs(x))^2').toString()).toEqual('3*x^2');
|
|
1898
|
+
});
|
|
1885
1899
|
});
|
|
1886
1900
|
|
|
1887
1901
|
describe('Further arithmetic test cases', function () {
|
|
@@ -2541,6 +2555,15 @@ describe('trigonometric functions', function () {
|
|
|
2541
2555
|
expect(round(value, 14)).toEqual(round(testCases[i].expectedValue),14);
|
|
2542
2556
|
}
|
|
2543
2557
|
});
|
|
2558
|
+
it('should handle inverse trig in complex domain', function() {
|
|
2559
|
+
expect(nerdamer('asin(2)').evaluate().text()).toEqual('-1.3169578969248164*i+1.570796326794896580');
|
|
2560
|
+
expect(nerdamer('asin(2.19549352839451962743423602992)').evaluate().text()).toEqual('-1.423114269539483*i+1.570796326794896580');
|
|
2561
|
+
expect(nerdamer('acos(2)').evaluate().text()).toEqual('1.3169578969248164*i');
|
|
2562
|
+
expect(nerdamer('atan(i)').evaluate().text()).toEqual('Infinity*i');
|
|
2563
|
+
|
|
2564
|
+
expect(nerdamer('asec(0.89)').evaluate().text()).toEqual('0.000000000000000250+0.4921996534425188*i'); // Has rounding errors
|
|
2565
|
+
expect(nerdamer('acsc(0.23)').evaluate().text()).toEqual('-2.1493278111894223*i+1.570796326794897197'); // Has rounding errors
|
|
2566
|
+
});
|
|
2544
2567
|
it('should throw for wrong trigonometric arguments', function () {
|
|
2545
2568
|
// given
|
|
2546
2569
|
var testCases = [
|
|
@@ -2563,13 +2586,13 @@ describe('trigonometric functions', function () {
|
|
|
2563
2586
|
}
|
|
2564
2587
|
});
|
|
2565
2588
|
it('should throw for malformed expression', function () {
|
|
2566
|
-
expect(function(){nerdamer('+')}).toThrowError();
|
|
2567
|
-
expect(function(){nerdamer('(+)')}).toThrowError();
|
|
2568
|
-
expect(function(){nerdamer('cos(')}).toThrowError();
|
|
2569
|
-
expect(function(){nerdamer('(x+1))')}).toThrowError();
|
|
2570
|
-
expect(function(){nerdamer('/2')}).toThrowError();
|
|
2571
|
-
expect(function(){nerdamer('()')}).toThrowError();
|
|
2572
|
-
expect(function(){nerdamer('5+')}).toThrowError();
|
|
2589
|
+
expect(function(){nerdamer('+');}).toThrowError();
|
|
2590
|
+
expect(function(){nerdamer('(+)');}).toThrowError();
|
|
2591
|
+
expect(function(){nerdamer('cos(');}).toThrowError();
|
|
2592
|
+
expect(function(){nerdamer('(x+1))');}).toThrowError();
|
|
2593
|
+
expect(function(){nerdamer('/2');}).toThrowError();
|
|
2594
|
+
expect(function(){nerdamer('()');}).toThrowError();
|
|
2595
|
+
expect(function(){nerdamer('5+');}).toThrowError();
|
|
2573
2596
|
});
|
|
2574
2597
|
it('should calculate correctly with variables', function () {
|
|
2575
2598
|
// given
|
|
@@ -2714,6 +2737,10 @@ describe('trigonometric functions', function () {
|
|
|
2714
2737
|
expect(parsed.toString()).toEqual(testCases[i].expected);
|
|
2715
2738
|
}
|
|
2716
2739
|
});
|
|
2740
|
+
it('should handle known trig cases for `numer`', function() {
|
|
2741
|
+
expect(nerdamer('tan(pi)', {}, 'numer').text()).toEqual('0');
|
|
2742
|
+
expect(nerdamer('cot(90*pi/180)', {}, 'numer').text()).toEqual('0');
|
|
2743
|
+
});
|
|
2717
2744
|
});
|
|
2718
2745
|
|
|
2719
2746
|
describe('hyperbolic trigonometric functions', function () {
|
package/spec/extra.spec.js
CHANGED
|
@@ -5,182 +5,50 @@
|
|
|
5
5
|
var nerdamer = require('../nerdamer.core.js');
|
|
6
6
|
require('../Extra');
|
|
7
7
|
|
|
8
|
-
describe('
|
|
9
|
-
|
|
10
|
-
it('should transform Laplace correctly', function () {
|
|
11
|
-
// given
|
|
12
|
-
var testCases = [
|
|
13
|
-
{
|
|
14
|
-
given: 'laplace(5, t, s)',
|
|
15
|
-
expected: '5*s^(-1)'
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
given: 'laplace(a*t, t, s)',
|
|
19
|
-
expected: 'a*s^(-2)'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
given: 'laplace(cos(a*t), t, s)',
|
|
23
|
-
expected: '(a^2+s^2)^(-1)*s'
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
given: 'laplace(cos(x), t, s)',
|
|
27
|
-
expected: 'cos(x)*s^(-1)'
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
given: 'laplace(sinh(a*t), t, s)',
|
|
31
|
-
expected: '(-a^2+s^2)^(-1)*a'
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
given: 'laplace(a*t^2, t, s)',
|
|
35
|
-
expected: '2*a*s^(-3)'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
given: 'laplace(2*sqrt(t), t, s)',
|
|
39
|
-
expected: 's^(-3/2)*sqrt(pi)'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
given: 'laplace(x*e^(a*t), t, s)',
|
|
43
|
-
expected: '(-a+s)^(-1)*x'
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
given: 'laplace(x*(sin(a*t)-a*t*cos(a*t)), t, s)',
|
|
47
|
-
expected: '((a^2+s^2)^(-1)*a-((1+a^2*s^(-2))^(-2)*s^(-2)-(1+a^2*s^(-2))^(-2)*a^2*s^(-4))*a)*x'
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
given: 'laplace(sin(a*t), t, s)',
|
|
51
|
-
expected: '(a^2+s^2)^(-1)*a'
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
given: 'laplace(t*sin(a*t), t, s)',
|
|
55
|
-
expected: '2*(1+a^2*s^(-2))^(-2)*a*s^(-3)'
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
given: 'laplace(sin(a*t+b), t, s)',
|
|
59
|
-
expected: '(1+a^2*s^(-2))^(-1)*a*cos(b)*s^(-2)+(1+a^2*s^(-2))^(-1)*s^(-1)*sin(b)'
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
given: 'laplace(t^2*e^(a*t), t, s)',
|
|
63
|
-
expected: '-2*(-s+a)^(-3)'
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
given: 'laplace(6*t*e^(-9*t)*sin(6*t), t, s)',
|
|
67
|
-
expected: '-72*(-9-s)^(-3)*(1+36*(-9-s)^(-2))^(-2)'
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
//NOTE: this unit test was incorrect before. I don't know how this was missed.
|
|
71
|
-
given: 'laplace(sinh(t)*e^t, t, s)',
|
|
72
|
-
expected: '(-1/2)*(-s+2)^(-1)+(-1/2)*s^(-1)'
|
|
73
|
-
}
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
77
|
-
// when
|
|
78
|
-
var parsed = nerdamer(testCases[i].given);
|
|
8
|
+
describe('Extra Calculus', function () {
|
|
79
9
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
10
|
+
it('should transform Laplace correctly', function () {
|
|
11
|
+
expect(nerdamer('laplace(5, t, s)').toString()).toEqual('5*s^(-1)');
|
|
12
|
+
expect(nerdamer('laplace(a*t, t, s)').toString()).toEqual('a*s^(-2)');
|
|
13
|
+
expect(nerdamer('laplace(cos(a*t), t, s)').toString()).toEqual('(a^2+s^2)^(-1)*s');
|
|
14
|
+
expect(nerdamer('laplace(cos(x), t, s)').toString()).toEqual('cos(x)*s^(-1)');
|
|
15
|
+
expect(nerdamer('laplace(sinh(a*t), t, s)').toString()).toEqual('(-a^2+s^2)^(-1)*a');
|
|
16
|
+
expect(nerdamer('laplace(a*t^2, t, s)').toString()).toEqual('2*a*s^(-3)');
|
|
17
|
+
expect(nerdamer('laplace(2*sqrt(t), t, s)').toString()).toEqual('s^(-3/2)*sqrt(pi)');
|
|
18
|
+
expect(nerdamer('laplace(x*e^(a*t), t, s)').toString()).toEqual('(-a+s)^(-1)*x');
|
|
19
|
+
expect(nerdamer('laplace(x*(sin(a*t)-a*t*cos(a*t)), t, s)').toString()).toEqual('((a^2+s^2)^(-1)*a-((1+a^2*s^(-2))^(-2)*s^(-2)-(1+a^2*s^(-2))^(-2)*a^2*s^(-4))*a)*x');
|
|
20
|
+
expect(nerdamer('laplace(sin(a*t), t, s)').toString()).toEqual('(a^2+s^2)^(-1)*a');
|
|
21
|
+
expect(nerdamer('laplace(t*sin(a*t), t, s)').toString()).toEqual('2*(1+a^2*s^(-2))^(-2)*a*s^(-3)');
|
|
22
|
+
expect(nerdamer('laplace(sin(a*t+b), t, s)').toString()).toEqual('(1+a^2*s^(-2))^(-1)*a*cos(b)*s^(-2)+(1+a^2*s^(-2))^(-1)*s^(-1)*sin(b)');
|
|
23
|
+
expect(nerdamer('laplace(t^2*e^(a*t), t, s)').toString()).toEqual('-2*(-s+a)^(-3)');
|
|
24
|
+
expect(nerdamer('laplace(6*t*e^(-9*t)*sin(6*t), t, s)').toString()).toEqual('-72*(-9-s)^(-3)*(1+36*(-9-s)^(-2))^(-2)');
|
|
25
|
+
expect(nerdamer('laplace(sinh(t)*e^t, t, s)').toString()).toEqual('(-1/2)*(-s+2)^(-1)+(-1/2)*s^(-1)');
|
|
83
26
|
});
|
|
84
|
-
|
|
85
|
-
it('should invert a Laplace transform correctly', function () {
|
|
86
|
-
// given
|
|
87
|
-
var testCases = [
|
|
88
|
-
{
|
|
89
|
-
given: 'ilt(a/(b*x), x, t)',
|
|
90
|
-
expected: 'a*b^(-1)'
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
given: 'ilt(a*6/(b*s^6),s,t)',
|
|
94
|
-
expected: '(1/20)*a*b^(-1)*t^5'
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
given: 'ilt(3*s/(4*s^2+5),s,t)',
|
|
98
|
-
expected: '(3/4)*cos((1/2)*sqrt(5)*t)'
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
given: 'ilt(2/(3*s^2+1),s,t)',
|
|
102
|
-
expected: '2*sin((1/3)*sqrt(3)*t)*sqrt(3)^(-1)'
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
given: 'ilt(5*sqrt(pi)/(3*s^(3/2)),s,t)',
|
|
106
|
-
expected: '(10/3)*sqrt(t)'
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
given: 'ilt(3/(7*s^2+1)^2, s, t)',
|
|
110
|
-
expected: '(-3/14)*cos((1/7)*sqrt(7)*t)*t+(3/2)*sin((1/7)*sqrt(7)*t)*sqrt(7)^(-1)'
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
given: 'ilt(5*s/(s^2+4)^2, s, t)',
|
|
114
|
-
expected: '(5/4)*sin(2*t)*t'
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
given: 'ilt(8*s^2/(2*s^2+3)^2, s, t)',
|
|
118
|
-
expected: '2*sin((1/2)*sqrt(6)*t)*sqrt(6)^(-1)+cos((1/2)*sqrt(6)*t)*t'
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
given: 'ilt((6*s^2-1)/(4*s^2+1)^2, s, t)',
|
|
122
|
-
expected: '(1/8)*sin((1/2)*t)+(5/16)*cos((1/2)*t)*t'
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
given: 'ilt((5*(sin(1)*s+3*cos(1)))/(s^2+9),s, t)',
|
|
126
|
-
expected: '5*cos(1)*sin(3*t)+5*cos(3*t)*sin(1)'
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
//TODO: Although this is computed correctly we need to get rid of the silly factorial(0)^(-1)
|
|
130
|
-
given: 'ilt(((s+1)*(s+2)*(s+3))^(-1), s, t)',
|
|
131
|
-
expected: '(1/2)*e^(-3*t)*factorial(0)^(-1)+(1/2)*e^(-t)*factorial(0)^(-1)-e^(-2*t)*factorial(0)^(-1)'
|
|
132
|
-
}
|
|
133
|
-
];
|
|
134
|
-
|
|
135
|
-
for (var i = 0; i < testCases.length; ++i) {
|
|
136
|
-
// when
|
|
137
|
-
var parsed = nerdamer(testCases[i].given);
|
|
138
27
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
28
|
+
it('should invert a Laplace transform correctly', function () {
|
|
29
|
+
expect(nerdamer('ilt(a/(b*x), x, t)').toString()).toEqual('a*b^(-1)');
|
|
30
|
+
expect(nerdamer('ilt(a*6/(b*s^6),s,t)').toString()).toEqual('(1/20)*a*b^(-1)*t^5');
|
|
31
|
+
expect(nerdamer('ilt(3*s/(4*s^2+5),s,t)').toString()).toEqual('(3/4)*cos((1/2)*sqrt(5)*t)');
|
|
32
|
+
expect(nerdamer('ilt(2/(3*s^2+1),s,t)').toString()).toEqual('2*sin((1/3)*sqrt(3)*t)*sqrt(3)^(-1)');
|
|
33
|
+
expect(nerdamer('ilt(5*sqrt(pi)/(3*s^(3/2)),s,t)').toString()).toEqual('(10/3)*sqrt(t)');
|
|
34
|
+
expect(nerdamer('ilt(3/(7*s^2+1)^2, s, t)').toString()).toEqual('(-3/14)*cos((1/7)*sqrt(7)*t)*t+(3/2)*sin((1/7)*sqrt(7)*t)*sqrt(7)^(-1)');
|
|
35
|
+
expect(nerdamer('ilt(5*s/(s^2+4)^2, s, t)').toString()).toEqual('(5/4)*sin(2*t)*t');
|
|
36
|
+
expect(nerdamer('ilt(8*s^2/(2*s^2+3)^2, s, t)').toString()).toEqual('2*sin((1/2)*sqrt(6)*t)*sqrt(6)^(-1)+cos((1/2)*sqrt(6)*t)*t');
|
|
37
|
+
expect(nerdamer('ilt((6*s^2-1)/(4*s^2+1)^2, s, t)').toString()).toEqual('(1/8)*sin((1/2)*t)+(5/16)*cos((1/2)*t)*t');
|
|
38
|
+
expect(nerdamer('ilt((5*(sin(1)*s+3*cos(1)))/(s^2+9),s, t)').toString()).toEqual('5*cos(1)*sin(3*t)+5*cos(3*t)*sin(1)');
|
|
39
|
+
expect(nerdamer('ilt(((s+1)*(s+2)*(s+3))^(-1), s, t)').toString()).toEqual('(1/2)*e^(-3*t)+(1/2)*e^(-t)-e^(-2*t)');
|
|
40
|
+
expect(nerdamer('ilt(1/(s^2+s+1),s,t)').toString()).toEqual('2*e^((-1/2)*t)*sin((1/2)*sqrt(3)*t)*sqrt(3)^(-1)');
|
|
41
|
+
expect(nerdamer('ilt(1/(s^2+2s+1),s,t)').toString()).toEqual('e^(-t)*t');
|
|
142
42
|
});
|
|
143
|
-
|
|
144
|
-
it('should calculate mode correctly', function () {
|
|
145
|
-
// given
|
|
146
|
-
var testCases = [
|
|
147
|
-
{
|
|
148
|
-
given: 'mode(r,r,r,r)',
|
|
149
|
-
expected: 'r'
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
given: 'mode(1,2)',
|
|
153
|
-
expected: 'mode(1,2)'
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
given: 'mode(1,2,3,1,2)',
|
|
157
|
-
expected: 'mode(1,2)'
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
given: 'mode(1,1,2)',
|
|
161
|
-
expected: '1'
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
given: 'mode(a,a,b,c,a,b,d)',
|
|
165
|
-
expected: 'a'
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
given: 'mode(x, r+1, 21, tan(x), r+1)',
|
|
169
|
-
expected: '1+r'
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
given: 'mode(x, r+1, 21, tan(x), r+1, x)',
|
|
173
|
-
expected: 'mode(1+r,x)'
|
|
174
|
-
}
|
|
175
|
-
];
|
|
176
43
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
44
|
+
it('should calculate mode correctly', function () {
|
|
45
|
+
expect(nerdamer('mode(r,r,r,r)').toString()).toEqual('r');
|
|
46
|
+
expect(nerdamer('mode(1,2)').toString()).toEqual('mode(1,2)');
|
|
47
|
+
expect(nerdamer('mode(1,2,3,1,2)').toString()).toEqual('mode(1,2)');
|
|
48
|
+
expect(nerdamer('mode(1,1,2)').toString()).toEqual('1');
|
|
49
|
+
expect(nerdamer('mode(a,a,b,c,a,b,d)').toString()).toEqual('a');
|
|
50
|
+
expect(nerdamer('mode(x, r+1, 21, tan(x), r+1)').toString()).toEqual('1+r');
|
|
51
|
+
expect(nerdamer('mode(x, r+1, 21, tan(x), r+1, x)').toString()).toEqual('mode(1+r,x)');
|
|
184
52
|
});
|
|
185
53
|
});
|
|
186
54
|
|