0.0.9 ā€¢ Published 4 years ago

algebrain v0.0.9

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

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
0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4-d

4 years ago

0.0.4-c

4 years ago

0.0.4-b

4 years ago

0.0.4

4 years ago

0.0.3-f

4 years ago

0.0.3-e

4 years ago

0.0.3-d

4 years ago

0.0.3-c

4 years ago

0.0.3-b

4 years ago

0.0.3-a

4 years ago

0.0.2

5 years ago

0.0.1-alpha2

5 years ago

0.0.1-alpha

5 years ago

0.0.1

5 years ago

0.0.0-alpha5

5 years ago

0.0.0-alpha4

5 years ago

0.0.0-alpha3

5 years ago

0.0.0-alpha2

5 years ago

0.0.0-alpha1

5 years ago

0.0.0-alpha

5 years ago

0.0.0

5 years ago