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

@alexo/lambda

v0.5.2

Published

Macro Lambda Calculus

Downloads

79

Readme

This package implements the lambda calculus using interaction nets, providing CLI and API.

Its browserified version is available as an online demo.

Algorithms

The following encodings of the lambda calculus are included:

The embedded read-back mechanism is described in Section 7 of 10.4204/EPTCS.225.7.

Benchmarks

The following is output of the test.sh script provided in the package:

SAMPLE          ABSTRACT         CLOSED        OPTIMAL       STANDARD
counter              N/A         162/25         582/14        2322/14
w2eta               37/7         137/16          207/7          374/7
1021              199/55     11871/1088     1599877/55     4307803/55
22210i            494/68       2539/254       58603/68            N/A
3222i            1206/50       8638/819      804530/50            N/A
1022i            4317/69     33369/3139            N/A            N/A
2222101   2621862/327818            N/A            N/A            N/A
facty6nt        1112/210     80562/2436    2790152/210    3013433/210
facty9i         1629/287 3746232/130949            N/A            N/A
33-fact4        3770/704      16114/912      80708/704     234075/704
fibo16nt      24931/3042    134135/5673   5462375/3042   8959455/3042
fact100i      28502/3752   121854/10565            N/A            N/A
35-fact5     72944/13480   805218/16206  4702711/13480            N/A
fibo20i       93534/6863   536843/24626   1961508/6863   4023117/6863
fact1knt 6215039/1353692            N/A            N/A            N/A

T/B should be read as total of T interactions, of which B were β-reductions.

CLI

This package provides the lambda command with the following interface:

Usage: lambda [options] (<term> | -f <file>)

Options:
  --algo, -a     Select algorithm         [string]
  --debug, -d    Evaluate step by step   [boolean]
  --exec, -e     Process m4(1) macros    [boolean]
  --file, -f     Read term from file     [boolean]
  --inet, -i     Show interaction net    [boolean]
  --limit, -l    Limit interactions       [number]
  --macros, -m   Read macros from file    [string]
  --perf, -p     Print benchmarks        [boolean]
  --stats, -s    Save statistics to file  [string]
  --term, -t     Output expanded term    [boolean]
  --help, -h     Show help               [boolean]
  --version, -v  Show version number     [boolean]

Combinators

CLI predefines a number of commonly used combinators:

# Common combinators
I = x: x;
K = x, y: x;
S = x, y, z: x z (y z);
Y = (a: a a) (a, f: f (a a f));

# Booleans
T = K;
F = K I;
Not = p, a, b: p b a;
And = p, q: p q F;
Or = p, q: p T q;
Xor = p, q: p Not I q;

# Pairs/lists
[] = K T;
[]? = l: l (h, t: F);
Cons = h, t, x: x h t;
Head = l: l T;
Tail = l: l F;

# Church arithmetic
+1 = n, f, x: f (n f x);
+ = m, n, f, x: m f (n f x);
* = m, n, f: m (n f);
^ = m, n: n m;
-1 = n, f, x: n (g, h: h (g f)) (K x) I;
- = m, n: n -1 m;
0? = n: n (K F) T;

# Church numerals
0 = f, x: x;
1 = f, x: f x;
2 = +1 1;
3 = +1 2;
4 = ^ 2 2;
5 = + 2 3;
6 = * 2 3;
7 = +1 6;
8 = ^ 2 3;
9 = ^ 3 2;
10 = * 2 5;
16 = ^ 2 4;
20 = * 2 10;
30 = * 3 10;
32 = ^ 2 5;
64 = ^ 2 6;
100 = ^ 10 2;
128 = ^ 2 7;
256 = ^ 2 8;
512 = ^ 2 9;
1k = ^ 10 3;
1ki = ^ 2 10;
1m = ^ 10 6;
1mi = ^ 2 20;
1g = ^ 10 9;
1gi = ^ 2 30;

# Recursive functions
FactY = Y (f, n: (0? n) 1 (* (f (-1 n)) n));
Fact = n: n (f, i: * (f (+1 i)) i) (K 1) 1;
Fibo = n: n (f, a, b: f (+ a b) a) F 1 0;

API

require("@alexo/lambda") returns a function of a lambda term defined in a variant of the lambda calculus called Macro Lambda Calculus (MLC) that allows macro definitions in order to input complex expressions. The last term in the input is the term whose normal form is to be found.

For developing and testing purposes, the package also exports two additional functions .prepare(term) and .debug(). The .debug() function applies a single reduction step to the interaction net compiled by the previous .prepare() call and returns a human-readable string representation of the current interaction net state.

Grammar

Input consists of an optional list of macro definitions and a term:

%token NAME

%%

text : defs term
     ;
defs : /* empty */
     | defs NAME '=' term ';'
     ;
term : appl
     | abst
     ;
abst : NAME ',' abst
     | NAME ':' term
     ;
appl :      atom
     | appl atom
     ;
atom : '(' term ')'
     |     NAME
     ;

License

Copyright (c) 2017 Anton Salikhmetov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.