# compute.ts

> The engine is based on incremental computation algorithms. When a calculation is submitted to the engine, all the computed values are memorized. So, if you change some variable and query an evaluation, the engine is able to compute the result very fast be

Latest version **2.0.3** (published 2021-06-25) · 0 weekly downloads

## Install

```sh
npm install compute.ts
pnpm add compute.ts
yarn add compute.ts
bun add compute.ts
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2021-06-25 |
| First published | 2021-06-18 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mathieu BERTHELLEMY |
| Maintainers | mberthellemy |
| Keywords | incremental computation, incremental engine, incremental calculation, incremental, computation, engine, calculation, mathematics, graph, dag, directed acyclic graph, affectation, evaluation, affect, eval |

## Links

- npm: https://www.npmjs.com/package/compute.ts
- npm.io page: https://npm.io/package/compute.ts

## Dependencies (10)

- [@compute.ts/core](https://npm.io/package/@compute.ts/core.md) ^2.0.0
- [@compute.ts/date](https://npm.io/package/@compute.ts/date.md) ^2.0.0
- [@compute.ts/math](https://npm.io/package/@compute.ts/math.md) ^2.0.0
- [@compute.ts/array](https://npm.io/package/@compute.ts/array.md) ^2.0.0
- [@compute.ts/number](https://npm.io/package/@compute.ts/number.md) ^2.0.0
- [@compute.ts/string](https://npm.io/package/@compute.ts/string.md) ^2.0.0
- [@compute.ts/boolean](https://npm.io/package/@compute.ts/boolean.md) ^2.0.0
- [@compute.ts/function](https://npm.io/package/@compute.ts/function.md) ^2.0.0
- [@compute.ts/dictionary](https://npm.io/package/@compute.ts/dictionary.md) ^2.0.0
- [@compute.ts/structural](https://npm.io/package/@compute.ts/structural.md) ^2.0.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 2.0.3 (latest) — 2021-06-25
- 2.0.2 — 2021-06-25
- 2.0.1 — 2021-06-23
- 2.0.0 — 2021-06-21
- 1.0.0 — 2021-06-18

## README

![](https://colibri-engine.com/assets/img/compute.png)


![](https://img.shields.io/npm/types/@compute.ts/core)
![](https://img.shields.io/npm/v/@compute.ts/core)
![](https://img.shields.io/npm/l/@compute.ts/core)
![](https://img.shields.io/badge/coverage-undefined-lightgrey.svg)
![](https://img.shields.io/badge/files-58-orange)
![](https://img.shields.io/badge/lines-3877-orange)
![](https://img.shields.io/badge/made%20in-France-blue)

## Presentation
The engine is based on incremental computation algorithms. When a calculation is submitted to the engine, all the computed values are memorized. So, if you change some variable and query an evaluation, the engine is able to compute the result very fast because it recomputes only what has changed.

## Libraries
The project provides several libraries that each comes with dozens of operators. Please note the cross-compatibility of the libraries.
- [@compute.ts/boolean](https://www.npmjs.com/package/@compute.ts/boolean)
- [@compute.ts/number](https://www.npmjs.com/package/@compute.ts/number)
- [@compute.ts/string](https://www.npmjs.com/package/@compute.ts/string)
- [@compute.ts/date](https://www.npmjs.com/package/@compute.ts/date)
- [@compute.ts/dictionary](https://www.npmjs.com/package/@compute.ts/dictionary)
- [@compute.ts/function](https://www.npmjs.com/package/@compute.ts/function)
- [@compute.ts/math](https://www.npmjs.com/package/@compute.ts/math)
- [@compute.ts/structural](https://www.npmjs.com/package/@compute.ts/structural)


## Usage 
### Imports
The engine library permits you to import the operators in a very simple way.
```typescript
import {/* required operators */} from "@compute.ts/{library}" ;
```

### Variable
The engine API permits you to define some special scalars called variables. There are special because once the model is loaded into the engine, you are able to change its values with the affect operation.

```typescript
import {number} from "@compute.ts/number" ;

const x = number();

x.affect(12);
```


### Expression
The library allows you to create expressions such as "and", "sum", "isLessThan". An expression represents a step of the computation of the calculation. There, take a set of nodes (variables or expressions) and return a single value—the expressions value.
```typescript
import {sum, number} from "@compute.ts/number";

const x = number();
const y = number();
const fx = sum(x, y);

fx.eval()
```


### toString
The library allows you to visualize a node in a very convinient way.
```typescript
import {sum, number} from "@compute.ts/number";

const x0 = number(12);
const x1 = number(12);
const x2 = number(12);
const y0 = sum(x0, x1);
const y1 = minus(x1, x2);
const z = divide(y0, y1);

z.toString();
// ☐ divide
// ├─ ☐ sum
// │  ├─ ☑ 2
// │  └─ ☑ ∅
// └─ ☐ minus
//    ├─ ☑ ∅
//    └─ ☑ ∅
//
// ☐ = the expression need to be evaluated
// ☑ = the expression has been evaluated
// ∅ = the expression value is undefined

x1.affect(4);
x2.affect(8);
z.eval();

z.toString();
// ☑ divide(6, -4) ➔ -1.5
// ├─ ☑ sum(2, 4) ➔ 6
// │  ├─ ☑ 2
// │  └─ ☑ 4
// └─ ☑ minus(4, 8) ➔ -4
//    ├─ ☑ 4
//    └─ ☑ 8
//
// ➔ = current value of the expression
// ☑ = the expression has been evaluated
```



### alias
If you create an alias for a given expression.
```typescript
import {sum, number} from "@compute.ts/number";

const x0 = number(12);
const x1 = number(4);
const x2 = number(8);
const y0 = sum(x0, x1);
const y1 = minus(x1, x2).alias('y1');
const z = divide(y0, y1);

z.eval();

z.toString();
// ☑ divide ➔ -1.5
// ├─ ☑ sum ➔ 6
// │  ├─ ☑ 2
// │  └─ ☑ 4
// └─ ☑  -4     [y1]


```


### describe
If you create a description for a given expression.
```typescript
import {sum, number} from "@compute.ts/number";

const x0 = number(12);
const x1 = number(4);
const x2 = number(8);
const x3 = number(4);
const y0 = sum(x0, x1);
const z = divide(y0, x3).alias('z').describe('The final result');

z.eval();

z.toString();
// ☑ divide ➔ -1.5      [z: The final result]
// ├─ ☑ sum ➔ 6
// │  ├─ ☑ 2
// │  └─ ☑ 4
// └─ ☑  -4


```

## Example 
### Polynom computation

```typescript
import {number} from "@compute.ts/number";
import {x2} from "@compute.ts/math";

const x = number();
const a = number(3);
const b = number(5);
const c = number(7);
const fx = a.times(x2(x)).plus(b.times(x)).plus(c);

x.affect(1)
fx.eval(); // = 15
```
* * *
### Polynom resolution

```typescript
import {number, zero} from "@compute.ts/number";
import {x2, sqrt} from "@compute.ts/math";

const a = number();
const b = number();
const c = number();
const delta = x2(b).minus(times(4, a, c));
const hasSolution = delta.greaterOrEqualThan(zero);
const x1 = opposite(b).minus(sqrt(delta)).divideBy(times(2, a));
const x2 = opposite(b).sum(sqrt(delta)).divideBy(times(2, a));

a.affect(1);
b.affect(2);
c.affect(3);

hasSolution.eval() // = true
x1.eval(); // = 2/3
x2.eval(); // = 1
```

## About the author
I am a software developer with 4 years of project specializing in the development of web solutions. Digital Nomad, I work while traveling.  After 3 years into the french industry, I've started to work as a freelance software architect or fullstack developer.

Based on state-of-the-art web technologies, I offer you to architect & develop the best version of your project. My experience in the web app development assure you to build a nice looking, performant and stable product.

Minimalist, I like to travel, to meet people, learn new things and handmade stuff. Scuba & sky diving licenced. I like also hamburgers, Kinder chocolate and crepes. Karate black belt.

https://berthellemy.com/

* * *
![](https://colibri-engine.com/assets/img/brand/logo_animated.gif)

---
_Source: https://npm.io/package/compute.ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
