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

algebrain

v0.0.9

Published

Combuter Algebra System focusing on symbolic transformations

Downloads

8

Readme

Algebrain 🧠

Build Status Coverage Status

Combuter Algebra System focusing on symbolic transformations.

100% writen in typescript.

Parser generated using ANTLR4.

Note: Algebrain is still at a very early and unstable stage.

Install

$ npm install algebrain

Usage

Expressions

import Algebrain from "algebrain";

const expr = Algebrain.parse("(3^2)*1.6+5/(y-12.34)");
// Your string expression is now a tree of nodes:
//  +
//  ├── *
//  │   ├── 1.6
//  │   └── ^
//  │       ├── 3
//  │       └── 2
//  └── /
//      ├── 5
//      └── -
//          ├── y
//          └── 12.34

const evaluated = expr.evaluate();
// Evaluated tree of the following form:
// +
// ├── 14.4
// └── /
//     ├── 5
//     └── -
//         ├── y
//         └── 12.34

console.log(`My evaluated expression is: ${evaluated}`);
// > My evaluated expression is: 14.4+5/(y-12.34)

Under the hood, the above parsing uses an extensive API for structuring algebraic expressions:

// Algebrain heavily relies on the immutable package for persistent data structures
import { List } from "immutable";
import { Operator, Num, Symbol, OperatorSymbol } from "algebrain";

// The above expression: 14.4+5/(y-12.34), is constructed as:
const expr = new Operator(OperatorSymbol.Plus, List([
    new Num(14.4),
    new Operator(OperatorSymbol.Div, List([
        new Num(5),
        new Operator(OperatorSymbol.Minus, List([
            new Symbol("y"),
            new Num(12.34)
        ]))
    ]))
]));

console.log(expr.toString());
// > 14.4+5/(y-12.34)

Transformations

By exploiting the concept of rewriting rules, Algebrain enables the use of custom transformations, that can be entirely developed and compiled within its environment.

import Algebrain, { Transformation } from "algebrain";

const rules = [
    Algebrain.parse("fib(0)=0"),
    Algebrain.parse("fib(1)=1"),
    Algebrain.parse("fib($a)=fib($a-1)+fib($a-2) if const($a)"),
];

const fibonacci = new Transformation("fib", rules);

const expr = Algebrain.parse("fib(15)");

console.log(`The 15th term of fibonacci is: ${expr.transform(fibonacci)}`);
// > The 15h term of fibonacci is 610

Interpreter - The execution framework of Algebrain

Similar to any traditional Computer Algebra System, Algebrain provides a progamming language and an intepreter. Every Algebrain statement or expression, when parsed, results to an object implementing the Executable interface.

✍️ more documentation to come...

Web UI

There is a web-app client that materiliases a friendly interface for exploring algebrain at https://algebrain.io

The source repo of the React app can be found here.

Develop

# Linting
npm run lint

# Unit tests w/ coverage thresholds
npm run test

# Compile typescript
npm run build

# Please commit through the following npm scripts
npm run precommit
npm run commit