Skip to content

Commit

Permalink
abstract field operations
Browse files Browse the repository at this point in the history
  • Loading branch information
fibo committed Oct 23, 2012
1 parent 9212dc9 commit cb73a5a
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 186 deletions.
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -22,7 +22,17 @@ My goal is to provide users with the feature of creating their own algebra field
Suppose for example the set of strings with the concatenation operator,
it could be extended to a group and maybe to a field and build "matrices of strings".

# Testing
# Development

## Branches

The git repository has the following remote branches:

* real
* complex
* quaternion

## Testing

Install mocha globally

Expand Down
3 changes: 0 additions & 3 deletions index.js
@@ -1,12 +1,9 @@

exports.Field = require('./lib/Field.js');
exports.FieldElement = require('./lib/FieldElement.js');
exports.Matrix = require('./lib/Matrix.js');
exports.SquareMatrix = require('./lib/SquareMatrix.js');
exports.GeneralLinearGroup = require('./lib/GeneralLinearGroup.js');
exports.Group = require('./lib/Group.js');
exports.GroupElement = require('./lib/GroupElement.js');
exports.RingElement = require('./lib/RingElement.js');
exports.Vector = require('./lib/Vector.js');
exports.VectorSpace = require('./lib/VectorSpace.js');

Expand Down
22 changes: 19 additions & 3 deletions lib/Field.js
Expand Up @@ -9,16 +9,32 @@ function Field(arg) {

util.inherits(Field, Group);

Field.prototype.inv = function(element) {
try {
var element = this.coerceToElement(element);
return element.clone().inv();
}
catch (err) {}
}

Field.prototype.mul = function(element1, element2) {
return element1.clone().mul(element2);
try {
var element1 = this.coerceToElement(element1);
return element1.clone().mul(element2);
}
catch (err) {}
}

Field.prototype.div = function(element1, element2) {
return element1.clone().div(element2);
try {
var element1 = this.coerceToElement(element1);
return element1.clone().div(element2);
}
catch (err) {}
}

Field.prototype.getOne = function() {
// TODO throw Error
// TODO throw Error (unimplemented abstract function
}

module.exports = Field;
Expand Down
15 changes: 0 additions & 15 deletions lib/FieldElement.js

This file was deleted.

32 changes: 27 additions & 5 deletions lib/Group.js
Expand Up @@ -3,24 +3,46 @@ function Group(arg) {
var self = this;
}

Group.prototype.coerceToElement = function(element) {
// TODO deve essere tipo unimplemented abstract method
// fai una classe per tutti in modo tale da lanciare sempre lo stesso errore.
throw new Error();
}

Group.prototype.neg = function(element) {
return element.clone().neg();
try {
var element = this.coerceToElement(element);
return element.clone().neg();
}
catch (err) {}
}

Group.prototype.eq = function(element1, element2) {
return element1.eq(element2);
try {
var element1 = this.coerceToElement(element1);
return element1.eq(element2);
}
catch (err) {}
}

Group.prototype.add = function(element1, element2) {
return element1.clone().add(element2);
try {
var element1 = this.coerceToElement(element1);
return element1.clone().add(element2);
}
catch (err) {}
}

Group.prototype.sub = function(element1, element2) {
return element1.clone().sub(element2);
try {
var element1 = this.coerceToElement(element1);
return element1.clone().sub(element2);
}
catch (err) {}
}

Group.prototype.getZero = function() {
// TODO throw Error unhimplemented abstract function
// TODO throw Error unimplemented abstract function
}

module.exports = Group;
Expand Down
20 changes: 0 additions & 20 deletions lib/GroupElement.js

This file was deleted.

26 changes: 15 additions & 11 deletions lib/Real/Element.js
Expand Up @@ -17,12 +17,6 @@ var RealElement = function(arg) {
}
}

self.neg = function () {
_num = 0 - _num;

return self;
}

self.eq = function (x) {
var num = coerce(x);

Expand All @@ -34,6 +28,12 @@ var RealElement = function(arg) {
}
}

self.neg = function () {
_num = 0 - _num;

return self;
}

self.add = function (x) {
var num = coerce(x);

Expand All @@ -50,6 +50,12 @@ var RealElement = function(arg) {
return self;
}

self.inv = function () {
_num = 1 / _num;

return self;
}

self.mul = function (x) {
var num = coerce(x);

Expand All @@ -67,11 +73,9 @@ var RealElement = function(arg) {
}
}

RealElement.prototype = {
clone: function () {
return new RealElement(this.num());
}
};
RealElement.prototype.clone = function () {
return new RealElement(this.num());
}

module.exports = RealElement;

16 changes: 14 additions & 2 deletions lib/Real/Field.js
Expand Up @@ -10,9 +10,21 @@ var RealField = function() {

util.inherits(RealField, Field);

RealField.prototype.getZero = function () { return new Real(0); };
RealField.prototype.coerceToElement = function (arg) {
// TODO sistema bene, mancano tutte le casistiche, i test ecc
// poi considera che voglio fare i numei trascendenti, le radici dei polinomi, ecc
// gli potrei passare dei numeri complessi, ecc
if( typeof arg == 'number' ) {
return new Real(arg);
}
else {
return arg;
}
}

RealField.prototype.getZero = function () { return new Real(0); }

RealField.prototype.getOne = function () { return new Real(1); };
RealField.prototype.getOne = function () { return new Real(1); }

module.exports = RealField;

17 changes: 0 additions & 17 deletions lib/RingElement.js

This file was deleted.

28 changes: 0 additions & 28 deletions test/FieldElement.js

This file was deleted.

42 changes: 0 additions & 42 deletions test/GroupElement.js

This file was deleted.

0 comments on commit cb73a5a

Please sign in to comment.