Skip to content

Commit 5fb1b7b

Browse files
committed
Fix #635. Test added.
1 parent 597013b commit 5fb1b7b

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

Algebra.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -4178,7 +4178,7 @@ if((typeof module) !== 'undefined') {
41784178
var symbols = symbol.collectSymbols();
41794179
//assumption 1.
41804180
//since it's a composite, it has a length of at least 1
4181-
var retval, a, b, d1, d2, n1, n2, x, y, c, den, num;
4181+
var retval, a, b, d1, d2, n1, n2, s, x, y, c, den, num;
41824182
a = symbols.pop(); //grab the first symbol
41834183
//loop through each term and make denominator common
41844184
while(symbols.length) {
@@ -4190,11 +4190,11 @@ if((typeof module) !== 'undefined') {
41904190
c = _.multiply(d1.clone(), d2.clone());
41914191
x = _.multiply(n1, d2);
41924192
y = _.multiply(n2, d1);
4193-
a = _.divide(_.add(x, y), c);
4193+
s = _.add(x, y);
4194+
a = _.divide(s, c);
41944195
}
41954196
den = _.expand(a.getDenom());
41964197
num = _.expand(a.getNum());
4197-
41984198
//simplify imaginary
41994199
if(num.isImaginary() && den.isImaginary()) {
42004200
retval = __.Simplify.complexSimp(num, den);
@@ -4351,7 +4351,6 @@ if((typeof module) !== 'undefined') {
43514351
symbol = sym_array.pop();
43524352
//remove gcd from denominator
43534353
symbol = __.Simplify.fracSimp(symbol);
4354-
43554354
//nothing more to do
43564355
if(symbol.isConstant() || symbol.group === core.groups.S) {
43574356
sym_array.push(symbol);

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -4562,20 +4562,23 @@ var nerdamer = (function (imports) {
45624562
symbol = _.expand(symbol);
45634563

45644564
//if the symbol already is the denominator... DONE!!!
4565-
if(symbol.power.lessThan(0)) {
4565+
if(symbol.power.lessThan(0) || symbol.group === EX && symbol.power.multiplier.lessThan(0)) {
45664566
var d = _.parse(symbol.multiplier.den);
45674567
retval = symbol.toUnitMultiplier();
45684568
retval.power.negate();
45694569
retval = _.multiply(d, retval); //put back the coeff
45704570
}
45714571
else if(symbol.group === CB) {
45724572
retval = _.parse(symbol.multiplier.den);
4573-
for(var x in symbol.symbols)
4574-
if(symbol.symbols[x].power < 0)
4573+
for(var x in symbol.symbols) {
4574+
var s = symbol.symbols[x];
4575+
if(s.power < 0 || s.group === EX && s.power.multiplier.lessThan(0))
45754576
retval = _.multiply(retval, symbol.symbols[x].clone().invert());
4577+
}
45764578
}
4577-
else
4579+
else {
45784580
retval = _.parse(symbol.multiplier.den);
4581+
}
45794582
return retval;
45804583
},
45814584
getNum: function () {
@@ -4585,7 +4588,7 @@ var nerdamer = (function (imports) {
45854588
if(symbol.group === CB && symbol.power.lessThan(0))
45864589
symbol = _.expand(symbol);
45874590
//if the symbol already is the denominator... DONE!!!
4588-
if(symbol.power.greaterThan(0) && symbol.group !== CB) {
4591+
if(symbol.power.greaterThan(0) && symbol.group !== CB || symbol.group === EX && symbol.power.multiplier.greaterThan(0)) {
45894592
retval = _.multiply(_.parse(symbol.multiplier.num), symbol.toUnitMultiplier());
45904593
}
45914594
else if(symbol.group === CB) {
@@ -4596,6 +4599,9 @@ var nerdamer = (function (imports) {
45964599
}
45974600
});
45984601
}
4602+
// else if(symbol.group === EX && this.previousGroup === S) {
4603+
// retval = _.multiply(_.parse(symbol.multiplier.num), symbol.toUnitMultiplier());
4604+
// }
45994605
else {
46004606
retval = _.parse(symbol.multiplier.num);
46014607
}

spec/algebra.spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ describe('Algebra', function () {
802802
{
803803
given: 'simplify(a/b+b/a)',
804804
expected: '(a*b)^(-1)*(a^2+b^2)'
805+
},
806+
{
807+
given: 'simplify(((2*e^t)/(e^t))+(1/(e^t)))',
808+
expected: '(1+2*e^t)*e^(-t)'
805809
}
806810
];
807811

0 commit comments

Comments
 (0)