Skip to content

noti0na1/LambdaCalculus-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

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

How To Use

First you need to add lambda-calculus.jar to your project libraries. You could find it at release. 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.

public class ExampleUse extends Lambda {
    // use it!
}

Example

// 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

TODO

  • add more comments
  • add documents
  • ...

Report A Problem

Feel free to report mistakes I made or give suggestions at GitHub Issue.

I am also glad to talk about lambda with me.