Skip to content

Commit

Permalink
Let simplify handle a/(b/c) (#1734)
Browse files Browse the repository at this point in the history
Co-authored-by: Jos de Jong <[email protected]>
  • Loading branch information
dbramwell and josdejong authored Feb 4, 2020
1 parent 1d5ad22 commit 88733f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/function/algebra/simplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ export const createSimplify = /* #__PURE__ */ factory(name, dependencies, (
// { l: '(n1/n2)/n3', r: 'n1/(n2*n3)' },
// { l: '(n*n1)/(n*n2)', r: 'n1/n2' },

{ l: '1*n', r: 'n' } // this pattern can be produced by simplifyConstant
{ l: '1*n', r: 'n' }, // this pattern can be produced by simplifyConstant

{ l: 'n1/(n2/n3)', r: '(n1*n3)/n2' }

]

Expand Down
7 changes: 7 additions & 0 deletions test/unit-tests/function/algebra/simplify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ describe('simplify', function () {
simplifyAndCompare('myMultiArg(x, y, z, w)', 'myMultiArg(x, y, z, w)')
})

it('should simplify a/(b/c)', function () {
simplifyAndCompare('x/(x/y)', 'y')
simplifyAndCompare('x/(y/z)', 'x * z/y')
simplifyAndCompare('(x + 1)/((x + 1)/(z + 3))', 'z + 3')
simplifyAndCompare('(x + 1)/((y + 2)/(z + 3))', '(x + 1) * (z + 3)/(y + 2)')
})

it('should support custom rules', function () {
const node = math.simplify('y+x', [{ l: 'n1-n2', r: '-n2+n1' }], { x: 5 })
assert.strictEqual(node.toString(), 'y + 5')
Expand Down

0 comments on commit 88733f7

Please sign in to comment.