Skip to content

Commit 150eb0e

Browse files
committed
vector fixes
1 parent bcb0bbd commit 150eb0e

7 files changed

+16
-15
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The license is unchanged, everything is free under MIT terms.
88

99
The npm js installation point has moved: `npm i nerdamer-prime`.
1010

11+
NOTICE: Starting with version 1.2.0, vector and matrix semantics are changing to be more useful for linear algebra. If this causes you problems, please stick with 1.1.26 and let us know so we can see how we could make compatible changes.
12+
1113
Our intentions:
1214

1315
To keep Nerdamer in good repair, and make improvements where we need them and where we can. Mostly bug fixes. If you investigate
@@ -20,7 +22,7 @@ e.g. SymPy in a WASM webworker if you need more. See here for a demo: [SymPy liv
2022
We have made some improvements - simplification of logs and squareroots, and bug fixes related to those areas and factoring. Unit tests
2123
are fixed except for a couple of known flaws. There will be further work in this area. We will also work on vectors, which are not
2224
useful for our product [together.math](https://www.together.science/) today. Those will be breaking changes
23-
(you are welcome to fork an earlier version).
25+
(*THESE ARE NOW IN PROGRESS* for versions >= 1.2.0, you are welcome to fork an earlier version).
2426

2527
If you have a clear bug, file an issue with the code to repro. If you want a new feature - and that includes many things that you will
2628
think of as "obvious flaws" - file the issue, but we probably won't do it. But someone else can! We will absolutely consider compatible

all.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nerdamer.core.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11508,12 +11508,12 @@ var nerdamer = (function (imports) {
1150811508
while(--n);
1150911509
return index;
1151011510
},
11511-
text_: function (x) {
11512-
let result = text(this);
11511+
text_: function (x, options) {
11512+
let result = text(this, options);
1151311513
return (this.rowVector?"[":"")+result+(this.rowVector?"]":"");
1151411514
},
11515-
text: function (x) {
11516-
let result = text(this);
11515+
text: function (x, options) {
11516+
let result = text(this, options);
1151711517
return (this.rowVector?"[":"")+result+(this.rowVector?"]":"");
1151811518
},
1151911519
toString: function () {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description": "javascript light-weight symbolic math library",
77
"name": "nerdamer-prime",
88
"license": "MIT",
9-
"version": "1.1.27",
9+
"version": "1.2.0",
1010
"homepage": "https://github.com/together-science/nerdamer-prime",
1111
"directory": {
1212
"lib": "./"

spec/algebra.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ describe('Algebra', function () {
325325
expect(nerdamer('sqrt(2*baseunit_m^2*sin(3*alpha))').toString()).toEqual('baseunit_m*sqrt(2)*sqrt(sin(3*alpha))');
326326
});
327327
it('should calculate nth roots correctly', function() {
328-
expect(nerdamer('roots((-1)^(1/5))').evaluate().text()).toEqual('[0.5877852522924731*i+0.809016994374947,-0.309016994374947+0.9510565162951536*i,-1,-0.309016994374948-0.9510565162951536*i,-0.5877852522924734*i+0.809016994374947]');
329-
expect(nerdamer('roots((2)^(1/3))').evaluate().text()).toEqual('[1.122462048309381,-1.122462048309381]');
328+
expect(nerdamer('roots((-1)^(1/5))').evaluate().text()).toEqual('[(181485532/308761629)*i+260449120/321932817,(55918065/58795733)*i-39088169/126491972,-1,(-8795017271979437/9247628423009475)*i-24157817/78176338,(-8677593/14763203)*i+102334155/126491972]');
329+
expect(nerdamer('roots((2)^(1/3))').evaluate().text()).toEqual('[131293077/116968834,-131293077/116968834]');
330330
});
331331
it('should complete the square', function() {
332332
expect(nerdamer('sqcomp(a*x^2+b*x-11*c, x)').toString()).toEqual('((1/2)*abs(b)*sqrt(a)^(-1)+sqrt(a)*x)^2+(-1/4)*(abs(b)*sqrt(a)^(-1))^2-11*c');

spec/core.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ describe('Nerdamer core', function () {
18161816
});
18171817
it('should remove near duplicates from vectors', function() {
18181818
expect(nerdamer('vectrim([cos(0), 1, 1.000000000000001])').toString()).toEqual('[1]');
1819-
expect(nerdamer('vectrim([cos(0), 1, 1.000000000000001], 0)').text()).toEqual('[1,1.000000000000001]');
1819+
expect(nerdamer('vectrim([cos(0), 1, 1.000000000000001], 0)').text()).toEqual('[1,900719925474100/900719925474099]');
18201820
});
18211821
it('should convert degrees to radians', function() {
18221822
expect(nerdamer('radians(45)').toString()).toEqual('(1/4)*pi');

spec/solve.spec.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ describe('Solve', function () {
6363
expect(nerdamer('solve(x^3-10x^2+31x-30,x)').toString()).toEqual('[3,5,2]');
6464
expect(nerdamer('solve(8x^3-26x^2+3x+9,x)').toString()).toEqual('[3/4,-1/2,3]');
6565
expect(nerdamer('solve(x^3-1/2x^2-13/2x-3,x)').toString()).toEqual('[-2,3,-1/2]');
66-
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]');
66+
expect(nerdamer('solve(x^3+2x^2+3x-4=0,x)').evaluate().text()).toEqual('[70419755/90741794,(9781803879340745/14554630046086988)*i+70419755/181483588,(5721734032321405/8513534220250202)*i-96689750724854153216/249185798564226019925]');
6767
expect(nerdamer('solve(x*log(x),x)').toString()).toEqual('[1]');
6868
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]');
69-
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]');
69+
expect(nerdamer('solve((x^3-4)/(x^3+7x-11),x)').evaluate().text()).toEqual('[123554237/77834292,(17162560630828463/12484317038729784)*i+123554237/155668584,(10039007984057947/7302532595409636)*i-17388712991038935924736/21908405527990418074125]');
7070
expect(nerdamer('solve((93222358/131836323)*(-2*y+549964829/38888386)=10, y)').toString()).toEqual('[1/3625267041734188]');
7171
expect(nerdamer('solve(sqrt(x)+sqrt(2x+1)=5,x) ').toString()).toEqual('[4]');
7272
expect(nerdamer('solve(sqrt(x)-1,x) ').toString()).toEqual('[1]');
@@ -95,7 +95,7 @@ describe('Solve', function () {
9595
// np issue #26
9696
// expect(nerdamer("solve(h=1/2*(9.81)*m*s^(-2)*t^2, t)").evaluate().text()).toEqual("[0.4515236409857309*s*sqrt(h)*sqrt(m)^(-1),-0.4515236409857309*s*sqrt(h)*sqrt(m)^(-1)]");
9797
// like:
98-
expect(nerdamer("solve(h=1/2*(9.81)*t^2, t)").evaluate().text()).toEqual("[-0.4515236409857309*sqrt(h),0.4515236409857309*sqrt(h)]");
98+
expect(nerdamer("solve(h=1/2*(9.81)*t^2, t)").evaluate().text()).toEqual("[(-35364869/78323405)*sqrt(h),(35364869/78323405)*sqrt(h)]");
9999
expect(nerdamer("h=(981/200)*m*s^(-2)*t^2").solveFor("t").toString()).toEqual('(-10/327)*abs(s)*m^(-1)*sqrt(218)*sqrt(h)*sqrt(m),(10/327)*abs(s)*m^(-1)*sqrt(218)*sqrt(h)*sqrt(m)');
100100
});
101101

@@ -155,8 +155,7 @@ describe('Solve', function () {
155155
expect(nerdamer('solve(a^2-a-1=0,a)').toString()).toEqual('[(1/2)*sqrt(5)+1/2,(-1/2)*sqrt(5)+1/2]');
156156
// issue #26
157157
expect(nerdamer("solve(h=(981/200)*baseunit_m*baseunit_s^(-2)*t^2, t)").text())
158-
.toEqual('[-0.0305810397553517*baseunit_m^(-1)*baseunit_s*sqrt(218)*sqrt(baseunit_m)*sqrt(h),'+
159-
'0.0305810397553517*baseunit_m^(-1)*baseunit_s*sqrt(218)*sqrt(baseunit_m)*sqrt(h)]');
158+
.toEqual('[(-10/327)*baseunit_m^(-1)*baseunit_s*sqrt(218)*sqrt(baseunit_m)*sqrt(h),(10/327)*baseunit_m^(-1)*baseunit_s*sqrt(218)*sqrt(baseunit_m)*sqrt(h)]');
160159
expect(nerdamer('solve(abs(a-b)=0, a)').toString()).toEqual('[b]');
161160
expect(nerdamer('solve(abs(a-b)=5, a)').toString()).toEqual('[-5+b,-(-5-b)]');
162161
// issue #43

0 commit comments

Comments
 (0)