Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Gödel (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)