Agda (theorem prover)
   HOME

TheInfoList



OR:

Agda is a dependently typed
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
language originally developed by Ulf Norell at
Chalmers University of Technology Chalmers University of Technology ( sv, Chalmers tekniska högskola, often shortened to Chalmers) is a Swedish university located in Gothenburg that conducts research and education in technology and natural sciences at a high international leve ...
with implementation described in his PhD thesis. The original Agda system was developed at Chalmers by Catarina Coquand in 1999. The current version, originally known as Agda 2, is a full rewrite, which should be considered a new language that shares a name and tradition. Agda is also a proof assistant based on the propositions-as-types paradigm, but unlike
Coq Coq is an interactive theorem prover first released in 1989. It allows for expressing mathematical assertions, mechanically checks proofs of these assertions, helps find formal proofs, and extracts a certified program from the constructive proof ...
, has no separate
tactics Tactic(s) or Tactical may refer to: * Tactic (method), a conceptual action implemented as one or more specific tasks ** Military tactics, the disposition and maneuver of units on a particular sea or battlefield ** Chess tactics ** Political tact ...
language, and proofs are written in a functional programming style. The language has ordinary programming constructs such as data types,
pattern matching In computer science, pattern matching is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact: "either it will or will not be ...
,
records A record, recording or records may refer to: An item or collection of data Computing * Record (computer science), a data structure ** Record, or row (database), a set of fields in a database related to one entity ** Boot sector or boot record, r ...
, let expressions and modules, and a
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
-like syntax. The system has Emacs and
Atom Every atom is composed of a nucleus and one or more electrons bound to the nucleus. The nucleus is made of one or more protons and a number of neutrons. Only the most common variety of hydrogen has no neutrons. Every solid, liquid, gas, ...
interfaces but can also be run in batch mode from the command line. Agda is based on Zhaohui Luo's unified theory of dependent types (UTT), a type theory similar to Martin-Löf type theory. Agda is named after the
Swedish Swedish or ' may refer to: Anything from or related to Sweden, a country in Northern Europe. Or, specifically: * Swedish language, a North Germanic language spoken primarily in Sweden and Finland ** Swedish alphabet, the official alphabet used by ...
song "Hönan Agda", written by Cornelis Vreeswijk, which is about a
hen Hen commonly refers to a female animal: a female chicken, other gallinaceous bird, any type of bird in general, or a lobster. It is also a slang term for a woman. Hen or Hens may also refer to: Places Norway *Hen, Buskerud, a village in Ringer ...
named Agda. This alludes to the naming of
Coq Coq is an interactive theorem prover first released in 1989. It allows for expressing mathematical assertions, mechanically checks proofs of these assertions, helps find formal proofs, and extracts a certified program from the constructive proof ...
.


Features


Inductive types

The main way of defining data types in Agda is via inductive data types which are similar to
algebraic data type In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite type, i.e., a type formed by combining other types. Two common classes of algebraic types are product types (i.e., ...
s in non-dependently typed programming languages. Here is a definition of Peano numbers in Agda: data ℕ : Set where zero : ℕ suc : ℕ → ℕ Basically, it means that there are two ways to construct a value of type \mathbb, representing a natural number. To begin, zero is a natural number, and if n is a natural number, then suc n, standing for the
successor Successor may refer to: * An entity that comes after another (see Succession (disambiguation)) Film and TV * ''The Successor'' (film), a 1996 film including Laura Girling * ''The Successor'' (TV program), a 2007 Israeli television program Musi ...
of n, is a natural number too. Here is a definition of the "less than or equal" relation between two natural numbers: data _≤_ : ℕ → ℕ → Set where z≤n : → zero ≤ n s≤s : → n ≤ m → suc n ≤ suc m The first constructor, z≤n, corresponds to the axiom that zero is less than or equal to any natural number. The second constructor, s≤s, corresponds to an inference rule, allowing to turn a proof of n ≤ m into a proof of suc n ≤ suc m. So the value s≤s (z≤n ) is a proof that one (the successor of zero), is less than or equal to two (the successor of one). The parameters provided in curly brackets may be omitted if they can be inferred.


Dependently typed pattern matching

In core type theory, induction and recursion principles are used to prove theorems about inductive types. In Agda, dependently typed pattern matching is used instead. For example, natural number addition can be defined like this: add zero n = n add (suc m) n = suc (add m n) This way of writing recursive functions/inductive proofs is more natural than applying raw induction principles. In Agda, dependently typed pattern matching is a primitive of the language; the core language lacks the induction/recursion principles that pattern matching translates to.


Metavariables

One of the distinctive features of Agda, when compared with other similar systems such as
Coq Coq is an interactive theorem prover first released in 1989. It allows for expressing mathematical assertions, mechanically checks proofs of these assertions, helps find formal proofs, and extracts a certified program from the constructive proof ...
, is heavy reliance on metavariables for program construction. For example, one can write functions like this in Agda: add : ℕ → ℕ → ℕ add x y = ? ? here is a metavariable. When interacting with the system in emacs mode, it will show the user expected type and allow them to refine the metavariable, i.e., to replace it with more detailed code. This feature allows incremental program construction in a way similar to tactics-based proof assistants such as Coq.


Proof automation

Programming in pure type theory involves a lot of tedious and repetitive proofs. Although Agda has no separate tactics language, it is possible to program useful tactics within Agda itself. Typically, this works by writing an Agda function that optionally returns a proof of some property of interest. A tactic is then constructed by running this function at type-checking time, for example using the following auxiliary definitions: data Maybe (A : Set) : Set where Just : A → Maybe A Nothing : Maybe A data isJust : Maybe A → Set where auto : ∀ → isJust (Just x) Tactic : ∀ (x : Maybe A) → isJust x → A Tactic Nothing () Tactic (Just x) auto = x Given a function check-even : (n : \mathbb) → Maybe (Even n) that inputs a number and optionally returns a proof of its evenness, a tactic can then be constructed as follows: check-even-tactic : → isJust (check-even n) → Even n check-even-tactic = Tactic (check-even n) lemma0 : Even zero lemma0 = check-even-tactic auto lemma2 : Even (suc (suc zero)) lemma2 = check-even-tactic auto The actual proof of each lemma will be automatically constructed at type-checking time. If the tactic fails, type-checking will fail. Additionally, to write more complex tactics, Agda has support for automation via
reflection Reflection or reflexion may refer to: Science and technology * Reflection (physics), a common wave phenomenon ** Specular reflection, reflection from a smooth surface *** Mirror image, a reflection in a mirror or in water ** Signal reflection, in ...
. The reflection mechanism allows one to quote program fragments into – or unquote them from – the abstract syntax tree. The way reflection is used is similar to the way Template Haskell works. Another mechanism for proof automation is proof search action in emacs mode. It enumerates possible proof terms (limited to 5 seconds), and if one of the terms fits the specification, it will be put in the meta variable where the action is invoked. This action accepts hints, e.g., which theorems and from which modules can be used, whether the action can use pattern matching, etc.


Termination checking

Agda is a total language, i.e., each program in it must terminate and all possible patterns must be matched. Without this feature, the logic behind the language becomes inconsistent, and it becomes possible to prove arbitrary statements. For termination checking, Agda uses the approach of the Foetus termination checker.Abel, Andreas. "foetus – Termination checker for simple functional programs." ''Programming Lab Report'' 474 (1998).


Standard library

Agda has an extensive de facto standard library, which includes many useful definitions and theorems about basic data structures, such as natural numbers, lists, and vectors. The library is in beta, and is under active development.


Unicode

One of the more notable features of Agda is a heavy reliance on
Unicode Unicode, formally The Unicode Standard,The formal version reference is is an information technology standard for the consistent encoding, representation, and handling of text expressed in most of the world's writing systems. The standard, wh ...
in program source code. The standard emacs mode uses shortcuts for input, such as \Sigma for Σ.


Backends

There are two compiler backends, MAlonzo for Haskell and one for
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
.


See also

*
List of proof assistants In computer science and mathematical logic, a proof assistant or interactive theorem prover is a software tool to assist with the development of formal proofs by human-machine collaboration. This involves some sort of interactive proof editor ...


References


Further reading

* *


External links

*
Introduction to Agda
a five-part YouTube playlist by Daniel Peebles
Brutal Introduction to Dependent Types in Agda


{{Projects at Chalmers University of Technology Programming languages Dependently typed languages Functional languages Pattern matching programming languages Academic programming languages Statically typed programming languages Proof assistants Free software programmed in Haskell Haskell programming language family Cross-platform free software Free compilers and interpreters Chalmers University of Technology Programming languages created in 2007 2007 software