λ-Calculus

Notation

Externally a fairly standard notation is used, as would be familiar to someone using a textbook to study λ-calculus, or as close as we can get without using unicode. I would like to use the unicode 'λ' symbol to represent lambda in FriCAS I/O in many cases this would work fine but there are some consoles and lisps that don't support unicode so, for now, I have held off doing this for maximum compatibility.

I have therefore used the '\' symbol to stand for λ.

Internally the domain stores bound variables using De Bruijn index, in most cases this should not concern the user as I/O uses string names for variables. Converting bound variables internally to index values means that the same variable name can be used, in different lambda terms, without ambiguity and without the need for α-substitution.

De Bruijn index which is a integer where

0=inside current (inner) lambda term

1= next outer lambda term

2= next outer and so on

...

We will see how this works in the tutorial below.

So internally the λ-calculus is stored as a binary tree structure using the following syntax:

<term> ::= "\" var "."<term> | n | <term><term> | "("<term>")"

where:

\ = λ

n = De Bruijn index which is a integer where, 0=inside inner lambda term, 1= next outer lambda term, 2= next outer and so on.

var = a string representation of variable (this form is used for unbound variables)

brackets can be used around whole terms.

Tutorial

If you are working with a version of FriCAS before 1.1.3 then the Lambda domain needs to be installed on your system, for later versions its already installed. The source code is in a file called computation.spad, which is available here:

Constructors

First we can enter some variables, at the moment they are not inside a λ-term so they can't yet be bound, but later we can put them into a λ-term..

A numeric name is interpreted as a De Bruijn index when put inside a λ-term, although we don't need this notation for I/O unless we are trying to avoid some ambiguity, because free and bound variables can be constructed by giving the variable name as a string. So in (4) is not yet a vaild term on its own but it will be when put inside a λ-term, when this is done it will be given the name of the bound variable rather than "0".

Internally a string name will be converted to a De Bruijn index when put inside a matching λ-term, otherwise it will be interpreted as a free variable.

In (7) 'x' is a the bound variable and so, when the λ-term was created, this will be converted to De Bruijn index, in (7) we call toString to see the internal representation:

In (8) we see that when entered as a numeric index the bound variable will still be displayed as a string.

In (9) and (10) we can see that the 'unbind' function can be used to unbind the bound variable 'x' that is, although 'x' has the same string value as the lambda term, it is treated as though it were different. We can see this because the toString output does not have a index value. In (11) we call 'bind' to re-bind it.

So we can already construct any type of lambda term, however its a bit tedious to construct complex lambda terms in this way, an easier way is to use 'parseLambda' to construct the lambda term from a string. Again we can enter variables as either alpha or numeric characters depending on whether we want to specify the index value directly or allow the code to generate it.

In (14) we can see the use of numeric terms to avoid the ambiguity caused by nested λ-terms with the same name.

Issues

I realise that Axiom/FriCAS already has a way to create anonymous functions using +-> in a λ-calculus sort of way. But the aim here is to represent λ-calculus as a pure mathematical structure so that we can experiment with the properties of this structure without the messy features that are required for a practical computer language. I also need a domain structure which is related to SKI combinators and IntuitionisticLogic domain and can be coerced to and from these other domain types as demonstrated on this page.

I also realise that this is written in SPAD which is written in Lisp which is based on λ-Calculus (perhaps it could later be optimised by having direct calls to Lisp?)

Relationship to Other Domains

λ-calculus can be coerced to and from SKI combinators. For a tutorial about how to coerce to/from this algebra see this page.

This page discusses implementing λ-Calculus using Axiom/FriCAS which is a Computer Algebra System. These are part of a series of pages (starting here) where we discuss implementing computer related structures in Axiom/FriCAS.

Computer Algebra Systems

On this page I have put some information about computer algebra systems and in particular Axiom/FriCAS.

Related Topics

Other Code

This is one of a series of pages describing code that I have written for FriCAS. Some of this code has already been included with the FriCAS library and so can be used as soon as FriCAS is installed (as described here). Other code on these pages is not yet included with FriCAS and so would have to be compiled from within FriCAS. For an overview of all the code I have written, on various topics, see page here.

See also

I also have Axiom/FriCAS coding for SKI combinators, as explained on this page, where there is explanation and tutorial.

For a tutorial about how to coerce λ-calculus to/from SKI combinators see this page.

Axiom/Fricas Information on this Site

Here are some of the pages I have written to discuss the things I have found while experimenting with the use of Axiom/Fricas to compute mathematics.

Writing Logic Code Using a CAS Program

This page discusses how to write a program to implement logic, lattices, partial orders, etc. using Axiom/FriCAS open source program.

SPAD Language

Although the Axiom/FriCAS computer algebra system is written in Lisp, users of the program don't need to know Lisp. The SPAD (a contraction of Scratchpad) language is used when we want to implement custom algebras and mathematical structures.