https://github.com/noti0na1/lambdacalculus-java
Lambda calculus implemented in Java
https://github.com/noti0na1/lambdacalculus-java
computer-science java lambda lambda-calculus utlc
Last synced: 3 months ago
JSON representation
Lambda calculus implemented in Java
- Host: GitHub
- URL: https://github.com/noti0na1/lambdacalculus-java
- Owner: noti0na1
- License: apache-2.0
- Created: 2016-11-20T02:57:40.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-07T04:46:51.000Z (over 8 years ago)
- Last Synced: 2025-03-19T02:11:29.266Z (4 months ago)
- Topics: computer-science, java, lambda, lambda-calculus, utlc
- Language: Java
- Size: 21.5 KB
- Stars: 20
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lambda Calculus in Java
A library implementing lambda calculus in Java
[TOC]
## Information
Lambda calculus (also written as λ-calculus) is a formal system in
mathematical logic for expressing computation based on function
abstraction and application using variable binding and substitution
(wikipedia).* What is Lambda Calculus: https://en.wikipedia.org/wiki/Lambda_calculus
* More materials: [A Tutorial Introduction to the Lambda Calculus](www.inf.fu-berlin.de/lehre/WS03/alpi/lambda.pdf)
I write this library in order to understand lambda calculus deeper and,
meanwhile, recall how to white Java.## Features
* Easy to write lambda expression
* It can reduce expression in one step or fully
* All expression can be pretty-printed
* Arithmetic, logic and pairs are implemented in [com.notnl.lambda.examples](https://github.com/noti0na1/LambdaCalculus-java/tree/master/src/com/notnl/lambda/example)## How To Use
First you need to add lambda-calculus.jar to your project libraries. You
could find it at
[release](https://github.com/noti0na1/LambdaCalculus-java/releases).
You can build it from the source as well.The best way to create lambda expression is to extend the
com.notnl.lambda.Lambda class and use its handy functions directly.```java
public class ExampleUse extends Lambda {
// use it!
}
```## Example
```java
// create a variable x
Expression x = var("x");
System.out.println("x = " + x.toString());// create a function
Expression fun = λ("x", apply(λ("x", apply("f", "x")), "x"));
// λx.(λx.f x) x
System.out.println("fun = " + fun.toString());
// λx.f x
System.out.println("fun (reduced) = " + fun.reduce().toString());// apply this function
Expression app = apply(fun, "z");
// (λx.(λx.f x) x) z
System.out.println("app = " + app.toString());
// f z
System.out.println("app (fully reduced) = " + app.deepReduce().toString());
// print reduce steps
// or app.printReduceSteps(2) to print certain steps
app.printReduceSteps();
// (λx.(λx.f x) x) ((λx.x) z)
// (λx.f x) ((λx.x) z)
// (λx.f x) z
// f z
```See more examples in [com.notnl.lambda.examples](https://github.com/noti0na1/LambdaCalculus-java/tree/master/src/com/notnl/lambda/example)
## TODO
* add more comments
* add documents
* ...## Report A Problem
Feel free to report mistakes I made or give suggestions at [GitHub Issue](https://github.com/noti0na1/LambdaCalculus-java/issues).
I am also glad to talk about lambda with me.