Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Minor bug fixes #415

Merged
merged 4 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 89 additions & 10 deletions Algebra.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ if((typeof module) !== 'undefined') {
isInt = core.Utils.isInt,
Symbol = core.Symbol,
CONST_HASH = core.Settings.CONST_HASH,
math = core.Utils.importFunctions();

math = core.Utils.importFunctions(),
evaluate = core.Utils.evaluate;
//*************** CLASSES ***************//
/**
* Converts a symbol into an equivalent polynomial arrays of
Expand Down Expand Up @@ -2114,7 +2114,7 @@ if((typeof module) !== 'undefined') {
factors.pFactor = symbol.power.toString();
symbol.toLinear();
}

var vars = variables(symbol),
multiVar = vars.length > 1;

Expand Down Expand Up @@ -2148,7 +2148,6 @@ if((typeof module) !== 'undefined') {

factors.add(_.pow(symbol, _.parse(p)));
//last minute clean up
factors.clean();
return factors.toSymbol();
}

Expand Down Expand Up @@ -2477,6 +2476,7 @@ if((typeof module) !== 'undefined') {
l = vars.length, n = symbols.length;
//take all the variables in the symbol and organize by variable name
//e.g. a^2+a^2+b*a -> {a: {a^3, a^2, b*a}, b: {b*a}}

for(var i=0; i<l; i++) {
var v = vars[i];
sorted[v] = new Symbol(0);
Expand Down Expand Up @@ -2512,17 +2512,23 @@ if((typeof module) !== 'undefined') {
symbol = d[1];
//we don't want to just flip the sign. If the remainder is -1 then we accomplished nothing
//and we just return the symbol;
//If r equals zero then there's nothing left to do so we're done
if(r.equals(-1))
return symbol;

var factor = divided[0];
if(symbol.equals(factor)) {
var rem = __.Factor.reduce(factor, factors);

if(!symbol.equals(rem))
return __.Factor.mfactor(rem, factors);
}
else
else {
factors.add(factor);
//if the remainder of the symbol is zero then we're done. TODO: Rethink this logic a bit.
if(symbol.equals(0))
return r;
}

if(r.isConstant('all')) {
factors.add(r);
Expand All @@ -2532,6 +2538,7 @@ if((typeof module) !== 'undefined') {
return __.Factor.mfactor(r, factors);
}
}

}

//difference of squares factorization
Expand Down Expand Up @@ -3345,6 +3352,75 @@ if((typeof module) !== 'undefined') {
f: _.add(_.pow(sym.clone(), new Symbol(2)), d.clone())
};
},
trigSimp: function(symbol, map) {
symbol = symbol.clone();
map = map || {};
//create the map
symbol.each(function(x) {
if(x.group === FN) {
var key = x.args.toString();
var entry = map[key];
entry ? entry.push(x) : map[key] = [x];
}
}, true);

//1. try simplify cos(x)^2+sin(x)^2

for(var x in map) {
var sin, cos;
map[x].map(function(s, i) {
//fish out sin(x)^2 and cos(x)^2
if(s.power.equals(2) && !s.multiplier.isNegative()) {
if(s.fname === 'cos')
cos = s;
else if(s.fname === 'sin')
sin = s;
}
});
//if we have sin and cos then we can simplify
if(sin && cos) {
//add them together and divide by two since each contributes half
var m = cos.multiplier.add(sin.multiplier);
//get the remainder which may be there if they're not equal and divide it back to get wholes
var r = m.mod(new core.Frac(m.greaterThan(new core.Frac(2)) ? 2 : 1));
//get the whole
var w = m.subtract(r).divide(new core.Frac(2));
//r belongs to the greater of the two
if(cos.multiplier.greaterThan(sin.multiplier)) {
sin.power = new core.Frac(0);
sin.multiplier = w;
cos.multiplier = r;
}
else if(sin.multiplier.greaterThan(cos.multiplier)) {
cos.power = new core.Frac(0);
cos.multiplier = w;
sin.multiplier = r;
}
else {
//doesn't matter which but we'll throw the bone to cos
cos.multiplier = w;
cos.power = new core.Frac(0);
sin.multiplier = new core.Frac(0);
}
}
}


return symbol;
},
simplify: function(symbol) {
var simplified;
symbol = symbol.clone(); //make a copy
//first go for the "cheapest" simplification which may eliminate
//your problems right away. factor -> evaluate. Remember
//that there's no need to expand since factor already does that
simplified = evaluate(__.Factor.factor(symbol));
//If the simplfied is a sum then we can make a few more simplifications
//1. Try cos(x)^2+sin(x)^2
simplified = __.trigSimp(evaluate(simplified));

return evaluate(simplified);
},
Classes: {
Polynomial: Polynomial,
Factors: Factors,
Expand Down Expand Up @@ -3380,6 +3456,12 @@ if((typeof module) !== 'undefined') {
numargs: 1,
build: function() { return __.Factor.factor; }
},
{
name: 'simplify',
visible: true,
numargs: 1,
build: function() { return __.simplify; }
},
{
name: 'gcd',
visible: true,
Expand Down Expand Up @@ -3460,7 +3542,4 @@ if((typeof module) !== 'undefined') {
}
]);
nerdamer.api();
})();



})();
92 changes: 46 additions & 46 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at martin.r.donk@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at martin.r.donk@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
32 changes: 16 additions & 16 deletions all.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* Author : Martin Donk
* Website : http://www.nerdamer.com
* Email : martin.r.donk@gmail.com
* Source : https://github.com/jiggzson/nerdamer
* Can be used to load all add-ons with one require
*/

var nerdamer = require('./nerdamer.core.js');
require('./Algebra.js');
require('./Calculus.js');
require('./Solve.js');
require('./Extra.js');

//export nerdamer
module.exports = nerdamer;
/*
* Author : Martin Donk
* Website : http://www.nerdamer.com
* Email : martin.r.donk@gmail.com
* Source : https://github.com/jiggzson/nerdamer
* Can be used to load all add-ons with one require
*/
var nerdamer = require('./nerdamer.core.js');
require('./Algebra.js');
require('./Calculus.js');
require('./Solve.js');
require('./Extra.js');
//export nerdamer
module.exports = nerdamer;
Loading