Implementation of the Lambda calculus
Project description
lambda_calculus
The lambda_calculus
package contains classes which implement basic operations of the lambda calculus.
To use it, simply import the classes Variable
, Abstraction
and Application
from this package
and nest them to create more complex lambda terms.
You can also use the visitors
subpackage to define your own operations on terms or
use predefined ones from the terms
subpackage.
More information is available on Read the Docs.
Notice
This package is intended to be used for educational purposes and is not optimized for speed.
Furthermore, it expects all terms to be finite, which means the absence of cycles.
RecursionError
may be raised if the visitors get passed an infinite term or the evaluation is too complex.
Requirements
Python >= 3.10 is required to use this package.
Installation
python3 -m pip install lambda-calculus
Examples
(λy.(λx.(λy. + x y)) y 3) 4
Nesting
from lambda_calculus import Variable, Abstraction, Application
term = Application(Variable("+"), Variable("x"))
term = Application(term, Variable("y"))
term = Abstraction("y", term)
term = Abstraction("x", term)
term = Application(term, Variable("y"))
term = Application(term, Variable("3"))
term = Abstraction("y", term)
term = Application(term, Variable("4"))
Utility Methods
from lambda_calculus import Variable, Abstraction, Application
x = Variable.with_valid_name("x")
y = Variable.with_valid_name("y")
term = Application.with_arguments(Variable.with_valid_name("+"), (x, y))
term = Abstraction.curried(("x", "y"), term)
term = Application.with_arguments(term, (y, Variable.with_valid_name("3")))
term = Abstraction("y", term)
term = Application(term, Variable.with_valid_name("4"))
Method Chaining
from lambda_calculus import Variable, Abstraction, Application
x = Variable.with_valid_name("x")
y = Variable.with_valid_name("y")
term = Variable("+") \
.apply_to(x, y) \
.abstract("x", "y") \
.apply_to(y, Variable("3")) \
.abstract("y") \
.apply_to(Variable("4"))
Evaluation
from lambda_calculus import Variable, Application
from lambda_calculus.visitors.normalisation import BetaNormalisingVisitor
assert BetaNormalisingVisitor().skip_intermediate(term) == Application.with_arguments(
Variable("+"),
(Variable("4"), Variable("3"))
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lambda_calculus-3.1.0.tar.gz
.
File metadata
- Download URL: lambda_calculus-3.1.0.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11346feda8f8340f597f1f11894711fc5787afc48b413a2b838611ea6b0f43ec |
|
MD5 | 40b623797fd375941ed9b69c231c2b2b |
|
BLAKE2b-256 | 1d8a3cec317310fb60a1897c2810da391c6c1c380d3f6c4475e0e69db0fe2b9c |
File details
Details for the file lambda_calculus-3.1.0-py3-none-any.whl
.
File metadata
- Download URL: lambda_calculus-3.1.0-py3-none-any.whl
- Upload date:
- Size: 30.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a5dadd3598645c08f1f21d770015000b5cd0aab19f3c341313fe7f8babfa9e |
|
MD5 | 7917d9307cb218e35e3bb43092665298 |
|
BLAKE2b-256 | 80f90e24b641329e6945b082a739c2a8e3c34fe7335bcc16e2d0d9386d5e03d0 |