From 7113a122572809416d18e267115b655a6c49ae9d Mon Sep 17 00:00:00 2001 From: Nitin Date: Sun, 26 Feb 2017 00:40:12 +0530 Subject: [PATCH 01/14] readme changed --- README.md | 89 ++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 4e4af18c..7335388c 100644 --- a/README.md +++ b/README.md @@ -1,74 +1,61 @@ -## A step by step solver for math +# Mathsteps +[![Join the chat at https://gitter.im/mathsteps-chat/Lobby](https://badges.gitter.im/mathsteps-chat/Lobby.svg)](https://gitter.im/mathsteps-chat/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/socraticorg/mathsteps.svg?branch=master)](https://travis-ci.org/socraticorg/mathsteps) -[![Join the chat at https://gitter.im/mathsteps-chat/Lobby](https://badges.gitter.im/mathsteps-chat/Lobby.svg)](https://gitter.im/mathsteps-chat/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Build Status](https://travis-ci.org/socraticorg/mathsteps.svg?branch=master)](https://travis-ci.org/socraticorg/mathsteps) +Mathsteps is a step-by-step math solver. It helps in solving equations, simplifying an expression and factoring a polynomial. (more to come 😄) -https://www.youtube.com/watch?v=iCrargw1rrM +**Solve an equation** -## Requirements - -Mathsteps requires Node version > 6.0.0 - -## Usage +```javascript +const steps = mathsteps.solveEquation('2x + 3x = 35'); +``` -To install mathsteps using npm: +**See all the change types** +```javascript +const changes = mathsteps.ChangeTypes; +``` +Learn [how to use mathsteps](https://github.com/socraticorg/mathsteps/wiki/How-to-use-mathsteps) and [how the codebase works](https://github.com/socraticorg/mathsteps/wiki/Mathsteps-organization). - npm install mathsteps +## Examples +Here is an example to get you started. -```js +```javascript const mathsteps = require('mathsteps'); const steps = mathsteps.simplifyExpression('2x + 2x + x + x'); steps.forEach(step => { - console.log("before change: " + step.oldNode); // before change: 2 x + 2 x + x + x - console.log("change: " + step.changeType); // change: ADD_POLYNOMIAL_TERMS - console.log("after change: " + step.newNode); // after change: 6 x - console.log("# of substeps: " + step.substeps.length); // # of substeps: 3 + console.log("before change: " + step.oldNode); + console.log("change: " + step.changeType); + console.log("after change: " + step.newNode); + console.log("no of substeps: " + step.substeps.length); }); -``` - -To solve an equation: -```js -const steps = mathsteps.solveEquation('2x + 3x = 35'); -steps.forEach(step => { - console.log("before change: " + step.oldEquation.print()); // e.g. before change: 2x + 3x = 35 - console.log("change: " + step.changeType); // e.g. change: SIMPLIFY_LEFT_SIDE - console.log("after change: " + step.newEquation.print()); // e.g. after change: 5x = 35 - console.log("# of substeps: " + step.substeps.length); // e.g. # of substeps: 2 -}); +/* +before change: 2 x + 2 x + x + x +change: ADD_POLYNOMIAL_TERMS +after change: 6 x +no of substeps: 3 +*/ ``` +In this example we have an equation `2x + 2x + x + x` that is being simplified by the method `simplifyExpression`. It returns the output which tells about the equation before and after applying the change, what change was applied and the no of substeps. -To see all the change types: -```js -const changes = mathsteps.ChangeTypes; +## Installation +Mathsteps is available as the `mathsteps` package on [npm](https://www.npmjs.com/package/mathsteps). +``` +npm install mathsteps --save ``` - - ## Contributing +The main objective of the mathsteps is to continue to evolve and provide more operations and features. Read below to learn how can you contribute to the project. -Hi! If you're interested in working on this, that would be super awesome! -Learn more here: [CONTRIBUTING.md](CONTRIBUTING.md). - -## Build - -First clone the project from github: - - git clone https://github.com/socraticorg/mathsteps.git - cd mathsteps - -Install the project dependencies: - - npm install +**Contributing guide** +Read our [contributing guide](CONTRIBUTING.md) to suggest more features, report bugs or contribute code. ## Test +``` +npm test +``` -To execute tests for the library, install the project dependencies once: - - npm install - -Then, the tests can be executed: +## License +Apache-2.0 - npm test From f5ec0d63224beb0fbee86bbbb9b2b10a5c6b9561 Mon Sep 17 00:00:00 2001 From: Nitin Tulswani Date: Sun, 26 Feb 2017 00:44:05 +0530 Subject: [PATCH 02/14] breaks --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7335388c..d42d1dc5 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ npm install mathsteps --save The main objective of the mathsteps is to continue to evolve and provide more operations and features. Read below to learn how can you contribute to the project. **Contributing guide** + Read our [contributing guide](CONTRIBUTING.md) to suggest more features, report bugs or contribute code. ## Test From d9f4271be32d38952ec4f0227434951f742837d7 Mon Sep 17 00:00:00 2001 From: Nitin Date: Thu, 13 Apr 2017 22:33:52 +0530 Subject: [PATCH 03/14] flow --- .flowconfig | 9 +++++++++ README.md | 1 + lib/node/Creator.js | 22 +++++++++++++++------- lib/node/Type.js | 20 +++++++++++--------- package.json | 2 ++ 5 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 .flowconfig diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 00000000..f58eb0d3 --- /dev/null +++ b/.flowconfig @@ -0,0 +1,9 @@ +[ignore] +.*/test/.* +.*/scripts/.* + +[include] + +[libs] + +[options] diff --git a/README.md b/README.md index 7335388c..d42d1dc5 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ npm install mathsteps --save The main objective of the mathsteps is to continue to evolve and provide more operations and features. Read below to learn how can you contribute to the project. **Contributing guide** + Read our [contributing guide](CONTRIBUTING.md) to suggest more features, report bugs or contribute code. ## Test diff --git a/lib/node/Creator.js b/lib/node/Creator.js index 165a6863..86c76f93 100644 --- a/lib/node/Creator.js +++ b/lib/node/Creator.js @@ -1,14 +1,22 @@ +// @flow + /* Functions to generate any mathJS node supported by the stepper see http://mathjs.org/docs/expressions/expression_trees.html#nodes for more information on nodes in mathJS */ +type value = string | number; + +type baseNode = { + [property: string]: value +} + const math = require('mathjs'); const NodeType = require('./Type'); const NodeCreator = { - operator (op, args, implicit=false) { + operator (op: string, args: Array, implicit: boolean=false) { switch (op) { case '+': return new math.expression.node.OperatorNode('+', 'add', args); @@ -28,27 +36,27 @@ const NodeCreator = { // In almost all cases, use Negative.negate (with naive = true) to add a // unary minus to your node, rather than calling this constructor directly - unaryMinus (content) { + unaryMinus (content: Array) { return new math.expression.node.OperatorNode( '-', 'unaryMinus', [content]); }, - constant (val) { + constant (val: number) { return new math.expression.node.ConstantNode(val); }, - symbol (name) { + symbol (name: string) { return new math.expression.node.SymbolNode(name); }, - parenthesis (content) { + parenthesis (content: value) { return new math.expression.node.ParenthesisNode(content); }, // exponent might be null, which means there's no exponent node. // similarly, coefficient might be null, which means there's no coefficient // the symbol node can never be null. - polynomialTerm (symbol, exponent, coeff, explicitCoeff=false) { + polynomialTerm (symbol: baseNode, exponent: baseNode, coeff: Object, explicitCoeff: boolean=false) { let polyTerm = symbol; if (exponent) { polyTerm = this.operator('^', [polyTerm, exponent]); @@ -68,7 +76,7 @@ const NodeCreator = { }, // Given a root value and a radicand (what is under the radical) - nthRoot (radicandNode, rootNode) { + nthRoot (radicandNode: baseNode, rootNode: baseNode) { const symbol = NodeCreator.symbol('nthRoot'); return new math.expression.node.FunctionNode(symbol, [radicandNode, rootNode]); } diff --git a/lib/node/Type.js b/lib/node/Type.js index 97f7406e..4717c9a2 100644 --- a/lib/node/Type.js +++ b/lib/node/Type.js @@ -1,25 +1,27 @@ +// @flow + /* For determining the type of a mathJS node. */ const NodeType = {}; -NodeType.isOperator = function(node, operator=null) { +NodeType.isOperator = function(node: Object, operator: string | null) { return node.type === 'OperatorNode' && node.fn !== 'unaryMinus' && '*+-/^'.includes(node.op) && (operator ? node.op === operator : true); }; -NodeType.isParenthesis = function(node) { +NodeType.isParenthesis = function(node: Object) { return node.type === 'ParenthesisNode'; }; -NodeType.isUnaryMinus = function(node) { +NodeType.isUnaryMinus = function(node: Object) { return node.type === 'OperatorNode' && node.fn === 'unaryMinus'; }; -NodeType.isFunction = function(node, functionName=null) { +NodeType.isFunction = function(node: Object, functionName: string | null) { if (node.type !== 'FunctionNode') { return false; } @@ -29,7 +31,7 @@ NodeType.isFunction = function(node, functionName=null) { return true; }; -NodeType.isSymbol = function(node, allowUnaryMinus=true) { +NodeType.isSymbol = function(node: Object, allowUnaryMinus: boolean | true) { if (node.type === 'SymbolNode') { return true; } @@ -41,7 +43,7 @@ NodeType.isSymbol = function(node, allowUnaryMinus=true) { } }; -NodeType.isConstant = function(node, allowUnaryMinus=false) { +NodeType.isConstant = function(node: Object, allowUnaryMinus: boolean=false) { if (node.type === 'ConstantNode') { return true; } @@ -59,7 +61,7 @@ NodeType.isConstant = function(node, allowUnaryMinus=false) { } }; -NodeType.isConstantFraction = function(node, allowUnaryMinus=false) { +NodeType.isConstantFraction = function(node: Object, allowUnaryMinus:boolean=false) { if (NodeType.isOperator(node, '/')) { return node.args.every(n => NodeType.isConstant(n, allowUnaryMinus)); } @@ -68,7 +70,7 @@ NodeType.isConstantFraction = function(node, allowUnaryMinus=false) { } }; -NodeType.isConstantOrConstantFraction = function(node, allowUnaryMinus=false) { +NodeType.isConstantOrConstantFraction = function(node: Object, allowUnaryMinus:boolean=false) { if (NodeType.isConstant(node, allowUnaryMinus) || NodeType.isConstantFraction(node, allowUnaryMinus)) { return true; @@ -78,7 +80,7 @@ NodeType.isConstantOrConstantFraction = function(node, allowUnaryMinus=false) { } }; -NodeType.isIntegerFraction = function(node, allowUnaryMinus=false) { +NodeType.isIntegerFraction = function(node: Object, allowUnaryMinus:boolean=false) { if (!NodeType.isConstantFraction(node, allowUnaryMinus)) { return false; } diff --git a/package.json b/package.json index 4bd61c77..e84d71b5 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,12 @@ "eslint": "^3.10.2", "eslint-config-google": "^0.7.0", "eslint-plugin-sort-requires": "^2.1.0", + "flow-bin": "^0.43.1", "mocha": "2.4.5" }, "scripts": { "lint": "node_modules/.bin/eslint .", + "flow": "flow", "test": "node_modules/.bin/mocha --recursive", "setup-hooks": "ln -s ../../scripts/git-hooks/pre-commit.sh .git/hooks/pre-commit" }, From b417d6c222d251fb0fc8a46d4c09dffb557e7871 Mon Sep 17 00:00:00 2001 From: Nitin Date: Thu, 13 Apr 2017 22:38:03 +0530 Subject: [PATCH 04/14] flow --- lib/node/Creator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node/Creator.js b/lib/node/Creator.js index 86c76f93..c6878ccc 100644 --- a/lib/node/Creator.js +++ b/lib/node/Creator.js @@ -49,7 +49,7 @@ const NodeCreator = { return new math.expression.node.SymbolNode(name); }, - parenthesis (content: value) { + parenthesis (content: baseNode) { return new math.expression.node.ParenthesisNode(content); }, From 353c2526006be309ca35fbe25415ec06687382b9 Mon Sep 17 00:00:00 2001 From: Nitin Date: Thu, 13 Apr 2017 22:44:20 +0530 Subject: [PATCH 05/14] removed flow code from Type.js --- lib/node/Type.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/node/Type.js b/lib/node/Type.js index 4717c9a2..97f7406e 100644 --- a/lib/node/Type.js +++ b/lib/node/Type.js @@ -1,27 +1,25 @@ -// @flow - /* For determining the type of a mathJS node. */ const NodeType = {}; -NodeType.isOperator = function(node: Object, operator: string | null) { +NodeType.isOperator = function(node, operator=null) { return node.type === 'OperatorNode' && node.fn !== 'unaryMinus' && '*+-/^'.includes(node.op) && (operator ? node.op === operator : true); }; -NodeType.isParenthesis = function(node: Object) { +NodeType.isParenthesis = function(node) { return node.type === 'ParenthesisNode'; }; -NodeType.isUnaryMinus = function(node: Object) { +NodeType.isUnaryMinus = function(node) { return node.type === 'OperatorNode' && node.fn === 'unaryMinus'; }; -NodeType.isFunction = function(node: Object, functionName: string | null) { +NodeType.isFunction = function(node, functionName=null) { if (node.type !== 'FunctionNode') { return false; } @@ -31,7 +29,7 @@ NodeType.isFunction = function(node: Object, functionName: string | null) { return true; }; -NodeType.isSymbol = function(node: Object, allowUnaryMinus: boolean | true) { +NodeType.isSymbol = function(node, allowUnaryMinus=true) { if (node.type === 'SymbolNode') { return true; } @@ -43,7 +41,7 @@ NodeType.isSymbol = function(node: Object, allowUnaryMinus: boolean | true) { } }; -NodeType.isConstant = function(node: Object, allowUnaryMinus: boolean=false) { +NodeType.isConstant = function(node, allowUnaryMinus=false) { if (node.type === 'ConstantNode') { return true; } @@ -61,7 +59,7 @@ NodeType.isConstant = function(node: Object, allowUnaryMinus: boolean=false) { } }; -NodeType.isConstantFraction = function(node: Object, allowUnaryMinus:boolean=false) { +NodeType.isConstantFraction = function(node, allowUnaryMinus=false) { if (NodeType.isOperator(node, '/')) { return node.args.every(n => NodeType.isConstant(n, allowUnaryMinus)); } @@ -70,7 +68,7 @@ NodeType.isConstantFraction = function(node: Object, allowUnaryMinus:boolean=fal } }; -NodeType.isConstantOrConstantFraction = function(node: Object, allowUnaryMinus:boolean=false) { +NodeType.isConstantOrConstantFraction = function(node, allowUnaryMinus=false) { if (NodeType.isConstant(node, allowUnaryMinus) || NodeType.isConstantFraction(node, allowUnaryMinus)) { return true; @@ -80,7 +78,7 @@ NodeType.isConstantOrConstantFraction = function(node: Object, allowUnaryMinus:b } }; -NodeType.isIntegerFraction = function(node: Object, allowUnaryMinus:boolean=false) { +NodeType.isIntegerFraction = function(node, allowUnaryMinus=false) { if (!NodeType.isConstantFraction(node, allowUnaryMinus)) { return false; } From c969fe981d623dcdb73565c57b0c57e6152747c5 Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:01:36 +0530 Subject: [PATCH 06/14] removed babili preset --- .babelrc | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..8a87b4dc --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} \ No newline at end of file From 2dc2ba4adda20295ea5902fd260394770d0b41c1 Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:01:55 +0530 Subject: [PATCH 07/14] added build script --- package.json | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e84d71b5..511981d4 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,35 @@ { "name": "mathsteps", - "version": "0.1.5", + "version": "0.1.6", "description": "Step by step math solutions", - "main": "index.js", + "main": "./build/mathsteps.min.js", "dependencies": { "mathjs": "3.8.0" }, "engines": { "node": ">=6.0.0" }, + "files": [ + "build" + ], "devDependencies": { + "babel-core": "^6.25.0", + "babel-loader": "^7.1.1", + "babel-preset-es2015": "^6.24.1", + "babili-webpack-plugin": "^0.1.2", + "clean-webpack-plugin": "^0.1.16", "eslint": "^3.10.2", "eslint-config-google": "^0.7.0", "eslint-plugin-sort-requires": "^2.1.0", - "flow-bin": "^0.43.1", - "mocha": "2.4.5" + "mocha": "2.4.5", + "webpack": "^3.0.0" }, "scripts": { + "build": "NODE_ENV=production ./node_modules/.bin/webpack --config ./config/webpack.config.js --display-max-modules 0", "lint": "node_modules/.bin/eslint .", - "flow": "flow", + "prebuild": "rm -rf ./build", + "setup-hooks": "ln -s ../../scripts/git-hooks/pre-commit.sh .git/hooks/pre-commit", "test": "node_modules/.bin/mocha --recursive", - "setup-hooks": "ln -s ../../scripts/git-hooks/pre-commit.sh .git/hooks/pre-commit" }, "repository": { "type": "git", From b7e3a4ad67923b6c38084373228329a16d8f05b1 Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:02:03 +0530 Subject: [PATCH 08/14] webpack --- config/webpack.config.js | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 config/webpack.config.js diff --git a/config/webpack.config.js b/config/webpack.config.js new file mode 100644 index 00000000..aac59106 --- /dev/null +++ b/config/webpack.config.js @@ -0,0 +1,43 @@ +const webpack = require("webpack"); +const path = require("path"); +const BabiliPlugin = require("babili-webpack-plugin"); +const CleanWebpackPlugin = require("clean-webpack-plugin"); + +module.exports = { + entry: path.resolve(__dirname, "../index.js"), + output: { + path: path.resolve(__dirname, "../build"), + filename: "mathsteps.min.js", + libraryTarget: "umd", + library: "mathsteps" + }, + externals: { + mathjs: "mathjs" + }, + module: { + rules: [ + { + test: /\.js$/, + exclude: [/node_modules/, /scripts/, /test/, /Config/], + use: ["babel-loader"] + } + ] + }, + plugins: [ + new webpack.LoaderOptionsPlugin({ // Options for loader that will run on files + minimize: true, + debug: false, + options: { + context: __dirname + } + }), + new webpack.optimize.ModuleConcatenationPlugin(), // Webpack 3 (scope hoisting) + new webpack.optimize.UglifyJsPlugin(), // Minifier + new webpack.DefinePlugin({ // Production ready build + "process.env": { + NODE_ENV: JSON.stringify("production") + } + }), + new CleanWebpackPlugin([path.resolve(__dirname, "../build")]) // Prebuild (kinda hook) + ] +}; \ No newline at end of file From 7948910602db9cbc482f5a5f06fefebaed522b06 Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:08:07 +0530 Subject: [PATCH 09/14] ignore build --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f58d10d0..9815ae84 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules *.log .DS_Store +build From afdafd69e7346694aa1856ff4438da30ca0f55c5 Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:08:36 +0530 Subject: [PATCH 10/14] remove flow --- .flowconfig | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .flowconfig diff --git a/.flowconfig b/.flowconfig deleted file mode 100644 index f58eb0d3..00000000 --- a/.flowconfig +++ /dev/null @@ -1,9 +0,0 @@ -[ignore] -.*/test/.* -.*/scripts/.* - -[include] - -[libs] - -[options] From 6fe18e1e2279dcb1128eca22f9d691d21257bfd6 Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:09:27 +0530 Subject: [PATCH 11/14] remove flow annotations --- lib/node/Creator.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/node/Creator.js b/lib/node/Creator.js index c6878ccc..5fdc89b0 100644 --- a/lib/node/Creator.js +++ b/lib/node/Creator.js @@ -1,22 +1,14 @@ -// @flow - /* Functions to generate any mathJS node supported by the stepper see http://mathjs.org/docs/expressions/expression_trees.html#nodes for more information on nodes in mathJS */ -type value = string | number; - -type baseNode = { - [property: string]: value -} - const math = require('mathjs'); const NodeType = require('./Type'); const NodeCreator = { - operator (op: string, args: Array, implicit: boolean=false) { + operator (op, args, implicit) { switch (op) { case '+': return new math.expression.node.OperatorNode('+', 'add', args); @@ -36,27 +28,27 @@ const NodeCreator = { // In almost all cases, use Negative.negate (with naive = true) to add a // unary minus to your node, rather than calling this constructor directly - unaryMinus (content: Array) { + unaryMinus (content) { return new math.expression.node.OperatorNode( '-', 'unaryMinus', [content]); }, - constant (val: number) { + constant (val) { return new math.expression.node.ConstantNode(val); }, - symbol (name: string) { + symbol (name) { return new math.expression.node.SymbolNode(name); }, - parenthesis (content: baseNode) { + parenthesis (content) { return new math.expression.node.ParenthesisNode(content); }, // exponent might be null, which means there's no exponent node. // similarly, coefficient might be null, which means there's no coefficient // the symbol node can never be null. - polynomialTerm (symbol: baseNode, exponent: baseNode, coeff: Object, explicitCoeff: boolean=false) { + polynomialTerm (symbol, exponent, coeff, explicitCoeff) { let polyTerm = symbol; if (exponent) { polyTerm = this.operator('^', [polyTerm, exponent]); @@ -76,7 +68,7 @@ const NodeCreator = { }, // Given a root value and a radicand (what is under the radical) - nthRoot (radicandNode: baseNode, rootNode: baseNode) { + nthRoot (radicandNode, rootNode) { const symbol = NodeCreator.symbol('nthRoot'); return new math.expression.node.FunctionNode(symbol, [radicandNode, rootNode]); } From 057d80494cb33577f6fdcc5d4274b9a980d56c94 Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:14:44 +0530 Subject: [PATCH 12/14] some corrections --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b137855a..18dc9fe4 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,10 @@ }, "scripts": { "build": "NODE_ENV=production ./node_modules/.bin/webpack --config ./config/webpack.config.js --display-max-modules 0", - "lint": "node_modules/.bin/eslint .", + "lint": "node_modules/.bin/eslint ./lib", "prebuild": "rm -rf ./build", "setup-hooks": "ln -s ../../scripts/git-hooks/pre-commit.sh .git/hooks/pre-commit", - "test": "node_modules/.bin/mocha --recursive", + "test": "node_modules/.bin/mocha --recursive" }, "repository": { "type": "git", From 8fd93e2061d1da0a09e2693c079dcefe151abb51 Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:15:52 +0530 Subject: [PATCH 13/14] revert --- README.md | 84 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index b852cf02..31d56b31 100644 --- a/README.md +++ b/README.md @@ -1,66 +1,74 @@ -# Mathsteps -[![Join the chat at https://gitter.im/mathsteps-chat/Lobby](https://badges.gitter.im/mathsteps-chat/Lobby.svg)](https://gitter.im/mathsteps-chat/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/socraticorg/mathsteps.svg?branch=master)](https://travis-ci.org/socraticorg/mathsteps) +## A step by step solver for math -Mathsteps is a step-by-step math solver. It helps in solving equations, simplifying an expression and factoring a polynomial. (more to come 😄) +[![Join the chat at https://gitter.im/mathsteps-chat/Lobby](https://badges.gitter.im/mathsteps-chat/Lobby.svg)](https://gitter.im/mathsteps-chat/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/socraticorg/mathsteps.svg?branch=master)](https://travis-ci.org/socraticorg/mathsteps) -**Solve an equation** +https://www.youtube.com/watch?v=iCrargw1rrM -```javascript -const steps = mathsteps.solveEquation('2x + 3x = 35'); -``` +## Requirements -**See all the change types** -```javascript -const changes = mathsteps.ChangeTypes; -``` -Learn [how to use mathsteps](https://github.com/socraticorg/mathsteps/wiki/How-to-use-mathsteps) and [how the codebase works](https://github.com/socraticorg/mathsteps/wiki/Mathsteps-organization). +Mathsteps requires Node version > 6.0.0 + +## Usage + +To install mathsteps using npm: -## Examples -Here is an example to get you started. + npm install mathsteps -```javascript +```js const mathsteps = require('mathsteps'); const steps = mathsteps.simplifyExpression('2x + 2x + x + x'); steps.forEach(step => { - console.log("before change: " + step.oldNode); - console.log("change: " + step.changeType); - console.log("after change: " + step.newNode); - console.log("no of substeps: " + step.substeps.length); console.log("before change: " + step.oldNode.toString()); // before change: 2 x + 2 x + x + x console.log("change: " + step.changeType); // change: ADD_POLYNOMIAL_TERMS console.log("after change: " + step.newNode.toString()); // after change: 6 x console.log("# of substeps: " + step.substeps.length); // # of substeps: 3 }); - -/* -before change: 2 x + 2 x + x + x -change: ADD_POLYNOMIAL_TERMS -after change: 6 x -no of substeps: 3 -*/ ``` -In this example we have an equation `2x + 2x + x + x` that is being simplified by the method `simplifyExpression`. It returns the output which tells about the equation before and after applying the change, what change was applied and the no of substeps. -## Installation -Mathsteps is available as the `mathsteps` package on [npm](https://www.npmjs.com/package/mathsteps). +To solve an equation: +```js +const steps = mathsteps.solveEquation('2x + 3x = 35'); + +steps.forEach(step => { + console.log("before change: " + step.oldEquation.print()); // e.g. before change: 2x + 3x = 35 + console.log("change: " + step.changeType); // e.g. change: SIMPLIFY_LEFT_SIDE + console.log("after change: " + step.newEquation.print()); // e.g. after change: 5x = 35 + console.log("# of substeps: " + step.substeps.length); // e.g. # of substeps: 2 +}); ``` -npm install mathsteps --save + +To see all the change types: +```js +const changes = mathsteps.ChangeTypes; ``` + + ## Contributing -The main objective of the mathsteps is to continue to evolve and provide more operations and features. Read below to learn how can you contribute to the project. -**Contributing guide** +Hi! If you're interested in working on this, that would be super awesome! +Learn more here: [CONTRIBUTING.md](CONTRIBUTING.md). + +## Build + +First clone the project from github: + + git clone https://github.com/socraticorg/mathsteps.git + cd mathsteps -Read our [contributing guide](CONTRIBUTING.md) to suggest more features, report bugs or contribute code. +Install the project dependencies: + + npm install ## Test -``` -npm test -``` -## License -Apache-2.0 +To execute tests for the library, install the project dependencies once: + + npm install + +Then, the tests can be executed: + npm test From bfdf4b4dd2367003b45ebceaee12074423b08b5b Mon Sep 17 00:00:00 2001 From: Nitin Date: Sat, 1 Jul 2017 02:19:05 +0530 Subject: [PATCH 14/14] updated --- lib/node/Creator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node/Creator.js b/lib/node/Creator.js index 5fdc89b0..165a6863 100644 --- a/lib/node/Creator.js +++ b/lib/node/Creator.js @@ -8,7 +8,7 @@ const math = require('mathjs'); const NodeType = require('./Type'); const NodeCreator = { - operator (op, args, implicit) { + operator (op, args, implicit=false) { switch (op) { case '+': return new math.expression.node.OperatorNode('+', 'add', args); @@ -48,7 +48,7 @@ const NodeCreator = { // exponent might be null, which means there's no exponent node. // similarly, coefficient might be null, which means there's no coefficient // the symbol node can never be null. - polynomialTerm (symbol, exponent, coeff, explicitCoeff) { + polynomialTerm (symbol, exponent, coeff, explicitCoeff=false) { let polyTerm = symbol; if (exponent) { polyTerm = this.operator('^', [polyTerm, exponent]);