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.1.tar.gz (13.0 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.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: curryparty-0.4.1.tar.gz
  • Upload date:
  • Size: 13.0 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.1.tar.gz
Algorithm Hash digest
SHA256 fd4b0f8829c7ec2ae6997dc9dc3f7fa8cd3b265141dd6bd50ca650acee987db0
MD5 f31cc2074d01b8cdb6658a5086aa37f1
BLAKE2b-256 c802947ca62a67e24b0689378ed5a098caa188b2e35f5de5ea6fd5ac21d4a8c1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: curryparty-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29631843790f0c5f29af1d37cd2f404b10ddba32e24d5e0ee63537cea0efbe3f
MD5 ed21e2f08a3a516043cd5fbba2f728d9
BLAKE2b-256 b36455c466401857035d9f3e3528a9ca962b7f6fa073e60c86d51c688c8fc0c2

See more details on using hashes here.

Provenance

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