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.3.tar.gz (14.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.3-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: curryparty-0.4.3.tar.gz
  • Upload date:
  • Size: 14.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.3.tar.gz
Algorithm Hash digest
SHA256 30bccc7eaa43242b4ce217e5258186270ce39630a07e4b34d0f11992d98d8ac1
MD5 34d5f7c7d7f56cd533d0509e0368ecdf
BLAKE2b-256 e6f25e118e63e5b1b3ce6c21c45bfb6ada465f02d88d15759726c7c54e1fc833

See more details on using hashes here.

Provenance

The following attestation bundles were made for curryparty-0.4.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: curryparty-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 16.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4fe5a6c4ff8022cc574ecbcc9b66ab7cb238c01cd4bcbd1d26b846671db1a3ac
MD5 6c252f69d9a0d38dfaae433141881f9b
BLAKE2b-256 f6a758a17c29abbd8ad16a06299a7ea68bf1f99f67c1df0aa3ad40945b549997

See more details on using hashes here.

Provenance

The following attestation bundles were made for curryparty-0.4.3-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