All Projects → ljedrz → Lambda_calculus

ljedrz / Lambda_calculus

Licence: cc0-1.0
A simple, zero-dependency implementation of the untyped lambda calculus in Safe Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Lambda calculus

Aws Lambda Workshop
Some incremental examples suitable to host an AWS Lambda Functions workshop
Stars: ✭ 18 (-60.87%)
Mutual labels:  lambda-calculus
Jsonpath Rs
JSONPath for Rust
Stars: ✭ 31 (-32.61%)
Mutual labels:  rust-library
Ltext
λtext - higher-order file applicator
Stars: ✭ 37 (-19.57%)
Mutual labels:  lambda-calculus
Epsagon Go
Automated tracing library for Go 1.x ⚡️
Stars: ✭ 24 (-47.83%)
Mutual labels:  lambda-functions
Rust Csv
A CSV parser for Rust, with Serde support.
Stars: ✭ 911 (+1880.43%)
Mutual labels:  rust-library
Photon
⚡ Rust/WebAssembly image processing library
Stars: ✭ 963 (+1993.48%)
Mutual labels:  rust-library
Libimagequant Rust
libimagequant (pngquant) bindings for the Rust language
Stars: ✭ 17 (-63.04%)
Mutual labels:  rust-library
Run script
Run shell scripts in rust.
Stars: ✭ 42 (-8.7%)
Mutual labels:  rust-library
Simulacrum
A small library for creating mock objects in Rust.
Stars: ✭ 21 (-54.35%)
Mutual labels:  rust-library
Reqray
Log call tree summaries after each request for rust programs instrumented with `tracing`.
Stars: ✭ 37 (-19.57%)
Mutual labels:  rust-library
Dblib Linear
Formalisation of the linear lambda calculus in Coq
Stars: ✭ 10 (-78.26%)
Mutual labels:  lambda-calculus
Learn Aws Lambda
✨ Learn how to use AWS Lambda to easily create infinitely scalable web services
Stars: ✭ 910 (+1878.26%)
Mutual labels:  lambda-functions
Arccstr
Thread-safe, reference-counted null-terminated immutable Rust strings.
Stars: ✭ 34 (-26.09%)
Mutual labels:  rust-library
Tract
Tiny, no-nonsense, self-contained, Tensorflow and ONNX inference
Stars: ✭ 899 (+1854.35%)
Mutual labels:  rust-library
Pts
implementation of Pure Type Systems (PTS) in Rust.
Stars: ✭ 41 (-10.87%)
Mutual labels:  lambda-calculus
Rusticsom
Rust library for Self Organising Maps (SOM).
Stars: ✭ 18 (-60.87%)
Mutual labels:  rust-library
Zion
A statically-typed strictly-evaluated garbage-collected readable programming language.
Stars: ✭ 33 (-28.26%)
Mutual labels:  lambda-calculus
Dtparse
A dateutil-compatible timestamp parser for Rust
Stars: ✭ 45 (-2.17%)
Mutual labels:  rust-library
Log
Logging implementation for Rust
Stars: ✭ 1,012 (+2100%)
Mutual labels:  rust-library
Finalfusion Rust
finalfusion embeddings in Rust
Stars: ✭ 35 (-23.91%)
Mutual labels:  rust-library

lambda_calculus

license current version build status

lambda_calculus is a simple, zero-dependency implementation of pure lambda calculus in Safe Rust.

Documentation

Features

  • a parser for lambda expressions, both in classic and De Bruijn index notation
  • 7 β-reduction strategies
  • a set of standard terms (combinators)
  • lambda-encoded boolean, pair, tuple, option and result data types
  • single-pair-encoded list
  • Church-, Scott- and Parigot-encoded numerals and lists
  • Stump-Fu (embedded iterators)- and binary-encoded numerals
  • signed numbers

Installation

Include the library by adding the following to your Cargo.toml:

[dependencies]
lambda_calculus = "^3.0"

And the following to your code:

#[macro_use]
extern crate lambda_calculus;

Compilation features:

  • backslash_lambda: changes the display of lambdas from λ to \
  • encoding: builds the data encoding modules; default feature

Example feature setup in Cargo.toml:

[dependencies.lambda_calculus]
version = "^3.0"
default-features = false # do not build the data encoding modules
features = ["backslash_lambda"] # use a backslash lambda

Examples

Comparing classic and De Bruijn index notation

code:

use lambda_calculus::data::num:⛪️:{succ, pred};

fn main() {
    println!("SUCC := {0} = {0:?}", succ());
    println!("PRED := {0} = {0:?}", pred());
}

stdout:

SUCC := λa.λb.λc.b (a b c) = λλλ2(321)
PRED := λa.λb.λc.a (λd.λe.e (d b)) (λd.c) (λd.d) = λλλ3(λλ1(24))(λ2)(λ1)

Parsing lambda expressions

code:

use lambda_calculus::*;

fn main() {
    assert_eq!(
        parse(&"λa.λb.λc.b (a b c)", Classic),
        parse(&"λλλ2(321)", DeBruijn)
    );
}

Showing β-reduction steps

code:

use lambda_calculus::*;
use lambda_calculus::data::num:⛪️:pred;

fn main() {
    let mut expr = app!(pred(), 1.into_church());

    println!("{} order β-reduction steps for PRED 1 are:", NOR);

    println!("{}", expr);
    while expr.reduce(NOR, 1) != 0 {
        println!("{}", expr);
    }
}

stdout:

normal order β-reduction steps for PRED 1 are:
(λa.λb.λc.a (λd.λe.e (d b)) (λd.c) (λd.d)) (λa.λb.a b)
λa.λb.(λc.λd.c d) (λc.λd.d (c a)) (λc.b) (λc.c)
λa.λb.(λc.(λd.λe.e (d a)) c) (λc.b) (λc.c)
λa.λb.(λc.λd.d (c a)) (λc.b) (λc.c)
λa.λb.(λc.c ((λd.b) a)) (λc.c)
λa.λb.(λc.c) ((λc.b) a)
λa.λb.(λc.b) a
λa.λb.b

Comparing the number of steps for different reduction strategies

code:

use lambda_calculus::*;
use lambda_calculus::data::num:⛪️:fac;

fn main() {
    let expr = app(fac(), 3.into_church());

    println!("comparing normalizing orders' reduction step count for FAC 3:");
    for &order in [NOR, APP, HNO, HAP].iter() {
        println!("{}: {}", order, expr.clone().reduce(order, 0));
    }
}

stdout:

comparing normalizing orders' reduction step count for FAC 3:
normal: 46
applicative: 39
hybrid normal: 46
hybrid applicative: 39

Comparing different numeral encodings

code:

use lambda_calculus::*;

fn main() {
    println!("comparing different encodings of number 3 (De Bruijn indices):");
    println!("  Church encoding: {:?}", 3.into_church());
    println!("   Scott encoding: {:?}", 3.into_scott());
    println!(" Parigot encoding: {:?}", 3.into_parigot());
    println!("Stump-Fu encoding: {:?}", 3.into_stumpfu());
    println!("  binary encoding: {:?}", 3.into_binary());
}

stdout:

comparing different encodings of number 3 (De Bruijn indices):
  Church encoding: λλ2(2(21))
   Scott encoding: λλ1(λλ1(λλ1(λλ2)))
 Parigot encoding: λλ2(λλ2(λλ2(λλ1)1)(2(λλ1)1))(2(λλ2(λλ1)1)(2(λλ1)1))
Stump-Fu encoding: λλ2(λλ2(2(21)))(λλ2(λλ2(21))(λλ2(λλ21)(λλ1)))
  binary encoding: λλλ1(13)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].