Repository: josdejong/mathjs
Pull request #778 (2017-01-20 22:54:59)

Add Support for Complex Numbers in Kronecker Product Function
Just changing from:
```javascript
y * x
```
to 
```javascript
math.multiply(y,x)
```

So Complex Numbers are supported.

Also added a unit test, so it all works.
Any feedback or things to change just say! 😄 


Patch:
diff --git a/.travis.yml b/.travis.yml
index a93f6fc0c..272aee154 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,4 +4,3 @@ node_js:
   - 0.12
   - 4
   - 6
-  - 7
diff --git a/HISTORY.md b/HISTORY.md
index 1cbe45db4..460150ea3 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,13 +1,6 @@
 # History
 
 
-## not yet released, version 3.9.0
-
-- Implemented Kronecker Product, function `kron`. Thanks @adamisntdead.
-- Fixed #765: `FunctionAssignmentNode.toString()` returning a string
-  incompatible with the function assignment syntax.
-
-
 ## 2016-12-15, version 3.8.1
 
 - Implemented function `mad` (median absolute deviation). Thanks @ruhleder.
diff --git a/lib/expression/node/FunctionAssignmentNode.js b/lib/expression/node/FunctionAssignmentNode.js
index aa68b9e36..2fe3f20ed 100644
--- a/lib/expression/node/FunctionAssignmentNode.js
+++ b/lib/expression/node/FunctionAssignmentNode.js
@@ -139,7 +139,8 @@ function factory (type, config, load, typed) {
     if (needParenthesis(this, parenthesis)) {
       expr = '(' + expr + ')';
     }
-    return this.name + '(' + this.params.join(', ') + ') = ' + expr;
+    return 'function ' + this.name +
+        '(' + this.params.join(', ') + ') = ' + expr;
   };
 
   /**
diff --git a/lib/function/matrix/kron.js b/lib/function/matrix/kron.js
index 608d0269e..a2b06f31d 100644
--- a/lib/function/matrix/kron.js
+++ b/lib/function/matrix/kron.js
@@ -4,6 +4,7 @@ var size = require('../../utils/array').size;
 
 function factory(type, config, load, typed) {
   var matrix = load(require('../../type/matrix/function/matrix'));
+  var multiplyScalar = load(require('../arithmetic/multiplyScalar'))
     /**
      * Calculates the kronecker product of 2 matrices / vectors.
      *
@@ -73,7 +74,7 @@ function factory(type, config, load, typed) {
             return b.map(function(b) {
                 return a.map(function(y) {
                     return b.map(function(x) {
-                        return r.push(y * x);
+                        return r.push(multiplyScalar(y, x));
                     });
                 }, t.push(r = []));
             });
diff --git a/package.json b/package.json
index a5c0dca97..f51d4b7f6 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,6 @@
   "description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.",
   "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
   "contributors": [
-    "Adam Kelly (https://github.com/adamisntdead)",
     "Andy Pan (https://github.com/andy0130tw)",
     "Bart Kiers (https://github.com/bkiers)",
     "Brett Jurgens (https://github.com/brettjurgens)",


Test patch:
diff --git a/test/expression/node/FunctionAssignmentNode.test.js b/test/expression/node/FunctionAssignmentNode.test.js
index dac19fa23..be0860b8f 100644
--- a/test/expression/node/FunctionAssignmentNode.test.js
+++ b/test/expression/node/FunctionAssignmentNode.test.js
@@ -284,7 +284,7 @@ describe('FunctionAssignmentNode', function() {
 
   it ('should respect the \'all\' parenthesis option', function () {
     var expr = math.parse('f(x)=x+1');
-    assert.equal(expr.toString({parenthesis: 'all'}), 'f(x) = (x + 1)');
+    assert.equal(expr.toString({parenthesis: 'all'}), 'function f(x) = (x + 1)');
     assert.equal(expr.toTex({parenthesis: 'all'}), '\\mathrm{f}\\left(x\\right):=\\left( x+1\\right)');
   });
 
@@ -294,7 +294,7 @@ describe('FunctionAssignmentNode', function() {
     var o = new OperatorNode('+', 'add', [a, x]);
     var n = new FunctionAssignmentNode('f', ['x'], o);
 
-    assert.equal(n.toString(), 'f(x) = 2 + x');
+    assert.equal(n.toString(), 'function f(x) = 2 + x');
   });
 
   it ('should stringify a FunctionAssignmentNode conataining an AssignmentNode', function () {
@@ -303,7 +303,7 @@ describe('FunctionAssignmentNode', function() {
     var n1 = new AssignmentNode(new SymbolNode('a'), a);
     var n = new FunctionAssignmentNode('f', ['x'], n1);
 
-    assert.equal(n.toString(), 'f(x) = (a = 2)');
+    assert.equal(n.toString(), 'function f(x) = (a = 2)');
   });
 
   it ('should stringify a FunctionAssignmentNode with custom toString', function () {
diff --git a/test/expression/parse.test.js b/test/expression/parse.test.js
index 5995ad5de..c13691a4a 100644
--- a/test/expression/parse.test.js
+++ b/test/expression/parse.test.js
@@ -786,17 +786,6 @@ describe('parse', function() {
       assert.deepEqual(parseAndEval('partialAdd(2)(3)', scope), 5);
     });
 
-    it('should invoke a function which is a property of a function', function () {
-      function f () {
-        return '42'
-      }
-      f.foo = function () {
-        return 'bar'
-      }
-
-      assert.deepEqual(parseAndEval('f.foo()', {f: f}), 'bar');
-    });
-
     it('should invoke a function on an object with the right context', function () {
       approx.equal(parseAndEval('(2.54 cm).toNumeric("inch")'), 1);
       assert.deepEqual(parseAndEval('bignumber(2).plus(3)'), math.bignumber(5));
diff --git a/test/function/matrix/kron.test.js b/test/function/matrix/kron.test.js
index ac9ca021f..d090f1a3e 100644
--- a/test/function/matrix/kron.test.js
+++ b/test/function/matrix/kron.test.js
@@ -38,6 +38,23 @@ describe('kron', function() {
     assert.deepEqual(math.kron([1,2,6,8], [12,1,2,3]), [[12,1,2,3,24,2,4,6,72,6,12,18,96,8,16,24]]);
   });
 
+  it('should support complex numbers', function() {
+    assert.deepEqual(math.kron([
+      [1,math.complex(0,1)],
+      [math.complex(0,1),2]
+    ],
+    [
+      [2,2],
+      [2,2]
+    ]),
+    [
+      [2,2,math.complex(0,2),math.complex(0,2)],
+      [2,2,math.complex(0,2),math.complex(0,2)],
+      [math.complex(0,2),math.complex(0,2),4,4],
+      [math.complex(0,2),math.complex(0,2),4,4]
+    ]);
+  });
+
   it('should throw an error for greater then 2 dimensions', function() {
     assert.throws(function () {
       math.kron([[[1, 1], [1, 1]], [[1, 1], [1, 1]]], [[[1, 2, 3], [4, 5, 6]], [[6, 7, 8], [9, 10, 11]]]);