Skip to main content

Python playground to learn lambda calculus

Project description

Curry party

curryparty is a library created to explore, visualize and teach lambda-calculus concepts.

Install

Run pip install curryparty or uv add curryparty depending on your package manager.

How to use

from curryparty import L, o

# Build classic lambda calculus expressions

# Identity: λx. x
identity = L("x").o("x").build()

# Const (K combinator): λx. λy. x
const = L("x", "y").o("x").build()

# Omega: λx. x x
omega = L("x").o("x", "x").build()
print(omega(omega))  # (λ0 x0(x0))((λ1 x1(x1)))

# Church numerals
zero = L("f", "x").o("x").build()
one = L("f", "x").o("f", "x").build()
two = L("f", "x").o("f", o("f", "x")).build()

succ = L("n", "f", "x").o("f", o("n", "f", "x")).build()

# S combinator: λf. λg. λx. f x (g x)
s_comb = L("f", "g", "x").o("f", "x", o("g", "x")).build()

# Beta reduction
# Nothing happens until you reduce:
app = identity(identity)
print(app)  # (λ0 x0)((λ1 x1))

# Perform one reduction step:
reduced = app.beta()
print(reduced)  # λ0 x0

# Multiple reductions:
term = succ(zero)
print(f"Steps: {len(list(term.reduction_chain()))}")  # Steps: 3

# Print each step:
for step in term.reduction_chain():
    print(step)

# Or get the final result directly:
result = succ(zero).reduce()
print(result)  # λ0 λ1 x0(x1) (i.e, one)

But the main point of this library is the svg-based display system. If you use a notebook such as jupyternotebook or marimo, you will see something like this:

notebook_display

You can also use term.show_reduction to get an animated version.

Tutorial

lambda.py shows a tutorial in marimo format. Click on the button to try it out:

Open with marimo

How it works

Under the wood, all the terms are converted into a list of nodes, that can either be a lambda, an application (with 2 arguments) or a variable (with 0 arguments).

For efficiency, they are converted to a polars dataframe in prefix traversal order. If you want to understand how it works, start by looking at the .nodes attribute of any term.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

curryparty-0.4.2.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curryparty-0.4.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file curryparty-0.4.2.tar.gz.

File metadata

  • Download URL: curryparty-0.4.2.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for curryparty-0.4.2.tar.gz
Algorithm Hash digest
SHA256 a281aa6638364208468c43c74f8cca4b35f070afed5bd1bb8a50508af5235b3e
MD5 d9ca5595f9490354fce597ea9aa4b772
BLAKE2b-256 27e1954739a91b5650ff2165549eb5b114f206b69744d4fa353b3e40a560de79

See more details on using hashes here.

Provenance

The following attestation bundles were made for curryparty-0.4.2.tar.gz:

Publisher: publish.yml on rambip/curryparty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file curryparty-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: curryparty-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for curryparty-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cd7cd23ac3cea1222617225ac9b14492e733923f6927d27744e7f12db2ec0f6
MD5 c53b169bed885ca117454883582783fb
BLAKE2b-256 57706c7a129d5b3e4713cca321cd11758521df8d3f0f1429c2b1603af07c7e38

See more details on using hashes here.

Provenance

The following attestation bundles were made for curryparty-0.4.2-py3-none-any.whl:

Publisher: publish.yml on rambip/curryparty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page