Gödel is a declarative, general-purpose programming language that adheres to the logic programming paradigm. It is a strongly typed language, the type system being based on many-sorted logic with parametric polymorphism. It is named after logician Kurt Gödel.
Features
Gödel has a module system, and it supports arbitrary precision integers, arbitrary precision rationals, and also floating-point numbers. It can solve constraints over finite domains of integers and also linear rational constraints. It supports processing of finite sets. It also has a flexible computation rule and a pruning operator which generalises the commit of the concurrent logic programming languages.
Gödel's meta-logical facilities provide support for meta-programs that do analysis, transformation, compilation, verification, and debugging, among other tasks.
Sample code
The following Gödel module is a specification of the greatest common divisor (GCD) of two numbers. It is intended to demonstrate the declarative nature of Gödel, not to be particularly efficient.
The <code>CommonDivisor</code> predicate says that if <code>i</code> and <code>j</code> are not zero, then <code>d</code> is a common divisor of <code>i</code> and <code>j</code> if it lies between <code>1</code> and the smaller of <code>i</code> and <code>j</code> and divides both <code>i</code> and <code>j</code> exactly.
The <code>Gcd</code> predicate says that <code>d</code> is a greatest common divisor of <code>i</code> and <code>j</code> if it is a common divisor of <code>i</code> and <code>j</code>, and there is no <code>e</code> that is also a common divisor of <code>i</code> and <code>j</code> and is greater than <code>d</code>.
MODULE GCD.
IMPORT Integers.
PREDICATE Gcd : Integer * Integer * Integer.
Gcd(i,j,d) <-
CommonDivisor(i,j,d) &
~ SOME [e] (CommonDivisor(i,j,e) & e > d).
PREDICATE CommonDivisor : Integer * Integer * Integer.
CommonDivisor(i,j,d) <-
IF (i = 0 \/ j = 0)
THEN
d = Max(Abs(i),Abs(j))
ELSE
1 =< d =< Min(Abs(i),Abs(j)) &
i Mod d = 0 &
j Mod d = 0.
External links
- https://web.archive.org/web/20091207092823/http://www.scs.leeds.ac.uk/hill/GOEDEL/expgoedel.html
- https://mitpress.mit.edu/9780262519151/the-godel-programming-language/
