Skip to content

Commit

Permalink
Merge pull request #102 from zvxryb/simplify-common-exponent
Browse files Browse the repository at this point in the history
Simplify common exponent
  • Loading branch information
MatthewJA committed May 19, 2015
2 parents 065bb27 + c4049cc commit 251d3c6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion coffeequate/src/operators/Mul.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,27 @@ define [
if constantterm?.evaluate?() == 0
return new terminals.Constant("0")

newLikeTerms = []
for term0 in liketerms
[base0, power0] = term0

found = false
unless power0.evaluate?() == 1
for term1 in newLikeTerms
[base1, power1] = term1

if power1.equals?(power0, equivalencies)
base1.push(base0)
found = true
break

newLikeTerms.push([[base0], power0]) unless found
liketerms = ([
(if base.length == 1 then base[0] else new Mul(base...))
.expandAndSimplify(),
power
] for [base, power] in newLikeTerms)

newMul = null
for liketerm in liketerms
if liketerm[1].evaluate?() != 1
Expand Down Expand Up @@ -651,4 +672,4 @@ define [
return false
return true

return Mul
return Mul

0 comments on commit 251d3c6

Please sign in to comment.