Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deric-w/lambda_calculus
Python package for the lambda calculus
https://github.com/deric-w/lambda_calculus
education lambda-calculus python3
Last synced: 22 days ago
JSON representation
Python package for the lambda calculus
- Host: GitHub
- URL: https://github.com/deric-w/lambda_calculus
- Owner: Deric-W
- License: gpl-3.0
- Created: 2022-08-22T17:59:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-20T03:59:15.000Z (3 months ago)
- Last Synced: 2025-01-09T08:59:32.247Z (about 1 month ago)
- Topics: education, lambda-calculus, python3
- Language: Python
- Homepage: https://lambda-calculus.readthedocs.io/
- Size: 140 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lambda_calculus
[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)
![Tests](https://github.com/Deric-W/lambda_calculus/actions/workflows/Tests.yaml/badge.svg)
[![codecov](https://codecov.io/gh/Deric-W/lambda_calculus/branch/main/graph/badge.svg?token=SU3982mC17)](https://codecov.io/gh/Deric-W/lambda_calculus)
[![Documentation Status](https://readthedocs.org/projects/lambda-calculus/badge/?version=stable)](https://lambda-calculus.readthedocs.io/en/stable/?badge=stable)The [`lambda_calculus`](https://pypi.org/project/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](https://lambda-calculus.readthedocs.io/).
## 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
```sh
python3 -m pip install lambda-calculus
```## Examples
(λy.(λx.(λy. + x y)) y 3) 4
### Nesting
```python
from lambda_calculus import Variable, Abstraction, Applicationterm = 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
```python
from lambda_calculus import Variable, Abstraction, Applicationx = 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
```python
from lambda_calculus import Variable, Abstraction, Applicationx = 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
```python
from lambda_calculus import Variable, Application
from lambda_calculus.visitors.normalisation import BetaNormalisingVisitorassert BetaNormalisingVisitor().skip_intermediate(term) == Application.with_arguments(
Variable("+"),
(Variable("4"), Variable("3"))
)
```