npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kas-meri

v0.2.2

Published

A lightweight JavaScript CAS for comparing expressions and equations.

Downloads

3

Readme

KAS

A lightweight JavaScript CAS for comparing expressions and equations. It is used throughout Khan Academy's interactive exercises.

This library is forked from https://github.com/Khan/KAS to address some minor issues

What can it do?

It can parse plain text math, LaTeX, or a mix of both:

var expr = KAS.parse("3x \\frac{42}{42} sin^2y").expr;
expr.print();
// "3*x*42/42*sin(y)^(2)"

It can evaluate expressions:

var expr = KAS.parse("(x^2+y^2)^.5").expr;
expr.eval({x: 3, y: 4});
// 5

It can compare expressions and equations:

var expr1 = KAS.parse("(1-x)(-1-6x)").expr;
var expr2 = KAS.parse("(6x+1)(x-1)").expr;
KAS.compare(expr1, expr2).equal;
// true

var eq1 = KAS.parse("2w+50/w=25").expr;
var eq2 = KAS.parse("w(12.5-w)=25").expr;
KAS.compare(eq1, eq2).equal;
// true

It can perform basic transforms that always simplify an expression:

var expr = KAS.parse("1+1+x+x+x+y").expr;
expr.collect().print();
// "2+3*x+y"

var expr = KAS.parse("b^(2*y*log_b x)").expr;
expr.collect().print();
// "x^(2*y)"

It can perform non-simplifying transforms on an expression:

var expr = KAS.parse("ab(c+d)e^f").expr;
expr.print();
// "a*b*(c+d)*e^(f)"
expr.expand().print();
// "a*b*e^(f)*c+a*b*e^(f)*d"
expr.expand().factor().print();
// "a*b*e^(f)*(c+d)"

It can combine the above abilities to perform powerful simplification:

var expr = KAS.parse("((nx^5)^5)/(n^-2x^2)^-3").expr;
expr.print();
// "(n*x^(5))^(5)*(n^(-2)*x^(2))^(-1*-3)"
expr.simplify().print();
// "n^(-1)*x^(31)"

var expr = KAS.parse("(15np-25mp)/(15p^2-5p)+(20mp+10p^2)/(15p^2-5p)").expr;
expr.print();
// "(15*n*p+-25*m*p)*(15*p^(2)+-5*p)^(-1)+(20*m*p+10*p^(2))*(15*p^(2)+-5*p)^(-1)"
expr.simplify().print();
// "(-1+3*p)^(-1)*(3*n+-1*m+2*p)"

How to build the library

npm install
npm run build

How to build the parser

First, make any changes in src/parser-generator.js

npm install
npm run build:parser

License

MIT License