Skip to content

Commit 1bcf673

Browse files
Savagely cut for length. Not quite there yet but a lot closer
1 parent 30f9930 commit 1bcf673

File tree

1 file changed

+59
-82
lines changed

1 file changed

+59
-82
lines changed

paper/paper.md

Lines changed: 59 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -92,36 +92,28 @@ bibliography: paper.bib
9292
# Summary
9393

9494
Agda [@agda2024manual] is a dependently-typed functional
95-
language that serves both as a traditional programming language
96-
and as an interactive theorem prover (ITP).
97-
In other words, its type system is expressive enough to formulate
98-
complex formal requirements on programs as types, and its compiler allows users to interactively build terms and check that they satisfy these requirements.
99-
Through the Curry-Howard lens [@DBLP:journals/cacm/Wadler15],
100-
these types and terms can be seen respectively as theorem
101-
statements and proofs.
95+
language that serves as both a programming language
96+
and an interactive theorem prover (ITP).
97+
More precisely, one can formulate requirements on programs as types, and building programs satisfying these requirements is performed in a fundamentally interactive manner.
98+
The Curry-Howard lens [@DBLP:journals/cacm/Wadler15], types and terms can be seen as theorems and their proofs.
10299

103-
This paper presents the Agda standard library [@agda-stdlib-v2.0], hereafter referred to as `agda-stdlib`, which provides definitions intended to be helpful for users to develop Agda programs and proofs.
104-
Unlike the standard libraries of traditional programming languages, `agda-stdlib` provides not only standard utilities and data structures, but also a range of basic discrete mathematics useful for proving the correctness of programs.
100+
We present the Agda standard library [@agda-stdlib-v2.0], hereafter referred to as `agda-stdlib`, which provides definitions intended to be generally helpful in developments of programs and proofs.
101+
Unlike standard libraries of traditional programming languages, `agda-stdlib` provides not only standard utilities and data structures, but also a range of basic discrete mathematics useful for proving the correctness of programs.
105102

106103
# Statement of need
107104

108-
Most programming languages include a "standard" library offering a basic set of algorithms, data structures, and operating system procedures.
109-
However, there are two reasons why a standard library is particularly significant for Agda compared to traditional programming languages.
105+
There are two reasons why a standard library for Agda is different than for traditional languages.
110106

111-
First, like other theorem provers, the Agda language provides only a small set of primitives from which programs can be constructed.
112-
As a result, many concepts traditionally considered part of a language must be defined within the program itself.
113-
This approach reduces compiler complexity and enhances its reliability, and also demonstrates the strength of the core Agda language as it can push these concepts out to the library.
114-
For example, in a fresh Agda environment, there is no predefined notion of an integer, let alone more complex data structures such as vectors or maps.
115-
This lack of basic data types increases the need for a standard library when compared to more mainstream languages.
107+
First, Agda's language is small but sufficient to define many concepts usually considered part of a language (such
108+
as the notion of an integer).
109+
This reduces compiler complexity. But it increases the need for a standard library.
116110

117-
Second, Agda users often seek to prove that programs constructed using data types in the standard library are "correct."
118-
Constructing the proof that a function obeys a specification (e.g. that a sorting function outputs a permutation of the original list in non-decreasing order) often requires more effort, both in terms of lines of code and in developer time, than writing the original operation.
119-
By providing proofs of correctness for operations it defines, the standard library saves users significant time during proof development.
111+
Second, as correctness is an important goal of most Agda users, it is important that functions provided by `agda-stdlib` come with correctness guarantees. Such proofs often require significant effort which should not be downloaded to users.
120112

121113
# Impact
122114

123115
A wide range of projects make use of `agda-stdlib`.
124-
In the list below we present a selection of such projects:
116+
Here is a selection:
125117

126118
- Programming Language Foundations in Agda [@plfa22.08]
127119

@@ -135,91 +127,76 @@ In the list below we present a selection of such projects:
135127

136128
- Verification of routing protocols [@daggitt2023routing]
137129

138-
The library has also been used as a test bed for the design of co-inductive data types in Agda itself, as evidenced by the three different notions of co-inductive data present in the library.
139-
On occasion, the development of `agda-stdlib` has also had a synergistic relationship with that of Agda itself, prompting the implementation of several new language features, which we now discuss.
140-
Firstly, Agda is a research compiler supporting a wide range of possibly incompatible language extensions via command line options.
130+
`agda-stdlib` has also been used as a test bed for the design of co-inductive data types in Agda itself, resulting having in three different notions.
131+
132+
The development of `agda-stdlib` has also had a synergistic relationship with that of Agda itself, prompting new language features.
133+
Firstly, Agda supports a wide range of possibly incompatible language extensions.
141134
Examples include `--cubical` (changing the underlying type theory to cubical type theory [@DBLP:journals/jfp/VezzosiMA21]),
142-
`--with-K` (adding support for Streicher's axiom K [@streicher1993investigations], a reasoning principle incompatible with the `--cubical`-enabled type theory),
135+
`--with-K` (adding support for Streicher's axiom K [@streicher1993investigations], with incompatible with the `--cubical`-enabled type theory),
143136
or `--safe` (an ITP-oriented option enforcing that nothing is postulated and disabling parts of the FFI mechanism).
144-
In order for `agda-stdlib` to be compatible with as many different compiler options as possible, we designed the library to be broken into units
137+
In order for `agda-stdlib` to be compatible with as many different variants as possible, we designed the library in units
145138
requesting the minimal expressive power needed.
146-
To enable this, in 2019 Agda's language options were categorised as "infective", "coinfective" or "neither".
147-
Once used in a module, an "infective" option will impact all the import*ing* modules; these are typically for theory-changing options such as `--with-K`.
148-
On the contrary, "coinfective" options affect the import*ed* modules; these are typically for options adding extra safety checks like `--safe`.
149-
This categorisation enables libraries to integrate safe Agda code with code that uses "unsafe" operating system calls, while maintaining the safety guarantees of the former.
150-
Another feature motivated by the development of `agda-stdlib` is the ability to attach custom messages to definitions, which are then displayed by the compiler when the definitions are used.
151-
This allowed for the implementation of deprecation warnings, making it easier for users to evolve their code alongside new versions of `agda-stdlib`.
152-
153-
# Design
154-
155-
Designing a standard library for an ITP such as Agda presents several challenges.
156-
157-
Firstly, `agda-stdlib` contains basic discrete mathematics and algebra useful for proving program correctness.
158-
Organising this material into a coherent and logical structure is difficult, although some recent efforts have looked at generating such structure mechanistically [@carette2020leveraging] [@cohen2020hierarchy].
159-
For `agda-stdlib` there is a tension between organising the material to be as general as possible (e.g., defining subtraction using addition and inverse over some abstract algebraic structure) and providing direct and intuitive definitions (e.g., defining subtraction directly over integers).
160-
Additionally, there is the temptation to introduce new representations of existing mathematical objects that are easier to work with for a particular application, which can come at the potential cost of redundancy/duplication.
161-
Some theorem provers such as Rocq [@coq2024manual] have a rich ecosystem of external libraries, which reduces the emphasis on ensuring the existence of canonical definitions for common concepts, at the slightly increased risk of incompatibilities between various libraries.
162-
On the other hand, `batteries` and `mathlib` [@van2020maintaining] for Lean provide a repository of canonical definitions.
163-
Philosophically, `agda-stdlib` is more closely aligned with the approach of the MathLib library, and our aim is to provide canonical definitions for mathematical objects and introduce new representations only sparingly.
164-
165-
A second challenge is that `agda-stdlib` has embraced the "intrinsic style" of dependent types, in which correctness-related invariants are part of data structures, rather than separate predicates.
166-
Many definitions in `agda-stdlib` use this intrinsic style.
167-
For instance, the final definition of rational numbers is a record type that alongside the numerator and denominator contains a proof showing that the numerator and denominator have no common factors.
168-
The intrinsic style also includes returning proofs rather than, say, booleans from decision procedures.
169-
The standard library for instance uses this approach for its implementation of regular expression matching which along with the match returns a proof justifying it.
170-
Learning how to design a large library that uses this style is an ongoing journey, and we believe that `agda-stdlib` has been one of the first standard libraries to tackle this challenge.
171-
172-
Another significant influence on the design of `agda-stdlib` is Agda’s module system [@ivardeBruin2023] which supports lists of parameters whose types are dependent on the value of parameters earlier in the list.
173-
Several functional languages, such as Haskell [@haskell2010], and ITP libraries, like Lean's MathLib, use type classes as the primary mechanism for ad-hoc polymorphism and overloaded syntax.
174-
While Agda supports an alternative to type-classes known as instance arguments [@devriese2011bright] [@agda2024manual], we have found that the use of qualified, parameterised modules can reproduce most of the abstraction capabilities of instances and type-classes.
175-
The benefits of using parameterised modules instead of type-classes is that it allows users to specify in a single location how to instantiate all the uses of the abstract module parameters and reduces the overhead of instance search at type-checking time.
176-
A drawback is that users may sometimes need to use qualified imports or other similar mechanisms when instantiating the abstract code twice in the same scope.
177-
Another benefit of parameterised modules in the design of `agda-stdlib`, is that they have facilitated the safe and scalable embedding of non-constructive mathematics into what is primarily a constructive library.
178-
Non-constructive operations, such as classical reasoning, can be made available by passing the operations as parameters to the current module, allowing code access to them throughout the module.
179-
This enables users to write non-constructive code, without either having to postulate axioms incompatible with the `--safe` flag, or explicitly pass them through as arguments to every function in the module.
139+
Thus Agda's language options were categorised as "infective", "coinfective" or "neither".
140+
"infection" options impact all the import*ing* modules (example: `--with-K`).
141+
"coinfective" options affect the import*ed* modules (example: `--safe`).
142+
Another feature motivated by of `agda-stdlib` is attaching custom messages to definitions, displayed on use.
143+
This enabled deprecation warnings, easing the evolution of user code.
144+
145+
# Design Challenges
146+
147+
Organising libraries of discrete mathematics and algebra into a coherent and logical structure is notoriously difficult
148+
[@carette2020leveraging] [@cohen2020hierarchy].
149+
There is a tension between organising the material to be as general as possible and providing direct and intuitive definitions.
150+
Mathematical objects often permit multiple representations with varying application-specific usability profiles -- but this leads to redundancy/duplication.
151+
Some theorem provers ([@coq2024manual], [@paulson1994isabelle]) choose instead to have a rich ecosystem of external libraries, reducing the pressure to have canonical definitions for common concepts at the risk of incompatibilities between libraries.
152+
We have chosen, like Lean's `mathlib` [@van2020maintaining], to provide a repository of canonical definitions.
153+
154+
`agda-stdlib` has embraced the "intrinsic style" of dependent types, in which correctness invariants are part of the data structures themselves.
155+
For instance, the definition of rational numbers carries a proof showing that the numerator and denominator have no common factors.
156+
The intrinsic style also means returning proofs from decision procedures rather than booleans.
157+
We believe that `agda-stdlib` has been one of the first standard libraries to tackle this challenge.
158+
159+
Agda's parametrized modules which also embrace dependent types [@ivardeBruin2023] are used heavily.
160+
This contrasts with other language which instead rely on type classes for similar functionality.
161+
This lets users specify in a single location how to instantiate all the abstract module parameters and reduces the overhead of instance search.
162+
A drawback is the need for qualified imports when instantiating code twice in the same scope.
163+
Another benefit is ability to safely and scalably embed non-constructive mathematics into a primarily constructive library.
180164

181165
# Testing
182166

183-
Many of the core operations in `agda-stdlib` are accompanied by correctness proofs, and consequently the need for test suites that verify functional correctness is reduced.
184-
However there are tests for two critical areas.
185-
Firstly, it is possible to write code in Agda that cannot be reasoned about directly within Agda itself, e.g. functions that use the foreign function interface and tactics that use Agda macros. Therefore, tests for such code are included in the library's test suite.
186-
Secondly, performance of type-checking and compiled code cannot be analysed inside Agda itself, and so the library includes tests that can be used to reveal regressions in performance.
187-
Having said this, the test suite's coverage in these two areas is not complete as this has not yet been a major priority for the community.
167+
Correctness proofs do not entirely obviate the need for testing.
168+
There are tests for two critical areas: first functions that use features that cannot be reasoned about internally (such as the FFI and tactics implemented as macros); second, performance tests.
169+
However the test suite's coverage is incomplete as this is not a priority for the community.
188170

189171
# Notable improvements in version 2.0
190172

191-
Finally, we will briefly discuss the state of `agda-stdlib` version 2.0 [@agda-stdlib-v2.0] for which HTML-annotated sources are available at \url{https://agda.github.io/agda-stdlib/v2.0/}.
192-
The current developers believe we have successfully addressed some of the design flaws and missing functionality present in versions 1.0, including:
173+
The current developers believe that `agda-stdlib` version 2.0 [@agda-stdlib-v2.0] has successfully addressed some of the
174+
design flaws and missing functionality of previous versions, including:
175+
176+
- Minimised Dependency Graphs: the most commonly used modules rely on fewer parts of the library, resulting in faster load and compilation times in general.
193177

194-
- Minimised Dependency Graphs: We have reduced the depth of dependency graphs within the library, ensuring that the most commonly used modules rely on fewer parts of the library. This change has resulted in faster load and compilation times in general.
178+
- Standardisation: Mathematical objects such as groups, rings, orders, equivalences, etc., and their morphisms are now uniformly constructed from their sub-objects, enhancing consistency and usability.
195179

196-
- Standardisation: We have standardised the construction of mathematical objects such as groups, rings, orders, equivalences, etc., from their sub-objects, enhancing consistency and usability. We have also worked on standardizing morphisms of such objects.
180+
- Tactics Library: We have more tactics but experiments suggest that they are currently slower than those in comparable systems.
197181

198-
- Tactics Library: We have introduced a growing collection of tactics. Experiments suggest that these tactics are currently slower than those in comparable systems, indicating a potential area for future improvements.
182+
- Testing Framework: We have introduced a golden testing framework to let users write their own test suites.
199183

200-
- Testing Framework: We have introduced a golden testing framework that allows users to write their own test suites to assess the performance and correctness of their Agda code.
184+
HTML-annotated sources for version 2.0 of `agda-stdlib` is available at \url{https://agda.github.io/agda-stdlib/v2.0/}.
201185

202186
# Acknowledgements
203187

204-
We would like to thank those members of the Agda development team who are not authors on this paper, but nonetheless whose work on Agda makes the standard library possible. This includes, but is not limited to
205-
Jesper Cockx,
206-
Andrés Sicard-Ramírez and
207-
Andrea Vezzosi.
208-
We also would like to acknowledge the substantial feedback of Nils Anders Danielsson which led to improvements in the papers' presentation.
188+
Nils Anders Danielsson has provided substantial feedback on this paper.
209189

210190
The authors of this paper are listed approximately in order of contribution to the library. Manuscript preparation was carried out by Matthew Daggitt, Guillaume Allais, James McKinna, Jacques Carette and Nathan van Doorn. A full list of contributors to `agda-stdlib` may be found in the `LICENCE` in the GitHub source tree.
211191

212192
# Funding and conflicts of interest
213193

214194
The authors of this paper have no conflicts of interest to declare.
215-
Many of the contributions to the library by the authors of this paper were made over a significant period of time and while at other institutions than their current affiliation. Some of the contributions have been made while receiving funding for related projects, and a non-exhaustive list of such funding follows:
195+
The authors' contributions to `agda-stdlib` were made over a significant period of time and often at other institutions than their current affiliation.
196+
Some contributations were made thanks to funding for related projects, in particular:
216197

217-
- Jason Z. S. Hu made his contributions during his funded Master's and PhD study.
198+
- Jason Z. S. Hu during his funded Master's and PhD study.
218199

219-
- Shu-Hung You was partially supported when contributing to the library by the
220-
U.S. National Science Foundation under Awards No. 2237984 and No.
221-
2421308. Any opinions, findings and conclusions or recommendations
222-
expressed in this material are those of the author(s) and do not
223-
necessarily reflect the views of the National Science Foundation.
200+
- Shu-Hung You was partially supported by the U.S. National Science Foundation under Awards No. 2237984 and No. 2421308.
224201

225202
# References

0 commit comments

Comments
 (0)