Skip to content

Step by step math solutions for everyone

License

Notifications You must be signed in to change notification settings

taskbase/mathsteps

This branch is 19 commits ahead of, 2 commits behind google/mathsteps:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8a25862 · Mar 29, 2021
Mar 9, 2021
Mar 10, 2021
Feb 27, 2021
Mar 29, 2021
Mar 9, 2021
Feb 27, 2021
Mar 2, 2021
Mar 13, 2017
Mar 9, 2021
Feb 3, 2017
Mar 10, 2021
Mar 10, 2021

Repository files navigation

npm badge

Why Mathsteps

Mathsteps aims to provide step-by-step instructions like a tutor would give them to a student.

Requirements

Mathsteps requires Node version > 6.0.0

Usage Example

To install mathsteps using npm:

(Coming)

npm install @taskbase/mathsteps
const mathsteps = require('mathsteps');

const steps = mathsteps.simplifyExpression('2x + 2x + x + x');

steps.forEach(step => {
	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
});

To solve an equation:

const steps = mathsteps.solveEquation('2x + 3x = 35');

steps.forEach(step => {
    console.log("before change: " + step.oldEquation.ascii());  // e.g. before change: 2x + 3x = 35
    console.log("change: " + step.changeType);                  // e.g. change: SIMPLIFY_LEFT_SIDE
    console.log("after change: " + step.newEquation.ascii());   // e.g. after change: 5x = 35
    console.log("# of substeps: " + step.substeps.length);      // e.g. # of substeps: 2
});

To see all the change types:

const changes = mathsteps.ChangeTypes;

Which syntax is mathsteps expecting?

Asciimath

Simplify Expression

Simplifying Expressions

What can mathsteps simplifyExpression do?

  • arithmetic simplification: ["(2+2)*5", "20"]
  • collect and combines like terms: ["x^2 + 3x*(-4x) + 5x^3 + 3x^2 + 6", "5x^3 - 8x^2 + 6"]
  • simplify with division: ["(20 * x) / (5 * (40 * y))", "x / (10y)"]
  • deal with fractions: ["2(x+3)/3", "2x / 3 + 2"]
  • cancelling out: ["(1+2a)/a", "1 / a + 2"]
  • deal with absolute values: ["(x^3*y)/x^2 + abs(-5)", "x * y + 5"]
  • deal with nth roots: ["x * nthRoot(x^4, 2)", "x^3"]

unsure:

  • deal with higher order polynomials: ?

What can't mathsteps simplifyExpression do?

Solve Equation

Solving equations.

What can solveEquation do?

  • Solve linear equations with one variable
  • Solve for y in linear equations with x and y as variables.
  • Solve binomic equation
  • Some inequalities (e.g. "x + 2 > 3" to "x > 1")
  • Constant comparison (e.g. "1 = 2" to ChangeTypes.STATEMENT_IS_FALSE)

What can't solveEquation do?

  • Expressions with multiple variables other than y and x
  • Some inequalities (e.g. "( x )/( 2x + 7) >= 4")
  • Calculate square root of x^2, so result will stay e.g. x^2=2

Build

First clone the project from github:

git clone https://github.com/taskbase/mathsteps.git
cd mathsteps

Install the project dependencies:

npm ci
cd lib && npm ci && cd ..
cd example-consumer && npm ci && cd ..

Publish version

See scripts in package.json.

Test

To execute tests for the library, install the project dependencies:

npm ci

Then, the tests can be executed:

npm test

TODOs

  • Fix usage of factoring for simplification
  • Throw error instead of returning empty array?
  • Port to TypeScript!

Attribution

Based on google/mathsteps

About

Step by step math solutions for everyone

Resources

License

Stars

Watchers

Forks

Languages

  • TypeScript 99.9%
  • Shell 0.1%