Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
04bb0ee
added rules for patterns w/o constraints
aliang8 Apr 30, 2017
f37f48c
added rules test, some errors
aliang8 Apr 30, 2017
5745443
rm file
aliang8 Apr 30, 2017
b462d8a
rm file
aliang8 Apr 30, 2017
3ca4c7f
format
aliang8 Apr 30, 2017
adcbc10
fixed tabing, remove comments, added rules, need to check variables
aliang8 Apr 30, 2017
3cb89d4
added extra test cases, not done
aliang8 Apr 30, 2017
75ab164
not sure what's up with these tests
aliang8 Apr 30, 2017
3beef3e
finished adding cases, still some errors
aliang8 May 1, 2017
c35f087
fixed merge errors
aliang8 May 2, 2017
20bc705
one last test
aliang8 May 2, 2017
336c5c3
fixed tests and yarn
aliang8 May 2, 2017
3dbb8cd
done
aliang8 May 2, 2017
2335275
removed lint, added TODO
aliang8 May 2, 2017
d91eb26
merging
aliang8 May 5, 2017
7fdbd7e
rebasing
aliang8 May 7, 2017
e8e86a1
merge
aliang8 May 9, 2017
7a3e271
merged
aliang8 May 10, 2017
fbd4938
merge
aliang8 May 14, 2017
3ea7468
merge
aliang8 May 15, 2017
96d2bb9
merged
aliang8 May 18, 2017
caa0ae0
addingPolynomials
aliang8 May 20, 2017
14a091f
fixed comments
aliang8 May 20, 2017
aa21a98
added more tests, one of them fails
aliang8 May 20, 2017
08b3ca1
remove . file
aliang8 May 20, 2017
03ffdf1
merge
aliang8 May 20, 2017
648f0f7
remove alphabetize
aliang8 May 20, 2017
632b525
fixed comments
aliang8 May 20, 2017
7403644
removed comment
aliang8 May 20, 2017
2cb2f76
starting to work on LCM
aliang8 May 20, 2017
fa1c35c
fractional polynomial and rearrange coeffs
aliang8 May 21, 2017
85f51d0
remove . file
aliang8 May 21, 2017
9f81447
fixed failing case
aliang8 May 21, 2017
ac44821
multiplyingPolynomials
aliang8 May 21, 2017
56d4872
rules.js
aliang8 May 21, 2017
e02838b
multiplyingPolynomials
aliang8 May 21, 2017
06914d0
merge
aliang8 May 21, 2017
8233be5
nthroot
aliang8 May 21, 2017
58d9587
nthRoot
aliang8 May 21, 2017
9781f2d
fixed comments
aliang8 May 21, 2017
51885d6
back to master
aliang8 May 22, 2017
df804c1
working on nthRoot
aliang8 May 22, 2017
394be0d
merge error
aliang8 May 22, 2017
65fb550
fixing merge request
aliang8 May 22, 2017
b0bcc43
added root functions
aliang8 May 23, 2017
97e77f0
almost done with nthRoots
aliang8 May 23, 2017
77ca585
almost done with nthRoot functions
aliang8 May 23, 2017
b72b9c5
small fix
aliang8 May 23, 2017
bbe02be
remove old changes
aliang8 May 23, 2017
cc56267
remove old changes
aliang8 May 23, 2017
99deef2
Merge branch 'master' into master
aliang8 May 25, 2017
ff2b3cb
Merge branch 'master' into nthRoot
aliang8 May 26, 2017
93377b6
factoring rules
aliang8 May 27, 2017
7a527eb
working on factoring
aliang8 May 28, 2017
636d6fe
merge
aliang8 May 30, 2017
7209708
added factoring support
aliang8 May 31, 2017
134b8d6
merge
aliang8 May 31, 2017
b79698f
working on factor perfect squares
aliang8 May 31, 2017
edbd6fd
working on last case
aliang8 May 31, 2017
b82efb4
complete factor perfect square trinomial
aliang8 May 31, 2017
cb5f6fe
factoring support for trinomials
aliang8 May 31, 2017
42f195e
finish factoring, refactoring code
aliang8 Jun 1, 2017
4d31fac
finished factoring trinomials
aliang8 Jun 2, 2017
afcd5ec
small fix
aliang8 Jun 2, 2017
bfdfde6
Delete .#random.test.js
aliang8 Jun 2, 2017
fd811ac
merge w/master
aliang8 Jun 5, 2017
a3715ff
merge
aliang8 Jun 5, 2017
3d62f6a
refactor factoring product sum
aliang8 Jun 7, 2017
6ed7f8c
merge
aliang8 Jun 7, 2017
1d77654
merge
aliang8 Jun 7, 2017
cd7cbb3
remove package-lock
aliang8 Jun 7, 2017
a6f3785
fixed factoring perfect squares trinomials
aliang8 Jun 7, 2017
8cf3d26
merge
aliang8 Jun 11, 2017
80bf390
change yarn.lock
aliang8 Jun 11, 2017
6a29516
remove dot file
aliang8 Jun 11, 2017
a9f5f86
fixing changes
aliang8 Jun 13, 2017
e81b234
separate files
aliang8 Jun 13, 2017
ab710f8
rm package-lock
aliang8 Jun 13, 2017
bc60b87
added explaination of factoring rule
aliang8 Jun 13, 2017
ddd2192
starting work on rearrange_terms
aliang8 Jun 13, 2017
06ab528
refactored code and test
aliang8 Jun 14, 2017
4fb7bd4
added rerranging term rule
aliang8 Jun 14, 2017
0dd219b
updated yarn
aliang8 Jun 14, 2017
2558b48
revert yarn.lock
aliang8 Jun 14, 2017
1012628
change index.js
aliang8 Jun 15, 2017
d0b5364
merge with master
aliang8 Jun 15, 2017
984557f
revert yarn.lock to masters
aliang8 Jun 15, 2017
4b45333
fixed ternaries, added TODO
aliang8 Jun 19, 2017
b75e4b4
rules-list
aliang8 Jun 19, 2017
8971f88
merge
aliang8 Jun 19, 2017
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
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {defineRule, definePatternRule, canApplyRule, applyRule, rewriteNode} from './lib/rule'
import {flattenOperands} from './lib/utils'
import * as rules from './lib/rule-list.js'
import * as simple_rules from './lib/simple-rules.js'
import * as factor_rules from './lib/factor-rules.js'

export {
applyRule,
Expand All @@ -9,5 +10,6 @@ export {
defineRule,
rewriteNode,
flattenOperands,
rules,
simple_rules,
factor_rules,
}
81 changes: 81 additions & 0 deletions lib/__test__/factor_rules.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import assert from 'assert'
import {parse, print, evaluate} from 'math-parser'

import {applyRule, canApplyRule} from '../rule'
import * as factor_rules from '../factor-rules'

const applyRuleString = (rule, input) => print(applyRule(rule, parse(input)))
const canApplyRuleString = (rule, input) => canApplyRule(rule, parse(input))

const suite = (title, rule, tests) => describe(title, () => {
tests.forEach(t => {
it(`${t[0]} => ${t[1]}`, () => {
assert.equal(print(applyRule(rule, parse(t[0]))), t[1])
})
})
})

suite.only = (title, rule, tests) => describe.only(title, () => {
tests.forEach(t => {
it(`${t[0]} => ${t[1]}`, () => {
assert.equal(t[1], print(applyRule(rule, parse(t[0]))))
})
})
})

suite('factor symbol', factor_rules.FACTOR_SYMBOL, [
//['x^2 + x^5 + x^16', ''],
//['x^2 - x^5 - x^16', ''],
])

suite('factor difference of squares helper', factor_rules.FACTOR_DIFFERENCE_OF_SQUARES_HELPER, [
['4(xy)^2 - 16x^2', '(2 xy^1)^2 - (4 x^1)^2'],
['1 x^2 - 1 y^2', '(1 x^1)^2 - (1 y^1)^2']
])

suite('factor difference of squares', factor_rules.FACTOR_DIFFERENCE_OF_SQUARES, [
['(2x)^2 - (3y)^2', '(2 x + 3 y) (2 x - 3 y)'],
['(1 x^1)^2 - (1 y^1)^2', '(1 x^1 + 1 y^1) (1 x^1 - 1 y^1)']
])

suite('factor perfect squares', factor_rules.FACTOR_PERFECT_SQUARE_TRINOMIALS, [
['4x^2 + 12x^1 + 9', '(2 x^1 + 3)^2'],
['4x^4 - 12x^2 + 9', '(2 x^2 - 3)^2'],
['4x^2 - 12x^1y^1 + 9y^2', '(2 x^1 - 3 y^1)^2'],
['1a^2 + 2a^1 b^1 + 1b^2', '(1 a^1 + 1 b^1)^2'],
['1x^2 + 10x^1 + 25', '(1 x^1 + 5)^2'],
// TODO: handle this case
//['1x^2 + bx + (b/2)^4', '(x + b/2)^2']
])

suite('rearrange terms', factor_rules.REARRANGE_TERMS, [
['2 + 3x', '3 x + 2'],
['4 + 3x^2 + 2x', '3 x^2 + 2 x + 4'],
['3x - 2x^4 + 2x', '-2 x^4 + 3 x + 2 x'],
['9 + 12x^2 + 4x^4', '4 x^4 + 12 x^2 + 9']
])

suite('factor sum product rule', factor_rules.FACTOR_SUM_PRODUCT_RULE, [
// 1
['4x^4 + 12x^2 + 9','(2 x^2 + 3) (2 x^2 + 3)'],
// 2
['6x^4 + 13x^2 + 6', '(2 x^2 + 3) (3 x^2 + 2)'],
// 3
['2x^4 - 7x^2 + 6', '(1 x^2 - 2) (2 x^2 - 3)'],
// 4
['6x^2 - 13x^1 + 6', '(2 x^1 - 3) (3 x^1 - 2)'],
// 5
['2x^4 - 1x^2 - 6', '(1 x^2 - 2) (2 x^2 + 3)'],
// 6
['6x^4 + 7x^2 - 3', '(2 x^2 + 3) (3 x^2 - 1)'],
// 7
['2x^4 + 1x^2 - 6', '(1 x^2 + 2) (2 x^2 - 3)'],
// 8
['6x^4 - 7x^2 - 3', '(2 x^2 - 3) (3 x^2 + 1)'],
// TODO: handle this case
//['4x^2y^2 + 12a^2b^2x^1y^1 + 9x^b^4', ''],
['4a^2b^2 + 12a^1b^1x^1y^2 + 9x^2y^4', '(2 a^1 b^1 + 3 x^1 y^2) (2 a^1 b^1 + 3 x^1 y^2)'],
['12x^2 + 17 x^1 y^1 + 6y^2', '(3 x^1 + 2 y^1) (4 x^1 + 3 y^1)'],
['12x^2 + 17x^1 + 6', '(3 x^1 + 2) (4 x^1 + 3)'],
['4x^2 + 12x^1 + 9', '(2 x^1 + 3) (2 x^1 + 3)'],
])
6 changes: 3 additions & 3 deletions lib/__test__/rule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {build, query} from 'math-nodes'

import {defineRule, definePatternRule, canApplyRule, applyRule, rewriteNode} from '../rule'
import {populatePattern, patternToMatchFn} from '../pattern'
import * as rules from '../rule-list'
import * as simple_rules from '../simple-rules'

// returns the rewritten string
const rewriteString = (matchPattern, rewritePattern, input) => {
Expand Down Expand Up @@ -73,13 +73,13 @@ describe('rule functions', () => {
describe.only('rewriteNode', () => {
it('should rewrite nodes that that the rule matches', () => {
const ast = parse('2 * (x + 0)')
const result = rewriteNode(rules.REMOVE_ADDING_ZERO, ast.args[1])
const result = rewriteNode(simple_rules.REMOVE_ADDING_ZERO, ast.args[1])
assert.deepEqual(result, build.identifier('x'))
})

it('should return null when the rule does not match', () => {
const ast = parse('2 * (x + 0)')
const result = rewriteNode(rules.REMOVE_ADDING_ZERO, ast.args[0])
const result = rewriteNode(simple_rules.REMOVE_ADDING_ZERO, ast.args[0])
assert.equal(result, null)
})
})
Expand Down
Loading