{"id":13749282,"url":"https://github.com/ljedrz/lambda_calculus","last_synced_at":"2025-04-05T18:08:51.350Z","repository":{"id":46092282,"uuid":"87304221","full_name":"ljedrz/lambda_calculus","owner":"ljedrz","description":"A simple, zero-dependency implementation of the untyped lambda calculus in Safe Rust","archived":false,"fork":false,"pushed_at":"2024-07-23T08:59:57.000Z","size":668,"stargazers_count":113,"open_issues_count":1,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T11:13:56.440Z","etag":null,"topics":["beta-reduction","church-encoding","combinatory-logic","debruijn","embedded-iterators-encoding","lambda-calculus","lambda-expressions","lambda-functions","lambda-interpreter","parigot-encoding","reduction-strategies","rust","rust-library","scott-encoding","ski-combinators","stump-fu-encoding"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ljedrz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-05T12:00:25.000Z","updated_at":"2024-10-22T10:10:40.000Z","dependencies_parsed_at":"2024-01-13T01:48:29.583Z","dependency_job_id":"54d6d4e5-b7ee-47e3-a5be-9942e07c5f7d","html_url":"https://github.com/ljedrz/lambda_calculus","commit_stats":{"total_commits":706,"total_committers":7,"mean_commits":"100.85714285714286","dds":"0.12464589235127477","last_synced_commit":"c961a869398c1710dde5a609ee41a94d3f71cd74"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljedrz%2Flambda_calculus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljedrz%2Flambda_calculus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljedrz%2Flambda_calculus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljedrz%2Flambda_calculus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ljedrz","download_url":"https://codeload.github.com/ljedrz/lambda_calculus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378149,"owners_count":20929297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beta-reduction","church-encoding","combinatory-logic","debruijn","embedded-iterators-encoding","lambda-calculus","lambda-expressions","lambda-functions","lambda-interpreter","parigot-encoding","reduction-strategies","rust","rust-library","scott-encoding","ski-combinators","stump-fu-encoding"],"created_at":"2024-08-03T07:00:58.465Z","updated_at":"2025-04-05T18:08:51.331Z","avatar_url":"https://github.com/ljedrz.png","language":"Rust","readme":"# lambda_calculus\n[![license](https://img.shields.io/badge/license-CC0-blue.svg)](https://creativecommons.org/publicdomain/zero/1.0/)\n[![current version](https://img.shields.io/crates/v/lambda_calculus.svg)](https://crates.io/crates/lambda_calculus)\n[![docs.rs](https://docs.rs/lambda_calculus/badge.svg)](https://docs.rs/lambda_calculus)\n[![actively maintained](https://img.shields.io/badge/Maintenance%20Level-Actively%20Maintained-green.svg)](https://gist.github.com/cheerfulstoic/d107229326a01ff0f333a1d3476e068d)\n\n**lambda_calculus** is a simple, zero-dependency implementation of pure lambda calculus in Safe Rust.\n\n## Features\n\n- a parser for lambda expressions, both in classic and De Bruijn index notation\n- 7 β-reduction strategies\n- a set of standard terms (combinators)\n- lambda-encoded boolean, pair, tuple, option and result data types\n- single-pair-encoded list\n- Church-, Scott- and Parigot-encoded numerals and lists\n- Stump-Fu (embedded iterators)- and binary-encoded numerals\n- signed numbers\n\n## Installation\n\nInclude the library by adding the following to your Cargo.toml:\n```toml\n[dependencies]\nlambda_calculus = \"3\"\n```\n\nCompilation features:\n- `backslash_lambda`: changes the display of lambdas from `λ` to `\\`\n- `encoding`: builds the data encoding modules; default feature\n\nExample feature setup in Cargo.toml:\n```toml\n[dependencies.lambda_calculus]\nversion = \"3\"\ndefault-features = false # do not build the data encoding modules\nfeatures = [\"backslash_lambda\"] # use a backslash lambda\n```\n\n## Examples\n\n### Comparing classic and De Bruijn index notation\n\ncode:\n```rust\nuse lambda_calculus::data::num::church::{succ, pred};\n\nfn main() {\n    println!(\"SUCC := {0} = {0:?}\", succ());\n    println!(\"PRED := {0} = {0:?}\", pred());\n}\n```\nstdout:\n```\nSUCC := λa.λb.λc.b (a b c) = λλλ2(321)\nPRED := λa.λb.λc.a (λd.λe.e (d b)) (λd.c) (λd.d) = λλλ3(λλ1(24))(λ2)(λ1)\n```\n\n### Parsing lambda expressions\n\ncode:\n```rust\nuse lambda_calculus::*;\n\nfn main() {\n    assert_eq!(\n        parse(\u0026\"λa.λb.λc.b (a b c)\", Classic),\n        parse(\u0026\"λλλ2(321)\", DeBruijn)\n    );\n}\n```\n\n### Showing β-reduction steps\n\ncode:\n```rust\nuse lambda_calculus::*;\nuse lambda_calculus::data::num::church::pred;\n\nfn main() {\n    let mut expr = app!(pred(), 1.into_church());\n\n    println!(\"{} order β-reduction steps for PRED 1 are:\", NOR);\n\n    println!(\"{}\", expr);\n    while expr.reduce(NOR, 1) != 0 {\n        println!(\"{}\", expr);\n    }\n}\n```\nstdout:\n```\nnormal order β-reduction steps for PRED 1 are:\n(λa.λb.λc.a (λd.λe.e (d b)) (λd.c) (λd.d)) (λa.λb.a b)\nλa.λb.(λc.λd.c d) (λc.λd.d (c a)) (λc.b) (λc.c)\nλa.λb.(λc.(λd.λe.e (d a)) c) (λc.b) (λc.c)\nλa.λb.(λc.λd.d (c a)) (λc.b) (λc.c)\nλa.λb.(λc.c ((λd.b) a)) (λc.c)\nλa.λb.(λc.c) ((λc.b) a)\nλa.λb.(λc.b) a\nλa.λb.b\n```\n\n### Comparing the number of steps for different reduction strategies\n\ncode:\n```rust\nuse lambda_calculus::*;\nuse lambda_calculus::data::num::church::fac;\n\nfn main() {\n    let expr = app(fac(), 3.into_church());\n\n    println!(\"comparing normalizing orders' reduction step count for FAC 3:\");\n    for \u0026order in [NOR, APP, HNO, HAP].iter() {\n        println!(\"{}: {}\", order, expr.clone().reduce(order, 0));\n    }\n}\n```\nstdout:\n```\ncomparing normalizing orders' reduction step count for FAC 3:\nnormal: 46\napplicative: 39\nhybrid normal: 46\nhybrid applicative: 39\n```\n\n### Comparing different numeral encodings\n\ncode:\n```rust\nuse lambda_calculus::*;\n\nfn main() {\n    println!(\"comparing different encodings of number 3 (De Bruijn indices):\");\n    println!(\"  Church encoding: {:?}\", 3.into_church());\n    println!(\"   Scott encoding: {:?}\", 3.into_scott());\n    println!(\" Parigot encoding: {:?}\", 3.into_parigot());\n    println!(\"Stump-Fu encoding: {:?}\", 3.into_stumpfu());\n    println!(\"  binary encoding: {:?}\", 3.into_binary());\n}\n```\nstdout:\n```\ncomparing different encodings of number 3 (De Bruijn indices):\n  Church encoding: λλ2(2(21))\n   Scott encoding: λλ1(λλ1(λλ1(λλ2)))\n Parigot encoding: λλ2(λλ2(λλ2(λλ1)1)(2(λλ1)1))(2(λλ2(λλ1)1)(2(λλ1)1))\nStump-Fu encoding: λλ2(λλ2(2(21)))(λλ2(λλ2(21))(λλ2(λλ21)(λλ1)))\n  binary encoding: λλλ1(13)\n```\n","funding_links":[],"categories":["Lambda Calculus"],"sub_categories":["Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljedrz%2Flambda_calculus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fljedrz%2Flambda_calculus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljedrz%2Flambda_calculus/lists"}