1
0
Fork
You've already forked lambda-calculus
0
An interpreter for the lambda calculus
  • Common Lisp 100%
Find a file
2017年10月21日 13:40:53 +02:00
basic-functions.lisp Add the theta combinator 2017年10月21日 13:40:53 +02:00
lambda-calculus.asd Version 1.1 2016年12月20日 13:49:39 +01:00
lambda-calculus.lisp Accept variable names not made only of characters and digits 2017年10月21日 13:39:23 +02:00
LICENSE lambda-calculus 2016年11月25日 20:49:50 +01:00
README.org lambda-calculus 2016年11月25日 20:49:50 +01:00
test.lisp Add len and append functions. 2016年12月02日 19:03:42 +01:00

lambda-calculus, an interpreter for the lambda calculus

Description

This program is an interpreter for the pure lambda calculus.

The lambda terms have the following format:

  • A, where A is a symbol (alpha characters)
  • (B C), where B and C are lambda terms
  • (lambda D E), where D is a symbol and E is a lambda term

The beta-reduce function takes a lambda term and reduces it to its normal form using the beta-reduction rule.

The are-alpha-equivalent function takes two lambda terms and indicates if they are equivalent with regard to alpha-conversion.

Examples

The basic-functions.lisp file contains the Church encodings of a few basic functions (logic, arithmetic, pairs, Y combinator).

Load the interpreter and the basic functions:

(load "lambda-calculus")
(load "basic-functions")

A few examples:

(lambda-calculus:beta-reduce '(lambda a (lambda b a)))
-> (LAMBDA A (LAMBDA B A))
(lambda-calculus:beta-reduce '((lambda a (lambda b a)) x)
-> (LAMBDA B X)
(lambda-calculus:beta-reduce true.)
-> (LAMBDA A (LAMBDA B A))
(lambda-calculus:beta-reduce false.)
-> (LAMBDA A (LAMBDA B B))
(lambda-calculus:beta-reduce one.)
-> (LAMBDA F (LAMBDA X (F X)))
(lambda-calculus:beta-reduce `(,inc. ,one.))
-> (LAMBDA F (LAMBDA X (F (F X))))
(lambda-calculus:beta-reduce `((,eq. (,inc. ,one.)) ,two.))
-> (LAMBDA A (LAMBDA B A))
(lambda-calculus:are-alpha-equivalent '(lambda x x) '(lambda y y))
-> T
(lambda-calculus:are-alpha-equivalent '(lambda x (x y)) '(lambda y x))
-> NIL
(lambda-calculus:are-alpha-equivalent '(lambda x (lambda y (x y)))
 '(lambda y (lambda x (y x))))
-> T
(lambda-calculus:are-alpha-equivalent '(lambda x (lambda y (x y)))
 '(lambda y (lambda x (x y))))
-> NIL