The Agda Universal Algebra Library and Birkhoff's Theorem in Dependent Type Theory
TThe Agda Universal Algebra Library andBirkhoff ’s Theorem in Dependent Type Theory
William DeMeo (cid:97) (cid:83)
Department of Algebra, Charles University in Prague
Abstract
The Agda Universal Algebra Library (UALib) is a library of types and programs (theorems and proofs)we developed to formalize the foundations of universal algebra in Martin-Löf-style dependent typetheory using the Agda programming language and proof assistant. This paper describes the UALiband demonstrates that Agda is accessible to working mathematicians (such as ourselves) as a toolfor formally verifying nontrivial results in general algebra and related fields. The library includes asubstantial collection of definitions, theorems, and proofs from universal algebra and equational logicand as such provides many examples that exhibit the power of inductive and dependent types forrepresenting and reasoning about general algebraic and relational structures.The first major milestone of the UALib project is a complete proof of Birkhoff’s HSP theorem. Tothe best of our knowledge, this is the first time Birkhoff’s theorem has been formulated and proved independent type theory and verified with a proof assistant.
Theory of computation → Constructive mathematics; Theory of com-putation → Type theory; Theory of computation → Logic and verification; Computing methodologies → Representation of mathematical objects; Theory of computation → Type structures
Keywords and phrases
Universal algebra, Equational logic, Martin-Löf Type Theory, Birkhoff’s HSPTheorem, Formalization of mathematics, Agda, Proof assistant
Supplementary Material
Documentation : ualib.org Software : https://gitlab.com/ualib/ualib.gitlab.io.git Acknowledgements
The author wishes to thank Hyeyoung Shin and Siva Somayyajula for their contri-butions to this project and Martin Hötzel Escardo for creating the Type Topology library and teachinga course on Univalent Foundations of Mathematics with Agda at the 2019 Midlands Graduate Schoolin Computing Science.
Contents he Agda Universal Algebra Library 3
Preface
To support formalization in type theory of research level mathematics in universal algebraand related fields, we present the Agda Universal Algebra Library (UALib), a software librarycontaining formal statements and proofs of the core definitions and results of universal algebra.The UALib is written in Agda [8], a programming language and proof assistant based on Martin-Löf Type Theory that not only supports dependent and inductive types, but also providespowerful proof tactics for proving things about the objects that inhabit these types.The seminal idea for the Agda UALib project was the observation that, on the one hand,a number of fundamental constructions in universal algebra can be defined recursively, andtheorems about them proved by structural induction, while, on the other hand, inductive anddependent types make possible very precise formal representations of recursively defined objects,which often admit elegant constructive proofs of properties of such objects. An importantfeature of such proofs in type theory is that they are total functional programs and, as such,they are computable and composable.
Main Objectives
The first goal of the project is to express the foundations of universal algebra constructively,in type theory, and to formally verify the foundations using the Agda proof assistant. Thuswe aim to codify the edifice upon which our mathematical research stands, and demonstratethat advancements in our field can be expressed in type theory and formally verified in a waythat we, and other working mathematicians, can easily understand and check the results. Wehope the library inspires and encourages others to formalize and verify their own mathematicsresearch so that we may more easily understand and verify their results.Our field is deep and broad, so codifying all of its foundations may seem like a dauntingtask and a risky investment of time and resources. However, we believe the subject is wellserved by a new, modern, constructive presentation of its foundations. Finally, the mere act ofreinterpreting the foundations in an alternative system offers a fresh perspective, and this oftenleads to deeper insights and new discoveries.Indeed, we wish to emphasize that our ultimate objective is not merely to translate existingresults into a new more modern and formal language. Rather, an important goal of the UALibproject is a system that is useful for conducting research in mathematics, and that is how weintend to use our library now that we have achieved our initial objective of implementing asubstantial part of the foundations of universal algebra in Agda.In our own mathematics research, experience has taught us that a proof assistant equippedwith specialized libraries for universal algebra, as well as domain-specific tactics to automateproof idioms of our field, would be extremely valuable and powerful tool. Thus, we aim tobuild a library that serves as an indispensable part of our research tool kit. To this end, ourintermediate-term objectives includedeveloping domain specific “proof tactics” to express the idioms of universal algebra,implementing automated proof search for universal algebra,formalizing theorems from our own mathematics research,documenting the resulting software libraries so they are accessible to other mathematicians.
Prior art
There have been a number of efforts to formalize parts of universal algebra in type theory priorto ours, most notably
Capretta [3] (1999) formalized the basics of universal algebra in the Calculus of InductiveConstructions using the Coq proof assistant;Spitters and van der Weegen [10] (2011) formalized the basics of universal algebra and someclassical algebraic structures, also in the Calculus of Inductive Constructions using the Coqproof assistant, promoting the use of type classes as a preferable alternative to setoids;Gunther, et al [6] (2018) developed what seems to be (prior to the UALib) the most extensivelibrary of formal universal algebra to date; in particular, this work includes a formalizationof some basic equational logic; the project (like the UALib) uses Martin-Löf Type Theoryand the Agda proof assistant.Some other projects aimed at formalizing mathematics generally, and algebra in particular,have developed into very extensive libraries that include definitions, theorems, and proofs aboutalgebraic structures, such as groups, rings, modules, etc. However, the goals of these effortsseem to be the formalization of special classical algebraic structures, as opposed to the generaltheory of (universal) algebras. Moreover, the part of universal algebra and equational logicformalized in the UALib extends beyond the scope of prior efforts, including those listed above.In particular, the UALib now includes a proof of Birkhoff’s variety theorem. Most other proofsof this theorem that we know of are informal and nonconstructive. Contributions
Apart from the library itself, we describe the formal implementation and proof of a deep result,Garrett Birkhoff’s celebrated HSP theorem [2], which was among the first major results ofuniversal algebra. The theorem states that a variety (a class of algebras closed under quotients,subalgebras, and products) is an equational class (defined by the set of identities satisfied by allits members). The fact that we now have a formal proof of this is noteworthy, not only becausethis is the first time the theorem has been proved in dependent type theory and verified witha proof assistant, but also because the proof is constructive. As the paper [4] of Carlströmmakes clear, it is a highly nontrivial exercise to take a well-known informal proof of a theoremlike Birkhoff’s and show that it can be formalized using only constructive logic and naturaldeduction, without appealing to, say, the Law of the Excluded Middle or the Axiom of Choice.
Logical foundations
The Agda UALib is based on a minimal version of Martin-Löf dependent type theory (MLTT)that is the same or very close to the type theory on which Martín Escardó’s Type TopologyAgda library is based. This is also the type theory that Escardó taught us in the short courseIntroduction to Univalent Foundations of Mathematics with Agda at the Midlands GraduateSchool in the Foundations of Computing Science at University of Birmingham in 2019.We won’t go into great detail here because there are already other very nice resourcesavailable, such as the section A spartan Martin-Löf type theory of the lecture notes by Escardójust mentioned, as well as the ncatlab entry on Martin-Löf dependent type theory.We will have much more to say about types and type theory as we progress. For now, sufficeit to recall the handfull of objects that are assumed at the jumping-off point for MLTT: “prim-itive” types ( , , and N , denoting the empty type, one-element type, and natural numbers), After the completion of this work, the author learned about a constructive version of Birkhoff’s theoremthat was proved by Carlström in [4]. The latter is presented in the standard, informal style of mathematicalwriting in the current literature, and as far as we know it was never implemented formally and type-checkedwith a proof assistant. Nonetheless, a comparison of the version of the theorem presented in [4] to theAgda proof we give here would be interesting. he Agda Universal Algebra Library 5 type formers (+, Π , Σ , Id, denoting binary sum, product, sum, and the identity type), andan infinite collection of universes (types of types) and universe variables to denote them (forwhich we will use upper-case caligraphic letters like UUU , VVV , WWW , etc., typically from the latterhalf of the English alphabet).
Intended audience
This document describes Agda UALib in enough detail so that working mathematicians (andpossibly some normal people, too) might be able to learn enough about Agda and its librariesto put them to use when creating, formalizing, and verifying new theorems in universal algebraand model theory.While there are no strict prerequisites, we expect anyone with an interest in this work willhave been motivated by prior exposure to universal algebra, as presented in, say, [1], or [7], orcategory theory, as presented in, say, [9] or https://categorytheory.gitlab.io .Some prior exposure to type theory and Agda would be helpful, but even without thisbackground one might still be able to get something useful out of this by referring to one ormore of the resources mentioned in the references section below to fill in gaps as needed.It is assumed that readers of this documentation are actively experimenting with Agda usingEmacs with the agda2-mode extension installed. If you don’t have Agda and agda2-mode, followthe directions on the main Agda website: https://wiki.portal.chalmers.se/agda/pmwiki.php orconsult Martín Escardó’s installation instructions or our modified version of Martin’s instruc-tions.The main repository for the Agda UALib is gitlab.com/ualib/ualib.gitlab.io. There are moreinstallation instructions in the README.md file of the UALib repository, but a summary ofwhat’s required isGNU Emacs ( )Agda (version 2.6.1) ( wiki.portal.chalmers.se/agda/pmwiki.php )agda2-mode for Emacs ( agda.readthedocs.io/en/v2.6.0.1/tools/emacs-mode.html )A copy (or “clone”) of the gitlab.com/ualib/ualib.gitlab.io repository.Instructions for installing each of these are available in the README.md file of the UALibrepository.
Attributions and citations
Most of the mathematical results that formalized in the UALib are well known. Regardingthe Agda source code in the Agda UALib, this is mainly due to William DeMeo with onemajor caveat: we benefited greatly from, and the library depends upon, the lecture noteson Introduction to Univalent Foundations of Mathematics with Agda and the Type TopologyAgda Library by Escardó [5]. The author is indebted to Martin for making his library and notesavailable and for teaching a course on type theory in Agda at the Midlands Graduate Schoolin the Foundations of Computing Science in Birmingham in 2019.The following Agda documentation and tutorials helped inform and improve the UALib,especially the first one in the list.Escardó, Introduction to Univalent Foundations of Mathematics with AgdaWadler, Programming Languages Foundations in AgdaAltenkirk, Computer Aided Formal ReasoningBove and Dybjer, Dependent Types at WorkGunther, Gadea, Pagano, Formalization of Universal Algebra in AgdaNorell and Chapman, Dependently Typed Programming in Agda
References and resources
The official sources of information about Agda areAgda WikiAgda TutorialAgda User’s ManualAgda Language ReferenceAgda Standard LibraryAgda ToolsThe official sources of information about the Agda UALib are ualib.org (the web site) includes every line of code in the library, rendered as html andaccompanied by documentation, and gitlab.com/ualib/ualib.gitlab.io (the source code) freely available and licensed underthe Creative Commons Attribution-ShareAlike 4.0 International License.
License and citation information
This document and the Agda Universal Algebra Library by William DeMeo are licensed undera Creative Commons Attribution-ShareAlike BY-SA 4.0 International License and is based onwork at https://gitlab.com/ualib/ualib.gitlab.io .If you use the Agda UALib and/or you wish to refer to it or its documentation (e.g., in apublication), then please use the following BibTeX data (or refer to the dblp entry): @article{DeMeo:2021,author = {William DeMeo},title = {The {A}gda {U}niversal {A}lgebra {L}ibrary and{B}irkhoff's {T}heorem in {D}ependent {T}ype {T}heory},journal = {CoRR},volume = {abs/2101.10166},year = {2021},eprint = {2101.10166},archivePrefix = {arXiv},primaryClass = {cs.LO},url = {https://arxiv.org/abs/2101.10166},note = {source code: \url{https://gitlab.com/ualib/ualib.gitlab.io}}
Acknowledgments
The author wishes to thank Siva Somayyajula for the valuable contributions he made duringthe projects crucial early stages. Thanks also to Andrej Bauer, Clifford Bergman, VenanzioCapretta, Martin Escardo, Ralph Freese, Bill Lampe, Miklós Maróti, Peter Mayr, JB Nation,and Hyeyoung Shin for helpful discussions, instruction, advice, inspiration and encouragement.
Contributions welcomed!
Readers and users are encouraged to suggest improvements to the Agda UALib and/or itsdocumentation by submitting a new issue or merge request to the main repository at git-lab.com/ualib/ualib.gitlab.io/. he Agda Universal Algebra Library 7
This section presents the
UALib.Prelude submodule of the Agda UALib.
This subsection presents the
UALib.Prelude.Preliminaries submodule of the Agda UALib.
Notation . Here are some acronyms that we use frequently.MHE = Martín Hötzel EscardóMLTT = Martin-Löf Type Theory
Agda programs typically begin by setting some options and by importing from existing lib-raries. Options are specified with the
OPTIONS pragma and control the way Agda behavesby, for example, specifying which logical foundations should be assumed when the program istype-checked to verify its correctness. All Agda programs in the UALib begin with the pragma {- –without-K –exact-split –safe (1)This has the following effects: without-K disables Streicher’s K axiom; see [11]; exact-split makes Agda accept only definitions that are judgmental or definitional equalit-ies. As Escardó explains, this “makes sure that pattern matching corresponds to Martin-Löfeliminators;” for more details see [13]; safe ensures that nothing is postulated outright—every non-MLTT axiom has to be anexplicit assumption (e.g., an argument to a function or module); see [12] and [13].Throughout the UALib documentation assumptions 1–3 are taken for granted without mention-ing them explicitly. The
OPTIONS pragma is followed by some imports or the start of a module. Sometimes wewant to pass in parameters that will be assumed throughout the module. For instance, whenworking with algebras we often assume they come from a particular fixed signature S , whichwe could fix as a parameter at the start of a module. We’ll see many examples later, but here’san example: module _ { S : Signature OOO VVV } where . Throughout we use many of the nice tools that Escardó has developed and made available inthe Type Topology repository of Agda code for the “Univalent Foundations” of mathematics.(See [5] for more details.) We import these as follows. open import universes publicopen import Identity-Type renaming (_ ≡ _ to infix 0 _ ≡ _ ; refl to r e f l ) publicpattern refl x = r e f l { x = x }open import Sigma-Type renaming (_,_ to infixr 50 _,_) publicopen import MGS-MLTT using (_ ◦ _; domain; codomain; transport; _ ≡⟨ _ ⟩ _; _ ■ ;pr ; pr ; - Σ ; J ; Π ; ¬ ; _ × _; id ; _ ∼ _; _+_; ; ; ; _ ⇔ _;lr-implication; rl-implication; id; _ ; ap) public Standard Agda Type Topology/UALib
Level Universe
UUU : Level
UUU : UniverseSet
UUU UUU (cid:5) lsuc
UUU UUU + Set ( lsuc UUU ) UUU + (cid:5) lzero UUU Set ω UUU ω Table 1
Special notation for universe levels open import MGS-Equivalences using (is-equiv; inverse; invertible) publicopen import MGS-Subsingleton-Theorems using (funext; global-hfunext; dfunext;is-singleton; is-subsingleton; is-prop; Univalence; global-dfunext;univalence-gives-global-dfunext; _ • _; _ ≃ _; Π -is-subsingleton; Σ -is-subsingleton;logically-equivalent-subsingletons-are-equivalent) publicopen import MGS-Powersetrenaming (_ ∈ _ to _ ∈ _; _ ⊆ _ to _ ⊆ _; ∈ -is-subsingleton to ∈ -is-subsingleton)using ( P ; equiv-to-subsingleton; powersets-are-sets’; subset-extensionality’; propext; _holds; Ω ) publicopen import MGS-Embeddingsusing (Nat; Nat Π ; Nat Π -is-embedding; is-embedding; pr -embedding; ◦ -embedding; is-set;_ , → _; embedding-gives-ap-is-equiv; embeddings-are-lc; × -is-subsingleton; id-is-embedding) publicopen import MGS-Solved-Exercises using (to-subtype- ≡ ) publicopen import MGS-Unique-Existence using ( ∃ !; - ∃ !) publicopen import MGS-Subsingleton-Truncation using (_ · _; to- Σ - ≡ ; equivs-are-embeddings;invertibles-are-equivs; fiber; ⊆ -refl-consequence; hfunext) public Notice that we carefully specify which definitions and theorems we want to import from eachmodule. This is not absolutely necessary, but it helps us avoid name clashes and, more import-antly, makes explicit on which components of the type theory our development depends.
The first import in the list of open import directives above imports the universes module fromMartin Escardo’s Type Topology library. This provides, among other things, an elegant notationfor type universes that we have fully adopted and we use it throughout the Agda UALib. The Agda UALib adopts the notation of the Type Topology library. In particular, universesare denoted by capitalized script letters from the second half of the alphabet, e.g.,
UUU , VVV , WWW ,etc. Also defined in Type Topology are the operators (cid:5) and + . These map a universe UUU to UUU (cid:5) := Set
UUU and
UUU + : = lsuc UUU , respectively. Thus,
UUU (cid:5) is simply an alias for
Set
UUU , and we have
UUU (cid:5) : ( UUU + ) (cid:5) . Table 1 translates between standard Agda syntax and Type Topology/UALibnotation.To justify the introduction of this somewhat nonstandard notation for universe levels, MHE We won’t discuss every line of the universes module of the Type Topology library. Instead we merely touchupon the few lines of code that define the notational devices we adopt throughout the UALib. For thosewho wish for more details, MHE has made available an excellent set of notes from his course, MGS 2019.We highly recommend Martin’s notes to anyone who wants more information than we provide here aboutMartin-Löf Type Theory and the Univalent Foundations/HoTT extensions thereof. he Agda Universal Algebra Library 9 points out that the Agda library uses
Level for universes (so what we write as
UUU (cid:5) is written
Set
UUU in standard Agda), but in univalent mathematics the types in
UUU (cid:5) need not be sets, sothe standard Agda notation can be misleading.There will be many occasions calling for a type living in the universe that is the least upperbound of two universes, say,
UUU (cid:5) and
VVV (cid:5) . The universe (
UUU ⊔ VVV ) (cid:5) denotes this least upperbound. Here
UUU ⊔ VVV is used to denote the universe level corresponding to the least upperbound of the levels
UUU and
VVV , where the _ ⊔ _ is an Agda primitive designed for precisely thispurpose. Dependent pair types (or
Sigma types ) are defined in the Type Topology library as a record, asfollows: record Σ { UUU VVV } { X : UUU (cid:5) } ( Y : X → VVV (cid:5) ) :
UUU ⊔ VVV (cid:5) whereconstructor _,_fieldpr : X pr : Y pr infixr 50 _,_ We prefer the notation Σ x : X , y, which is closer to the standard syntax appearing in theliterature than Agda’s default syntax ( Σ λ ( x : X ) → y ). MHE makes the preferred notationavailable by making the index type explicit, as follows. - Σ : { UUU VVV : Universe} ( X : UUU (cid:5) ) ( Y : X → VVV (cid:5) ) → UUU ⊔ VVV (cid:5) - Σ X Y = Σ Y syntax - Σ X ( λ x → y ) = Σ x : X , y infixr -1 - Σ N.B.
The symbol : used here is not the same as the ordinary colon symbol (:), despite howsimilar they may appear. The symbol in the expression Σ x : X , y above is obtained by typing \:4 in agda2-mode.Our preferred notations for the first and second projections of a product are | _ | and ∥ _ ∥ ,respectively; however, we sometimes use more standard alternatives, such as pr and pr , or fst and snd , or some combination of these, to improve readability, or to avoid notation clasheswith other modules. module _ { UUU : Universe} where | _ | fst : { X : UUU (cid:5) }{ Y : X → VVV (cid:5) } → Σ Y → X | x , y | = x fst ( x , y ) = x ∥ _ ∥ snd : { X : UUU (cid:5) }{ Y : X → VVV (cid:5) } → ( z : Σ Y ) → Y (pr z ) ∥ x , y ∥ = y snd ( x , y ) = y Actually, because _ ⊔ _ has higher precedence than _ (cid:5) , we could omit parentheses here and simply write UUU ⊔ VVV (cid:5) . The so-called dependent function type (or “Pi type”) is defined in the Type Topology libraryas follows. Π : { X : UUU (cid:5) } ( A : X → VVV (cid:5) ) → UUU ⊔ VVV (cid:5) Π { UUU } {
VVV } { X } A = ( x : X ) → A x
To make the syntax for Π conform to the standard notation for Pi types, MHE uses the sametrick as the one used above for Sigma types. - Π : { UUU VVV : Universe} ( X : UUU (cid:5) ) ( Y : X → VVV (cid:5) ) → UUU ⊔ VVV (cid:5) - Π X Y = Π Y syntax - Π A ( λ x → b ) = Π x : A , b infixr -1 - Π In general, we may have many inhabitants of a given type and, via the Curry-Howard corres-pondence, many proofs of a given proposition. For instance, suppose we have a type X and anidentity relation ≡ x on X . Then, given two inhabitants a and b of type X , we may ask whether a ≡ x b .Suppose p and q inhabit the identity type a ≡ x b; that is, p and q are proofs of a ≡ x b , inwhich case we write p q : a ≡ x b . Then we might wonder whether and in what sense are thetwo proofs p and q the “same.” We are asking about an identity type on the identity type ≡ x ,and whether there is some inhabitant r of this type; i.e., whether there is a proof r : p ≡ x q that the proof of a ≡ x b is unique. (This property is sometimes called uniqueness of identityproofs .)Perhaps we have two proofs, say, r s : p ≡ x q . Then of course our next question will bewhether r ≡ x s has a proof! But at some level we may decide that the potential to distinguishtwo proofs of an identity in a meaningful way (so-called proof relevance ) is not useful or desirable.At that point, say, at level k , we might assume that there is at most one proof of any identityof the form p ≡ xk q . This is called truncation.We will see some examples of trunction later when we require it to complete some of theUALib modules leading up to the proof of Birkhoff’s HSP Theorem. Readers who want moredetails should refer to Section 34 and 35 of MHE’s notes, or Guillaume Brunerie, Truncationsand truncated higher inductive types, or Section 7.1 of the HoTT book.We take this opportunity to say what it means in type theory to say that a type is a set . Atype X : UUU (cid:5) with an identity relation ≡ x is called a set (or 0- groupoid ) if for every pair a b : X of elements of type X there is at most one proof of a ≡ x b . This is formalized in the TypeTopology library as follows: is-set : UUU (cid:5) → UUU (cid:5) is-set X = ( x y : X ) → is-subsingleton ( x ≡ y ) As MHE explains, “at this point, with the definition of these notions, we are entering the realm of univalentmathematics, but not yet needing the univalence axiom.” he Agda Universal Algebra Library 11
This subsection presents the
UALib.Relations.Equality submodule of the Agda UALib.
Perhaps the most important types in type theory are the equality types. The definitionalequality we use is a standard one and is often referred to as “reflexivity” or “refl”. In our case,it is defined in the Identity-Type module of the Type Topology library, but apart from syn-tax it is equivalent to the identity type used in most other Agda libraries. Here is the definition. data _ ≡ _ { UUU } { X : UUU (cid:5) } : X → X → UUU (cid:5) whererefl : { x : X } → x ≡ x We begin the
UALib.Relations.Equality module by formalizing the proof that ≡ is an equival-ence relation. module UALib.Prelude.Equality whereopen import UALib.Prelude.Preliminaries using ( OOO ; VVV ; Universe; _ (cid:5) ; _ ⊔ _; _ + ; _ ≡ _; refl; Σ ; - Σ ; _ × _; _,_;is-subsingleton; is-prop; | _ | ; ∥ _ ∥ ; ; pr ; pr ; ap) publicmodule _ { UUU : Universe}{ X : UUU (cid:5) } where ≡ -rfl : ( x : X ) → x ≡ x ≡ -rfl x = refl _ ≡ -sym : ( x y : X ) → x ≡ y → y ≡ x ≡ -sym x y (refl _) = refl _ ≡ -trans : ( x y z : X ) → x ≡ y → y ≡ z → x ≡ z ≡ -trans x y z (refl _) (refl _) = refl _ ≡ -Trans : ( x : X ){ y : X }( z : X ) → x ≡ y → y ≡ z → x ≡ z ≡ -Trans x { y } z (refl _) (refl _) = refl _ The only difference between ≡ -trans and ≡ -Trans is that the second argument to ≡ -Trans is implicit so we can omit it when applying ≡ -Trans . This is sometimes convenient; after all, ≡ -Trans is used to prove that the first and last arguments are the same, and often we don’tcare about the middle argument. A function is well defined only if it maps equivalent elements to a single element and we oftenuse this nature of functions in Agda proofs. If we have a function f : X → Y , two elements x x’ : X of the domain, and an identity proof p : x ≡ x’ , then we obtain a proof of f x ≡ f x’ bysimply applying the ap function like so, ap f p : f x ≡ f x’ .MHE defines ap in the Type Topology library so we needn’t redefine it here. Instead, wedefine two variations of ap that are sometimes useful. ap-cong : { UUU WWW : Universe} { A : UUU (cid:5) } { B : WWW (cid:5) }{ f g : A → B } { a b : A } → f ≡ g → a ≡ b———————– → f a ≡ g b ap-cong (refl _) (refl _) = refl _ We sometimes need a version of ap-cong that works for dependent types, such as the following(which we borrow from the
Relation/Binary/Core.agda module of the Agda Standard Lib-rary, transcribed into MHE/UALib notation of course). cong-app : {
UUU WWW : Universe} { A : UUU (cid:5) } { B : A → WWW (cid:5) }{ f g : ( a : A ) → B a } → f ≡ g → ( a : A ) ——————– → f a ≡ g a cong-app (refl _) a = refl _ ≡ -intro and ≡ -elim for pairs We conclude the Equality module with some occasionally useful introduction and eliminationrules for the equality relation on (nondependent) pair types. ≡ -elim-left : { UUU WWW : Universe} { A A : UUU (cid:5) } { B B : WWW (cid:5) } → ( A , B ) ≡ ( A , B ) ———————- → A ≡ A ≡ -elim-left e = ap pr e ≡ -elim-right : { UUU WWW : Universe} { A A : UUU (cid:5) }{ B B : WWW (cid:5) } → ( A , B ) ≡ ( A , B ) ———————– → B ≡ B ≡ -elim-right e = ap pr e ≡ - × -intro : { UUU WWW : Universe} { A A : UUU (cid:5) } { B B : WWW (cid:5) } → A ≡ A → B ≡ B ———————— → ( A , B ) ≡ ( A , B ) ≡ - × -intro (refl _ ) (refl _ ) = (refl _ ) ≡ - × -int : { UUU WWW : Universe} { A : UUU (cid:5) } { B : WWW (cid:5) }( a a’ : A )( b b’ : B ) → a ≡ a’ → b ≡ b’———————— → ( a , b ) ≡ ( a’ , b’ ) ≡ - × -int a a’ b b’ (refl _ ) (refl _ ) = (refl _ ) This subsection presents the
UALib.Prelude.Inverses submodule of the Agda UALib. Here wedefine (the syntax of) a type for the (semantic concept of) inverse image of a function.gpgp module UALib.Prelude.Inverses where he Agda Universal Algebra Library 13 open import UALib.Prelude.Equality publicopen import UALib.Prelude.Preliminaries using (_ ; funext; _ ◦ _; _ · _; id ; fst; snd; is-set; is-embedding;transport; to- Σ - ≡ ; invertible; equivs-are-embeddings; invertibles-are-equivs; fiber; r e f l ) public gp module _ { UUU WWW : Universe} wheredata Image_ ∋ _ { A : UUU (cid:5) }{ B : WWW (cid:5) }( f : A → B ) : B → UUU ⊔ WWW (cid:5) whereim : ( x : A ) → Image f ∋ f x eq : ( b : B ) → ( a : A ) → b ≡ f a → Image f ∋ b ImageIsImage : { A : UUU (cid:5) }{ B : WWW (cid:5) }( f : A → B ) ( b : B ) ( a : A ) → b ≡ f a————————- → Image f ∋ b ImageIsImage { A }{ B } f b a b ≡ fa = eq b a b ≡ fa Note that an inhabitant of
Image f ∋ b is a dependent pair ( a , p ), where a : A and p : b ≡ f a is a proof that f maps a to b . Thus, a proof that b belongs to the image of f (i.e., an inhabitantof Image f ∋ b ), always has a witness a : A , and a proof that b ≡ f a , so a (pseudo)inverse canactually be computed .For convenience, we define a pseudo-inverse function, which we call Inv , that takes b : B and ( a , p ) : Image f ∋ b and returns a . Inv : { A : UUU (cid:5) }{ B : WWW (cid:5) }( f : A → B )( b : B ) → Image f ∋ b → A Inv f .( f a ) (im a ) = a Inv f b (eq b a b ≡ fa ) = a Of course, we can prove that
Inv f is really the (right-)inverse of f . InvIsInv : { A : UUU (cid:5) } { B : WWW (cid:5) } ( f : A → B )( b : B ) ( b ∈ Imgf : Image f ∋ b ) ——————————— → f (Inv f b b ∈ Imgf ) ≡ b InvIsInv f .( f a ) (im a ) = refl _InvIsInv f b (eq b a b ≡ fa ) = b ≡ fa An epic (or surjective) function from type A : UUU (cid:5) to type B : WWW (cid:5) is as an inhabitant of the
Epic type, which we define as follows.
Epic : { A : UUU (cid:5) } { B : WWW (cid:5) } ( g : A → B ) → UUU ⊔ WWW (cid:5)
Epic g = ∀ y → Image g ∋ y We obtain the right-inverse (or pseudoinverse) of an epic function f by applying the function EpicInv (which we now define) to the function f along with a proof, fE : Epic f , that f is surjective. EpicInv : { A : UUU (cid:5) } { B : WWW (cid:5) }( f : A → B ) → Epic f————————- → B → A EpicInv f fE b = Inv f b ( fE b ) The function defined by
EpicInv f fE is indeed the right-inverse of f . EpicInvIsRightInv : funext
WWW WWW → { A : UUU (cid:5) } { B : WWW (cid:5) }( f : A → B ) ( fE : Epic f ) —————————- → f ◦ (EpicInv f fE ) ≡ id B EpicInvIsRightInv fe f fE = fe ( λ x → InvIsInv f x ( fE x )) We say that a function g : A → B is monic (or injective) if we have a proof of Monic g , where Monic : { A : UUU (cid:5) } { B : WWW (cid:5) }( g : A → B ) → UUU ⊔ WWW (cid:5)
Monic g = ∀ a a → g a ≡ g a → a ≡ a Again, we obtain a pseudoinverse. Here it is obtained by applying the function
MonicInv to g and a proof that g is monic. –The (pseudo-)inverse of a monic function MonicInv : { A : UUU (cid:5) } { B : WWW (cid:5) }( f : A → B ) → Monic f—————————– → ( b : B ) → Image f ∋ b → A MonicInv f _ = λ b Imf ∋ b → Inv f b Imf ∋ b The function defined by MonicInv f fM is the left-inverse of f . –The (psudo-)inverse of a monic is the left inverse. MonicInvIsLeftInv : { A : UUU (cid:5) }{ B : WWW (cid:5) }( f : A → B ) ( fmonic : Monic f )( x : A ) —————————————- → (MonicInv f fmonic ) ( f x ) (im x ) ≡ x MonicInvIsLeftInv f fmonic x = refl _
Finally, bijective functions are defined.
Bijective : { A : UUU (cid:5) }{ B : WWW (cid:5) }( f : A → B ) → UUU ⊔ WWW (cid:5)
Bijective f = Epic f × Monic f Inverse : { A : UUU (cid:5) } { B : WWW (cid:5) } ( f : A → B ) → Bijective f → B → A Inverse f fbi b = Inv f b (fst( fbi ) b ) This is the first point at which truncation comes into play. An embedding is defined in theType Topology library as follows: he Agda Universal Algebra Library 15 is-embedding : { X : UUU (cid:5) } { Y : VVV (cid:5) } → ( X → Y ) → UUU ⊔ VVV (cid:5) is-embedding f = ( y : codomain f ) → is-subsingleton (fiber f y ) where is-subsingleton : UUU (cid:5) → UUU (cid:5) is-subsingleton X = ( x y : X ) → x ≡ y and fiber : { X : UUU (cid:5) } { Y : VVV (cid:5) } ( f : X → Y ) → Y → UUU ⊔ VVV (cid:5) fiber f y = Σ x : domain f , f x ≡ y This is a natural way to represent what we usually mean in mathematics by embedding. It doesnot correspond simply to an injective map. However, if we assume that the codomain type, B , is a set (i.e., has unique identity proofs ), then we can prove that a injective (i.e., monic )function into B is an embedding as follows: module _ { UUU WWW : Universe} wheremonic-into-set-is-embedding : { A : { A : UUU (cid:5) }{ B : WWW (cid:5) } → is-set B → ( f : A → B ) → Monic f————————— → is-embedding f monic-into-set-is-embedding { A } Bset f fmon b ( a , fa ≡ b ) ( a’ , fa’ ≡ b ) = γ wherefaa’ : f a ≡ f a’ faa’ = ≡ -Trans ( f a ) ( f a’ ) fa ≡ b ( fa’ ≡ b )aa’ : a ≡ a’ aa’ = fmon a a’ faa’ A : A → WWW (cid:5) A a = f a ≡ b arg1 : Σ p : ( a ≡ a’ ) , (transport A p fa ≡ b ) ≡ fa’ ≡ b arg1 = aa’ , Bset ( f a’ ) b (transport A aa’ fa ≡ b ) fa’ ≡ b γ : a , fa ≡ b ≡ a’ , fa’ ≡ b γ = to- Σ - ≡ arg1 Of course, invertible maps are embeddings. invertibles-are-embeddings : { X : UUU (cid:5) } { Y : WWW (cid:5) }( f : X → Y ) → invertible f → is-embedding f invertibles-are-embeddings f fi = equivs-are-embeddings f (invertibles-are-equivs f fi ) Finally, if we have a proof p : is-embedding f that the map f is an embedding, here’s a tool thatmakes it easier to apply p . – Embedding elimination (makes it easier to apply is-embedding) embedding-elim : { X : UUU (cid:5) } { Y : WWW (cid:5) }{ f : X → Y } → is-embedding → ( x x’ : X ) ———————- → f x ≡ f x’ → x ≡ x’ embedding-elim { f = f } femb x x’ fxfx’ = γ wherefibx : fiber f ( f x )fibx = x , r e f l fibx’ : fiber f ( f x )fibx’ = x’ , (( fxfx’ ) )iss-fibffx : is-subsingleton (fiber f ( f x ))iss-fibffx = femb ( f x )fibxfibx’ : fibx ≡ fibx’fibxfibx’ = iss-fibffx fibx fibx’ γ : x ≡ x’ γ = ap pr fibxfibx’ This subsection presents the
UALib.Prelude.Extensionality submodule of the Agda UALib. module UALib.Prelude.Extensionality whereopen import UALib.Prelude.Inverses publicopen import UALib.Prelude.Preliminariesusing (_ ∼ _; UUU ω ; Π ; Ω ; P ; ⊆ -refl-consequence; _ ∈ _; _ ⊆ _; _holds) public Extensional equality of functions, or function extensionality, means that any two point-wiseequal functions are equal. As MHE points out, this is known to be not provable or disprovablein Martin-Löf type theory. It is an independent statement, which MHE abbreviates as funext .Here is how this notion is given a type in the Type Topology library funext : ∀ UUU VVV → ( UUU ⊔ VVV ) + (cid:5) funext UUU VVV = { X : UUU (cid:5) } { Y : VVV (cid:5) } { f g : X → Y } → f ∼ g → f ≡ g For readability we occasionally use the following alias for the funext type. extensionality : ∀ UUU WWW → UUU + ⊔ WWW + (cid:5) extensionality UUU WWW = { A : UUU (cid:5) } { B : WWW (cid:5) } { f g : A → B } → f ∼ g → f ≡ g Pointwise equality of functions is typically what one means in informal settings when one saysthat two functions are equal. Here is how MHE defines pointwise equality of (dependent) func-tion in Type Topology. _ ∼ _ : { X : UUU (cid:5) } { A : X → VVV (cid:5) } → Π A → Π A → UUU ⊔ VVV (cid:5) f ∼ g = ∀ x → f x ≡ g x In fact, if one assumes the univalence axiom, then the _ ∼ _ relation is equivalent to equality offunctions. See Function extensionality from univalence. he Agda Universal Algebra Library 17 Extensionality for dependent function types is defined as follows. dep-extensionality : ∀ UUU WWW → UUU + ⊔ WWW + (cid:5) dep-extensionality UUU WWW = { A : UUU (cid:5) } { B : A → WWW (cid:5) }{ f g : ∀ ( x : A ) → B x } → f ∼ g → f ≡ g Sometimes we need extensionality principles that work at all universe levels, and Agda is cap-able of expressing such principles, which belong to the special
UUU ω type, as follows: ∀ -extensionality : UUU ω ∀ -extensionality = ∀ { UUU VVV } → extensionality UUU VVV ∀ -dep-extensionality : UUU ω ∀ -dep-extensionality = ∀ { UUU VVV } → dep-extensionality UUU VVV
More details about the
UUU ω type are available at agda.readthedocs.io. extensionality-lemma : ∀ { III UUU VVV TTT } → { I : III (cid:5) }{ X : UUU (cid:5) }{ A : I → VVV (cid:5) }( p q : ( i : I ) → ( X → A i ) → TTT (cid:5) )( args : X → ( Π A )) → p ≡ q————————————————- → ( λ i → ( p i )( λ x → args x i )) ≡ ( λ i → ( q i )( λ x → args x i ))extensionality-lemma p q args p ≡ q =ap ( λ - → λ i → ( - i ) ( λ x → args x i )) p ≡ q This is the opposite of function extensionality and is defined as follows. intensionality : {
UUU WWW : Universe} { A : UUU (cid:5) } { B : WWW (cid:5) } { f g : A → B } → f ≡ g → ( x : A ) —————— → f x ≡ g x intensionality (refl _ ) _ = refl _ Of course, the intensionality principle has an analogue for dependent function types. dep-intensionality – alias (we sometimes give multiple names to a function, like this) dintensionality : {
UUU WWW : Universe} { A : UUU (cid:5) } { B : A → WWW (cid:5) } { f g : ( x : A ) → B x } → f ≡ g → ( x : A ) —————— → f x ≡ g x dintensionality (refl _ ) _ = refl _dep-intensionality = dintensionality (This page is almost entirely blank on purpose.) he Agda Universal Algebra Library 19 This section presents the
UALib.Algebras module of the Agda UALib.
This subsection presents the
UALib.Algebras.Signatures submodule of the Agda UALib. open import universes using (
UUU )module UALib.Algebras.Signatures whereopen import UALib.Prelude.Extensionality publicopen import UALib.Prelude.Preliminaries using ( ; ) public We define the type of operations and, as an example, the type of projections . module _ { UUU VVV : Universe} where –The type of operations
Op :
VVV (cid:5) → UUU (cid:5) → UUU ⊔ VVV (cid:5) Op I A = ( I → A ) → A–Example. the projections π : { I : VVV (cid:5) } { A : UUU (cid:5) } → I → Op I A π i x = x i The type Op encodes the arity of an operation as an arbitrary type I : VVV (cid:5) , which gives us avery general way to represent an operation as a function type with domain I → A (the typeof “tuples”) and codomain A . The last two lines of the code block above codify the i -th I -aryprojection operation on A . We define the signature of an algebraic structure in Agda like this.
Signature : (
OOO VVV : Universe) → ( OOO ⊔ VVV ) + (cid:5) Signature
OOO VVV = Σ F : OOO (cid:5) , ( F → VVV (cid:5) ) Here
OOO is the universe level of operation symbol types, while
VVV is the universe level of aritytypes.In the
UALib.Prelude module we define special syntax for the first and second projections—namely, | _ | and ∥ _ ∥ , resp (see Subsection 1.1.5). Consequently, if { S : Signature OOO VVV } is asignature, then | S | denotes the type of operation symbols , and ∥ S ∥ denotes the arity function. If f : | S | is an operation symbol in the signature S , then ∥ S ∥ f is the arity of f . Here is how we might define the signature for monoids as a member of the type
Signature
OOO VVV . module _ { OOO : Universe} where data monoid-op :
OOO (cid:5) wheree : monoid-op· : monoid-opmonoid-sig : Signature
OOO UUU monoid-sig = monoid-op , λ { e → ; · → } As expected, the signature for a monoid consists of two operation symbols, e and · , and afunction λ { e → ; · → } which maps e to the empty type (since e is the nullary identity)and maps · to the two element type (since · is binary). This subsection presents the
UALib.Algebras.Algebras submodule of the Agda UALib. module UALib.Algebras.Algebras whereopen import UALib.Algebras.Signatures publicopen import UALib.Prelude.Preliminaries using (
UUU ; ; ) public For a fixed signature S : Signature OOO VVV and universe
UUU , we define the type of algebras in thesignature S (or S - algebras ) and with domain (or carrier ) A : UUU (cid:5) as follows
Algebra : (
UUU : Universe)( S : Signature OOO VVV ) → OOO ⊔ VVV ⊔ UUU + (cid:5) Algebra
UUU S = Σ A : UUU (cid:5) , (( f : | S | ) → Op ( ∥ S ∥ f ) A ) We may refer to an inhabitant of
Algebra S UUU as an “ ∞ -algebra” because its domain can be anarbitrary type, say, A : UUU (cid:5) and need not be truncated at some level; in particular, A need tobe a set . (See the discussion in Section 1.1.7.)We take this opportunity to define the type of “0-algebras” which are algebras whose domainsare sets (as defined in Section 1.1.7). This type is probably closer to what most of us think ofwhen doing informal universal algebra. However, in the UALib will have so far only needed toknow that a domain of an algebra is a set in a handful of specific instances, so it seems preferableto work with general ( ∞ -)algebras throughout the library and then assume uniquness of identityproofs explicitly wherever a proof relies on this assumption.The type Algebra
UUU S itself has a type; it is OOO ⊔ VVV ⊔ UUU + (cid:5) . This type appears so often inthe UALib that we will define the following shorthand for its universe level: OV UUU = OOO ⊔ VVV ⊔ UUU + (cid:5) . Sometimes records are more convenient than sigma types. For such cases, we might prefer thefollowing representation of the type of algebras. module _ {
OOO VVV : Universe} whererecord algebra (
UUU : Universe) ( S : Signature OOO VVV ) : (
OOO ⊔ VVV ⊔ UUU ) + (cid:5) whereconstructor mkalgfielduniv : UUU (cid:5) op : ( f : | S | ) → (( ∥ S ∥ f ) → univ) → univ he Agda Universal Algebra Library 21 Of course, we can go back and forth between the two representations of algebras, like so. module _ {
UUU OOO VVV : Universe} { S : Signature OOO VVV } whereopen algebraalgebra → Algebra : algebra
UUU S → Algebra
UUU S algebra → Algebra A = (univ A , op A )Algebra → algebra : Algebra UUU S → algebra UUU S Algebra → algebra A = mkalg | A | ∥ A ∥ We conclude this module by defining a convenient shorthand for the interpretation of an oper-ation symbol that we will use often. _ ˆ _ : ( f : | S | )( A : Algebra UUU S ) → ( ∥ S ∥ f → | A | ) → | A | f ˆ A = λ x → ( ∥ A ∥ f ) x This is similar to the standard notation that one finds in the literature and seems much morenatural to us than the double bar notation that we started with.
Finally, we will want to assume that we always have at our disposal an arbitrary collection X of variable symbols such that, for every algebra A , no matter the type of its domain, we havea surjective map h : X → | A | from variables onto the domain of A . _ ↠ _ : { UUU XXX : Universe} → XXX (cid:5) → Algebra
UUU S → XXX ⊔ UUU (cid:5) X ↠ A = Σ h : ( X → | A | ) , Epic h This subsection presents the
UALib.Algebras.Products submodule of the Agda UALib.
Suppose we are given a type I : III (of “indices”) and an indexed family A : I → Algebra
UUU S of S -algebras. Then we define the product algebra d A in the following natural way. d : { III : Universe}{ I : III (cid:5) }( A : I → Algebra
UUU S ) → Algebra (
III ⊔ UUU ) S d { III }{ I } A =(( i : I ) → | A i | ) , λ ( f : | S | )( aaa : ∥ S ∥ f → ( j : I ) → | A j | )( i : I ) → ( f ˆ A i ) λ { x → aaa x i } Here, the domain is the dependent function type ∏ | A | := ( i : I ) → | A i | of “tuples”, the i -th components of which live in | A i | , and the operations are simply the operations of the A i , interpreted component-wise. To distinguish the product algebra from the standard product type available in the Agda Standard Library,instead of ∏ ( \prod ) or Π ( \Pi ), we use the symbol d , which is typed in agda2-mode as \Glb . The Birkhoff theorem involves products of entire arbitrary (nonindexed) classes of algebras,and it is not obvious how to handle this constructively, or whether it is even possible to do sowithout making extra assumptions about the class. (See [4] for a discussion of this issue.) Wedescribe our solution to this problem in §7.3.8.
This subsection presents the
UALib.Algebras.Lifts submodule of the Agda UALib. This sectionpresents the
UALib.Algebras.Lifts module of the Agda UALib. module UALib.Algebras.Lifts whereopen import UALib.Algebras.Products public
The hierarchy of universe levels in Agda is structured as
UUU : UUU , UUU : UUU , UUU : UUU , ….This means that UUU has type UUU (cid:5) and UUU n has type UUU n +1 (cid:5) for each n .It is important to note, however, this does not imply that UUU : UUU and UUU : UUU , and soon. In other words, Agda’s universe hierarchy is noncummulative . This makes it possible totreat universe levels more generally and precisely, which is nice. On the other hand, it is thisauthor’s experience that a noncummulative hierarchy can sometimes make for a nonfun proofassistant.Luckily, there are ways to subvert noncummulativity which, when used with care, do notintroduce logical inconsistencies into the type theory. We describe some techniques we developedfor this purpose that are specifically tailored for our domain of applications. Let us be more concrete about what is at issue here by giving an example. Unless we arepedantic enough to worry about which universe level each of our types inhabits, then eventu-ally we will encounter an error like the following:
Birkhoff.lagda:498,20-23(
UUU + ) != ( OOO + ) ⊔ ( VVV + ) ⊔ (( UUU + ) + )when checking that the expression SP K has typePred ( Σ ( λ A → (f : | S | ) → Op ( ∥ S ∥ f ) A)) _ WWW _2346
Just to confirm we all know the meaning of such errors, let’s translate the one above. Thiserror means that Agda encountered a type at universe level
UUU + , on line 498 (in columns20–23) of the file Birkhoff.lagda, but was expecting a type at level OOO + ⊔ VVV + ⊔ UUU + + instead.To make these situations easier to deal with, the UALib offers some domain specific tools forthe lifting and lowering of universe levels of the main types in the library. In particular, we havefunctions that will lift or lower the universes of algebra types, homomorphisms, subalgebras,and products.Of course, messing with the universe level of a type must be done carefully to avoid makingthe type theory inconsistent. In particular, a necessary condition is that a type of a givenuniverse level may not be converted to a type of lower universe level unless the given type wasobtained from lifting another type to a higher-than-necessary universe level . If this is not clear,don’t worry; just press on and soon enough there will be examples that make it clear. he Agda Universal Algebra Library 23
A general
Lift record type, similar to the one found in the Agda Standard Library (in the
Level module), is defined as follows. record Lift {
UUU WWW : Universe} ( X : UUU (cid:5) ) :
UUU ⊔ WWW (cid:5) whereconstructor liftfield lower : X open Lift Next, we give various ways to lift function types. lift-dom : {
XXX YYY WWW : Universe}{ X : XXX (cid:5) }{ Y : YYY (cid:5) } → ( X → Y ) → (Lift{ XXX }{ WWW } X → Y )lift-dom f = λ x → ( f (lower x ))lift-cod : { XXX YYY WWW : Universe}{ X : XXX (cid:5) }{ Y : YYY (cid:5) } → ( X → Y ) → ( X → Lift{
YYY }{ WWW } Y )lift-cod f = λ x → lift ( f x )lift-fun : { XXX YYY WWW ZZZ : Universe}{ X : XXX (cid:5) }{ Y : YYY (cid:5) } → ( X → Y ) → (Lift{ XXX }{ WWW } X → Lift{
YYY }{ ZZZ } Y )lift-fun f = λ x → lift ( f (lower x )) We will also need to know that lift and lower compose to the identity. lower ∼ lift : { XXX WWW : Universe}{ X : XXX (cid:5) } → lower{ XXX }{ WWW } ◦ lift ≡ id X lower ∼ lift = refl _lift ∼ lower : { XXX WWW : Universe}{ X : XXX (cid:5) } → lift ◦ lower ≡ id (Lift{ XXX }{ WWW } X )lift ∼ lower = refl _ Now, to be more domain-specific, we show how to lift algebraic operation types and then, finally,how to lift algebra types. module _ { S : Σ F : OOO (cid:5) , ( F → VVV (cid:5) )} wherelift-op : {
UUU : Universe}{ I : VVV (cid:5) }{ A : UUU (cid:5) } → (( I → A ) → A ) → ( WWW : Universe) → (( I → Lift{
UUU }{ WWW } A ) → Lift{
UUU }{ WWW } A )lift-op f WWW = λ x → lift ( f ( λ i → lower ( x i )))open algebralift-alg-record-type : { UUU : Universe} → algebra UUU S → ( WWW : Universe) → algebra ( UUU ⊔ WWW ) S lift-alg-record-type A WWW = mkalg (Lift (univ A )) ( λ ( f : | S | ) → lift-op ((op A ) f ) WWW )lift- ∞ -algebra lift-alg : { UUU : Universe} → Algebra
UUU S → ( WWW : Universe) → Algebra (
UUU ⊔ WWW ) S lift- ∞ -algebra A WWW = Lift | A | , ( λ ( f : | S | ) → lift-op ( ∥ A ∥ f ) WWW )lift-alg = lift- ∞ -algebra (This page is almost entirely blank on purpose.) he Agda Universal Algebra Library 25 This section presents the
UALib.Relations module of the Agda UALib.
This subsection presents the
UALib.Relations.Unary submodule of the Agda UALib. We needa mechanism for implementing the notion of subsets in Agda. A typical one is called
Pred (forpredicate). More generally,
Pred A UUU can be viewed as the type of a property that elements oftype A might satisfy. We write P : Pred A UUU to represent the semantic concept of a collectionof elements of type A that satisfy the property P . module UALib.Relations.Unary whereopen import UALib.Algebras.Lifts publicopen import UALib.Prelude.Preliminaries using ( ¬ ; propext; global-dfunext ) public Here is the definition, which is similar to the one found in the
Relation/Unary.agda file of theAgda Standard Library. module _ {
UUU : Universe} wherePred :
UUU (cid:5) → ( VVV : Universe) → UUU ⊔ VVV + (cid:5) Pred A VVV = A → VVV (cid:5)
Section 1.1.7 describes the concepts of truncation and set for “proof-relevant” mathematics.Sometimes we will want to assume “proof-irrelevance” and assume that certain types are sets.Recall, this mean there is at most one proof that two elements are the same. For predicates,analogously, we may wish to assume that there is at most one proof that a given element satis-fies the predicate.
Pred : UUU (cid:5) → ( VVV : Universe) → UUU ⊔ VVV + (cid:5) Pred A VVV = Σ P : ( A → VVV (cid:5) ) , ∀ x → is-subsingleton ( P x ) Below we will often consider predicates over the class of all algebras of a particular type. Wewill define the type of algebras
Algebra
UUU S (for some universe level UUU ). Like all types,
Algebra
UUU S itself has a type which happens to be OOO ⊔ VVV ⊔ UUU + (cid:5) (see Section 2.2). Therefore, the typeof Pred ( Algebra
UUU S ) UUU is OOO ⊔ VVV ⊔ UUU + (cid:5) as well.The inhabitants of the type Pred ( Algebra
UUU S ) UUU are maps of the form A → UUU (cid:5) ; given analgebra A : Algebra UUU S , we have Pred A UUU = A → UUU (cid:5) . We introduce notation for denoting that x “belongs to” or “inhabits” type P , or that x “hasproperty” P , by writing either x ∈ P or P x (cf.
Relation/Unary.agda in the Agda StandardLibrary. module _ {
UUU WWW : Universe} where_ ∈ _ : { A : UUU (cid:5) } → A → Pred A WWW → WWW (cid:5) x ∈ P = P x _ / ∈ _ : { A : UUU (cid:5) } → A → Pred A WWW → WWW (cid:5) x / ∈ P = ¬ ( x ∈ P )infix 4 _ ∈ _ _ / ∈ _ The “subset” relation is denoted, as usual, with the ⊆ symbol (cf. Relation/Unary.agda inthe Agda Standard Library). _ ⊆ _ : { UUU WWW TTT : Universe}{ A : UUU (cid:5) } → Pred A WWW → Pred A TTT → UUU ⊔ WWW ⊔ TTT (cid:5) P ⊆ Q = ∀ { x } → x ∈ P → x ∈ Q _ ⊇ _ : { UUU WWW TTT : Universe}{ A : UUU (cid:5) } → Pred A WWW → Pred A TTT → UUU ⊔ WWW ⊔ TTT (cid:5) P ⊇ Q = Q ⊆ P infix 4 _ ⊆ _ _ ⊇ _ In type theory everything is a type. As we have just seen, this includes subsets. Since thenotion of equality for types is usually a nontrivial matter, it may be nontrivial to representequality of subsets. Fortunately, it is straightforward to write down a type that representswhat it means for two subsets to be the in informal (pencil-paper) mathematics. In the AgdaUALib this subset equality is denoted by = (cid:5) and define as follows. _= (cid:5) _ : { UUU WWW TTT : Universe}{ A : UUU (cid:5) } → Pred A WWW → Pred A TTT → UUU ⊔ WWW ⊔ TTT (cid:5) P = (cid:5) Q = ( P ⊆ Q ) × ( Q ⊆ P ) Here is a small collection of tools that will come in handy later. Hopefully the meaning of eachis self-explanatory. _ ∈∈ _ : { UUU WWW TTT : Universe}{ A : UUU (cid:5) } { B : WWW (cid:5) } → ( A → B ) → Pred B TTT → UUU ⊔ TTT (cid:5) _ ∈∈ _ f S = ( x : _) → f x ∈ S Pred-refl : {
UUU WWW : Universe}{ A : UUU (cid:5) }{ P Q : Pred A WWW } → P ≡ Q → ( a : A ) ———————- → a ∈ P → a ∈ Q Pred-refl (refl _) _ = λ z → z Pred- ≡ : { UUU WWW : Universe}{ A : UUU (cid:5) }{ P Q : Pred A WWW } → P ≡ Q → P = (cid:5) Q Pred- ≡ (refl _) = ( λ z → z ) , λ z → z Pred- ≡→⊆ : {
UUU WWW : Universe}{ A : UUU (cid:5) }{ P Q : Pred A WWW } → P ≡ Q → ( P ⊆ Q )Pred- ≡→⊆ (refl _) = ( λ z → z )Pred- ≡→⊇ : { UUU WWW : Universe}{ A : UUU (cid:5) }{ P Q : Pred A WWW } → P ≡ Q → ( P ⊇ Q )Pred- ≡→⊇ (refl _) = ( λ z → z )Pred-= (cid:5) - ≡ : { UUU WWW : Universe} → propext WWW → global-dfunext → { A : UUU (cid:5) }{ P Q : Pred A WWW } → (( x : A ) → is-subsingleton ( P x )) → (( x : A ) → is-subsingleton ( Q x )) ———————- → P = (cid:5) Q → P ≡ Q he Agda Universal Algebra Library 27 Pred-= (cid:5) - ≡ pe gfe { A }{ P }{ Q } ssP ssQ ( pq , qp ) = gfe γ where γ : ( x : A ) → P x ≡ Q x γ x = pe ( ssP x ) ( ssQ x ) pq qp– Disjoint Union. data _ ˙ ∪ _ { UUU WWW : Universe}( A : UUU (cid:5) ) ( B : WWW (cid:5) ) :
UUU ⊔ WWW (cid:5) whereinj : ( x : A ) → A ˙ ∪ B inj : ( y : B ) → A ˙ ∪ B infixr 1 _ ˙ ∪ _ – Union. _ ∪ _ : { UUU WWW TTT : Universe}{ A : UUU (cid:5) } → Pred A WWW → Pred A TTT → Pred A _ P ∪ Q = λ x → x ∈ P ˙ ∪ x ∈ Q infixr 1 _ ∪ _ – The empty set. ∅ : { UUU : Universe}{ A : UUU (cid:5) } → Pred A UUU ∅ = λ _ → – Singletons. { _ } : { UUU : Universe}{ A : UUU (cid:5) } → A → Pred A _ { x } = x ≡ _Im_ ⊆ _ : { UUU WWW TTT : Universe} { A : UUU (cid:5) } { B : WWW (cid:5) } → ( A → B ) → Pred B TTT → UUU ⊔ TTT (cid:5)
Im_ ⊆ _ { A = A } f S = ( x : A ) → f x ∈ S img : { UUU : Universe}{ X : UUU (cid:5) } { Y : UUU (cid:5) }( f : X → Y ) ( P : Pred Y UUU ) → Im f ⊆ P → X → Σ P img { Y = Y } f P Imf ⊆ P = λ x → f x , Imf ⊆ P x The product Π P of a predicate P : Pred X UUU is inhabited iff P x holds for all x : X . Π P-meaning : {
XXX UUU : Universe}{ X : XXX (cid:5) }{ P : Pred X UUU } → Π P → ( x : X ) → P x Π P-meaning f x = f x The following is a pair of useful “transport” lemmas for predicates. module _ {
UUU WWW : Universe} wherecong-app-pred : { A : UUU (cid:5) }{ B B : Pred A WWW }( x : A ) → x ∈ B → B ≡ B —————————— → x ∈ B cong-app-pred x x ∈ B (refl _ ) = x ∈ B cong-pred : { A : UUU (cid:5) }{ B : Pred A WWW }( x y : A ) → x ∈ B → x ≡ y—————————- → y ∈ B cong-pred x . x x ∈ B (refl _ ) = x ∈ B This subsection presents the
UALib.Relations.Binary submodule of the Agda UALib. In settheory, a binary relation on a set A is simply a subset of the product A × A . As such, we couldmodel these as predicates over the type A × A , or as relations of type A → A → RRR (cid:5) (for someuniverse
RRR ). We define these below.A generalization of the notion of binary relation is a relation from A to B , which we definefirst and treat binary relations on a single A as a special case. module UALib.Relations.Binary whereopen import UALib.Relations.Unary publicmodule _ { UUU : Universe} whereREL : {
RRR : Universe} → UUU (cid:5) → RRR (cid:5) → ( NNN : Universe) → ( UUU ⊔ RRR ⊔ NNN + ) (cid:5) REL
A B
NNN = A → B → NNN (cid:5)
The kernel of a function can be defined in many ways. For example,
KER : {
RRR : Universe} { A : UUU (cid:5) } { B : RRR (cid:5) } → ( A → B ) → UUU ⊔ RRR (cid:5)
KER {
RRR } { A } g = Σ x : A , Σ y : A , g x ≡ g y or as a unary relation (predicate) over the Cartesian product, KER-pred : {
RRR : Universe} { A : UUU (cid:5) }{ B : RRR (cid:5) } → ( A → B ) → Pred ( A × A ) RRR
KER-pred g ( x , y ) = g x ≡ g y or as a relation from A to B , Rel :
UUU (cid:5) → ( NNN : Universe) → UUU ⊔ NNN + (cid:5) Rel A NNN = REL
A A
NNN
KER-rel : {
RRR : Universe}{ A : UUU (cid:5) } { B : RRR (cid:5) } → ( A → B ) → Rel A RRR
KER-rel g x y = g x ≡ g y ker : { A B : UUU (cid:5) } → ( A → B ) → UUU (cid:5) ker = KER{
UUU }ker-rel : {
A B : UUU (cid:5) } → ( A → B ) → Rel A UUU ker-rel = KER-rel {
UUU }ker-pred : {
A B : UUU (cid:5) } → ( A → B ) → Pred ( A × A ) UUU ker-pred = KER-pred {
UUU } –The identity relation. : { A : UUU (cid:5) } → UUU (cid:5) { A } = Σ a : A , Σ b : A , a ≡ b–...as a binary relation... -rel : { A : UUU (cid:5) } → Rel A UUU he Agda Universal Algebra Library 29 -rel a b = a ≡ b–...as a binary predicate... -pred : { A : UUU (cid:5) } → Pred ( A × A ) UUU -pred ( a , a’ ) = a ≡ a’ -pred’ : { A : UUU (cid:5) } → UUU (cid:5) -pred’ { A } = Σ p : ( A × A ) , | p | ≡ ∥ p ∥ –...on the domain of an algebra... -alg-rel : { S : Signature OOO VVV }{ A : Algebra UUU S } → UUU (cid:5) -alg-rel { A = A } = Σ a : | A | , Σ b : | A | , a ≡ b– The total relation A × A : { A : UUU (cid:5) } → Rel A UUU a b = reflexive : { RRR : Universe}{ X : UUU (cid:5) } → Rel X RRR → UUU ⊔ RRR (cid:5) reflexive _ ≈ _ = ∀ x → x ≈ x symmetric : { RRR : Universe}{ X : UUU (cid:5) } → Rel X RRR → UUU ⊔ RRR (cid:5) symmetric _ ≈ _ = ∀ x y → x ≈ y → y ≈ x transitive : { RRR : Universe}{ X : UUU (cid:5) } → Rel X RRR → UUU ⊔ RRR (cid:5) transitive _ ≈ _ = ∀ x y z → x ≈ y → y ≈ z → x ≈ z is-subsingleton-valued : { RRR : Universe}{ A : UUU (cid:5) } → Rel A RRR → UUU ⊔ RRR (cid:5) is-subsingleton-valued _ ≈ _ = ∀ x y → is-prop ( x ≈ y ) Recall, in Section 1.1.7 we described the concept of truncation as it relates to “proof-relevant”mathematics. Given a binary relation P , it may be necessary or desirable to assume thatthere is at most one way to prove that a given pair of elements is P -related We use Escardo’s is-subsingleton type to express this strong (truncation at level 1) assumption in the followingdefinition: We say that ( x , y ) belongs to P , or that x and y are P -related if and only if both P x y and is-subsingleton ( P x y ) holds. Rel : UUU (cid:5) → ( NNN : Universe) → UUU ⊔ NNN + (cid:5) Rel A NNN = Σ P : ( A → A → NNN (cid:5) ) , ∀ x y → is-subsingleton ( P x y ) As above we define a set to be a type X with the following property: for all x y : X there is atmost one proof that x ≡ y . In other words, X is a set if and only if it satisfies the following: ∀ x y : X → is-subsingleton ( x ≡ y ) This is another example of “proof-irrelevance”; indeed, proofs of P x y are indistinguishable, or rather anydistinctions are irrelevant in the context of interest. We denote and define implication as follows. – (syntactic sugar) _on_ : {
UUU VVV WWW : Universe}{ A : UUU (cid:5) }{ B : VVV (cid:5) }{ C : WWW (cid:5) } → ( B → B → C ) → ( A → B ) → ( A → A → C ) _*_ on g = λ x y → g x * g y _ ⇒ _ : { UUU VVV WWW XXX : Universe}{ A : UUU (cid:5) } { B : VVV (cid:5) } → REL
A B
WWW → REL
A B
XXX → UUU ⊔ VVV ⊔ WWW ⊔ XXX (cid:5) P ⇒ Q = ∀ { i j } → P i j → Q i j infixr 4 _ ⇒ _ Here is a more general version that we borrow from the standard library and translate intoMHE/UALib notation. _=[_] ⇒ _ : { UUU VVV RRR SSS : Universe}{ A : UUU (cid:5) } { B : VVV (cid:5) } → Rel A RRR → ( A → B ) → Rel B SSS → UUU ⊔ RRR ⊔ SSS (cid:5) P =[ g ] ⇒ Q = P ⇒ ( Q on g )infixr 4 _=[_] ⇒ _ This subsection presents the
UALib.Relations.Equivalences submodule of the Agda UALib. Thisis all standard stuff. The notions of reflexivity, symmetry, and transitivity are defined as onewould hope and expect, so we present them here without further explanation. module UALib.Relations.Equivalences whereopen import UALib.Relations.Binary publicmodule _ {
UUU RRR : Universe} whererecord IsEquivalence { A : UUU (cid:5) } ( _ ≈ _ : Rel A RRR ) :
UUU ⊔ RRR (cid:5) wherefieldrfl : reflexive _ ≈ _ sym : symmetric _ ≈ _ trans : transitive _ ≈ _ is-equivalence-relation : { X : UUU (cid:5) } → Rel X RRR → UUU ⊔ RRR (cid:5) is-equivalence-relation _ ≈ _ = is-subsingleton-valued _ ≈ _ × reflexive _ ≈ _ × symmetric _ ≈ _ × transitive _ ≈ _ he Agda Universal Algebra Library 31 The zero relation -rel is equivalent to the identity relation ≡ and, of course, these are bothequivalence relations. Indeed, we saw in Subsection 1.2.1 that ≡ is reflexive, symmetric, andtransitive, so we simply apply the corresponding proofs where appropriate. module _ { UUU : Universe} where -IsEquivalence : { A : UUU (cid:5) } → IsEquivalence{
UUU }{ A = A } -rel -IsEquivalence = record { rfl = ≡ -rfl; sym = ≡ -sym; trans = ≡ -trans } ≡ -IsEquivalence : { A : UUU (cid:5) } → IsEquivalence{
UUU }{ A = A } _ ≡ _ ≡ -IsEquivalence = record { rfl = ≡ -rfl ; sym = ≡ -sym ; trans = ≡ -trans } Finally, it’s useful to have on hand a proof of the fact that the kernel of a function is an equi-valence relation. map-kernel-IsEquivalence : {
WWW : Universe}{ A : UUU (cid:5) }{ B : WWW (cid:5) }( f : A → B ) → IsEquivalence (KER-rel f )map-kernel-IsEquivalence { WWW } f =record { rfl = λ x → r e f l ; sym = λ x y x → ≡ -sym{ WWW } ( f x ) ( f y ) x ; trans = λ x y z x x → ≡ -trans ( f x ) ( f y ) ( f z ) x x } This subsection presents the
UALib.Relations.Quotients submodule of the Agda UALib. module UALib.Relations.Quotients whereopen import UALib.Relations.Equivalences publicopen import UALib.Prelude.Preliminaries using (_ ⇔ _; id) publicmodule _ { UUU RRR : Universe} where
For a binary relation R on A , we denote a single R -class as [ a ] R (the class containing a ). Thisnotation is defined in UALib as follows. – relation class [_] : { A : UUU (cid:5) } → A → Rel A RRR → Pred A RRR [ a ] R = λ x → R a x
So, x ∈ [ a ] R iff R a x , and the following elimination rule is a tautology. []-elim : { A : UUU (cid:5) }{ a x : A }{ R : Rel A RRR } → R a x ⇔ ( x ∈ [ a ] R )[]-elim = id , id We define type of all classes of a relation R as follows. C : { A : UUU (cid:5) }{ R : Rel A RRR } → Pred A RRR → ( UUU ⊔ RRR + ) (cid:5) C { A }{ R } = λ ( C : Pred A RRR ) → Σ a : A , C ≡ ( [ a ] R ) There are a few ways we could define the quotient with respect to a relation. We have foundthe following to be the most convenient. – relation quotient (predicate version) _/_ : ( A : UUU (cid:5) ) → Rel A RRR → UUU ⊔ ( RRR + ) (cid:5) A / R = Σ C : Pred A RRR , C { A }{ R } C– old version: A / R = Σ C : Pred A
RRR , Σ a : A , C ≡ ( [ a ] R ) We then define the following introduction rule for a relation class with designated representative. ⟦_⟧ : { A : UUU (cid:5) } → A → { R : Rel A RRR } → A / R ⟦ a ⟧ { R } = ([ a ] R ) , a , r e f l –So, x ∈ [ a ] p R iff R a x, and the following elimination rule is a tautology. ⟦⟧-elim : { A : UUU (cid:5) }{ a x : A }{ R : Rel A RRR } → R a x ⇔ ( x ∈ [ a ] R )⟦⟧-elim = id , id If the relation is reflexive, then we have the following elimination rules. /-refl : { A : UUU (cid:5) }{ a a’ : A }{ R : Rel A RRR } → reflexive R → [ a ] R ≡ [ a’ ] R → R a a’ /-refl{ A = A }{ a }{ a’ }{ R } rfl x = γ wherea’in : a’ ∈ [ a’ ] R a’in = rfl a’ γ : a’ ∈ [ a ] R γ = cong-app-pred a’ a’in ( x )/-refl’ : { A : UUU (cid:5) }{ a a’ : A }{ R : Rel A RRR } → transitive R → R a’ a → ([ a ] R ) ⊆ ([ a’ ] R )/-refl’{ A = A }{ a }{ a’ }{ R } trn Ra’a { x } aRx = trn a’ a x Ra’a aRx ⌜ _ ⌝ : { A : UUU (cid:5) }{ R : Rel A RRR } → A / R → A ⌜ aaa ⌝ = | ∥ aaa ∥ | – type ⌜ and ⌝ as ‘\cul‘ and ‘\cur‘ and an elimination rule for relation class representative, defined as follows. /-Refl : { A : UUU (cid:5) }{ a a’ : A }{ R : Rel A RRR } → reflexive R → ⟦ a ⟧{ R } ≡ ⟦ a’ ⟧ → R a a’ /-Refl rfl (refl _) = rfl _ Later we will need the following additional quotient tools. open IsEquivalence{
UUU }{ RRR }/-subset : { A : UUU (cid:5) }{ a a’ : A }{ R : Rel A RRR } → IsEquivalence R → R a a’ → ([ a ] R ) ⊆ ([ a’ ] R )/-subset { A = A }{ a }{ a’ }{ R } Req Raa’ { x } Rax = (trans
Req ) a’ a x (sym Req a a’ Raa’ ) Rax /-supset : { A : UUU (cid:5) }{ a a’ : A }{ R : Rel A RRR } → IsEquivalence R → R a a’ → ([ a ] R ) ⊇ ([ a’ ] R )/-supset { A = A }{ a }{ a’ }{ R } Req Raa’ { x } Ra’x = (trans
Req ) a a’ x Raa’ Ra’x /-= (cid:5) : { A : UUU (cid:5) }{ a a’ : A }{ R : Rel A RRR } → IsEquivalence R → R a a’ → ([ a ] R ) = (cid:5) ([ a’ ] R )/-= (cid:5) { A = A }{ a }{ a’ }{ R } Req Raa’ = /-subset
Req Raa’ , /-supset
Req Raa’ he Agda Universal Algebra Library 33
We need a (subsingleton) identity type for congruence classes over sets so that we can equate twoclasses even when they are presented using different representatives. For this we assume thatour relations are on sets, rather than arbitrary types. As mentioned earlier, this is equivalentto assuming that there is at most one proof that two elements of a set are the same.(Recall, a type is called a set if it has unique identity proofs ; as a general principle, this issometimes referred to as “proof irrelevance” or “uniqueness of identity proofs”—two proofs ofa single identity are the same.) class-extensionality : propext
RRR → global-dfunext → { A : UUU (cid:5) }{ a a’ : A }{ R : Rel A RRR } → ( ∀ a x → is-subsingleton ( R a x )) → IsEquivalence
R———————— → R a a’ → ([ a ] R ) ≡ ([ a’ ] R )class-extensionality pe gfe { A = A }{ a }{ a’ }{ R } ssR Req Raa’ =Pred-= (cid:5) - ≡ pe gfe { A }{[ a ] R }{[ a’ ] R } ( ssR a ) ( ssR a’ ) (/-= (cid:5) Req Raa’ )to-subtype-⟦⟧ : { A : UUU (cid:5) }{ R : Rel A RRR }{ C D : Pred A RRR }{ c : C C }{ d : C D } → ( ∀ C → is-subsingleton ( C { A }{ R } C )) → C ≡ D → ( C , c ) ≡ ( D , d )to-subtype-⟦⟧ { D = D }{ c }{ d } ssA CD = to- Σ - ≡ ( CD , ssA D (transport C CD c ) d )class-extensionality’ : propext RRR → global-dfunext → { A : UUU (cid:5) }{ a a’ : A }{ R : Rel A RRR } → ( ∀ a x → is-subsingleton ( R a x )) → ( ∀ C → is-subsingleton ( C C )) → IsEquivalence
R————————————— → R a a’ → (⟦ a ⟧ { R }) ≡ (⟦ a’ ⟧ { R })class-extensionality’ pe gfe { A = A }{ a }{ a’ }{ R } ssR ssA Req Raa’ = γ whereCD : ([ a ] R ) ≡ ([ a’ ] R )CD = class-extensionality pe gfe { A }{ a }{ a’ }{ R } ssR Req Raa’ γ : (⟦ a ⟧ { R }) ≡ (⟦ a’ ⟧ { R }) γ = to-subtype-⟦⟧ ssA CD The following definitions and lemmas are useful for asserting and proving facts about compat-ibility of relations and functions. module _ {
UUU VVV WWW : Universe} { γ : VVV (cid:5) } { Z : UUU (cid:5) } wherelift-rel : Rel Z WWW → ( γ → Z ) → ( γ → Z ) → VVV ⊔ WWW (cid:5) lift-rel
R f g = ∀ x → R ( f x ) ( g x ) compatible-fun : ( f : ( γ → Z ) → Z )( R : Rel Z WWW ) → VVV ⊔ UUU ⊔ WWW (cid:5) compatible-fun f R = (lift-rel R ) =[ f ] ⇒ R– relation compatible with an operation module _ {
UUU WWW : Universe} { S : Signature OOO VVV } wherecompatible-op : { A : Algebra UUU S } → | S | → Rel | A | WWW → UUU ⊔ VVV ⊔ WWW (cid:5) compatible-op { A } f R = ∀ { aaa }{ bbb } → (lift-rel R ) aaa bbb → R (( f ˆ A ) aaa ) (( f ˆ A ) bbb ) – alternative notation: (lift-rel R) =[ f ˆ A ] ⇒ R–The given relation is compatible with all ops of an algebra. compatible : ( A : Algebra UUU S ) → Rel | A | WWW → OOO ⊔ UUU ⊔ VVV ⊔ WWW (cid:5) compatible A R = ∀ f → compatible-op{ A } f R çpad We’ll see this definition of compatibility at work very soon when we define congruencerelations in the next section. This subsection presents the
UALib.Relations.Congruences submodule of the Agda UALib. No-tice that module begins by assuming a signature S : Signature OOO VVV which is then present andavailable throughout the module. open import UALib.Algebras.Signatures using (Signature;
OOO ; VVV )module UALib.Relations.Congruences { S : Signature OOO VVV } whereopen import UALib.Relations.Quotients hiding (Signature;
OOO ; VVV ) publicCon : {
UUU : Universe}( A : Algebra UUU S ) → OOO ⊔ VVV ⊔ UUU + (cid:5) Con {
UUU } A = Σ θ : ( Rel | A | UUU ) , IsEquivalence θ × compatible A θ con : { UUU : Universe}( A : Algebra UUU S ) → Pred (Rel | A | UUU ) (
OOO ⊔ VVV ⊔ UUU )con A = λ θ → IsEquivalence θ × compatible A θ record Congruence { UUU WWW : Universe} ( A : Algebra UUU S ) : OOO ⊔ VVV ⊔ UUU ⊔ WWW + (cid:5) whereconstructor mkconfield ⟨ _ ⟩ : Rel | A | WWW
Compatible : compatible A ⟨ _ ⟩ IsEquiv : IsEquivalence ⟨ _ ⟩ open Congruencecompatible-equivalence : { UUU WWW : Universe}{ A : Algebra UUU S } → Rel | A | WWW → OOO ⊔ VVV ⊔ WWW ⊔ UUU (cid:5) compatible-equivalence {
UUU }{ WWW } { A } R = compatible A R × IsEquivalence R We defined the trivial (or “diagonal” or “identity” or “zero”) relation -rel in Subsection 3.2.2,and we observed in Subsection 3.3.1 that -rel is equivalent to the identity relation ≡ and thatthese are both equivalence relations. Therefore, in order to build a congruence of some algebra A out of the trivial relation, it remains to show that -rel is compatible with all operations of A . We do this now and immediately after we construct the corresponding congruence. module _ { UUU : Universe} { S : Signature OOO VVV } where he Agda Universal Algebra Library 35 -compatible-op : funext VVV UUU → { A : Algebra UUU S } ( f : | S | ) → compatible-op { UUU = UUU }{ A = A } f -rel -compatible-op fe { A } f ptws0 = ap ( f ˆ A ) ( fe ( λ x → ptws0 x )) -compatible : funext VVV UUU → { A : Algebra UUU S } → compatible A -rel -compatible fe { A } = λ f args → -compatible-op fe { A } f args Now that we have the ingredients required to construct a congruence, we carry out the con-struction as follows. ∆ : { UUU : Universe} → funext VVV UUU → ( A : Algebra UUU S ) → Congruence A ∆ fe A = mkcon -rel ( -compatible fe ) ( -IsEquivalence ) An important construction in universal algebra is the quotient of an algebra A with respect toa congruence relation θ of A . This quotient is typically denote by A / θ and Agda allows us todefine and express quotients using the standard notation. _ ⧸ _ : { UUU RRR : Universe}( A : Algebra UUU S ) → Congruence{
UUU }{ RRR } A———————– → Algebra (
UUU ⊔ RRR + ) S A ⧸ θ = (( | A | / ⟨ θ ⟩ ) , – carrier (i.e. domain or universe)) ( λ f args – operations → ([ ( f ˆ A ) ( λ i → | ∥ args i ∥ | ) ] ⟨ θ ⟩ ) ,(( f ˆ A ) ( λ i → | ∥ args i ∥ | ) , refl _ ))) The zero element of a quotient can be expressed as follows.
Zero ⧸ : { UUU RRR : Universe}{ A : Algebra UUU S }( θ : Congruence{ UUU }{ RRR } A ) → Rel ( | A | / ⟨ θ ⟩ ) ( UUU ⊔ RRR + )Zero ⧸ θ = λ x x → x ≡ x Finally, the following elimination rule is sometimes useful. ⧸ -refl :{ UUU RRR : Universe} ( A : Algebra UUU S ){ θ : Congruence{ UUU }{ RRR } A } { a a’ : | A | } → ⟦ a ⟧{ ⟨ θ ⟩ } ≡ ⟦ a’ ⟧ → ⟨ θ ⟩ a a’ ⧸ -refl A { θ } (refl _) = IsEquivalence.rfl (IsEquiv θ ) _ (This page is almost entirely blank on purpose.) he Agda Universal Algebra Library 37 This section presents the
UALib.Homomorphisms module of the Agda UALib.
This subsection describes the
UALib.Homomorphisms.Basic submodule of the Agda UALib. Thedefinition of homomorphism in the Agda UALib is an extensional one; that is, the homomorph-ism condition holds pointwise. This will become clearer once we have the formal definitions inhand. Generally speaking, though, we say that two functions f g : X → Y are extensionallyequal iff they are pointwise equal, that is, for all x : X we have f x ≡ g x .Now let’s quickly dispense with the usual preliminaries so we can get down to the businessof defining homomorphisms. open import UALib.Algebras.Signatures using (Signature; OOO ; VVV )module UALib.Homomorphisms.Basic { S : Signature OOO VVV } whereopen import UALib.Relations.Congruences{ S = S } publicopen import UALib.Prelude.Preliminaries using (_ ≡⟨ _ ⟩ _; _ ■ ) public To define homomorphism , we first say what it means for an operation f , interpreted in thealgebras A and B , to commute with a function g : A → B . compatible-op-map : { QQQ UUU : Universe}( A : Algebra QQQ S )( B : Algebra UUU S )( f : | S | )( g : | A | → | B | ) → VVV ⊔ UUU ⊔ QQQ (cid:5) compatible-op-map
A B f g = ∀ aaa → g (( f ˆ A ) aaa ) ≡ ( f ˆ B ) ( g ◦ aaa ) Note the appearance of the shorthand ∀ aaa in the definition of compatible-op-map . We canget away with this in place of the fully type-annotated equivalent, ( aaa : ∥ S ∥ f → | A | ) sinceAgda is able to infer that the aaa here must be a tuple on | A | of “length” ∥ S ∥ f (the arity of f ). op_interpreted-in_and_commutes-with : { QQQ UUU : Universe}( f : | S | ) ( A : Algebra QQQ S ) ( B : Algebra UUU S )( g : | A | → | B | ) → VVV ⊔ QQQ ⊔ UUU (cid:5) op f interpreted-in A and B commutes-with g = compatible-op-map A B f g We now define the type hom
A B of homomorphisms from A to B by first defining theproperty is-homomorphism , as follows. is-homomorphism : { QQQ UUU : Universe}( A : Algebra QQQ S )( B : Algebra UUU S ) → ( | A | → | B | ) → OOO ⊔ VVV ⊔ QQQ ⊔ UUU (cid:5) is-homomorphism
A B g = ∀ ( f : | S | ) → compatible-op-map A B f g hom : { QQQ UUU : Universe} → Algebra
QQQ S → Algebra
UUU S → OOO ⊔ VVV ⊔ QQQ ⊔ UUU (cid:5) hom
A B = Σ g : ( | A | → | B | ) , is-homomorphism A B g A simple example is the identity map, which is proved to be a homomorphism as follows. i d : {
UUU : Universe} ( A : Algebra UUU S ) → hom A A i d _ = ( λ x → x ) , λ _ _ → r e f l id-is-hom : { UUU : Universe}{ A : Algebra UUU S } → is-homomorphism A A ( id | A | )id-is-hom = λ _ _ → refl _ Recall, the equalizer of two functions (resp., homomorphisms) g h : A → B is the subset of A on which the values of the functions g and h agree. We define the equalizer of functions andhomomorphisms in Agda as follows. –Equalizers of functions E : { UUU WWW : Universe}{ A : UUU (cid:5) }{ B : WWW (cid:5) }( g h : A → B ) → Pred A WWW E g h x = g x ≡ h x–Equalizers of homomorphisms EH : { UUU WWW : Universe}{ A : Algebra UUU S }{ B : Algebra WWW S }( g h : hom A B ) → Pred | A | WWW EH g h x = | g | x ≡ | h | x We will define subuniverses in the
UALib.Subalgebras.Subuniverses module, but we note here thatthe equalizer of homomorphisms f rom A to B will turn out to be subuniverse of A . Indeed,this easily follow from, EH -is-closed : { UUU WWW : Universe} → funext VVV WWW → { A : Algebra UUU S }{ B : Algebra WWW S }( g h : hom A B ) { f : | S | } ( aaa : ( ∥ S ∥ f ) → | A | ) → ( ( x : ∥ S ∥ f ) → ( aaa x ) ∈ ( EH { A = A }{ B = B } g h ) ) ————————————————— → | g | (( f ˆ A ) aaa ) ≡ | h | (( f ˆ A ) aaa ) EH -is-closed fe { A }{ B } g h { f } aaa p = | g | (( f ˆ A ) aaa ) ≡⟨ ∥ g ∥ f aaa ⟩ ( f ˆ B )( | g | ◦ aaa ) ≡⟨ ap (_ ˆ B )( fe p ) ⟩ ( f ˆ B )( | h | ◦ aaa ) ≡⟨ ( ∥ h ∥ f aaa ) ⟩| h | (( f ˆ A ) aaa ) ■ This subsection describes the
UALib.Homomorphisms.Kernels submodule of the Agda UALib.The kernel of a homomorphism is a congruence and conversely for every congruence θ , thereexists a homomorphism with kernel θ . open import UALib.Algebras.Signatures using (Signature; OOO ; VVV )open import UALib.Prelude.Preliminaries using (global-dfunext)module UALib.Homomorphisms.Kernels { S : Signature OOO VVV } { gfe : global-dfunext} whereopen import UALib.Homomorphisms.Basic{ S = S } publicmodule _ { UUU WWW : Universe} whereopen Congruence he Agda Universal Algebra Library 39 hom-kernel-is-compatible : ( A : Algebra UUU S ){ B : Algebra WWW S }( h : hom A B ) → compatible A (KER-rel | h | )hom-kernel-is-compatible A { B } h f { aaa }{ aaa ’ } Kerhab = γ where γ : | h | (( f ˆ A ) aaa ) ≡ | h | (( f ˆ A ) aaa ’ ) γ = | h | (( f ˆ A ) aaa ) ≡⟨ ∥ h ∥ f aaa ⟩ ( f ˆ B ) ( | h | ◦ aaa ) ≡⟨ ap ( λ - → ( f ˆ B ) - ) ( gfe λ x → Kerhab x ) ⟩ ( f ˆ B ) ( | h | ◦ aaa ’ ) ≡⟨ ( ∥ h ∥ f aaa ’ ) ⟩| h | (( f ˆ A ) aaa ’ ) ■ hom-kernel-is-equivalence : ( A : Algebra UUU S ){ B : Algebra WWW S }( h : hom A B ) → IsEquivalence (KER-rel | h | )hom-kernel-is-equivalence A h = map-kernel-IsEquivalence | h | It is convenient to define a function that takes a homomorphism and constructs a congruencefrom its kernel. We call this function hom-kernel-congruence , but since we will use it often wealso give it a short alias— kercon . kercon – (alias) hom-kernel-congruence : ( A : Algebra UUU S ){ B : Algebra WWW S }( h : hom A B ) → Congruence A hom-kernel-congruence A { B } h = mkcon (KER-rel | h | )(hom-kernel-is-compatible A { B } h )(hom-kernel-is-equivalence A { B } h )kercon = hom-kernel-congruence – (alias) quotient-by-hom-kernel : ( A : Algebra UUU S ){ B : Algebra WWW S }( h : hom A B ) → Algebra (
UUU ⊔ WWW + ) S quotient-by-hom-kernel A { B } h = A ⧸ (hom-kernel-congruence A { B } h ) – NOTATION. _[_]/ker_ : ( A : Algebra UUU S )( B : Algebra WWW S )( h : hom A B ) → Algebra (
UUU ⊔ WWW + ) S A [ B ]/ker h = quotient-by-hom-kernel A { B } h epi : { UUU WWW : Universe} → Algebra
UUU S → Algebra
WWW S → OOO ⊔ VVV ⊔ UUU ⊔ WWW (cid:5) epi
A B = Σ g : ( | A | → | B | ) , is-homomorphism A B g × Epic g epi-to-hom : { UUU WWW : Universe}( A : Algebra UUU S ){ B : Algebra WWW S } → epi A B → hom A B epi-to-hom A φ = | φ | , fst ∥ φ ∥ module _ { UUU WWW : Universe} whereopen Congruencecanonical-projection : ( A : Algebra UUU S ) ( θ : Congruence{ UUU }{ WWW } A ) → epi A ( A ⧸ θ ) canonical-projection A θ = c π , c π -is-hom , c π -is-epicwherec π : | A | → | A ⧸ θ | c π a = ⟦ a ⟧ – ([ a ] (KER-rel | h | )) , ? c π -is-hom : is-homomorphism A ( A ⧸ θ ) c π c π -is-hom f aaa = γ where γ : c π (( f ˆ A ) aaa ) ≡ ( f ˆ ( A ⧸ θ )) ( λ x → c π ( aaa x )) γ = c π (( f ˆ A ) aaa ) ≡⟨ r e f l ⟩ ⟦ ( f ˆ A ) aaa ⟧ ≡⟨ r e f l ⟩ ( f ˆ ( A ⧸ θ )) ( λ x → ⟦ aaa x ⟧) ≡⟨ r e f l ⟩ ( f ˆ ( A ⧸ θ )) ( λ x → c π ( aaa x )) ■ c π -is-epic : Epic c π c π -is-epic (.( ⟨ θ ⟩ a ) , a , refl _) = Image_ ∋ _.im a π k – alias kernel-quotient-projection : { UUU WWW : Universe} – (pe : propext
WWW ) ( A : Algebra UUU S ){ B : Algebra WWW S }( h : hom A B ) ———————————– → epi A ( A [ B ]/ker h )kernel-quotient-projection A { B } h = canonical-projection A (kercon A { B } h ) π k = kernel-quotient-projection This subsection describes the
UALib.Homomorphisms.Noether submodule of the Agda UALib. open import UALib.Algebras.Signatures using (Signature;
OOO ; VVV )open import UALib.Prelude.Preliminaries using (global-dfunext)module UALib.Homomorphisms.Noether { S : Signature OOO VVV }{ gfe : global-dfunext} whereopen import UALib.Homomorphisms.Kernels{ S = S }{ gfe } hiding ( global-dfunext ) public Here is a version of the so-called
First Homomorphism Theorem (aka, the
First IsomorphismTheorem ). open CongruenceFirstIsomorphismTheorem : { UUU WWW : Universe}( A : Algebra UUU S )( B : Algebra WWW S )( φ : hom A B ) ( φ E : Epic | φ | ) – extensionality assumptions: { pe : propext WWW }( Bset : is-set | B | ) he Agda Universal Algebra Library 41 → ( ∀ a x → is-subsingleton ( ⟨ kercon A { B } φ ⟩ a x )) → ( ∀ C → is-subsingleton ( C { A = | A | }{ ⟨ kercon A { B } φ ⟩ } C )) ————————————————————————————– → Σ f : (epi ( A [ B ]/ker φ ) B ) , ( | φ | ≡ | f | ◦ | π k A { B } φ | ) × is-embedding | f | FirstIsomorphismTheorem {
UUU }{ WWW } A B φ φ E { pe } Bset ssR ssA =(fmap , fhom , fepic) , commuting , fembwhere θ : Congruence A θ = kercon A { B } φ A / θ : Algebra ( UUU ⊔ WWW + ) S A / θ = A [ B ]/ker φ fmap : | A / θ | → | B | fmap a = | φ | ⌜ a ⌝ fhom : is-homomorphism A / θ B fmapfhom f aaa = | φ | ( fst ∥ ( f ˆ A / θ ) aaa ∥ ) ≡⟨ r e f l ⟩| φ | ( ( f ˆ A ) ( λ x → ⌜ ( aaa x ) ⌝ ) ) ≡⟨ ∥ φ ∥ f ( λ x → ⌜ ( aaa x ) ⌝ ) ⟩ ( f ˆ B ) ( | φ | ◦ ( λ x → ⌜ ( aaa x ) ⌝ )) ≡⟨ ap ( λ - → ( f ˆ B ) - ) ( gfe λ x → r e f l ) ⟩ ( f ˆ B ) ( λ x → fmap ( aaa x )) ■ fepic : Epic fmapfepic b = γ wherea : | A | a = EpicInv | φ | φ E b a/ θ : | A / θ | a/ θ = ⟦ a ⟧bfa : b ≡ fmap a/ θ bfa = (cong-app (EpicInvIsRightInv gfe | φ | φ E ) b ) γ : Image fmap ∋ b γ = Image_ ∋ _.eq b a/ θ bfacommuting : | φ | ≡ fmap ◦ | π k A { B } φ | commuting = r e f l fmon : Monic fmapfmon (.( ⟨ θ ⟩ a ) , a , refl _) (.( ⟨ θ ⟩ a’ ) , a’ , refl _) faa’ = γ wherea θ a’ : ⟨ θ ⟩ a a’ a θ a’ = faa’ γ : ( ⟨ θ ⟩ a , a , r e f l ) ≡ ( ⟨ θ ⟩ a’ , a’ , r e f l ) γ = class-extensionality’ pe gfe ssR ssA (IsEquiv θ ) a θ a’femb : is-embedding fmapfemb = monic-into-set-is-embedding Bset fmap fmon
The composition of homomorphisms is again a homomorphism. For convenience, we give a fewversions of this theorem which differ only with respect to which of their arguments are implicit. module _ {
QQQ UUU WWW : Universe} where – composition of homomorphisms 1
HCompClosed : ( A : Algebra QQQ S )( B : Algebra UUU S )( C : Algebra WWW S ) → hom A B → hom B C ——————– → hom A C
HCompClosed ( A , FA ) ( B , FB ) ( C , FC ) ( g , ghom ) ( h , hhom ) = h ◦ g , γ where γ : ( f : | S | )( a : ∥ S ∥ f → A ) → ( h ◦ g )( FA f a ) ≡ FC f ( h ◦ g ◦ a ) γ f a = ( h ◦ g ) ( FA f a ) ≡⟨ ap h ( ghom f a ) ⟩ h ( FB f ( g ◦ a )) ≡⟨ hhom f ( g ◦ a ) ⟩ FC f ( h ◦ g ◦ a ) ■ – composition of homomorphisms 2 HomComp : ( A : Algebra QQQ S ){ B : Algebra UUU S }( C : Algebra WWW S ) → hom A B → hom B C ——————– → hom A C
HomComp A { B } C f g = HCompClosed A B C f g– composition of homomorphisms 3 ◦ -hom : { XXX YYY ZZZ : Universe}( A : Algebra XXX S )( B : Algebra YYY S )( C : Algebra ZZZ S ){ f : | A | → | B | } { g : | B | → | C | } → is-homomorphism{ XXX }{ YYY } A B f → is-homomorphism{ YYY }{ ZZZ } B C g—————————————————– → is-homomorphism{ XXX }{ ZZZ } A C ( g ◦ f ) ◦ -hom A B C { f } { g } fhom ghom = ∥ HCompClosed
A B C ( f , fhom ) ( g , ghom ) ∥ – composition of homomorphisms 4 ◦ -Hom : { XXX YYY ZZZ : Universe}( A : Algebra XXX S ){ B : Algebra YYY S }( C : Algebra ZZZ S ){ f : | A | → | B | } { g : | B | → | C | } → is-homomorphism{ XXX }{ YYY } A B f → is-homomorphism{ YYY }{ ZZZ } B C g————————————————— → is-homomorphism{ XXX }{ ZZZ } A C ( g ◦ f ) ◦ -Hom A { B } C { f } { g } = ◦ -hom A B C { f } { g }trans-hom : { XXX YYY ZZZ : Universe}( A : Algebra XXX S )( B : Algebra YYY S )( C : Algebra ZZZ S )( f : | A | → | B | )( g : | B | → | C | ) he Agda Universal Algebra Library 43 → is-homomorphism{ XXX }{ YYY } A B f → is-homomorphism{ YYY }{ ZZZ } B C g——————————————————– → is-homomorphism{ XXX }{ ZZZ } A C ( g ◦ f )trans-hom { XXX }{ YYY }{ ZZZ } A B C f g = ◦ -hom { XXX }{ YYY }{ ZZZ } A B C { f }{ g } If g : hom A B , h : hom A C , h is surjective, and ker h ⊆ ker g , then there exists φ : hom CB } such that g = φ ◦ h , that is, such that the following diagram commutes. A ---- h -->> C \ .\ .g ∃ φ \ .\ .V B This, or some variation of it, is sometimes referred to as the
Second Isomorphism Theorem . Weformalize its statement and proof as follows. (Notice that the proof is constructive.) homFactor : {
UUU : Universe} → funext UUU UUU → { A B C : Algebra
UUU S }( g : hom A B ) ( h : hom A C ) → ker-pred | h | ⊆ ker-pred | g | → Epic | h | ——————————- → Σ φ : (hom C B ) , | g | ≡ | φ | ◦ | h | homFactor fe { A = A , FA }{ B = B , FB }{ C = C , FC }( g , ghom ) ( h , hhom ) Kh ⊆ Kg hEpi = ( φ , φ IsHomCB) , g ≡ φ ◦ hwherehInv : C → A hInv = λ c → (EpicInv h hEpi ) c φ : C → B φ = λ c → g ( hInv c ) ξ : ( x : A ) → ker-pred h ( x , hInv ( h x )) ξ x = ( cong-app (EpicInvIsRightInv fe h hEpi ) ( h x ) ) g ≡ φ ◦ h : g ≡ φ ◦ h g ≡ φ ◦ h = fe λ x → Kh ⊆ Kg ( ξ x ) ζ : ( f : | S | )( c : ∥ S ∥ f → C )( x : ∥ S ∥ f ) → c x ≡ ( h ◦ hInv)( c x ) ζ f c x = (cong-app (EpicInvIsRightInv fe h hEpi ) ( c x )) ι : ( f : | S | )( c : ∥ S ∥ f → C ) → ( λ x → c x ) ≡ ( λ x → h (hInv ( c x ))) ι f c = ap ( λ - → - ◦ c )(EpicInvIsRightInv fe h hEpi ) useker : ( f : | S | ) ( c : ∥ S ∥ f → C ) → g (hInv ( h ( FA f (hInv ◦ c )))) ≡ g ( FA f (hInv ◦ c ))useker = λ f c → Kh ⊆ Kg (cong-app(EpicInvIsRightInv fe h hEpi )( h ( FA f (hInv ◦ c )))) φ IsHomCB : ( f : | S | )( a : ∥ S ∥ f → C ) → φ ( FC f a ) ≡ FB f ( φ ◦ a ) φ IsHomCB f c = g (hInv ( FC f c )) ≡⟨ i ⟩ g (hInv ( FC f ( h ◦ (hInv ◦ c )))) ≡⟨ ii ⟩ g (hInv ( h ( FA f (hInv ◦ c )))) ≡⟨ iii ⟩ g ( FA f (hInv ◦ c )) ≡⟨ iv ⟩ FB f ( λ x → g (hInv ( c x ))) ■ wherei = ap ( g ◦ hInv) (ap ( FC f ) ( ι f c ))ii = ap ( λ - → g (hInv - )) ( hhom f (hInv ◦ c )) iii = useker f c iv = ghom f (hInv ◦ c ) This subsection describes the
UALib.Homomorphisms.Products submodule of the Agda UALib. open import UALib.Algebras.Signatures using (Signature;
OOO ; VVV )open import UALib.Prelude.Preliminaries using (global-dfunext)module UALib.Homomorphisms.Products { S : Signature OOO VVV }{ gfe : global-dfunext} whereopen import UALib.Homomorphisms.Noether{ S = S }{ gfe } public d -hom : global-dfunext → { QQQ UUU III : Universe}{ I : III (cid:5) }{ A : I → Algebra
QQQ S }{ B : I → Algebra
UUU S } → (( i : I ) → hom ( A i )( B i )) ———————– → hom ( d A ) ( d B ) d -hom gfe { QQQ }{ UUU }{ III }{ I }{ A }{ B } homs = φ , φ homwhere φ : | d A | → | d B | φ = λ x i → | homs i | ( x i ) φ hom : is-homomorphism ( d A ) ( d B ) φφ hom f aaa = gfe ( λ i → ∥ homs i ∥ f ( λ x → aaa x i )) he Agda Universal Algebra Library 45 Later we will need a proof of the fact that projecting out of a product algebra onto one of itsfactors is a homomorphism. d -projection-hom : { UUU III : Universe}{ I : III (cid:5) }{ A : I → Algebra
UUU S } —————————- → ( i : I ) → hom ( d A ) ( A i ) d -projection-hom { UUU }{ III }{ I }{ A } i = φ i , φ ihomwhere φ i : | d A | → | A i | φ i = λ x → x i φ ihom : is-homomorphism ( d A ) ( A i ) φ i φ ihom f aaa = φ i (( f ˆ d A ) aaa ) ≡⟨ r e f l ⟩ (( f ˆ d A ) aaa ) i ≡⟨ r e f l ⟩ ( f ˆ A i ) ( λ x → aaa x i ) ≡⟨ r e f l ⟩ ( f ˆ A i ) ( λ x → φ i ( aaa x )) ■ (Of course, we could prove a more general result involving projections onto multiple factors, butso far the single-factor result has sufficed.) This subsection describes the
UALib.Homomorphisms.Isomorphisms submodule of the Agda UALib.We implement (the extensional version of) the notion of isomorphism between algebraic struc-tures. open import UALib.Algebras.Signatures using (Signature;
OOO ; VVV )open import UALib.Prelude.Preliminaries using (global-dfunext)module UALib.Homomorphisms.Isomorphisms { S : Signature OOO VVV }{ gfe : global-dfunext} whereopen import UALib.Homomorphisms.Products{ S = S }{ gfe } publicopen import UALib.Prelude.Preliminaries using (is-equiv; hfunext; Nat; Nat Π ; Nat Π -is-embedding) public_ ∼ = _ : { UUU WWW : Universe} ( A : Algebra UUU S ) ( B : Algebra WWW S ) → OOO ⊔ VVV ⊔ UUU ⊔ WWW (cid:5) A ∼ = B = Σ f : (hom A B ) , Σ g : (hom B A ) , (( | f | ◦ | g | ) ∼ | i d B | ) × (( | g | ◦ | f | ) ∼ | i d A | ) Recall, f ∼ g means f and g are extensionally equal; i.e., ∀ x , f x ≡ g x . Here are some useful definitions and theorems for working with isomorphisms of algebraic struc-tures. module _ {
UUU WWW : Universe}{ A : Algebra UUU S }{ B : Algebra WWW S } where ∼ = -hom : ( φ : A ∼ = B ) → hom A B ∼ = -hom φ = | φ |∼ = -inv-hom : ( φ : A ∼ = B ) → hom B A ∼ = -inv-hom φ = fst ∥ φ ∥∼ = -map : ( φ : A ∼ = B ) → | A | → | B |∼ = -map φ = | ∼ = -hom φ |∼ = -map-is-homomorphism : ( φ : A ∼ = B ) → is-homomorphism A B ( ∼ = -map φ ) ∼ = -map-is-homomorphism φ = ∥ ∼ = -hom φ ∥∼ = -inv-map : ( φ : A ∼ = B ) → | B | → | A |∼ = -inv-map φ = | ∼ = -inv-hom φ |∼ = -inv-map-is-homomorphism : ( φ : A ∼ = B ) → is-homomorphism B A ( ∼ = -inv-map φ ) ∼ = -inv-map-is-homomorphism φ = ∥ ∼ = -inv-hom φ ∥∼ = -map-invertible : ( φ : A ∼ = B ) → invertible ( ∼ = -map φ ) ∼ = -map-invertible φ = ( ∼ = -inv-map φ ) , ( ∥ snd ∥ φ ∥ ∥ , | snd ∥ φ ∥ | ) ∼ = -map-is-equiv : ( φ : A ∼ = B ) → is-equiv ( ∼ = -map φ ) ∼ = -map-is-equiv φ = invertibles-are-equivs ( ∼ = -map φ ) ( ∼ = -map-invertible φ ) ∼ = -map-is-embedding : ( φ : A ∼ = B ) → is-embedding ( ∼ = -map φ ) ∼ = -map-is-embedding φ = equivs-are-embeddings ( ∼ = -map φ ) ( ∼ = -map-is-equiv φ ) REFL- ∼ = ID ∼ = : { UUU : Universe} ( A : Algebra UUU S ) → A ∼ = A ID ∼ = A = i d A , i d A , ( λ a → r e f l ) , ( λ a → r e f l )REFL- ∼ = = ID ∼ = refl- ∼ = id ∼ = : { UUU : Universe} { A : Algebra UUU S } → A ∼ = A id ∼ = { UUU }{ A } = ID ∼ = { UUU } A refl- ∼ = = id ∼ = sym- ∼ = : { QQQ UUU : Universe}{ A : Algebra QQQ S }{ B : Algebra UUU S } → A ∼ = B → B ∼ = A sym- ∼ = h = fst ∥ h ∥ , fst h , ∥ snd ∥ h ∥ ∥ , | snd ∥ h ∥ | trans- ∼ = : { QQQ UUU WWW : Universe}( A : Algebra QQQ S )( B : Algebra UUU S )( C : Algebra WWW S ) → A ∼ = B → B ∼ = C —————- → A ∼ = C trans- ∼ = A B C ab bc = f , g , α , β wheref1 : hom A B f1 = | ab | f2 : hom B C f2 = | bc | f : hom A C f = HCompClosed
A B C f1 f2 he Agda Universal Algebra Library 47 g1 : hom
C B g1 = fst ∥ bc ∥ g2 : hom B A g2 = fst ∥ ab ∥ g : hom C A g = HCompClosed
C B A g1 g2f1 ∼ g2 : | f1 | ◦ | g2 | ∼ | i d B | f1 ∼ g2 = | snd ∥ ab ∥ | g2 ∼ f1 : | g2 | ◦ | f1 | ∼ | i d A | g2 ∼ f1 = ∥ snd ∥ ab ∥ ∥ f2 ∼ g1 : | f2 | ◦ | g1 | ∼ | i d C | f2 ∼ g1 = | snd ∥ bc ∥ | g1 ∼ f2 : | g1 | ◦ | f2 | ∼ | i d B | g1 ∼ f2 = ∥ snd ∥ bc ∥ ∥ α : | f | ◦ | g | ∼ | i d C | α x = ( | f | ◦ | g | ) x ≡⟨ r e f l ⟩| f2 | ( ( | f1 | ◦ | g2 | ) ( | g1 | x )) ≡⟨ ap | f2 | (f1 ∼ g2 ( | g1 | x )) ⟩| f2 | ( | i d B | ( | g1 | x )) ≡⟨ r e f l ⟩ ( | f2 | ◦ | g1 | ) x ≡⟨ f2 ∼ g1 x ⟩| i d C | x ■ β : | g | ◦ | f | ∼ | i d A | β x = (ap | g2 | (g1 ∼ f2 ( | f1 | x ))) · g2 ∼ f1 x TRANS- ∼ = : { QQQ UUU WWW : Universe}{ A : Algebra QQQ S }{ B : Algebra UUU S }{ C : Algebra WWW S } → A ∼ = B → B ∼ = C —————- → A ∼ = C TRANS- ∼ = { A = A }{ B = B }{ C = C } = trans- ∼ = A B C
Trans- ∼ = : { QQQ UUU WWW : Universe}( A : Algebra QQQ S ){ B : Algebra UUU S }( C : Algebra WWW S ) → A ∼ = B → B ∼ = C —————- → A ∼ = C Trans- ∼ = A { B } C = trans- ∼ = A B C
Fortunately, the lift operation preserves isomorphism (i.e., it’s an “algebraic invariant”), whichis why it’s a workable solution to the “level hell” problem we mentioned earlier. open Lift –An algebra is isomorphic to its lift to a higher universe level lift-alg- ∼ = : { UUU WWW : Universe}{ A : Algebra UUU S } → A ∼ = (lift-alg A WWW )lift-alg- ∼ = = (lift , λ _ _ → r e f l ) , (lower , λ _ _ → r e f l ) ,( λ _ → r e f l ) , ( λ _ → r e f l )lift-alg-hom : ( XXX : Universe){
YYY : Universe}(
ZZZ : Universe){
WWW : Universe}( A : Algebra XXX S ) ( B : Algebra YYY S ) → hom A B ————————– → hom (lift-alg A ZZZ ) (lift-alg B WWW )lift-alg-hom
XXX ZZZ { WWW } A B ( f , fhom ) = lift ◦ f ◦ lower , γ wherelh : is-homomorphism (lift-alg A ZZZ ) A lowerlh = λ _ _ → r e f l lABh : is-homomorphism (lift-alg A ZZZ ) B ( f ◦ lower)lABh = ◦ -hom (lift-alg A ZZZ ) A B {lower}{ f } lh fhom Lh : is-homomorphism B (lift-alg B WWW ) liftLh = λ _ _ → r e f l γ : is-homomorphism (lift-alg A ZZZ ) (lift-alg B WWW ) (lift ◦ ( f ◦ lower)) γ = ◦ -hom (lift-alg A ZZZ ) B (lift-alg B WWW ) { f ◦ lower}{lift} lABh Lhlift-alg-iso : ( XXX : Universe){
YYY : Universe}(
ZZZ : Universe){
WWW : Universe}( A : Algebra XXX S ) ( B : Algebra YYY S ) → A ∼ = B ————————– → (lift-alg A ZZZ ) ∼ = (lift-alg B WWW )lift-alg-iso
XXX { YYY } ZZZ { WWW } A B A ∼ = B = TRANS- ∼ = (TRANS- ∼ = lA ∼ = A A ∼ = B ) lift-alg- ∼ = wherelA ∼ = A : (lift-alg A ZZZ ) ∼ = A lA ∼ = A = sym- ∼ = lift-alg- ∼ = The lift is also associative, up to isomorphism at least. lift-alg-assoc : {
UUU WWW III : Universe}{ A : Algebra UUU S } → lift-alg A ( WWW ⊔ III ) ∼ = (lift-alg (lift-alg A WWW ) III )lift-alg-assoc {
UUU } {
WWW } {
III } { A } = TRANS- ∼ = (TRANS- ∼ = ζ lift-alg- ∼ = ) lift-alg- ∼ = where ζ : lift-alg A ( WWW ⊔ III ) ∼ = A ζ = sym- ∼ = lift-alg- ∼ = lift-alg-associative : { UUU WWW III : Universe}( A : Algebra UUU S ) → lift-alg A ( WWW ⊔ III ) ∼ = (lift-alg (lift-alg A WWW ) III )lift-alg-associative{
UUU }{ WWW }{ III } A = lift-alg-assoc{ UUU }{ WWW }{ III }{ A } d ∼ = : global-dfunext → { QQQ UUU III : Universe}{ I : III (cid:5) }{ A : I → Algebra
QQQ S }{ B : I → Algebra
UUU S } he Agda Universal Algebra Library 49 → (( i : I ) → ( A i ) ∼ = ( B i )) ————————— → d A ∼ = d B d ∼ = gfe { QQQ }{ UUU }{ III }{ I }{ A }{ B } AB = γ whereF : ∀ i → | A i | → | B i | F i = | fst ( AB i ) | Fhom : ∀ i → is-homomorphism ( A i ) ( B i ) (F i )Fhom i = ∥ fst ( AB i ) ∥ G : ∀ i → | B i | → | A i | G i = fst | snd ( AB i ) | Ghom : ∀ i → is-homomorphism ( B i ) ( A i ) (G i )Ghom i = snd | snd ( AB i ) | F ∼ G : ∀ i → (F i ) ◦ (G i ) ∼ ( | i d ( B i ) | )F ∼ G i = fst ∥ snd ( AB i ) ∥ G ∼ F : ∀ i → (G i ) ◦ (F i ) ∼ ( | i d ( A i ) | )G ∼ F i = snd ∥ snd ( AB i ) ∥ φ : | d A | → | d B | φ a i = F i ( a i ) φ hom : is-homomorphism ( d A ) ( d B ) φφ hom f aaa = gfe ( λ i → (Fhom i ) f ( λ x → aaa x i )) ψ : | d B | → | d A | ψ b i = | fst ∥ AB i ∥ | ( b i ) ψ hom : is-homomorphism ( d B ) ( d A ) ψψ hom f bbb = gfe ( λ i → (Ghom i ) f ( λ x → bbb x i )) φ ~ ψ : φ ◦ ψ ∼ | i d ( d B ) | φ ~ ψ bbb = gfe λ i → F ∼ G i ( bbb i ) ψ ~ φ : ψ ◦ φ ∼ | i d ( d A ) | ψ ~ φ aaa = gfe λ i → G ∼ F i ( aaa i ) γ : d A ∼ = d B γ = ( φ , φ hom) , (( ψ , ψ hom) , φ ~ ψ , ψ ~ φ ) A nearly identical proof goes through for isomorphisms of lifted products. lift-alg- d ∼ = : global-dfunext → { QQQ UUU III ZZZ : Universe}{ I : III (cid:5) }{ A : I → Algebra
QQQ S }{ B : (Lift{ III }{ ZZZ } I ) → Algebra
UUU S } → (( i : I ) → ( A i ) ∼ = ( B (lift i ))) ————————— → lift-alg ( d A ) ZZZ ∼ = d B lift-alg- d ∼ = gfe { QQQ }{ UUU }{ III }{ ZZZ }{ I }{ A }{ B } AB = γ where F : ∀ i → | A i | → | B (lift i ) | F i = | fst ( AB i ) | Fhom : ∀ i → is-homomorphism ( A i ) ( B (lift i )) (F i )Fhom i = ∥ fst ( AB i ) ∥ G : ∀ i → | B (lift i ) | → | A i | G i = fst | snd ( AB i ) | Ghom : ∀ i → is-homomorphism ( B (lift i )) ( A i ) (G i )Ghom i = snd | snd ( AB i ) | F ∼ G : ∀ i → (F i ) ◦ (G i ) ∼ ( | i d ( B (lift i )) | )F ∼ G i = fst ∥ snd ( AB i ) ∥ G ∼ F : ∀ i → (G i ) ◦ (F i ) ∼ ( | i d ( A i ) | )G ∼ F i = snd ∥ snd ( AB i ) ∥ φ : | d A | → | d B | φ a i = F (lower i ) ( a (lower i )) φ hom : is-homomorphism ( d A ) ( d B ) φφ hom f aaa = gfe ( λ i → (Fhom (lower i )) f ( λ x → aaa x (lower i ))) ψ : | d B | → | d A | ψ b i = | fst ∥ AB i ∥ | ( b (lift i )) ψ hom : is-homomorphism ( d B ) ( d A ) ψψ hom f bbb = gfe ( λ i → (Ghom i ) f ( λ x → bbb x (lift i ))) φ ~ ψ : φ ◦ ψ ∼ | i d ( d B ) | φ ~ ψ bbb = gfe λ i → F ∼ G (lower i ) ( bbb i ) ψ ~ φ : ψ ◦ φ ∼ | i d ( d A ) | ψ ~ φ aaa = gfe λ i → G ∼ F i ( aaa i )A ∼ = B : d A ∼ = d B A ∼ = B = ( φ , φ hom) , (( ψ , ψ hom) , φ ~ ψ , ψ ~ φ ) γ : lift-alg ( d A ) ZZZ ∼ = d B γ = Trans- ∼ = (lift-alg ( d A ) ZZZ ) ( d B ) (sym- ∼ = lift-alg- ∼ = ) A ∼ = B Here are some useful tools for working with embeddings. embedding-lift-nat : {
QQQ UUU III : Universe} → hfunext III QQQ → hfunext III UUU → { I : III (cid:5) }{ A : I → QQQ (cid:5) }{ B : I → UUU (cid:5) }( h : Nat A B ) → (( i : I ) → is-embedding ( h i )) —————————- → is-embedding(Nat Π h )embedding-lift-nat hfiq hfiu h hem = Nat Π -is-embedding hfiq hfiu h hem he Agda Universal Algebra Library 51 embedding-lift-nat’ : { QQQ UUU III : Universe} → hfunext III QQQ → hfunext III UUU → { I : III (cid:5) }{ A : I → Algebra
QQQ S }{ B : I → Algebra
UUU S }( h : Nat (fst ◦ A ) (fst ◦ B )) → (( i : I ) → is-embedding ( h i )) ——————————- → is-embedding(Nat Π h )embedding-lift-nat’ hfiq hfiu h hem = Nat Π -is-embedding hfiq hfiu h hem embedding-lift : { QQQ UUU III : Universe} → hfunext III QQQ → hfunext III UUU → { I : III (cid:5) } – global-dfunext → { QQQ UUU III : Universe}{I :
III (cid:5) } { A : I → Algebra
QQQ S }{ B : I → Algebra
UUU S } → ( h : ∀ i → | A i | → | B i | ) → (( i : I ) → is-embedding ( h i )) ——————————————– → is-embedding( λ ( x : | d A | ) ( i : I ) → ( h i ) ( x i ))embedding-lift { QQQ } {
UUU } {
III } hfiq hfiu { I } { A } { B } h hem =embedding-lift-nat’ { QQQ } {
UUU } {
III } hfiq hfiu { I } { A } { B } h hem iso → embedding : { UUU WWW : Universe}{ A : Algebra UUU S }{ B : Algebra WWW S } → ( φ : A ∼ = B ) → is-embedding (fst | φ | )iso → embedding { UUU }{ WWW }{ A }{ B } φ = γ wheref : hom A B f = | φ | g : hom B A g = | snd φ | finv : invertible | f | finv = | g | , (snd ∥ snd φ ∥ , fst ∥ snd φ ∥ ) γ : is-embedding | f | γ = equivs-are-embeddings | f | (invertibles-are-equivs | f | finv) This subsection describes the
UALib.Homomorphisms.HomomorphicImages submodule of theAgda UALib. open import UALib.Algebras.Signatures using (Signature;
OOO ; VVV )open import UALib.Prelude.Preliminaries using (global-dfunext)module UALib.Homomorphisms.HomomorphicImages { S : Signature OOO VVV }{ gfe : global-dfunext} whereopen import UALib.Homomorphisms.Isomorphisms{ S = S }{ gfe } public We begin with what seems to be (for our purposes at least) the most useful way to represent,in Martin-Löf type theory, the class of homomomrphic images of an algebra.
HomImage : {
UUU WWW : Universe}{ A : Algebra UUU S }( B : Algebra WWW S )( φ : hom A B ) → | B | → UUU ⊔ WWW (cid:5)
HomImage B φ = λ b → Image | φ | ∋ b HomImagesOf : {
UUU WWW : Universe} → Algebra
UUU S → OOO ⊔ VVV ⊔ UUU ⊔ WWW + (cid:5) HomImagesOf {
UUU }{ WWW } A = Σ B : (Algebra WWW S ) , Σ φ : ( | A | → | B | ) , is-homomorphism A B φ × Epic φ Here are a few more definitions, derived from the one above, that will come in handy. _is-hom-image-of_ : {
UUU WWW : Universe} ( B : Algebra WWW S ) → ( A : Algebra UUU S ) → OOO ⊔ VVV ⊔ UUU ⊔ WWW + (cid:5) _is-hom-image-of_ { UUU }{ WWW } B A = Σ C φ : (HomImagesOf{ UUU }{ WWW } A ) , | C φ | ∼ = B _is-hom-image-of-class_ : { UUU : Universe} → Algebra
UUU S → Pred (Algebra
UUU S )( UUU + ) → OOO ⊔ VVV ⊔ UUU + (cid:5) _is-hom-image-of-class_ { UUU } B KKK = Σ A : (Algebra UUU S ) , ( A ∈ KKK ) × ( B is-hom-image-of A )HomImagesOfClass : { UUU : Universe} → Pred (Algebra
UUU S ) ( UUU + ) → OOO ⊔ VVV ⊔ UUU + (cid:5) HomImagesOfClass
KKK = Σ B : (Algebra _ S ) , ( B is-hom-image-of-class KKK )all-ops-in_and_commute-with : {
UUU WWW : Universe}( A : Algebra UUU S )( B : Algebra WWW S ) → ( | A | → | B | ) → OOO ⊔ VVV ⊔ UUU ⊔ WWW (cid:5) all-ops-in A and B commute-with g = is-homomorphism A B g open Liftlift-function : ( XXX : Universe){
YYY : Universe}(
ZZZ : Universe){
WWW : Universe}( A : XXX (cid:5) )( B : YYY (cid:5) ) → ( f : A → B ) ———————————– → Lift{
XXX }{ ZZZ } A → Lift{
YYY }{ WWW } B lift-function XXX { YYY } ZZZ { WWW } A B f = λ la → lift ( f (lower la ))lift-of-alg-epic-is-epic : ( XXX : Universe){
YYY : Universe}(
ZZZ : Universe){
WWW : Universe}( A : Algebra XXX S )( B : Algebra YYY S )( f : hom A B ) → Epic | f | ————————————— → Epic | lift-alg-hom XXX ZZZ { WWW } A B f | lift-of-alg-epic-is-epic XXX { YYY } ZZZ { WWW } A B f fepi = lEwherelA : Algebra (
XXX ⊔ ZZZ ) S lA = lift-alg A ZZZ lB : Algebra (
YYY ⊔ WWW ) S lB = lift-alg B WWW he Agda Universal Algebra Library 53 lf : hom (lift-alg A ZZZ ) (lift-alg B WWW )lf = lift-alg-hom
XXX ZZZ
A B f lE : ( y : | lB | ) → Image | lf | ∋ y lE y = ξ whereb : | B | b = lower y ζ : Image | f | ∋ b ζ = fepi ba : | A | a = Inv | f | b ζη : y ≡ | lf | (lift a) η = y ≡⟨ (intensionality lift ∼ lower) y ⟩ lift b ≡⟨ ap lift (InvIsInv | f | (lower y ) ζ ) ⟩ lift ( | f | a) ≡⟨ (ap ( λ - → lift ( | f | ( - a)))) (lower ∼ lift{ WWW = WWW }) ⟩ lift ( | f | ((lower{ WWW = WWW } ◦ lift) a)) ≡⟨ r e f l ⟩ (lift ◦ | f | ◦ lower{ WWW = WWW }) (lift a) ≡⟨ r e f l ⟩| lf | (lift a) ■ ξ : Image | lf | ∋ y ξ = eq y (lift a) η lift-alg-hom-image : { XXX YYY ZZZ WWW : Universe}{ A : Algebra XXX S }{ B : Algebra YYY S } → B is-hom-image-of A ———————————- → (lift-alg B WWW ) is-hom-image-of (lift-alg A ZZZ )lift-alg-hom-image {
XXX }{ YYY }{ ZZZ }{ WWW }{ A }{ B } (( C , φ , φ hom , φ epic ) , C ∼ = B ) = γ wherelA : Algebra ( XXX ⊔ ZZZ ) S lA = lift-alg A ZZZ lB lC : Algebra (
YYY ⊔ WWW ) S lB = lift-alg B WWW lC = lift-alg C WWW l φ : hom lA lCl φ = (lift-alg-hom XXX ZZZ
A C ) ( φ , φ hom )l φ epic : Epic | l φ | l φ epic = lift-of-alg-epic-is-epic XXX ZZZ
A C ( φ , φ hom ) φ epic lC φ : HomImagesOf { XXX ⊔ ZZZ }{ YYY ⊔ WWW } lAlC φ = lC , | l φ | , ∥ l φ ∥ , l φ epiclC ∼ = lB : lC ∼ = lBlC ∼ = lB = lift-alg-iso YYY WWW
C B C ∼ = B γ : lB is-hom-image-of lA γ = lC φ , lC ∼ = lB (This page is almost entirely blank on purpose.) he Agda Universal Algebra Library 55 This section presents the
UALib.Terms module of the Agda UALib.
This subsection describes the
UALib.Terms.Basic submodule of the Agda UALib. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Terms.Basic{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Homomorphisms.HomomorphicImages{ S = S }{ gfe } hiding ( Universe ; _ (cid:5) ) public We define a type called
Term which represents the type of terms of a given signature. As usual,the type X : U (cid:5) represents an arbitrary collection of variable symbols. data Term { XXX : Universe}{ X : XXX (cid:5) } :
OOO ⊔ VVV ⊔ XXX + (cid:5) wheregenerator : X → Term{
XXX }{ X }node : ( f : | S | )( args : ∥ S ∥ f → Term{
XXX }{ X }) → Termopen Term
This subsection describes the
UALib.Terms.Free submodule of the Agda UALib. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Terms.Free{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Terms.Basic{ S = S }{ gfe }{ X } hiding ( Algebra ) public
Terms can be viewed as acting on other terms and we can form an algebraic structure whosedomain and basic operations are both the collection of term operations. We call this the termalgebra and denote it by T X . In the Agda this algebra can be defined quite simply, as onewould hope and expect. –The term algebra T X. T : { XXX : Universe}( X : XXX (cid:5) ) → Algebra (
OOO ⊔ VVV ⊔ XXX + ) S T { XXX } X = Term{ XXX }{ X } , node The Term algebra is absolutely free (or “universal”) for algebras in the signature S . That is,for every S -algebra A , every map h : X → | A | lifts to a homomorphism from T X to A , and the induced homomorphism is unique. –1.a. Every map (X → A ) lifts. free-lift : { XXX UUU : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( h : X → | A | ) → | T X | → | A | free-lift _ h (generator x ) = h x free-lift A h (node f args ) = ( f ˆ A ) λ i → free-lift A h ( args i ) –1.b. The lift is (extensionally) a hom lift-hom : { XXX UUU : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( h : X → | A | ) → hom ( T X ) A lift-hom A h = free-lift A h , λ f a → ap (_ ˆ A ) r e f l –2. The lift to (free → A ) is (extensionally) unique. free-unique : { XXX UUU : Universe}{ X : XXX (cid:5) } → funext VVV UUU → ( A : Algebra UUU S )( g h : hom ( T X ) A ) → ( ∀ x → | g | (generator x ) ≡ | h | (generator x )) → ( t : Term{ XXX }{ X }) ———————— → | g | t ≡ | h | t free-unique _ _ _ _ p (generator x ) = p x free-unique fe A g h p (node f args ) = | g | (node f args ) ≡⟨ ∥ g ∥ f args ⟩ ( f ˆ A )( λ i → | g | ( args i )) ≡⟨ ap (_ ˆ A ) γ ⟩ ( f ˆ A )( λ i → | h | ( args i )) ≡⟨ ( ∥ h ∥ f args ) ⟩| h | (node f args ) ■ where γ = fe λ i → free-unique fe A g h p ( args i ) Next we note the easy fact that the lift induced by h agrees with h on X and that the lift issurjective if h is. lift-agrees-on-X : { XXX UUU : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( h : X → | A | )( x : X ) ———————————— → h x ≡ | lift-hom A h | (generator x )lift-agrees-on-X _ h x = r e f l lift-of-epi-is-epi : { XXX UUU : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( h : X → | A | ) ———————- → Epic h → Epic | lift-hom A h | lift-of-epi-is-epi { XXX }{ UUU }{ X } A h hE y = γ he Agda Universal Algebra Library 57 whereh pre : Image h ∋ y h pre = hE y h y : X h y = Inv h y ( hE y ) η : y ≡ | lift-hom A h | (generator h y) η = y ≡⟨ (InvIsInv h y h pre) ⟩ h h y ≡⟨ lift-agrees-on-X A h h y ⟩| lift-hom A h | (generator h y) ■ γ : Image | lift-hom A h | ∋ y γ = eq y (generator h y) η Since it’s absolutely free, T X is the domain of a homomorphism to any algebra we like. Thefollowing function makes it easy to lay our hands on such homomorphisms. T hom-gen : { XXX UUU : Universe}{ X : XXX (cid:5) } ( C : Algebra UUU S ) → Σ h : (hom ( T X ) C ), Epic | h | T hom-gen { XXX }{ UUU }{ X } C = h , lift-of-epi-is-epi C h hEwhereh : X → | C | h = fst ( X C )hE : Epic h hE = snd ( X C )h : hom ( T X ) C h = lift-hom C h This subsection describes the
UALib.Terms.Operations submodule of the Agda UALib. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Terms.Operations{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Terms.Free{ S = S }{ gfe }{ X } public When we interpret a term in an algebra we call the result a term operation . Given a term p : Term and an algebra A , we denote by p (cid:5) A the interpretation of p in A . This is definedinductively as follows: if p is x : X (a variable) and if aaa : X → | A | is a tuple of elements of | A | , then define ( p (cid:5) A ) aaa = aaa x ; if p = f sss , where f : | S | is an operation symbol and sss : ∥ S ∥ f → T X is an ( ∥ S ∥ f )-tupleof terms and aaa : X → | A | is a tuple from A , then define ( p (cid:5) A ) aaa = (( f sss ) (cid:5) A ) aaa = ( f ˆ A ) λ i → (( sss i ) (cid:5) A ) aaa In the Agda UALib term interpretation is defined as follows. _ (cid:5) _ : { XXX UUU : Universe}{ X : XXX (cid:5) } → Term{
XXX }{ X } → ( A : Algebra UUU S ) → ( X → | A | ) → | A | ((generator x ) (cid:5) A ) aaa = aaa x ((node f args ) (cid:5) A ) aaa = ( f ˆ A ) λ i → ( args i (cid:5) A ) aaa Observe that intepretation of a term is the same as free-lift (modulo argument order). free-lift-interpretation : {
XXX UUU : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( h : X → | A | )( p : Term) → ( p (cid:5) A ) h ≡ free-lift A h p free-lift-interpretation A h (generator x ) = r e f l free-lift-interpretation A h (node f args ) = ap ( f ˆ A ) ( gfe λ i → free-lift-interpretation A h ( args i ))lift-hom-interpretation : { XXX UUU : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( h : X → | A | )( p : Term) → ( p (cid:5) A ) h ≡ | lift-hom A h | p lift-hom-interpretation = free-lift-interpretation Here we want ( ttt : X → | T (X) | ) → (( p (cid:5) T ( X )) ttt ) ≡ p ttt . . . , but what is ( p (cid:5) T ( X )) ttt ? Bydefinition, it depends on the form of p as follows:if p ≡ ( generator x ), then ( p (cid:5) T ( X )) ttt ≡ (( generator x ) (cid:5) T ( X )) ttt ≡ ttt x if p ≡ ( node f args ), then ( p (cid:5) T ( X )) ttt ≡ (( node f args ) (cid:5) T ( X )) ttt ≡ ( f ˆ T ( X )) λ i → ( args i (cid:5) T ( X )) ttt .We claim that if p : | T (X) | then there exists p : | T (X) | and ttt : X → | T (X) | such that p ≡ ( p (cid:5) T ( X )) ttt . We prove this fact as follows. term-op-interp1 : { XXX : Universe}{ X : XXX (cid:5) }( f : | S | )( args : ∥ S ∥ f → Term) → node f args ≡ ( f ˆ T X ) args term-op-interp1 = λ f args → r e f l term-op-interp2 : { XXX : Universe}{ X : XXX (cid:5) }( f : | S | ){ a1 a2 : ∥ S ∥ f → Term{
XXX }{ X }} → a1 ≡ a2 → node f a1 ≡ node f a2 term-op-interp2 f a1 ≡ a2 = ap (node f ) a1 ≡ a2 term-op-interp3 : { XXX : Universe}{ X : XXX (cid:5) }( f : | S | ){ a1 a2 : ∥ S ∥ f → Term} → a1 ≡ a2 → node f a1 ≡ ( f ˆ T X ) a2 term-op-interp3 f { a1 }{ a2 } a1a2 = (term-op-interp2 f a1a2 ) · (term-op-interp1 f a2 )term-gen : { XXX : Universe}{ X : XXX (cid:5) }( p : | T X | ) → Σ p : | T X | , p ≡ ( p (cid:5) T X ) generatorterm-gen (generator x ) = (generator x ) , r e f l term-gen (node f args ) = node f ( λ i → | term-gen ( args i ) | ) ,term-op-interp3 f ( gfe λ i → ∥ term-gen ( args i ) ∥ )tg : { XXX : Universe}{ X : XXX (cid:5) }( p : | T X | ) → Σ p : | T X | , p ≡ ( p (cid:5) T X ) generatortg p = term-gen p he Agda Universal Algebra Library 59 term-equality : { XXX : Universe}{ X : XXX (cid:5) }( p q : | T X | ) → p ≡ q → ( ∀ t → ( p (cid:5) T X ) t ≡ ( q (cid:5) T X ) t )term-equality p q (refl _) _ = refl _term-equality’ : { UUU XXX : Universe}{ X : XXX (cid:5) }{ A : Algebra UUU S }( p q : | T X | ) → p ≡ q → ( ∀ aaa → ( p (cid:5) A ) aaa ≡ ( q (cid:5) A ) aaa )term-equality’ p q (refl _) _ = refl _term-gen-agreement : { XXX : Universe}{ X : XXX (cid:5) }( p : | T X | ) → ( p (cid:5) T X ) generator ≡ ( | term-gen p | (cid:5) T X ) generatorterm-gen-agreement (generator x ) = r e f l term-gen-agreement { XXX }{ X }(node f args ) = ap ( f ˆ T X ) ( gfe λ x → term-gen-agreement ( args x ))term-agreement : { XXX : Universe}{ X : XXX (cid:5) }( p : | T X | ) → p ≡ ( p (cid:5) T X ) generatorterm-agreement p = snd (term-gen p ) · (term-gen-agreement p ) interp-prod : { XXX UUU : Universe} → funext VVV UUU → { X : XXX (cid:5) }( p : Term){ I : UUU (cid:5) }( A : I → Algebra
UUU S )( x : X → ∀ i → | ( A i ) | ) ——————————————————– → ( p (cid:5) ( d A )) x ≡ ( λ i → ( p (cid:5) A i ) ( λ j → x j i ))interp-prod _ (generator x ) A x = r e f l interp-prod fe (node f t ) A x =let IH = λ x → interp-prod fe ( t x ) A x in( f ˆ d A )( λ x → ( t x (cid:5) d A ) x ) ≡⟨ ap ( f ˆ d A )( fe IH ) ⟩ ( f ˆ d A )( λ x → ( λ i → ( t x (cid:5) A i )( λ j → x j i ))) ≡⟨ r e f l ⟩ ( λ i → ( f ˆ A i ) ( λ x → ( t x (cid:5) A i ) ( λ j → x j i ))) ■ interp-prod2 : { UUU XXX : Universe} → global-dfunext → { X : XXX (cid:5) }( p : Term){ I : UUU (cid:5) }( A : I → Algebra
UUU S ) ———————————————————————- → ( p (cid:5) d A ) ≡ λ ( args : X → | d A | ) → ( λ i → ( p (cid:5) A i )( λ x → args x i ))interp-prod2 _ (generator x ) A = r e f l interp-prod2 gfe { X } (node f t ) A = gfe λ ( tup : X → | d A | ) → let IH = λ x → interp-prod gfe ( t x ) A inlet tA = λ z → t z (cid:5) d A in( f ˆ d A )( λ s → tA s tup ) ≡⟨ ap ( f ˆ d A )( gfe λ x → IH x tup ) ⟩ ( f ˆ d A )( λ s → λ j → ( t s (cid:5) A j )( λ ` → tup ` j )) ≡⟨ r e f l ⟩ ( λ i → ( f ˆ A i )( λ s → ( t s (cid:5) A i )( λ ` → tup ` i ))) ■ This subsection describes the
UALib.Terms.Compatibility submodule of the Agda UALib. Herewe prove that every term commutes with every homomorphism and is compatible with every congruence. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Terms.Compatibility{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Terms.Operations{ S = S }{ gfe }{ X } public We first prove an extensional version of this fact. comm-hom-term : {
UUU WWW XXX : Universe} → funext VVV WWW → { X : XXX (cid:5) }( A : Algebra UUU S ) ( B : Algebra WWW S )( h : hom A B ) ( t : Term) ( a : X → | A | ) —————————————– → | h | (( t (cid:5) A ) a ) ≡ ( t (cid:5) B ) ( | h | ◦ a )comm-hom-term _ A B h (generator x ) a = r e f l comm-hom-term fe A B h (node f args ) a = | h | (( f ˆ A ) λ i → ( args i (cid:5) A ) a ) ≡⟨ ∥ h ∥ f ( λ r → ( args r (cid:5) A ) a ) ⟩ ( f ˆ B )( λ i → | h | (( args i (cid:5) A ) a )) ≡⟨ ap (_ ˆ B )( fe ( λ i → comm-hom-term fe A B h ( args i ) a )) ⟩ ( f ˆ B )( λ r → ( args r (cid:5) B )( | h | ◦ a )) ■ Here is an intensional version. comm-hom-term-intensional : global-dfunext → { UUU WWW XXX : Universe}{ X : XXX (cid:5) } → ( A : Algebra UUU S ) ( B : Algebra WWW S )( h : hom A B ) ( t : Term) —————————————- → | h | ◦ ( t (cid:5) A ) ≡ ( t (cid:5) B ) ◦ ( λ a → | h | ◦ a )comm-hom-term-intensional gfe A B h (generator x ) = r e f l comm-hom-term-intensional gfe { X = X } A B h (node f args ) = γ where γ : | h | ◦ ( λ a → ( f ˆ A ) ( λ i → ( args i (cid:5) A ) a )) ≡ ( λ a → ( f ˆ B )( λ i → ( args i (cid:5) B ) a )) ◦ _ ◦ _ | h | γ = ( λ a → | h | (( f ˆ A )( λ i → ( args i (cid:5) A ) a ))) ≡⟨ gfe ( λ a → ∥ h ∥ f ( λ r → ( args r (cid:5) A ) a )) ⟩ ( λ a → ( f ˆ B )( λ i → | h | (( args i (cid:5) A ) a ))) ≡⟨ ap ( λ - → ( λ a → ( f ˆ B )( - a ))) ih ⟩ ( λ a → ( f ˆ B )( λ i → ( args i (cid:5) B ) a )) ◦ _ ◦ _ | h | ■ whereIH : ( a : X → | A | )( i : ∥ S ∥ f ) → ( | h | ◦ ( args i (cid:5) A )) a ≡ (( args i (cid:5) B ) ◦ _ ◦ _ | h | ) a IH a i = intensionality (comm-hom-term-intensional gfe A B h ( args i )) a ih : ( λ a → ( λ i → | h | (( args i (cid:5) A ) a ))) ≡ ( λ a → ( λ i → (( args i (cid:5) B ) ◦ _ ◦ _ | h | ) a ))ih = gfe λ a → gfe λ i → IH a i he Agda Universal Algebra Library 61 If t : Term , θ : Con A , then a θ b → t ( a ) θ t ( b )). The statement and proof of this obvious butimportant fact may be formalized in Agda as follows. compatible-term : { UUU : Universe}{ X : UUU (cid:5) }( A : Algebra UUU S )( t : Term{ UUU }{ X })( θ : Con A ) ———————————————— → compatible-fun ( t (cid:5) A ) | θ | compatible-term A (generator x ) θ p = p x compatible-term A (node f args ) θ p = snd ∥ θ ∥ f λ x → (compatible-term A ( args x ) θ ) p compatible-term’ : { UUU : Universe} { X : UUU (cid:5) }( A : Algebra UUU S )( t : Term{ UUU }{ X }) ( θ : Con A ) ————————————————— → compatible-fun ( t (cid:5) A ) | θ | compatible-term’ A (generator x ) θ p = p x compatible-term’ A (node f args ) θ p = snd ∥ θ ∥ f λ x → (compatible-term’ A ( args x ) θ ) p (This page is almost entirely blank on purpose.) he Agda Universal Algebra Library 63 This section presents the
UALib.Subalgebras module of the Agda UALib.
This subsection describes the
UALib.Subalgebras.Subuniverses submodule of the Agda UALib.We show how to represent in Agda subuniverses of a given algebra or collection of algebras. Asusual, we start with the required imports. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Subalgebras.Subuniverses{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Terms.Compatibility{ S = S }{ gfe }{ X } publicSubuniverses : { QQQ UUU : Universe}( A : Algebra QQQ S ) → Pred (Pred | A | UUU ) (
OOO ⊔ VVV ⊔ QQQ ⊔ UUU )Subuniverses A B = ( f : | S | )( a : ∥ S ∥ f → | A | ) → Im a ⊆ B → ( f ˆ A ) a ∈ B SubunivAlg : {
QQQ UUU : Universe} ( A : Algebra QQQ S )( B : Pred | A | UUU ) → B ∈ Subuniverses A → Algebra (
QQQ ⊔ UUU ) S SubunivAlg A B B ∈ SubA = Σ B , λ f x → ( f ˆ A )( | _ | ◦ x ) , B ∈ SubA f ( | _ | ◦ x )( ∥ _ ∥ ◦ x )record Subuniverse { QQQ UUU : Universe}{ A : Algebra QQQ S } : OOO ⊔ VVV ⊔ ( QQQ ⊔ UUU ) + (cid:5) whereconstructor mksubfieldsset : Pred | A | UUU isSub : sset ∈ Subuniverses A This subsection describes the
UALib.Subalgebras.Generation submodule of the Agda UALib.Here we define the inductive type of the subuniverse generated by a given collection of ele-ments from the domain of an algebra, and prove that what we have defined is indeed thesmallest subuniverse containing the given elements. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Subalgebras.Generation{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }where open import UALib.Subalgebras.Subuniverses{ S = S }{ gfe }{ X } public We define an inductive type representing the subuniverse generated by a set in the obvious way. data Sg {
UUU WWW : Universe}( A : Algebra UUU S )( X : Pred | A | WWW ) :Pred | A | ( OOO ⊔ VVV ⊔ WWW ⊔ UUU ) wherevar : ∀ { v } → v ∈ X → v ∈ Sg A X app : ( f : | S | )( aaa : ∥ S ∥ f → | A | ) → Im aaa ⊆ Sg A X → ( f ˆ A ) aaa ∈ Sg A X For any subset X of the domain | A | of an algebra A , Sg X is a subuniverse. sgIsSub : { UUU WWW : Universe}{ A : Algebra UUU S }{ X : Pred | A | WWW } → Sg A X ∈ Subuniverses A sgIsSub = app By induction on the shape of elements of Sg X , we prove that Sg X is the smallest subuniverseof A containing X . sgIsSmallest : { UUU WWW RRR : Universe}( A : Algebra UUU S ){ X : Pred | A | WWW }( Y : Pred | A | RRR ) → Y ∈ Subuniverses A → X ⊆ Y → Sg A X ⊆ Y sgIsSmallest _ _ _ XinY (var Xv ) = XinY Xv sgIsSmallest A Y YsubA XinY (app f aaa SgXa ) = fa ∈ YwhereIH : Im aaa ⊆ Y IH i = sgIsSmallest A Y YsubA XinY ( SgXa i )fa ∈ Y : ( f ˆ A ) aaa ∈ Y fa ∈ Y =
YsubA f aaa IH When the element of Sg X is constructed as app f aaa SgXa , we may assume (the inductionhypothesis) that the arguments aaa belong to Y . Then the result of applying f to aaa must alsobelong to Y , since Y is a subuniverse. This subsection describes the
UALib.Subalgebras.Properties submodule of the Agda UALib. Herewe formalize and prove a few basic properties of subuniverses. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Subalgebras.Properties{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Subalgebras.Generation{ S = S }{ gfe }{ X } renaming ( generator to g ) publicopen import Relation.Unary using ( ∩ ) publicsub-inter-is-sub : { QQQ UUU : Universe}( A : Algebra QQQ S )( I : UUU (cid:5) )( A : I → Pred | A | UUU ) → (( i : I ) → A i ∈ Subuniverses A ) ————————————- he Agda Universal Algebra Library 65 → ∩ I A ∈ Subuniverses A sub-inter-is-sub A I A Ai-is-Sub f a ima ⊆ ∩ A = α where α : ( f ˆ A ) a ∈ ∩ I A α i = Ai-is-Sub i f a λ j → ima ⊆ ∩ A j i sub-term-closed : {
XXX QQQ UUU : Universe}{ X : XXX (cid:5) }( A : Algebra QQQ S )( B : Pred | A | UUU ) → B ∈ Subuniverses A → ( t : Term)( b : X → | A | ) → ( ∀ x → b x ∈ B ) ————————— → (( t (cid:5) A ) b ) ∈ B sub-term-closed _ _ B ≤ A ( g x ) b b ∈ B = b ∈ B x sub-term-closed A B B ≤ A (node f t ) b b ∈ B = B ≤ A f ( λ z → ( t z (cid:5) A ) b )( λ x → sub-term-closed A B B ≤ A ( t x ) b b ∈ B ) data TermImage { QQQ UUU : Universe}( A : Algebra QQQ S )( Y : Pred | A | UUU ) :Pred | A | ( OOO ⊔ VVV ⊔ QQQ ⊔ UUU ) wherevar : ∀ { y : | A | } → y ∈ Y → y ∈ TermImage A Y app : ( f : | S | ) ( t : ∥ S ∥ f → | A | ) → ( ∀ i → t i ∈ TermImage A Y ) —————————– → ( f ˆ A ) t ∈ TermImage A Y–1. TermImage is a subuniverse
TermImageIsSub : {
QQQ UUU : Universe}{ A : Algebra QQQ S }{ Y : Pred | A | UUU } ———————————- → TermImage A Y ∈ Subuniverses A TermImageIsSub = app – λ f a x → app f a x–2. Y ⊆ TermImageY Y ⊆ TermImageY : {
QQQ UUU : Universe}{ A : Algebra QQQ S }{ Y : Pred | A | UUU } ———————————- → Y ⊆ TermImage A Y Y ⊆ TermImageY { a } a ∈ Y = var a ∈ Y– 3. Sg^A(Y) is the smallest subuniverse containing Y– Proof: see ‘sgIsSmallest‘
SgY ⊆ TermImageY : {
QQQ UUU : Universe} ( A : Algebra QQQ S ) ( Y : Pred | A | UUU ) ———————————— → Sg A Y ⊆ TermImage A Y SgY ⊆ TermImageY A Y = sgIsSmallest A (TermImage A Y ) TermImageIsSub Y ⊆ TermImageY
This subsection describes the
UALib.Subalgebras.Homomorphisms submodule of the Agda UALib.Here we mechanize the interaction between homomorphisms and subuniverses—two central cogsof the universal algebra machine. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Subalgebras.Homomorphisms{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Subalgebras.Properties{ S = S }{ gfe }{ X } public The image of a homomorphism is a subuniverse of its codomain. hom-image-is-sub : {
UUU WWW : Universe} → global-dfunext → { A : Algebra UUU S } { B : Algebra WWW S } ( φ : hom A B ) ————————————————- → (HomImage B φ ) ∈ Subuniverses B hom-image-is-sub gfe { A }{ B } φ f b b ∈ Imf = eq (( f ˆ B ) b ) (( f ˆ A ) ar) γ wherear : ∥ S ∥ f → | A | ar = λ x → Inv | φ | ( b x )( b ∈ Imf x ) ζ : | φ | ◦ ar ≡ b ζ = gfe ( λ x → InvIsInv | φ | ( b x )( b ∈ Imf x )) γ : ( f ˆ B ) b ≡ | φ | (( f ˆ A )( λ x → Inv | φ | ( b x )( b ∈ Imf x ))) γ = ( f ˆ B ) b ≡⟨ ap ( f ˆ B )( ζ ) ⟩ ( f ˆ B )( | φ | ◦ ar) ≡⟨ ( ∥ φ ∥ f ar) ⟩| φ | (( f ˆ A ) ar) ■ Here we formalize the proof that homomorphisms are uniquely determined by their values ona generating set.
HomUnique : {
UUU WWW : Universe} → funext VVV UUU → { A B : Algebra
UUU S }( X : Pred | A | UUU ) ( g h : hom
A B ) he Agda Universal Algebra Library 67 → ( ∀ ( x : | A | ) → x ∈ X → | g | x ≡ | h | x ) ——————————————— → ( ∀ ( a : | A | ) → a ∈ Sg A X → | g | a ≡ | h | a )HomUnique _ _ _ _ gx ≡ hx a (var x ) = ( gx ≡ hx ) a x HomUnique {
UUU }{ WWW } fe { A }{ B } X g h gx ≡ hx a (app f { aaa } im aaa ⊆ SgX ) = | g | (( f ˆ A ) aaa ) ≡⟨ ∥ g ∥ f aaa ⟩ ( f ˆ B )( | g | ◦ aaa ) ≡⟨ ap ( f ˆ B )( fe induction-hypothesis) ⟩ ( f ˆ B )( | h | ◦ aaa ) ≡⟨ ( ∥ h ∥ f aaa ) ⟩| h | (( f ˆ A ) aaa ) ■ where induction-hypothesis = λ x → HomUnique{
UUU }{ WWW } fe { A }{ B } X g h gx ≡ hx ( aaa x ) ( im aaa ⊆ SgX x ) This subsection describes the
UALib.Subalgebras.Subalgebras submodule of the Agda UALib.Here we define a subalgebra of an algebra as well as the collection of all subalgebras of a givenclass of algebras. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Subalgebras.Subalgebras{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Subalgebras.Homomorphisms { S = S }{ gfe }{ X } publicopen import UALib.Prelude.Preliminaries using ( ◦ -embedding; id-is-embedding) Given algebras A : Algebra WWW S and B : Algebra UUU S , we say that B is a subalgebra of A ,and we write B IsSubalgebraOf A just in case B can be embedded in A ; in other terms, thereexists a map h : | A | → | B | from the universe of A to the universe of B such that h is anembedding (i.e., is-embedding h holds) and h is a homomorphism from A to B . _IsSubalgebraOf_ : { UUU WWW : Universe}( B : Algebra UUU S )( A : Algebra WWW S ) → OOO ⊔ VVV ⊔ UUU ⊔ WWW (cid:5) B IsSubalgebraOf A = Σ h : ( | B | → | A | ) , is-embedding h × is-homomorphism B A h Subalgebra : {
UUU WWW : Universe} → Algebra
WWW S → OOO ⊔ VVV ⊔ WWW ⊔ UUU + (cid:5) Subalgebra {
UUU } A = Σ B : (Algebra UUU S ) , B IsSubalgebraOf A We use the convenient ≤ notation for the subalgebra relation. _ ≤ _ : { UUU QQQ : Universe}( B : Algebra UUU S )( A : Algebra QQQ S ) → OOO ⊔ VVV ⊔ UUU ⊔ QQQ (cid:5) B ≤ A = B IsSubalgebraOf A _IsSubalgebraOfClass_ : { UUU QQQ WWW : Universe}( B : Algebra UUU S ) → Pred (Algebra
QQQ S ) WWW → _ (cid:5) _IsSubalgebraOfClass_ { UUU } B K = Σ A : (Algebra _ S ) , Σ SA : (Subalgebra{ UUU } A ) ,( A ∈ K ) × ( B ∼ = | SA | )SUBALGEBRAOFCLASS : { UUU QQQ WWW : Universe} → Pred (Algebra
QQQ S ) WWW → _ (cid:5) SUBALGEBRAOFCLASS {
UUU } K = Σ B : (Algebra UUU S ) , B IsSubalgebraOfClass K SubalgebraOfClass : {
UUU QQQ : Universe} → Pred (Algebra
QQQ S )( OOO ⊔ VVV ⊔ QQQ + ) → OOO ⊔ VVV ⊔ ( QQQ ⊔ UUU ) + (cid:5) SubalgebraOfClass {
UUU }{ QQQ } = SUBALGEBRAOFCLASS {
UUU }{ QQQ }{ OOO ⊔ VVV ⊔ QQQ + } Here are a number of useful facts about subalgebras. Many of them seem redundant, and theyare to some extent. However, each one differs slightly from the next, if only with respect tothe explicitness or implicitness of their arguments. The aim is to make it as convenient aspossible to apply the lemmas in different situations. (We’re in the UALib utility closet now,and elegance is not the priority.) –Transitivity of IsSubalgebra (explicit args)
TRANS- ≤ : { XXX YYY ZZZ : Universe}( A : Algebra XXX S )( B : Algebra YYY S )( C : Algebra ZZZ S ) → B ≤ A → C ≤ B —————— → C ≤ A TRANS- ≤ A B C
BA CB = | BA | ◦ | CB | , α , β where α : is-embedding ( | BA | ◦ | CB | ) α = ◦ -embedding (fst ∥ BA ∥ ) (fst ∥ CB ∥ ) β : is-homomorphism C A ( | BA | ◦ | CB | ) β = ◦ -hom C B A { | CB | }{ | BA | }(snd ∥ CB ∥ ) (snd ∥ BA ∥ ) –Transitivity of IsSubalgebra (implicit args) Trans- ≤ : { XXX YYY ZZZ : Universe}( A : Algebra XXX S ){ B : Algebra YYY S }( C : Algebra ZZZ S ) → B ≤ A → C ≤ B → C ≤ A Trans- ≤ A { B } C = TRANS- ≤ A B C –Transitivity of IsSubalgebra (implicit args) trans- ≤ : { XXX YYY ZZZ : Universe}{ A : Algebra XXX S }{ B : Algebra YYY S }{ C : Algebra ZZZ S } → B ≤ A → C ≤ B → C ≤ A trans- ≤ { A = A }{ B = B }{ C = C } = TRANS- ≤ A B C transitivity- ≤ : { XXX YYY ZZZ : Universe}( A : Algebra XXX S ){ B : Algebra YYY S }{ C : Algebra ZZZ S } → A ≤ B → B ≤ C → A ≤ C transitivity- ≤ A { B }{ C } A ≤ B B ≤ C = | B ≤ C | ◦ | A ≤ B | , ◦ -embedding (fst ∥ B ≤ C ∥ )(fst ∥ A ≤ B ∥ ) , ◦ -hom A B C { | A ≤ B | }{ | B ≤ C | }(snd ∥ A ≤ B ∥ )(snd ∥ B ≤ C ∥ ) he Agda Universal Algebra Library 69 –Reflexivity of IsSubalgebra (explicit arg) REFL- ≤ : { UUU : Universe}( A : Algebra UUU S ) → A ≤ A REFL- ≤ A = id | A | , id-is-embedding , id-is-hom –Reflexivity of IsSubalgebra (implicit arg) refl- ≤ : { UUU : Universe}{ A : Algebra UUU S } → A ≤ A refl- ≤ { A = A } = REFL- ≤ A –Reflexivity of IsSubalgebra (explicit arg) ISO- ≤ : { XXX YYY ZZZ : Universe}( A : Algebra XXX S )( B : Algebra YYY S )( C : Algebra ZZZ S ) → B ≤ A → C ∼ = B —————– → C ≤ A ISO- ≤ A B C B ≤ A C ∼ = B = h , hemb , hhomwheref : | C | → | B | f = fst | C ∼ = B | g : | B | → | A | g = | B ≤ A | h : | C | → | A | h = g ◦ fhemb : is-embedding hhemb = ◦ -embedding (fst ∥ B ≤ A ∥ ) (iso → embedding C ∼ = B )hhom : is-homomorphism C A hhhom = ◦ -hom C B A {f}{g} (snd | C ∼ = B | ) (snd ∥ B ≤ A ∥ )Iso- ≤ : { XXX YYY ZZZ : Universe}( A : Algebra XXX S ){ B : Algebra YYY S }( C : Algebra ZZZ S ) → B ≤ A → C ∼ = B → C ≤ A Iso- ≤ A { B } C = ISO- ≤ A B C iso- ≤ : { XXX YYY ZZZ : Universe}{ A : Algebra XXX S }{ B : Algebra YYY S }( C : Algebra ZZZ S ) → B ≤ A → C ∼ = B → C ≤ A iso- ≤ { A = A } { B = B } C = ISO- ≤ A B C trans- ≤ - ∼ = : { XXX YYY ZZZ : Universe}( A : Algebra XXX S ){ B : Algebra YYY S }( C : Algebra ZZZ S ) → A ≤ B → A ∼ = C → C ≤ B trans- ≤ - ∼ = { XXX }{ YYY }{ ZZZ } A { B } C A ≤ B B ∼ = C = ISO- ≤ B A C A ≤ B (sym- ∼ = B ∼ = C )TRANS- ≤ - ∼ = : { XXX YYY ZZZ : Universe}( A : Algebra XXX S ){ B : Algebra YYY S }( C : Algebra ZZZ S ) → A ≤ B → B ∼ = C → A ≤ C TRANS- ≤ - ∼ = { XXX }{ YYY }{ ZZZ } A { B } C A ≤ B B ∼ = C = h , hemb , hhomwheref : | A | → | B | f = | A ≤ B | g : | B | → | C | g = fst | B ∼ = C | h : | A | → | C | h = g ◦ fhemb : is-embedding hhemb = ◦ -embedding (iso → embedding B ∼ = C )(fst ∥ A ≤ B ∥ )hhom : is-homomorphism A C hhhom = ◦ -hom A B C {f}{g} (snd ∥ A ≤ B ∥ ) (snd | B ∼ = C | )mono- ≤ : { UUU QQQ WWW : Universe}( B : Algebra UUU S ){ K K ’ : Pred (Algebra QQQ S ) WWW } → K ⊆ K ’ → B IsSubalgebraOfClass K → B IsSubalgebraOfClass K ’ mono- ≤ B KK’ KB = | KB | , fst ∥ KB ∥ , KK’ ( | snd ∥ KB ∥ | ) , ∥ (snd ∥ KB ∥ ) ∥ lift-alg-is-sub : { UUU : Universe}{ K : Pred (Algebra UUU S )( OOO ⊔ VVV ⊔ UUU + )}{ B : Algebra UUU S } → B IsSubalgebraOfClass K → (lift-alg B UUU ) IsSubalgebraOfClass K lift-alg-is-sub { UUU }{ K }{ B }( A , ( sa , ( KA , B ∼ = sa ))) = A , sa , KA , trans- ∼ = _ _ _ (sym- ∼ = lift-alg- ∼ = ) B ∼ = sa lift-alg-lift- ≤ -lower : { XXX YYY ZZZ : Universe}( A : Algebra XXX S ){ B : Algebra YYY S } → B ≤ A → (lift-alg B ZZZ ) ≤ A lift-alg-lift- ≤ -lower { XXX }{ YYY }{ ZZZ } A { B } B ≤ A =iso- ≤ { XXX }{ YYY }{ ZZZ = (
YYY ⊔ ZZZ )}{ A }{ B } (lift-alg B ZZZ ) B ≤ A (sym- ∼ = lift-alg- ∼ = )lift-alg-lower- ≤ -lift : { XXX YYY ZZZ : Universe}( A : Algebra XXX S ){ B : Algebra YYY S } → B ≤ A → B ≤ (lift-alg A ZZZ )lift-alg-lower- ≤ -lift { XXX }{ YYY }{ ZZZ } A { B } B ≤ A = g ◦ f , α , β wherelA : Algebra ( XXX ⊔ ZZZ ) S lA = lift-alg A ZZZ A ∼ = lA : A ∼ = lAA ∼ = lA = lift-alg- ∼ = f : | B | → | A | f = | B ≤ A | g : | A | → | lA | g = ∼ = -map A ∼ = lA α : is-embedding (g ◦ f) he Agda Universal Algebra Library 71 α = ◦ -embedding ( ∼ = -map-is-embedding A ∼ = lA) (fst ∥ B ≤ A ∥ ) β : is-homomorphism B lA (g ◦ f) β = ◦ -hom B A lA {f}{g} (snd ∥ B ≤ A ∥ ) (snd | A ∼ = lA | )lift-alg-sub-lift : { UUU WWW : Universe}( A : Algebra UUU S ){ C : Algebra ( UUU ⊔ WWW ) S } → C ≤ A → C ≤ (lift-alg A WWW )lift-alg-sub-lift {
UUU }{ WWW } A { C } C ≤ A = g ◦ f , α , β wherelA : Algebra ( UUU ⊔ WWW ) S lA = lift-alg A WWW A ∼ = lA : A ∼ = lAA ∼ = lA = lift-alg- ∼ = f : | C | → | A | f = | C ≤ A | g : | A | → | lA | g = ∼ = -map A ∼ = lA α : is-embedding (g ◦ f) α = ◦ -embedding ( ∼ = -map-is-embedding A ∼ = lA) (fst ∥ C ≤ A ∥ ) β : is-homomorphism C lA (g ◦ f) β = ◦ -hom C A lA {f}{g} (snd ∥ C ≤ A ∥ ) (snd | A ∼ = lA | )lift-alg- ≤ : { XXX YYY ZZZ WWW : Universe}( A : Algebra XXX S ){ B : Algebra YYY S } → A ≤ B → (lift-alg A ZZZ ) ≤ (lift-alg B WWW )lift-alg- ≤ { XXX }{ YYY }{ ZZZ }{ WWW } A { B } A ≤ B =transitivity- ≤ lA { B }{lift-alg B WWW } (transitivity- ≤ lA { A }{ B } lAA A ≤ B ) B ≤ lBwherelA : Algebra ( XXX ⊔ ZZZ ) S lA = lift-alg A ZZZ lAA : lA ≤ A lAA = lift-alg-lift- ≤ -lower A { A } refl- ≤ B ≤ lB : B ≤ lift-alg B WWW B ≤ lB = lift-alg-lower- ≤ -lift B { B } refl- ≤ This subsection describes the
UALib.Subalgebras.WWMD submodule of the Agda UALib. In hisType Topology library, Martin Escardo gives a nice formalization of the notion of subgroup andits properties. In this module we merely do for general algebras what Martin does for groups.This is our first foray into univalent foundations, and our first chance to put Voevodsky’sunivalence axiom to work.
The present module is called
WWMD . Evidently, as one sees from the lengthy importstatement that starts with open import Prelude.Preliminaries
WWMD module can be safely skipped. As of 22 Jan 2021, it plays no role in any of theother modules of the Agda UALib. open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Subalgebras.WWMD{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Subalgebras.Homomorphisms { S = S }{ gfe }{ X } publicopen import UALib.Prelude.Preliminaries using ( ◦ -embedding; id-is-embedding; Univalence; Π -is-subsingleton; ∈ -is-subsingleton; pr -embedding; embedding-gives-ap-is-equiv; equiv-to-subsingleton; powersets-are-sets’;lr-implication; rl-implication; subset-extensionality’; inverse; × -is-subsingleton; _ ≃ _;logically-equivalent-subsingletons-are-equivalent; _ • _)module mhe_subgroup_generalization { WWW : Universe} { A : Algebra WWW S } ( ua : Univalence) whereop-closed : ( | A | → WWW (cid:5) ) → OOO ⊔ VVV ⊔ WWW (cid:5) op-closed B = ( f : | S | )( a : ∥ S ∥ f → | A | ) → (( i : ∥ S ∥ f ) → B ( a i )) → B (( f ˆ A ) a )subuniverse : OOO ⊔ VVV ⊔ WWW + (cid:5) subuniverse = Σ B : ( P | A | ) , op-closed ( _ ∈ B )being-op-closed-is-subsingleton : ( B : P | A | ) → is-subsingleton (op-closed ( _ ∈ B ))being-op-closed-is-subsingleton B = Π -is-subsingleton gfe ( λ f → Π -is-subsingleton gfe ( λ a → Π -is-subsingleton gfe ( λ _ → ∈ -is-subsingleton B (( f ˆ A ) a ))))pr -is-embedding : is-embedding | _ | pr -is-embedding = pr -embedding being-op-closed-is-subsingleton –so equality of subalgebras is equality of their underlying–subsets in the powerset: ap-pr : ( B C : subuniverse) → B ≡ C → | B | ≡ | C | ap-pr B C = ap | _ | ap-pr -is-equiv : ( B C : subuniverse) → is-equiv (ap-pr B C )ap-pr -is-equiv =embedding-gives-ap-is-equiv | _ | pr -is-embedding For lack of a better alternative, we named this module with the acronym for “What would Martin do?” he Agda Universal Algebra Library 73 subuniverse-is-a-set : is-set subuniversesubuniverse-is-a-set
B C = equiv-to-subsingleton(ap-pr B C , ap-pr -is-equiv B C )(powersets-are-sets’ ua | B | | C | )subuniverse-equality-gives-membership-equiv : ( B C : subuniverse) → B ≡ C———————————– → ( x : | A | ) → ( x ∈ | B | ) ⇔ ( x ∈ | C | )subuniverse-equality-gives-membership-equiv B C B ≡ C x =transport ( λ - → x ∈ | - | ) B ≡ C ,transport ( λ - → x ∈ | - | ) ( B ≡ C )membership-equiv-gives-carrier-equality : ( B C : subuniverse) → (( x : | A | ) → x ∈ | B | ⇔ x ∈ | C | ) —————————————– → | B | ≡ | C | membership-equiv-gives-carrier-equality B C ϕ =subset-extensionality’ ua α β where α : | B | ⊆ | C | α x = lr-implication ( ϕ x ) β : | C | ⊆ | B | β x = rl-implication ( ϕ x )membership-equiv-gives-subuniverse-equality : ( B C : subuniverse) → (( x : | A | ) → x ∈ | B | ⇔ x ∈ | C | ) ————————————— → B ≡ C membership-equiv-gives-subuniverse-equality B C =inverse (ap-pr B C )(ap-pr -is-equiv B C ) ◦ (membership-equiv-gives-carrier-equality B C )membership-equiv-is-subsingleton : (
B C : subuniverse) → is-subsingleton (( x : | A | ) → x ∈ | B | ⇔ x ∈ | C | )membership-equiv-is-subsingleton B C = Π -is-subsingleton gfe ( λ x → × -is-subsingleton( Π -is-subsingleton gfe ( λ _ → ∈ -is-subsingleton | C | x ))( Π -is-subsingleton gfe ( λ _ → ∈ -is-subsingleton | B | x )))subuniverse-equality : ( B C : subuniverse) → ( B ≡ C ) ≃ (( x : | A | ) → ( x ∈ | B | ) ⇔ ( x ∈ | C | ))subuniverse-equality B C =logically-equivalent-subsingletons-are-equivalent _ _(subuniverse-is-a-set
B C )(membership-equiv-is-subsingleton
B C ) (subuniverse-equality-gives-membership-equiv B C ,membership-equiv-gives-subuniverse-equality
B C )carrier-equality-gives-membership-equiv : (
B C : subuniverse) → | B | ≡ | C | —————————————- → ( ( x : | A | ) → x ∈ | B | ⇔ x ∈ | C | )carrier-equality-gives-membership-equiv B C (refl _) x = id , id –so we have... carrier-equiv : ( B C : subuniverse) → (( x : | A | ) → x ∈ | B | ⇔ x ∈ | C | ) ≃ ( | B | ≡ | C | )carrier-equiv B C =logically-equivalent-subsingletons-are-equivalent _ _(membership-equiv-is-subsingleton
B C )(powersets-are-sets’ ua | B | | C | )(membership-equiv-gives-carrier-equality B C ,carrier-equality-gives-membership-equiv
B C ) – ...which yields an alternative subuniverse equality lemma. subuniverse-equality’ : ( B C : subuniverse) → ( B ≡ C ) ≃ ( | B | ≡ | C | )subuniverse-equality’ B C =(subuniverse-equality
B C ) • (carrier-equiv B C ) he Agda Universal Algebra Library 75 This section presents the
UALib.Varieties module of the Agda UALib.
This subsection presents the
UALib.Varieties.ModelTheory submodule of the Agda UALib.Let S be a signature. By an identity or equation in S we mean an ordered pair of terms,written p ≈ q , from the term algebra T X . If A is an S -algebra we say that A satisfies p ≈ q provided p (cid:5) A ≡ q (cid:5) A holds. In this situation, we write A | = p ≈ q and say that A models the identity p ≈ q . If K is a class of algebras of the same signature, we write K | = p ∼∼∼ q if A | = p ≈ q for all A ∈ K . Unicode Hints . To produce the symbols ≈ and | = in Emacs agda2-mode, type \~~ and \models (resp.). The symbol ∼∼∼ is produced in Emacs agda2-mode with \~~~ . open import UALib.Algebras using (Signature; OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Varieties.ModelTheory{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Subalgebras.Subalgebras{ S = S }{ gfe }{ X } public We define the binary “models” relation | = relating algebras (or classes of algebras) to theidentities that they satisfy. Agda supports the definition of infix operations and relations, andwe use this to define | = so that we may write, e.g., A | = p ≈ q or K | = p ∼∼∼ q .After | = is defined, we prove just a couple of useful facts about | = . However, more is provedabout the models relation in the next section (Section 7.2). _ | = _ ≈ _ : { UUU XXX : Universe}{ X : XXX (cid:5) } → Algebra
UUU S → Term{
XXX }{ X } → Term → UUU ⊔ XXX (cid:5) A | = p ≈ q = ( p (cid:5) A ) ≡ ( q (cid:5) A )_ | = _ ∼∼∼ _ : { UUU XXX : Universe}{ X : XXX (cid:5) } → Pred (Algebra
UUU S ) (OV UUU ) → Term{
XXX }{ X } → Term → OOO ⊔ VVV ⊔ XXX ⊔ UUU + (cid:5) _ | = _ ∼∼∼ _ K p q = { A : Algebra _ S } → K A → A | = p ≈ q The set of identities that hold for all algebras in a class K is denoted by Th K , which we defineas follows. Because a class of structures has a different type than a single structure, we must use a slightly differentsyntax to avoid overloading the relations | = and ≈ . As a reasonable alternative to what we would normallyexpress informally as K | = p ≈ q , we have settled on K | = p ∼∼∼ q to denote this relation. Th : {
UUU XXX : Universe}{ X : XXX (cid:5) } → Pred (Algebra
UUU S ) (OV UUU ) → Pred (Term{
XXX }{ X } × Term) (
OOO ⊔ VVV ⊔ XXX ⊔ UUU + )Th K = λ ( p , q ) → K | = p ∼∼∼ q The class of algebras that satisfy all identities in a given set E is denoted by Mod E . We giventhree nearly equivalent definitions for this below. The only distinction between these is whetherthe arguments are explicit (so must appear in the argument list) or implicit (so we may let Agdado its best to guess the argument). MOD : (
UUU XXX : Universe)( X : XXX (cid:5) ) → Pred (Term{
XXX }{ X } × Term{
XXX }{ X }) ( OOO ⊔ VVV ⊔ XXX ⊔ UUU + ) → Pred (Algebra
UUU S ) ( OOO ⊔ VVV ⊔ XXX + ⊔ UUU + )MOD UUU XXX X E = λ A → ∀ p q → ( p , q ) ∈ E → A | = p ≈ q Mod : {
UUU XXX : Universe}( X : XXX (cid:5) ) → Pred (Term{
XXX }{ X } × Term{
XXX }{ X }) ( OOO ⊔ VVV ⊔ XXX ⊔ UUU + ) → Pred (Algebra
UUU S ) ( OOO ⊔ VVV ⊔ XXX + ⊔ UUU + )Mod X E = λ A → ∀ p q → ( p , q ) ∈ E → A | = p ≈ q mod : { UUU XXX : Universe}{ X : XXX (cid:5) } → Pred (Term{
XXX }{ X } × Term{
XXX }{ X }) ( OOO ⊔ VVV ⊔ XXX ⊔ UUU + ) → Pred (Algebra
UUU S ) ( OOO ⊔ VVV ⊔ XXX + ⊔ UUU + )mod E = λ A → ∀ p q → ( p , q ) ∈ E → A | = p ≈ q | = We have formally defined A | = p ≈ q , which represents the assertion that p ≈ q holds whenthis identity is interpreted in the algebra A ; syntactically, p (cid:5) A ≡ q (cid:5) A . Hopefully we alreadygrasp the semantic meaning of these strings of symbols, but our understanding is at best tenuousunless we have a handle on their computational meaning, since this tells us how we can use the definitions. So we pause to emphasize that we interpret the expression p (cid:5) A ≡ q (cid:5) A asan extensional equality , by which we mean that for each assignment function aaa : X → | A | —assigning values in the domain of A to the variable symbols in X —we have ( p (cid:5) A ) aaa ≡ ( q (cid:5) A ) aaa .The binary relation | = would be practically useless if it were not an algebraic invariant (i.e.,invariant under isomorphism), and this fact is proved by showing that a certain term operationidentity—namely, ( p (cid:5) B ) ≡ ( q (cid:5) B ) —holds extensionally , in the sense of the previous paragraph. | = - ∼ = | = -transport : { QQQ UUU XXX : Universe}{ X : XXX (cid:5) }{ A : Algebra QQQ S }{ B : Algebra UUU S }( p q : Term{ XXX }{ X }) → ( A | = p ≈ q ) → ( A ∼ = B ) → B | = p ≈ q | = -transport { QQQ }{ UUU }{ XXX }{ X }{ A }{ B } p q Apq ( f , g , f ∼ g , g ∼ f ) = γ where γ : ( p (cid:5) B ) ≡ ( q (cid:5) B ) γ = gfe λ x → ( p (cid:5) B ) x ≡⟨ r e f l ⟩ ( p (cid:5) B ) ( | i d B | ◦ x ) ≡⟨ ap ( λ - → ( p (cid:5) B ) - ) ( gfe λ i → (( f ∼ g )( x i )) ) ⟩ ( p (cid:5) B ) (( | f | ◦ | g | ) ◦ x ) ≡⟨ (comm-hom-term gfe A B f p ( | g | ◦ x )) ⟩| f | (( p (cid:5) A ) ( | g | ◦ x )) ≡⟨ ap ( λ - → | f | ( - ( | g | ◦ x ))) Apq ⟩ he Agda Universal Algebra Library 77 | f | (( q (cid:5) A ) ( | g | ◦ x )) ≡⟨ comm-hom-term gfe A B f q ( | g | ◦ x ) ⟩ ( q (cid:5) B ) (( | f | ◦ | g | ) ◦ x ) ≡⟨ ap ( λ - → ( q (cid:5) B ) - ) ( gfe λ i → ( f ∼ g ) ( x i )) ⟩ ( q (cid:5) B ) x ■ | = - ∼ = = | = -transport – (alias) The | = relation is also compatible with the lift operation. lift-alg- | = : { UUU WWW XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( p q : Term{ XXX }{ X }) → A | = p ≈ q → (lift-alg A WWW ) | = p ≈ q lift-alg- | = A p q Apq = | = - ∼ = p q Apq lift-alg- ∼ = lower-alg- | = : { UUU WWW XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( p q : Term{ XXX }{ X }) → lift-alg A WWW | = p ≈ q → A | = p ≈ q lower-alg- | = { UUU }{ WWW }{ XXX }{ X } A p q lApq = | = - ∼ = p q lApq (sym- ∼ = lift-alg- ∼ = ) This subsection presents the
UALib.Varieties.EquationalLogic submodule of the Agda UALib.We establish some important features of the “models” relation, which demonstrate the nicerelationships | = has with the other protagonists of our story, H, S, and P. We prove the followingclosure properties, or “invariance,” of the models relation. (These are needed, for example, inthe proof the Birkhoff HSP Theorem.)Algebraic invariance. The | = relation is an algebraic invariant (stable under isomorphism).Product invariance. Identities modeled by a class of algebras are also modeled by all productsof algebras in the class.Subalgebra invariance. Identities modeled by a class of algebras are also modeled by allsubalgebras of algebras in the class;Homomorphism invariance. Identities modeled by a class of algebras are also modeled byall homomorphic images (equivalently, all quotients) of algebras in the class; open import UALib.Algebras using (Signature; OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Varieties.EquationalLogic{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Varieties.ModelTheory { S = S }{ gfe }{ X } publicopen import UALib.Prelude.Preliminaries using ( ◦ -embedding; domain; embeddings-are-lc) publicov : Universe → Universeov
UUU = OOO ⊔ VVV ⊔ UUU + | = We have formally defined A | = p ≈ q , which represents the assertion that p ≈ q holds when thisidentity is interpreted in the algebra A ; syntactically, p (cid:5) A ≡ q (cid:5) A . It should be emphasized that the expression p (cid:5) A ≡ q (cid:5) A is interpreted computationally as an extensional equality , bywhich we mean that for each assignment function aaa : X → | A | , assigning values in the domainof A to the variable symbols in X, we have ( p (cid:5) A ) aaa ≡ ( q (cid:5) A ) aaa . The binary relation | = would be practically useless if it were not an algebraic invariant (i.e.,invariant under isomorphism). | = -I-invariance : { QQQ UUU XXX : Universe}{ X : XXX (cid:5) }{ A : Algebra QQQ S }{ B : Algebra UUU S }( p q : Term{ XXX }{ X }) → A | = p ≈ q → A ∼ = B → B | = p ≈ q | = -I-invariance { A = A }{ B = B } p q Apq ( f , g , f ∼ g , g ∼ f ) = γ where γ : p (cid:5) B ≡ q (cid:5) B γ = gfe λ x → ( p (cid:5) B ) x ≡⟨ r e f l ⟩ ( p (cid:5) B ) ( | i d B | ◦ x ) ≡⟨ ap ( λ - → ( p (cid:5) B ) - ) ( gfe λ i → (( f ∼ g )( x i )) ) ⟩ ( p (cid:5) B ) (( | f | ◦ | g | ) ◦ x ) ≡⟨ (comm-hom-term gfe A B f p ( | g | ◦ x )) ⟩| f | (( p (cid:5) A ) ( | g | ◦ x )) ≡⟨ ap ( λ - → | f | ( - ( | g | ◦ x ))) Apq ⟩| f | (( q (cid:5) A ) ( | g | ◦ x )) ≡⟨ comm-hom-term gfe A B f q ( | g | ◦ x ) ⟩ ( q (cid:5) B ) (( | f | ◦ | g | ) ◦ x ) ≡⟨ ap ( λ - → ( q (cid:5) B ) - ) ( gfe λ i → ( f ∼ g ) ( x i )) ⟩ ( q (cid:5) B ) x ■ As the proof makes clear, we show B | = p ≈ q by showing that p (cid:5) B ≡ q (cid:5) B holds extensionally ,that is, ∀ x , ( p (cid:5) B ) x ≡ ( q (cid:5) B ) x . The | = relation is also invariant under the algebraic lift and lower operations. | = -lift-alg-invariance : { UUU WWW XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( p q : Term{ XXX }{ X }) ———————————– → A | = p ≈ q → lift-alg A WWW | = p ≈ q | = -lift-alg-invariance A p q Apq = | = -I-invariance p q Apq lift-alg- ∼ = | = -lower-alg-invariance : { UUU WWW XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S )( p q : Term{ XXX }{ X }) ———————————– → lift-alg A WWW | = p ≈ q → A | = p ≈ q | = -lower-alg-invariance A p q lApq = | = -I-invariance p q lApq (sym- ∼ = lift-alg- ∼ = ) We show that identities modeled by a class of algebras is also modeled by all subalgebras of theclass. In other terms, every term equation p ≈ q that is satisfied by all A ∈ K is also satisfiedby every subalgebra of a member of K . he Agda Universal Algebra Library 79 | = -S-invariance : { UUU QQQ XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra QQQ S )(ov QQQ )}( p q : Term)( B : SubalgebraOfClass{ UUU }{ QQQ } K ) —————————- → K | = p ∼∼∼ q → | B | | = p ≈ q | = -S-invariance { X = X } p q ( B , A , SA , ( ka , BisSA )) Kpq = gfe λ b → (embeddings-are-lc | h | hem)( ξ b )whereh’ : hom | SA | A h’ = ( | snd SA | , snd ∥ snd SA ∥ )h : hom B A h = HCompClosed B ( | SA | ) A ( | BisSA | ) h’hem : is-embedding | h | hem = ◦ -embedding (fst ∥ snd SA ∥ ) (iso → embedding BisSA ) ξ : ( b : X → | B | ) → | h | (( p (cid:5) B ) b ) ≡ | h | (( q (cid:5) B ) b ) ξ b = | h | (( p (cid:5) B ) b ) ≡⟨ comm-hom-term gfe B A h p b ⟩ ( p (cid:5) A )( | h | ◦ b ) ≡⟨ intensionality ( Kpq ka ) ( | h | ◦ b ) ⟩ ( q (cid:5) A )( | h | ◦ b ) ≡⟨ (comm-hom-term gfe B A h q b ) ⟩| h | (( q (cid:5) B ) b ) ■ An identities satisfied by all algebras in a class are also satisfied by the product of algebras inthat class. | = -P-invariance : { UUU XXX : Universe}{ X : XXX (cid:5) }( p q : Term{ XXX }{ X })( I : UUU (cid:5) )( A : I → Algebra
UUU S ) ————————————- → ( ∀ i → ( A i ) | = p ≈ q ) → d A | = p ≈ q | = -P-invariance p q I A A pq = γ where γ : p (cid:5) d A ≡ q (cid:5) d A γ = gfe λ a → ( p (cid:5) d A ) a ≡⟨ interp-prod gfe p A a ⟩ ( λ i → (( p (cid:5) ( A i )) ( λ x → ( a x ) i ))) ≡⟨ gfe ( λ i → cong-app ( A pq i ) ( λ x → ( a x ) i )) ⟩ ( λ i → (( q (cid:5) ( A i )) ( λ x → ( a x ) i ))) ≡⟨ (interp-prod gfe q A a ) ⟩ ( q (cid:5) d A ) a ■ | = -P-class-invariance : { UUU XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S )(ov UUU )}( p q : Term{
XXX }{ X })( I : UUU (cid:5) )( A : I → Algebra
UUU S ) → ( ∀ i → A i ∈ K ) ————————- → K | = p ∼∼∼ q → d A | = p ≈ q | = -P-class-invariance p q I A K A α = γ where β : ∀ i → ( A i ) | = p ≈ q β i = α ( K A i ) γ : p (cid:5) d A ≡ q (cid:5) d A γ = | = -P-invariance p q I A β Another fact that will turn out to be useful is that a product of a collection of algebras models p ≈ q if the lift of each algebra in the collection models p ≈ q . | = -P-lift-invariance : { UUU WWW XXX : Universe}{ X : XXX (cid:5) }( p q : Term{ XXX }{ X })( I : UUU (cid:5) ) ( A : I → Algebra
UUU S ) —————————————————- → ( ∀ i → (lift-alg ( A i ) WWW ) | = p ≈ q ) → d A | = p ≈ q | = -P-lift-invariance { UUU }{ WWW } p q I A lApq = | = -P-invariance p q I A AipqwhereAipq : ( i : I ) → ( A i ) | = p ≈ q Aipq i = | = -I-invariance p q ( lApq i ) (sym- ∼ = lift-alg- ∼ = ) If an algebra A models an identity p ≈ q , then the pair ( p , q ) belongs to the kernel of everyhomomorphism ϕ : hom ( T X ) A from the term algebra to A ; that is, every homomorphismfrom T X to A maps p and q to the same element of A . | = -H-invariance : { UUU XXX : Universe}( X : XXX (cid:5) )( p q : Term{ XXX }{ X })( A : Algebra UUU S )( ϕ : hom ( T X ) A ) —————————- → A | = p ≈ q → | ϕ | p ≡ | ϕ | q | = -H-invariance X p q A ϕ β = | ϕ | p ≡⟨ ap | ϕ | (term-agreement p ) ⟩| ϕ | (( p (cid:5) T X ) g ) ≡⟨ (comm-hom-term gfe ( T X ) A ϕ p g ) ⟩ ( p (cid:5) A ) ( | ϕ | ◦ g ) ≡⟨ intensionality β ( | ϕ | ◦ g ) ⟩ ( q (cid:5) A ) ( | ϕ | ◦ g ) ≡⟨ (comm-hom-term gfe ( T X ) A ϕ q g ) ⟩| ϕ | (( q (cid:5) T X ) g ) ≡⟨ (ap | ϕ | (term-agreement q )) ⟩| ϕ | q ■ More generally, an identity is satisfied by all algebras in a class if and only if that identity isinvariant under all homomorphisms from the term algebra T X into algebras of the class. Moreprecisely, if K is a class of S -algebras and p , q terms in the language of S , then, K | = p ≈ q ⇔ ∀ A ∈ K , ∀ ϕ : hom ( T X ) A , ϕ ◦ ( p (cid:5) ( T X )) = ϕ ◦ ( q (cid:5) ( T X )). – ⇒ (the ”only if” direction) | = -H-class-invariance : { UUU XXX : Universe}( X : XXX (cid:5) ){ K : Pred (Algebra UUU S )(ov UUU )}( p q : Term) → K | = p ∼∼∼ q → ( A : Algebra UUU S )( ϕ : hom ( T X ) A ) —————————————- → A ∈ K → | ϕ | ◦ ( p (cid:5) T X ) ≡ | ϕ | ◦ ( q (cid:5) T X ) Those mainly interested in the formal proof of Birkhoff’s HSP theorem can safely skip this section; it isnot needed elsewhere in the UALib he Agda Universal Algebra Library 81 | = -H-class-invariance X p q α A ϕ ka = gfe ξ where ξ : ∀ ( aaa : X → | T X | ) → | ϕ | (( p (cid:5) T X ) aaa ) ≡ | ϕ | (( q (cid:5) T X ) aaa ) ξ aaa = | ϕ | (( p (cid:5) T X ) aaa ) ≡⟨ comm-hom-term gfe ( T X ) A ϕ p aaa ⟩ ( p (cid:5) A )( | ϕ | ◦ aaa ) ≡⟨ intensionality ( α ka ) ( | ϕ | ◦ aaa ) ⟩ ( q (cid:5) A )( | ϕ | ◦ aaa ) ≡⟨ (comm-hom-term gfe ( T X ) A ϕ q aaa ) ⟩| ϕ | (( q (cid:5) T X ) aaa ) ■ – ⇐ (the ”if” direction) | = -H-class-coinvariance : { UUU XXX : Universe}( X : XXX (cid:5) ){ K : Pred (Algebra UUU S )(ov UUU )}( p q : Term) → (( A : Algebra UUU S )( ϕ : hom ( T X ) A ) → A ∈ K → | ϕ | ◦ ( p (cid:5) T X ) ≡ | ϕ | ◦ ( q (cid:5) T X )) ————————————— → K | = p ∼∼∼ q | = -H-class-coinvariance X p q β { A } ka = γ where ϕ : ( aaa : X → | A | ) → hom ( T X ) A ϕ aaa = lift-hom A aaaγ : A | = p ≈ q γ = gfe λ aaa → ( p (cid:5) A )( | ϕ aaa | ◦ g ) ≡⟨ (comm-hom-term gfe ( T X ) A ( ϕ aaa ) p g ) ⟩ ( | ϕ aaa | ◦ ( p (cid:5) T X )) g ≡⟨ ap ( λ - → - g ) ( β A ( ϕ aaa ) ka ) ⟩ ( | ϕ aaa | ◦ ( q (cid:5) T X )) g ≡⟨ (comm-hom-term gfe ( T X ) A ( ϕ aaa ) q g ) ⟩ ( q (cid:5) A )( | ϕ aaa | ◦ g ) ■ | = -H-compatibility : { UUU XXX : Universe}( X : XXX (cid:5) ){ K : Pred (Algebra UUU S )(ov UUU )}( p q : Term) —————————————————————- → K | = p ∼∼∼ q ⇔ (( A : Algebra UUU S )( ϕ : hom ( T X ) A ) → A ∈ K → | ϕ | ◦ ( p (cid:5) T X ) ≡ | ϕ | ◦ ( q (cid:5) T X )) | = -H-compatibility X p q = | = -H-class-invariance X p q , | = -H-class-coinvariance X p q
This subsection presents the
UALib.Varieties.Varieties submodule of the Agda UALib. Fix asignature S , let K be a class of S -algebras, and define H K = algebras isomorphic to a homomorphic image of a members of K ; S K = algebras isomorphic to a subalgebra of a member of K ; P K = algebras isomorphic to a product of members of K .A straight-forward verification confirms that H , S , and P are closure operators (expansive,monotone, and idempotent). A class K of S -algebras is said to be closed under the taking ofhomomorphic images provided H K ⊆ K . Similarly, K is closed under the taking of subalgebras (resp., arbitrary products ) provided S K ⊆ K (resp., P K ⊆ K ).An algebra is a homomorphic image (resp., subalgebra; resp., product) of every algebra towhich it is isomorphic. Thus, the class H K (resp., S K ; resp., P K ) is closed under isomorphism. The operators H , S , and P can be composed with one another repeatedly, forming yet moreclosure operators.A variety is a class K of algebras in a fixed signature that is closed under the taking ofhomomorphic images ( H ), subalgebras ( S ), and arbitrary products ( P ). That is, K is a varietyif and only if H S P K ⊆ K .This module defines what we have found to be the most useful inductive types representingthe closure operators H , S , and P . Separately, we define the inductive type V for simultaneouslyrepresenting closure under H , S , and P . open import UALib.Algebras using (Signature; OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Varieties.Varieties{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Varieties.EquationalLogic{ S = S }{ gfe }{ X } public We define the inductive type H to represent classes of algebras that include all homomorphicimages of algebras in the class; i.e., classes that are closed under the taking of homomorphicimages. data H { UUU WWW : Universe}( K : Pred (Algebra UUU S )(ov UUU )) :Pred (Algebra (
UUU ⊔ WWW ) S )(ov( UUU ⊔ WWW )) wherehbase : { A : Algebra UUU S } → A ∈ K → lift-alg A WWW ∈ H K hlift : { A : Algebra UUU S } → A ∈ H{ UUU }{ UUU } K → lift-alg A WWW ∈ H K hhimg : { A B : Algebra _ S } → A ∈ H{ UUU }{ WWW } K → B is-hom-image-of A → B ∈ H K hiso : { A : Algebra _ S }{ B : Algebra _ S } → A ∈ H{ UUU }{ UUU } K → A ∼ = B → B ∈ H K The most useful inductive type that we have found for representing classes of algebras that areclosed under the taking of subalgebras as an inductive type. data S {
UUU WWW : Universe}( K : Pred (Algebra UUU S ) (ov UUU )) :Pred (Algebra (
UUU ⊔ WWW ) S ) (ov( UUU ⊔ WWW )) wheresbase : { A : Algebra UUU S } → A ∈ K → lift-alg A WWW ∈ S K slift : { A : Algebra UUU S } → A ∈ S{ UUU }{ UUU } K → lift-alg A WWW ∈ S K ssub : { A : Algebra UUU S }{ B : Algebra _ S } → A ∈ S{ UUU }{ UUU } K → B ≤ A → B ∈ S K ssubw : { A B : Algebra _ S } → A ∈ S{ UUU }{ WWW } K → B ≤ A → B ∈ S K siso : { A : Algebra UUU S }{ B : Algebra _ S } → A ∈ S{ UUU }{ UUU } K → A ∼ = B → B ∈ S K The most useful inductive type that we have found for representing classes of algebras closedunder arbitrary products is the following. data P {
UUU WWW : Universe}( K : Pred (Algebra UUU S )(ov UUU )) : Pred (Algebra (
UUU ⊔ WWW ) S )(ov( UUU ⊔ WWW )) wherepbase : { A : Algebra UUU S } → A ∈ K → lift-alg A WWW ∈ P K he Agda Universal Algebra Library 83 pliftu : { A : Algebra UUU S } → A ∈ P{ UUU }{ UUU } K → lift-alg A WWW ∈ P K pliftw : { A : Algebra ( UUU ⊔ WWW ) S } → A ∈ P{ UUU }{ WWW } K → lift-alg A ( UUU ⊔ WWW ) ∈ P K produ : { I : WWW (cid:5) }{ A : I → Algebra
UUU S } → ( ∀ i → ( A i ) ∈ P{ UUU }{ UUU } K ) → d A ∈ P K prodw : { I : WWW (cid:5) }{ A : I → Algebra _ S } → ( ∀ i → ( A i ) ∈ P{ UUU }{ WWW } K ) → d A ∈ P K pisou : { A : Algebra UUU S }{ B : Algebra _ S } → A ∈ P{ UUU }{ UUU } K → A ∼ = B → B ∈ P K pisow : { A B : Algebra _ S } → A ∈ P{ UUU }{ WWW } K → A ∼ = B → B ∈ P K A class K of S -algebras is called a variety if it is closed under each of the closure operators H , S , and P introduced above; the corresponding closure operator is often denoted V , but we willtypically denote it by V .Thus, if K is a class of S -algebras, then the variety generated by K is denoted by V K and defined to be the smallest class that contains K and is closed under H , S , and P .We now define V as an inductive type. data V { UUU WWW : Universe}( K : Pred (Algebra UUU S )(ov UUU )) :Pred (Algebra (
UUU ⊔ WWW ) S )(ov( UUU ⊔ WWW )) wherevbase : { A : Algebra UUU S } → A ∈ K → lift-alg A WWW ∈ V K vlift : { A : Algebra UUU S } → A ∈ V{ UUU }{ UUU } K → lift-alg A WWW ∈ V K vliftw : { A : Algebra _ S } → A ∈ V{ UUU }{ WWW } K → lift-alg A ( UUU ⊔ WWW ) ∈ V K vhimg : { A B : Algebra _ S } → A ∈ V{ UUU }{ WWW } K → B is-hom-image-of A → B ∈ V K vssub : { A : Algebra UUU S }{ B : Algebra _ S } → A ∈ V{ UUU }{ UUU } K → B ≤ A → B ∈ V K vssubw : { A B : Algebra _ S } → A ∈ V{ UUU }{ WWW } K → B ≤ A → B ∈ V K vprodu : { I : WWW (cid:5) }{ A : I → Algebra
UUU S } → ( ∀ i → ( A i ) ∈ V{ UUU }{ UUU } K ) → d A ∈ V K vprodw : { I : WWW (cid:5) }{ A : I → Algebra _ S } → ( ∀ i → ( A i ) ∈ V{ UUU }{ WWW } K ) → d A ∈ V K visou : { A : Algebra UUU S }{ B : Algebra _ S } → A ∈ V{ UUU }{ UUU } K → A ∼ = B → B ∈ V K visow : { A B : Algebra _ S } → A ∈ V{ UUU }{ WWW } K → A ∼ = B → B ∈ V K The types defined above represent operators with useful closure properties. We now prove ahandful of such properties since we will need them later. – P is a closure operator; in particular, it’s expansive.
P-expa : {
UUU : Universe}{ K : Pred (Algebra UUU S )(ov UUU )} → K ⊆ P{ UUU }{ UUU } K P-expa{
UUU }{ K } { A } KA = pisou{ A = (lift-alg A UUU )}{ B = A } (pbase KA ) (sym- ∼ = lift-alg- ∼ = ) – P is a closure operator; in particular, it’s idempotent. P-idemp : {
UUU : Universe}{
WWW : Universe}{ K : Pred (Algebra UUU S )(ov UUU )} → P{ UUU ⊔ WWW }{ UUU ⊔ WWW } (P{
UUU }{ UUU ⊔ WWW } K ) ⊆ P{ UUU }{ UUU ⊔ WWW } K P-idemp (pbase x ) = pliftw x P-idemp {
UUU }{ WWW } (pliftu x ) = pliftw (P-idemp{ UUU }{ WWW } x )P-idemp { UUU }{ WWW } (pliftw x ) = pliftw (P-idemp{ UUU }{ WWW } x )P-idemp { UUU }{ WWW } (produ x ) = prodw ( λ i → P-idemp{
UUU }{ WWW } ( x i ))P-idemp {
UUU }{ WWW } (prodw x ) = prodw ( λ i → P-idemp{
UUU }{ WWW } ( x i ))P-idemp {
UUU }{ WWW } (pisou x x ) = pisow (P-idemp{ UUU }{ WWW } x ) x P-idemp {
UUU }{ WWW } (pisow x x ) = pisow (P-idemp{ UUU }{ WWW } x ) x – S is a closure operator; in particular, it’s monotone. S-mono : {
UUU WWW : Universe}{
K K ’ : Pred (Algebra UUU S )(ov UUU )} → K ⊆ K ’ → S{ UUU }{ WWW } K ⊆ S{ UUU }{ WWW } K ’ S-mono ante (sbase x ) = sbase ( ante x )S-mono { UUU }{ WWW }{ K }{ K ’ } ante (slift{ A } x ) = slift{ UUU }{ WWW }{ K ’ } (S-mono{ UUU }{ UUU } ante x )S-mono ante (ssub{ A }{ B } sA B ≤ A ) = ssub (S-mono ante sA ) B ≤ A S-mono ante (ssubw{ A }{ B } sA B ≤ A ) = ssubw (S-mono ante sA ) B ≤ A S-mono ante (siso x x ) = siso (S-mono ante x ) x We sometimes want to go back and forth between our two representations of subalgebras ofalgebras in a class. The tools subalgebra → S and S → subalgebra were designed with that purposein mind. subalgebra → S : {
UUU WWW : Universe}{ K : Pred (Algebra UUU S )(OV UUU )}{ C : Algebra ( UUU ⊔ WWW ) S } → C IsSubalgebraOfClass K ———————————————————- → C ∈ S{ UUU }{ WWW } K subalgebra → S {
UUU }{ WWW }{ K }{ C } ( A , (( B , B ≤ A ) , KA , C ∼ = B )) = ssub sA C ≤ AwhereC ≤ A : C ≤ A C ≤ A = Iso- ≤ A C B ≤ A C ∼ = B slAu : lift-alg A UUU ∈ S{ UUU }{ UUU } K slAu = sbase KA sA : A ∈ S{ UUU }{ UUU } K sA = siso slAu (sym- ∼ = lift-alg- ∼ = )module _ { UUU : Universe}{ K : Pred (Algebra UUU S )(OV UUU )} whereS → subalgebra : { B : Algebra UUU S } → B ∈ S{ UUU }{ UUU } K → B IsSubalgebraOfClass K S → subalgebra (sbase{ B } x ) = B , ( B , refl- ≤ ) , x , (sym- ∼ = lift-alg- ∼ = )S → subalgebra (slift{ B } x ) = | BS | , SA , KA , TRANS- ∼ = (sym- ∼ = lift-alg- ∼ = ) B ∼ = SAwhereBS : B IsSubalgebraOfClass K BS = S → subalgebra x SA : SUBALGEBRA | BS | SA = fst ∥ BS ∥ KA : | BS | ∈ K KA = | snd ∥ BS ∥ | B ∼ = SA : B ∼ = | SA | B ∼ = SA = ∥ snd ∥ BS ∥ ∥ S → subalgebra { B } (ssub{ A } sA B ≤ A ) = γ whereAS : A IsSubalgebraOfClass K AS = S → subalgebra sA SA : SUBALGEBRA | AS | he Agda Universal Algebra Library 85 SA = fst ∥ AS ∥ B ≤ SA : B ≤ | SA | B ≤ SA = TRANS- ≤ - ∼ = B | SA | B ≤ A ( ∥ snd ∥ AS ∥ ∥ )B ≤ AS : B ≤ | AS | B ≤ AS = transitivity- ≤ B { | SA | }{ | AS | } B ≤ SA ∥ SA ∥ γ : B IsSubalgebraOfClass K γ = | AS | , ( B , B ≤ AS) , | snd ∥ AS ∥ | , refl- ∼ = S → subalgebra { B } (ssubw{ A } sA B ≤ A ) = γ whereAS : A IsSubalgebraOfClass K AS = S → subalgebra sA SA : SUBALGEBRA | AS | SA = fst ∥ AS ∥ B ≤ SA : B ≤ | SA | B ≤ SA = TRANS- ≤ - ∼ = B | SA | B ≤ A ( ∥ snd ∥ AS ∥ ∥ )B ≤ AS : B ≤ | AS | B ≤ AS = transitivity- ≤ B { | SA | }{ | AS | } B ≤ SA ∥ SA ∥ γ : B IsSubalgebraOfClass K γ = | AS | , ( B , B ≤ AS) , | snd ∥ AS ∥ | , refl- ∼ = S → subalgebra { B } (siso{ A } sA A ∼ = B ) = γ whereAS : A IsSubalgebraOfClass K AS = S → subalgebra sA SA : SUBALGEBRA | AS | SA = fst ∥ AS ∥ A ∼ = SA : A ∼ = | SA | A ∼ = SA = snd ∥ snd AS ∥ γ : B IsSubalgebraOfClass K γ = | AS | , SA , | snd ∥ AS ∥ | , (TRANS- ∼ = (sym- ∼ = A ∼ = B ) A ∼ = SA)
Next we observe that lifting to a higher universe does not break the property of being a subal-gebra of an algebra of a class. In other words, if we lift a subalgebra of an algebra in a class,the result is still a subalgebra of an algebra in the class. lift-alg-subP : {
UUU WWW : Universe}{ K : Pred (Algebra UUU S )(ov UUU )}{ B : Algebra UUU S } → B IsSubalgebraOfClass (P{
UUU }{ UUU } K ) ————————————————— → (lift-alg B WWW ) IsSubalgebraOfClass (P{
UUU }{ WWW } K )lift-alg-subP { UUU } {
WWW } { K } { B } ( A , ( C , C ≤ A ) , pA , B ∼ = C ) = γ wherelA lB lC : Algebra ( UUU ⊔ WWW ) S lA = lift-alg A WWW lB = lift-alg B WWW lC = lift-alg C WWW lC ≤ lA : lC ≤ lAlC ≤ lA = lift-alg- ≤ C { A } C ≤ A plA : lA ∈ P{ UUU }{ WWW } K plA = pliftu pA γ : lB IsSubalgebraOfClass (P{ UUU }{ WWW } K ) γ = lA , (lC , lC ≤ lA) , plA , (lift-alg-iso UUU WWW
B C B ∼ = C ) The next lemma would be too obvoius to care about were it not for the fact that we’ll need itlater, so it too must be formalized. S ⊆ SP : {
UUU WWW : Universe}{ K : Pred (Algebra UUU S )(ov UUU )} → S{ UUU }{ WWW } K ⊆ S{ UUU ⊔ WWW }{ UUU ⊔ WWW } (P{
UUU }{ WWW } K )S ⊆ SP {
UUU } {
WWW } { K } {.(lift-alg A WWW )} (sbase{ A } x ) =siso spllA (sym- ∼ = lift-alg- ∼ = )wherellA : Algebra ( UUU ⊔ WWW ) S llA = lift-alg (lift-alg A WWW ) (
UUU ⊔ WWW )spllA : llA ∈ S{ UUU ⊔ WWW }{ UUU ⊔ WWW } (P{
UUU }{ WWW } K )spllA = sbase{ UUU = (
UUU ⊔ WWW )}{
WWW = (
UUU ⊔ WWW )} (pbase x )S ⊆ SP {
UUU } {
WWW } { K } {.(lift-alg A WWW )} (slift{ A } x ) =subalgebra → S{ UUU ⊔ WWW }{ UUU ⊔ WWW }{P{
UUU }{ WWW } K }{lift-alg A WWW } lAscwheresplAu : A ∈ S{ UUU }{ UUU } (P{
UUU }{ UUU } K )splAu = S ⊆ SP{
UUU }{ UUU } x Asc : A IsSubalgebraOfClass (P{
UUU }{ UUU } K )Asc = S → subalgebra{ UUU }{P{
UUU }{ UUU } K }{ A } splAulAsc : (lift-alg A WWW ) IsSubalgebraOfClass (P{
UUU }{ WWW } K )lAsc = lift-alg-subP AscS ⊆ SP {
UUU } {
WWW } { K } { B } (ssub{ A } sA B ≤ A ) =ssub{ UUU ⊔ WWW }{ UUU ⊔ WWW } lAsp (lift-alg-sub-lift A B ≤ A )wherelA : Algebra ( UUU ⊔ WWW ) S lA = lift-alg A WWW splAu : A ∈ S{ UUU }{ UUU } (P{
UUU }{ UUU } K )splAu = S ⊆ SP{
UUU }{ UUU } sA Asc : A IsSubalgebraOfClass (P{
UUU }{ UUU } K )Asc = S → subalgebra{ UUU }{P{
UUU }{ UUU } K }{ A } splAulAsc : lA IsSubalgebraOfClass (P{ UUU }{ WWW } K )lAsc = lift-alg-subP AsclAsp : lA ∈ S{ UUU ⊔ WWW }{ UUU ⊔ WWW } (P{
UUU }{ WWW } K )lAsp = subalgebra → S{ UUU ⊔ WWW }{ UUU ⊔ WWW }{P{
UUU }{ WWW } K }{lA} lAscS ⊆ SP {
UUU } {
WWW } { K } { B } (ssubw{ A } sA B ≤ A ) = γ where he Agda Universal Algebra Library 87 spA : A ∈ S{ UUU ⊔ WWW }{ UUU ⊔ WWW } (P{
UUU }{ WWW } K )spA = S ⊆ SP sA γ : B ∈ S{ UUU ⊔ WWW }{ UUU ⊔ WWW } (P{
UUU }{ WWW } K ) γ = ssubw{ UUU ⊔ WWW }{ UUU ⊔ WWW } spA B ≤ A S ⊆ SP {
UUU } {
WWW } { K } { B } (siso{ A } sA A ∼ = B ) = siso{ UUU ⊔ WWW }{ UUU ⊔ WWW } lAsp lA ∼ = BwherelA : Algebra (
UUU ⊔ WWW ) S lA = lift-alg A WWW splAu : A ∈ S{ UUU }{ UUU } (P{
UUU }{ UUU } K )splAu = S ⊆ SP{
UUU }{ UUU } sA lAsc : lA IsSubalgebraOfClass (P{ UUU }{ WWW } K )lAsc = lift-alg-subP (S → subalgebra{ UUU }{P{
UUU }{ UUU } K }{ A } splAu)lAsp : lA ∈ S{ UUU ⊔ WWW }{ UUU ⊔ WWW } (P{
UUU }{ WWW } K )lAsp = subalgebra → S{ UUU ⊔ WWW }{ UUU ⊔ WWW }{P{
UUU }{ WWW } K }{lA} lAsclA ∼ = B : lA ∼ = B lA ∼ = B = Trans- ∼ = lA B (sym- ∼ = lift-alg- ∼ = ) A ∼ = B We need to formalize one more lemma before arriving the short term objective of this section,which is the proof of the inclusion PS ⊆ SP. lemPS ⊆ SP : {
UUU WWW : Universe}{ K : Pred (Algebra UUU S )(ov UUU )}{ hfe : hfunext
WWW UUU } → { I : WWW (cid:5) }{ B : I → Algebra
UUU S } → ( ∀ i → ( B i ) IsSubalgebraOfClass K ) ————————————- → d B IsSubalgebraOfClass (P{
UUU }{ WWW } K )lemPS ⊆ SP {
UUU }{ WWW }{ K }{ hfe }{ I }{ B } B ≤ K = d A , ( d SA , d SA ≤ d A ) , ξ , γ where A : I → Algebra
UUU S A = λ i → | B ≤ K i | SA : I → Algebra
UUU S SA = λ i → | fst ∥ B ≤ K i ∥ |
KA : ∀ i → A i ∈ K KA = λ i → | snd ∥ B ≤ K i ∥ | B ∼ = SA : ∀ i → B i ∼ = SA i B ∼ = SA = λ i → ∥ snd ∥ B ≤ K i ∥ ∥ pA : ∀ i → lift-alg ( A i ) WWW ∈ P{ UUU }{ WWW } K pA = λ i → pbase (KA i )SA ≤ A : ∀ i → (SA i ) IsSubalgebraOf ( A i )SA ≤ A = λ i → snd | ∥ B ≤ K i ∥ | h : ∀ i → | SA i | → | A i | h = λ i → | SA ≤ A i | d SA ≤ d A : d SA ≤ d A d SA ≤ d A = i , ii , iiiwherei : | d SA | → | d A | i = λ x i → (h i ) ( x i )ii : is-embedding iii = embedding-lift{ QQQ = UUU }{ UUU = UUU }{ III = WWW } hfe hfe { I }{SA}{ A }h( λ i → fst ∥ SA ≤ A i ∥ )iii : is-homomorphism ( d SA) ( d A ) iiii = λ f aaa → gfe λ i → (snd ∥ SA ≤ A i ∥ ) f ( λ x → aaa x i ) ξ : d A ∈ P K ξ = produ{ UUU }{ WWW }{ I = I }{ A = A } ( λ i → P-expa (KA i )) γ : d B ∼ = d SA γ = d ∼ = gfe B ∼ = SA K ) ⊆ SP( K ) Finally, we are in a position to prove that a product of subalgebras of algebras in a class K isa subalgebra of a product of algebras in K . module _ { UUU : Universe}{ K : Pred (Algebra UUU S )(ov UUU )} { hfe : hfunext (ov
UUU )(ov
UUU )} whereov uuu : Universeov uuu = ov
UUU PS ⊆ SP : (P{ov uuu }{ov uuu } (S{
UUU }{ov uuu } K )) ⊆ (S{ov uuu }{ov uuu } (P{ UUU }{ov uuu } K ))PS ⊆ SP (pbase (sbase x )) = sbase (pbase x )PS ⊆ SP (pbase (slift{ A } x )) = slift (S ⊆ SP{
UUU }{ov uuu }{ K } (slift x ))PS ⊆ SP (pbase { B } (ssub{ A } sA B ≤ A )) =siso (ssub{ UUU = ov uuu } (S ⊆ SP{
UUU }{ov uuu }{ K } (slift sA )) (lift-alg- ≤ B { A } B ≤ A )) refl- ∼ = PS ⊆ SP (pbase { B }(ssubw{ A } sA B ≤ A )) =ssub{ UUU = ov uuu }(slift{ov uuu }{ov uuu }(S ⊆ SP sA ))(lift-alg- ≤ B { A } B ≤ A )PS ⊆ SP (pbase (siso{ A }{ B } x A ∼ = B )) = siso (S ⊆ SP (slift x )) (lift-alg-iso UUU ov uuu A B A ∼ = B )PS ⊆ SP (pliftu x ) = slift (PS ⊆ SP x )PS ⊆ SP (pliftw x ) = slift (PS ⊆ SP x )PS ⊆ SP (produ{ I }{ A } x ) = γ where ξ : ( i : I ) → ( A i ) IsSubalgebraOfClass (P{ UUU }{ov uuu } K ) ξ i = S → subalgebra{ K = (P K )} (PS ⊆ SP ( x i )) η ’ : d A IsSubalgebraOfClass (P{ov uuu }{ov uuu } (P{
UUU }{ov uuu } K )) η ’ = lemPS ⊆ SP{
UUU = ov uuu }{ov uuu }{ K = (P K )}{ hfe }{ I = I }{ B = A } ξη : d A ∈ S{ov uuu }{ov uuu } (P{ov uuu }{ov uuu } (P{
UUU }{ov uuu } K )) η = subalgebra → S{ UUU = (ov uuu )}{
WWW = ov uuu }{ K = (P (P K ))}{ C = d A } η ’ γ : d A ∈ S{ov uuu }{ov uuu } (P{
UUU }{ov uuu } K ) γ = (S-mono{ UUU = ov uuu }{ K = (P (P K ))}{ K ’ = (P K )} (P-idemp)) η he Agda Universal Algebra Library 89 PS ⊆ SP (prodw{ I }{ A } x ) = γ where ξ : ( i : I ) → ( A i ) IsSubalgebraOfClass (P{ UUU }{ov uuu } K ) ξ i = S → subalgebra{ K = (P K )} (PS ⊆ SP ( x i )) η ’ : d A IsSubalgebraOfClass (P{ov uuu }{ov uuu } (P{
UUU }{ov uuu } K )) η ’ = lemPS ⊆ SP{
UUU = ov uuu }{ov uuu }{ K = (P K )}{ hfe }{ I = I }{ B = A } ξη : d A ∈ S{ov uuu }{ov uuu } (P{ov uuu }{ov uuu } (P{
UUU }{ov uuu } K )) η = subalgebra → S{ UUU = (ov uuu )}{
WWW = ov uuu }{ K = (P (P K ))}{ C = d A } η ’ γ : d A ∈ S{ov uuu }{ov uuu } (P{
UUU }{ov uuu } K ) γ = (S-mono{ UUU = ov uuu }{ K = (P (P K ))}{ K ’ = (P K )} (P-idemp)) η PS ⊆ SP (pisou{ A }{ B } pA A ∼ = B ) = siso{ov uuu }{ov uuu }{P{ UUU }{ov uuu } K }{ A }{ B } (PS ⊆ SP pA ) A ∼ = B PS ⊆ SP (pisow{ A }{ B } pA A ∼ = B ) = siso{ov uuu }{ov uuu }{P{ UUU }{ov uuu } K }{ A }{ B } (PS ⊆ SP pA ) A ∼ = B Here we prove three more inclusion relations (which will have bit parts to play in the formalproof of Birkhoff’s Theorem). P ⊆ V : {
UUU WWW : Universe}{ K : Pred (Algebra UUU S )(ov UUU )} → P{ UUU }{ WWW } K ⊆ V{ UUU }{ WWW } K P ⊆ V (pbase x ) = vbase x P ⊆ V{ UUU } (pliftu x ) = vlift (P ⊆ V{ UUU }{ UUU } x )P ⊆ V{ UUU }{ WWW } (pliftw x ) = vliftw (P ⊆ V{ UUU }{ WWW } x )P ⊆ V (produ x ) = vprodu ( λ i → P ⊆ V ( x i ))P ⊆ V (prodw x ) = vprodw ( λ i → P ⊆ V ( x i ))P ⊆ V (pisou x x ) = visou (P ⊆ V x ) x P ⊆ V (pisow x x ) = visow (P ⊆ V x ) x SP ⊆ V : {
UUU WWW : Universe}{ K : Pred (Algebra UUU S )(ov UUU )} → S{ UUU ⊔ WWW }{ UUU ⊔ WWW } (P{
UUU }{ WWW } K ) ⊆ V{ UUU }{ WWW } K SP ⊆ V (sbase{ A } PCloA ) = P ⊆ V (pisow
PCloA lift-alg- ∼ = )SP ⊆ V (slift{ A } x ) = vliftw (SP ⊆ V x )SP ⊆ V{ UUU }{ WWW } { K } (ssub{ A }{ B } spA B ≤ A ) = vssubw (SP ⊆ V spA ) B ≤ A SP ⊆ V{ UUU }{ WWW } { K } (ssubw{ A }{ B } spA B ≤ A ) = vssubw (SP ⊆ V spA ) B ≤ A SP ⊆ V (siso x x ) = visow (SP ⊆ V x ) x Next we formally state and prove that, given an arbitrary class K of algebras, the product ofall algebras in the class S ( K ) belongs to SP ( K ). That is, d S ( K ) ∈ SP ( K ). This turns out tobe a nontrivial exercise. In fact, it is not even immediately obvious (at least not to this author)how one expresses the product of an entire class of algebras as a dependent type. Nonetheless,after a number of failed attempts, the right type revealed itself. (Not surprisingly, now that wehave it, it seems almost obvious.) module class-product { UUU : Universe}{ K : Pred (Algebra UUU S )(ov UUU )} where
First, we define the type that will serve to index the class (as well as the product of its mem-bers), as follows. I : { UUU : Universe} → Pred (Algebra
UUU S )(ov UUU ) → (ov UUU ) (cid:5) I { UUU } K = Σ A : (Algebra UUU S ) , A ∈ K Taking the product over this index type I requires a function like the following, which takes anindex (i : I ) and returns the corresponding algebra. A : { UUU : Universe}{ K : Pred (Algebra UUU S )(ov UUU )} → I K → Algebra
UUU S A { UUU }{ K } = λ ( i : ( I K )) → | i | Finally, the product of all members of K is represented by the following type. class-product : { UUU : Universe} → Pred (Algebra
UUU S )(ov UUU ) → Algebra (ov
UUU ) S class-product { UUU } K = d ( A { UUU }{ K } ) Alternatively, we could have defined the class product in a way that explicitly displays theindex, like so. class-product’ : {
UUU : Universe} → Pred (Algebra
UUU S )(ov UUU ) → Algebra (ov
UUU ) S class-product’{ UUU } K = d λ ( i : ( Σ A : (Algebra UUU S ) , A ∈ K )) → | i | If p : A ∈ K is a proof that A belongs to K , then we can view the pair ( A , p ) ∈ I K as anindex over the class, and A ( A , p ) as the result of projecting the product onto the ( A , p )-thcomponent. d S( K ) ∈ SP( K ) Thus, the (informal) product d S ( K ) of all subalgebras of algebras in K is implemented (form-ally) in the UALib as d ( A { UUU }{S( K )}) , and our goal is to prove that this product belongs to SP ( K ). This is done in the UALib by first proving that the product belongs to PS ( K ) (see theproof of class-prod-s- ∈ -ps in UALib.Varieties ) and then applying the PS ⊆ SP lemma describedabove. – The product of all subalgebras of a class K belongs to SP( K ). module class-product-inclusions { UUU : Universe} { K : Pred (Algebra UUU S )(OV UUU )} whereopen class-product {
UUU = UUU }{ K = K }class-prod-s- ∈ -ps : class-product (S{ UUU }{ UUU } K ) ∈ (P{OV UUU }{OV
UUU } (S{
UUU }{OV
UUU } K ))class-prod-s- ∈ -ps = pisou{ UUU = (OV
UUU )}{
WWW = (OV
UUU )} ps d llA d llA ∼ = cpKwhereI : (OV UUU ) (cid:5) I = I (S{ UUU }{ UUU } K )sA : ( i : I) → ( A i ) ∈ (S{ UUU }{ UUU } K )sA i = ∥ i ∥ lA llA : I → Algebra (OV
UUU ) S lA i = lift-alg ( A i ) (OV UUU )llA i = lift-alg (lA i ) (OV UUU )slA : ( i : I) → (lA i ) ∈ (S{ UUU }{(OV
UUU )} K )slA i = siso (sA i ) lift-alg- ∼ = he Agda Universal Algebra Library 91 psllA : ( i : I) → (llA i ) ∈ (P{OV UUU }{OV
UUU } (S{
UUU }{(OV
UUU )} K ))psllA i = pbase{ UUU = (OV
UUU )}{
WWW = (OV
UUU )} (slA i )ps d llA : d llA ∈ P{OV
UUU }{OV
UUU } (S{
UUU }{OV
UUU } K )ps d llA = produ{ UUU = (OV
UUU )}{
WWW = (OV
UUU )} psllAllA ∼ = A : ( i : I) → (llA i ) ∼ = ( A i )llA ∼ = A i = Trans- ∼ = (llA i ) ( A i ) (sym- ∼ = lift-alg- ∼ = ) (sym- ∼ = lift-alg- ∼ = ) d llA ∼ = cpK : d llA ∼ = class-product (S{ UUU }{ UUU } K ) d llA ∼ = cpK = d ∼ = gfe llA ∼ = A – PS ⊆ SP, so the product of all subalgebras of algebras in K belongs to SP( K ). class-prod-s- ∈ -sp : hfunext (OV UUU ) (OV
UUU ) → class-product (S{ UUU }{ UUU } K ) ∈ (S{OV UUU }{OV
UUU } (P{
UUU }{OV
UUU } K ))class-prod-s- ∈ -sp hfe = PS ⊆ SP{ hfe = hfe } (class-prod-s- ∈ -ps) This subsection presents the
UALib.Varieties.Preservation submodule of the Agda UALib. Inthis module we show that identities are preserved by closure operators H , S , and P . This willestablish the easy direction of Birkhoff’s HSP Theorem. open import UALib.Algebras using (Signature; OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Varieties.Preservation{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Varieties.Varieties { S = S }{ gfe }{ X } public –H preserves identities H-id1 : {
UUU XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S )(OV UUU )}( p q : Term{
XXX }{ X }) —————————————- → ( K | = p ∼∼∼ q ) → (H{ UUU }{ UUU } K | = p ∼∼∼ q )H-id1 p q α (hbase x ) = lift-alg- | = _ p q ( α x )H-id1 { UUU } p q α (hlift{ A } x ) = γ where β : A | = p ≈ q β = H-id1 p q α x γ : lift-alg A UUU | = p ≈ q γ = lift-alg- | = _ p q β H-id1 p q α (hhimg{ A }{ C } HA (( B , φ , ( φ hom , φ sur )) , B ∼ = C ) ) = | = - ∼ = p q γ B ∼ = C where β : A | = p ≈ q β = (H-id1 p q α ) HA preim : ∀ bbb x → | A | preim bbb x = (Inv φ ( bbb x ) ( φ sur ( bbb x ))) ζ : ∀ bbb → φ ◦ (preim bbb ) ≡ bbbζ bbb = gfe λ x → InvIsInv φ ( bbb x ) ( φ sur ( bbb x )) γ : ( p (cid:5) B ) ≡ ( q (cid:5) B ) γ = gfe λ bbb → ( p (cid:5) B ) bbb ≡⟨ (ap ( p (cid:5) B ) ( ζ bbb )) ⟩ ( p (cid:5) B ) ( φ ◦ (preim bbb )) ≡⟨ (comm-hom-term gfe A B ( φ , φ hom ) p (preim bbb )) ⟩ φ (( p (cid:5) A )(preim bbb )) ≡⟨ ap φ (intensionality β (preim bbb )) ⟩ φ (( q (cid:5) A )(preim bbb )) ≡⟨ comm-hom-term gfe A B ( φ , φ hom ) q (preim bbb ) ⟩ ( q (cid:5) B )( φ ◦ (preim bbb )) ≡⟨ ap ( q (cid:5) B ) ( ζ bbb ) ⟩ ( q (cid:5) B ) bbb ■ H-id1 p q α (hiso{ A }{ B } x x ) = | = -transport p q (H-id1 p q α x ) x The converse is almost too obvious to bother with. Nonetheless, we formalize it for complete-ness.
H-id2 : {
UUU WWW XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S )(OV UUU )}{ p q : Term{
XXX }{ X }} → (H{ UUU }{ WWW } K | = p ∼∼∼ q ) → ( K | = p ∼∼∼ q )H-id2 { UUU }{ WWW }{ XXX }{ X } { K } { p }{ q } Hpq { A } KA = γ wherelA : Algebra ( UUU ⊔ WWW ) S lA = lift-alg A WWW plA : lA ∈ H{ UUU }{ WWW } K plA = hbase KA ξ : lA | = p ≈ q ξ = Hpq plA γ : A | = p ≈ q γ = lower-alg- | = A p q ξ S-id1 : {
UUU XXX : Universe}{ X : XXX (cid:5) }( K : Pred (Algebra UUU S )(OV UUU ))( p q : Term{
XXX }{ X }) ————————————- → ( K | = p ∼∼∼ q ) → (S{ UUU }{ UUU } K | = p ∼∼∼ q )S-id1 _ p q α (sbase x ) = lift-alg- | = _ p q ( α x ) he Agda Universal Algebra Library 93 S-id1 K p q α (slift x ) = lift-alg- | = _ p q ((S-id1 K p q α ) x )S-id1 K p q α (ssub{ A }{ B } sA B ≤ A ) =S- | = p q (( B , A , ( B , B ≤ A ) , inj r e f l , id ∼ = )) γ where –Apply S- | = to the class K ∪ { A } β : A | = p ≈ q β = S-id1 K p q α sA Apq : { A } | = p ∼∼∼ q Apq (refl _) = βγ : ( K ∪ { A } ) | = p ∼∼∼ q γ { B } (inj x ) = α x γ { B } (inj y ) = Apq y S-id1 K p q α (ssubw{ A }{ B } sA B ≤ A ) =S- | = p q (( B , A , ( B , B ≤ A ) , inj r e f l , id ∼ = ) ) γ where –Apply S- | = to the class K ∪ { A } β : A | = p ≈ q β = S-id1 K p q α sA Apq : { A } | = p ∼∼∼ q Apq (refl _) = βγ : ( K ∪ { A } ) | = p ∼∼∼ q γ { B } (inj x ) = α x γ { B } (inj y ) = Apq y S-id1 K p q α (siso{ A }{ B } x x ) = γ where ζ : A | = p ≈ q ζ = S-id1 K p q α x γ : B | = p ≈ q γ = | = -transport p q ζ x Again, the obvious converse is barely worth the bits needed to formalize it.
S-id2 : {
UUU WWW XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S )(OV UUU )}{ p q : Term{
XXX }{ X }} → (S{ UUU }{ WWW } K | = p ∼∼∼ q ) → ( K | = p ∼∼∼ q )S-id2 { UUU }{ WWW }{ XXX }{ X } { K } { p }{ q } Spq { A } KA = γ wherelA : Algebra ( UUU ⊔ WWW ) S lA = lift-alg A WWW plA : lA ∈ S{ UUU }{ WWW } K plA = sbase KA ξ : lA | = p ≈ q ξ = Spq plA γ : A | = p ≈ q γ = lower-alg- | = A p q ξ P-id1 : {
UUU XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S )(OV UUU )}( p q : Term{
XXX }{ X }) ———————————— → ( K | = p ∼∼∼ q ) → (P{ UUU }{ UUU } K | = p ∼∼∼ q )P-id1 p q α (pbase x ) = lift-alg- | = _ p q ( α x )P-id1 p q α (pliftu x ) = lift-alg- | = _ p q ((P-id1 p q α ) x )P-id1 p q α (pliftw x ) = lift-alg- | = _ p q ((P-id1 p q α ) x )P-id1 { UUU } {
XXX } p q α (produ{ I }{ A } x ) = γ wherelA : I → Algebra
UUU S lA i = (lift-alg ( A i ) UUU )IH : ( i : I ) → ( p (cid:5) (lA i )) ≡ ( q (cid:5) (lA i ))IH i = lift-alg- | = ( A i ) p q ((P-id1 p q α ) ( x i )) γ : p (cid:5) ( d A ) ≡ q (cid:5) ( d A ) γ = lift-products-preserve-ids p q I A IHP-id1{
UUU } p q α (prodw{ I }{ A } x ) = γ wherelA : I → Algebra
UUU S lA i = (lift-alg ( A i ) UUU )IH : ( i : I ) → ( p (cid:5) (lA i )) ≡ ( q (cid:5) (lA i ))IH i = lift-alg- | = ( A i ) p q ((P-id1 p q α ) ( x i )) γ : p (cid:5) ( d A ) ≡ q (cid:5) ( d A ) γ = lift-products-preserve-ids p q I A IHP-id1 p q α (pisou{ A }{ B } x x ) = γ where γ : B | = p ≈ q γ = | = -transport p q (P-id1 p q α x ) x P-id1 p q α (pisow{ A }{ B } x x ) = | = -transport p q ζ x where ζ : A | = p ≈ q ζ = P-id1 p q α x …and conversely… P-id2 : {
UUU WWW XXX : Universe}{ X : XXX (cid:5) }( K : Pred (Algebra UUU S )(OV UUU )){ p q : Term{
XXX }{ X }} ————————————– → ((P{ UUU }{ WWW } K ) | = p ∼∼∼ q ) → ( K | = p ∼∼∼ q )P-id2 { UUU }{ WWW } K { p }{ q } PKpq { A } KA = γ where he Agda Universal Algebra Library 95 lA : Algebra ( UUU ⊔ WWW ) S lA = lift-alg A WWW plA : lA ∈ P{ UUU }{ WWW } K plA = pbase KA ξ : lA | = p ≈ q ξ = PKpq plA γ : A | = p ≈ q γ = lower-alg- | = A p q ξ – V preserves identities V-id1 : {
UUU XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S )(OV UUU )}( p q : Term{
XXX }{ X }) → ( K | = p ∼∼∼ q ) → (V{ UUU }{ UUU } K | = p ∼∼∼ q )V-id1 p q α (vbase x ) = lift-alg- | = _ p q ( α x )V-id1 { UUU }{ XXX }{ X }{ K } p q α (vlift{ A } x ) = γ where β : A | = p ≈ q β = (V-id1 p q α ) x γ : lift-alg A UUU | = p ≈ q γ = lift-alg- | = A p q β V-id1 {
UUU }{ XXX }{ X }{ K } p q α (vliftw{ A } x ) = γ where β : A | = p ≈ q β = (V-id1 p q α ) x γ : lift-alg A UUU | = p ≈ q γ = lift-alg- | = A p q β V-id1 p q α (vhimg{ A }{ C } VA (( B , φ , ( φ h , φ E )) , B ∼ = C )) = | = - ∼ = p q γ B ∼ = C whereIH : A | = p ≈ q IH = V-id1 p q α VA preim : ∀ bbb x → | A | preim bbb x = (Inv φ ( bbb x ) ( φ E ( bbb x ))) ζ : ∀ bbb → φ ◦ (preim bbb ) ≡ bbb – ( bbb : → | B | )(x : X) ζ bbb = gfe λ x → InvIsInv φ ( bbb x ) ( φ E ( bbb x )) γ : ( p (cid:5) B ) ≡ ( q (cid:5) B ) γ = gfe λ bbb → ( p (cid:5) B ) bbb ≡⟨ (ap ( p (cid:5) B ) ( ζ bbb )) ⟩ ( p (cid:5) B ) ( φ ◦ (preim bbb )) ≡⟨ (comm-hom-term gfe A B ( φ , φ h ) p (preim bbb )) ⟩ φ (( p (cid:5) A )(preim bbb )) ≡⟨ ap φ (intensionality IH (preim bbb )) ⟩ φ (( q (cid:5) A )(preim bbb )) ≡⟨ comm-hom-term gfe A B ( φ , φ h ) q (preim bbb ) ⟩ ( q (cid:5) B )( φ ◦ (preim bbb )) ≡⟨ ap ( q (cid:5) B ) ( ζ bbb ) ⟩ ( q (cid:5) B ) bbb ■ V-id1{
UUU }{ XXX }{ X }{ K } p q α ( vssub { A }{ B } VA B ≤ A ) = S- | = p q (( B , A , ( B , B ≤ A ) , inj r e f l , id ∼ = ) ) γ whereIH : A | = p ≈ q IH = V-id1 {
UUU }{ XXX }{ X } p q α VA Asinglepq : { A } | = p ∼∼∼ q Asinglepq (refl _) = IH γ : ( K ∪ { A } ) | = p ∼∼∼ q γ { B } (inj x ) = α x γ { B } (inj y ) = Asinglepq y V-id1{
UUU }{ XXX }{ X }{ K } p q α ( vssubw { A }{ B } VA B ≤ A ) =S- | = p q (( B , A , ( B , B ≤ A ) , inj r e f l , id ∼ = ) ) γ whereIH : A | = p ≈ q IH = V-id1 {
UUU }{ XXX }{ X } p q α VA Asinglepq : { A } | = p ∼∼∼ q Asinglepq (refl _) = IH γ : ( K ∪ { A } ) | = p ∼∼∼ q γ { B } (inj x ) = α x γ { B } (inj y ) = Asinglepq y V-id1 {
UUU }{ XXX }{ X } p q α (vprodu{ I }{ A } V A ) = γ whereIH : ( i : I ) → A i | = p ≈ q IH i = V-id1{ UUU }{ XXX }{ X } p q α ( V A i ) γ : p (cid:5) ( d A ) ≡ q (cid:5) ( d A ) γ = product-id-compatibility p q I A IHV-id1 {
UUU }{ XXX }{ X } p q α (vprodw{ I }{ A } V A ) = γ whereIH : ( i : I ) → A i | = p ≈ q IH i = V-id1{ UUU }{ XXX }{ X } p q α ( V A i ) γ : p (cid:5) ( d A ) ≡ q (cid:5) ( d A ) γ = product-id-compatibility p q I A IHV-id1 p q α (visou{ A }{ B } VA A ∼ = B ) = | = - ∼ = p q (V-id1 p q α VA ) A ∼ = B V-id1 p q α (visow{ A }{ B } VA A ∼ = B ) = | = - ∼ = p q (V-id1 p q α VA ) A ∼ = B Once again, and for the last time, completeness dictates that we formalize the coverse, howeverobvious it may be.
V-id2 : {
UUU WWW XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S )(OV UUU )}{ p q : Term{
XXX }{ X }} → (V{ UUU }{ WWW } K | = p ∼∼∼ q ) → ( K | = p ∼∼∼ q )V-id2 { UUU }{ WWW }{ XXX }{ X } { K } { p }{ q } Vpq { A } KA = γ wherelA : Algebra ( UUU ⊔ WWW ) S lA = lift-alg A WWW he Agda Universal Algebra Library 97 vlA : lA ∈ V{ UUU }{ WWW } K vlA = vbase KA ξ : lA | = p ≈ q ξ = Vpq vlA γ : A | = p ≈ q γ = lower-alg- | = A p q ξ It follows from
V-id1 that, if K is a class of structures, the set of identities modeled by allstructures in K is the same as the set of identities modeled by all structures in V K . – Th (V K ) is precisely the set of identities modeled by K class-identities : { UUU XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S ) (OV UUU )}( p q : | T X | ) ———————————————————- → K | = p ∼∼∼ q ⇔ (( p , q ) ∈ Th (V K ))class-identities{ UUU }{ XXX }{ X }{ K } p q = ⇒ , ⇐ where ⇒ : K | = p ∼∼∼ q → p , q ∈ Th (V K ) ⇒ = λ α VCloA → V-id1 p q α VCloA ⇐ : p , q ∈ Th (V K ) → K | = p ∼∼∼ q ⇐ = λ Thpq { A } KA → lower-alg- | = A p q ( Thpq (vbase KA )) (This page is almost entirely blank on purpose.) he Agda Universal Algebra Library 99 This section presents the
UALib.Birkhoff module of the Agda UALib.
Recall, we proved in Section 5.2 that the term algebra T X is the absolutely free algebra in theclass of all S -structures. In this section, we formalize, for a given class K of S -algebras, the(relatively) free algebra in SP ( K ) over X . Indeed, a free algebra for a class K induces the freealgebra in the variety generated by K , via the following definitions: Θ( K , A ) := { θ ∈ Con A : A ⧸ θ ∈ S K } and ψ ( K , A ) := ∩ Θ( K , A ) . The free algebra in the variety generated by K is constructed by applying these definitions tothe special case in which A is the term algebra T X of S -terms over X .Since T X is free for (and in) the class A l g ( S ) of all S -algebras, it is free for every subclass K of S -algebras. Although T X is not necessarily a member of K , if we form the quotient F : = ( T X ) ⧸ ψ ( K , T X ), then it is not hard to see that F is a subdirect product of the algebrasin { ( T X ) ⧸ θ } , where θ ranges over Θ ( K , T X ), so F belongs to SP ( K ), and it follows that F satisfies all the identities modeled by K . Indeed, for each pair p q : T X , if K | = p ≈ q , then p and q must belong to the same ψ ( K , T X )-class, so p and q are identified in the quotient F .The F so defined is called the free algebra over K generated by X and, because of whatwe just observed, we say that F is free in SP ( K ). This section presents the [UALib.Birkhoff.FreeAlgebra][] module of the [Agda Universal AlgebraLibrary][]. Here we represent F as a type in Agda by first constructing the congruence ψ ( K , T X ) described above. open import UALib.Algebras using (Signature; OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Birkhoff.FreeAlgebra{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }whereopen import UALib.Varieties.Preservation { S = S }{ gfe }{ X } public We assume two ambient universes
UUU and
XXX , as well as a type X : XXX (cid:5) . As usual, this is accom-plished with the module directive. module the-free-algebra {
UUU XXX : Universe}{ X : XXX (cid:5) } where
We begin by defining the collection T img of homomorphic images of the term algebra thatbelong to a given class K . If Θ ( K , A ) is empty, then ψ ( K , A ) = 1 and A ⧸ ψ ( K , A ) is trivial. Since X is not a subset of F , technically it doesn’t make sense to say “ X generates F .” But as long as K contains a nontrivial algebra, ψ ( K , T X ) ∩ X will be nonempty, and we can identify X with X ⧸ ψ ( K , T X ) which does belong to F .
00 8 BIRKHOFF’S HSP THEOREM – H ( T X) (hom images of T X) T img : Pred (Algebra UUU S ) (OV UUU ) → OOO ⊔ VVV ⊔ ( UUU ⊔ XXX ) + (cid:5) T img K = Σ A : (Algebra UUU S ) , Σ φ : hom ( T X ) A , ( A ∈ K ) × Epic | φ | The inhabitants of this Sigma type represent algebras A ∈ K such that there exists a surjectivehomomorphism φ : hom ( T X ) A . Thus, T img represents the collection of all homomorphicimages of T X that belong to K . Of course, this is the entire class K , since the term algebrais absolutely free. Nonetheless, this representation of K is useful since it endows each elementwith extra information. Indeed, each inhabitant of T img K is a quadruple, ( A , φ , ka , p ),where A is an S -algebra, φ is a homomorphism from T X to A , ka is a proof that A belongsto K , and p is a proof that the underlying map | φ | is epic.Next we define a function mkti that takes an arbitrary algebra A in K and returns thecorresponding quadruple in T img K . mkti : { K : Pred (Algebra UUU S ) ooo vvv uuu }( A : Algebra UUU S ) → A ∈ K → T img K mkti A ka = ( A , | T hom-gen A | , ka , ∥ T hom-gen A ∥ ) Occasionally we want to extract the homomorphism φ from an inhabitant of T img , so we define. – The hom part of a hom image of T X. T φ : ( K : Pred (Algebra UUU S ) (OV UUU ))( ti : T img K ) → hom ( T X ) | ti | T φ _ ti = fst ∥ ti ∥ Finally, it is time to define the congruence relation modulo which T X will yield the relativelyfree algebra, F K X .We start by letting ψ be the collection of all identities ( p , q ) satisfied by all subalgebrasof algebras in K . ψ : ( K : Pred (Algebra UUU S ) (OV UUU )) → Pred ( | T X | × | T X | ) (OV UUU ) ψ K ( p , q ) = ∀ ( A : Algebra UUU S ) → ( sA : A ∈ S{ UUU }{ UUU } K ) → | lift-hom A (fst( X A )) | p ≡ | lift-hom A (fst( X A )) | q We convert the predicate ψ into a relation by Currying. ψ Rel : ( K : Pred (Algebra UUU S ) (OV UUU )) → Rel | ( T X ) | (OV UUU ) ψ Rel K p q = ψ K ( p , q ) We will want to express ψ Rel as a congruence of the term algebra T X , so we must prove that ψ Rel is compatible with the operations of T X (which are just the terms themselves) and that ψ Rel an equivalence relation. ψ compatible : ( K : Pred (Algebra UUU S ) (OV UUU )) → compatible ( T X ) ( ψ Rel K ) ψ compatible K f { i } { j } i ψ j A sA = γ whereti : T img (S{ UUU }{ UUU } K )ti = mkti A sA φ : hom ( T X ) A φ = fst ∥ ti ∥ γ : | φ | (( f ˆ T X ) i ) ≡ | φ | (( f ˆ T X ) j ) γ = | φ | (( f ˆ T X ) i ) ≡⟨ ∥ φ ∥ f i ⟩ he Agda Universal Algebra Library 101 ( f ˆ A ) ( | φ | ◦ i ) ≡⟨ ap ( f ˆ A ) ( gfe λ x → (( i ψ j x ) A sA )) ⟩ ( f ˆ A ) ( | φ | ◦ j ) ≡⟨ ( ∥ φ ∥ f j ) ⟩| φ | (( f ˆ T X ) j ) ■ ψ Refl : { K : Pred (Algebra UUU S ) (OV UUU )} → reflexive ( ψ Rel K ) ψ Refl = λ x C φ → r e f l ψ Symm : { K : Pred (Algebra UUU S ) (OV UUU )} → symmetric ( ψ Rel K ) ψ Symm p q p ψ Relq C φ = ( p ψ Relq C φ ) ψ Trans : { K : Pred (Algebra UUU S ) (OV UUU )} → transitive ( ψ Rel K ) ψ Trans p q r p ψ q q ψ r C φ = ( p ψ q C φ ) · ( q ψ r C φ ) ψ IsEquivalence : { K : Pred (Algebra UUU S ) (OV UUU )} → IsEquivalence ( ψ Rel K ) ψ IsEquivalence = record { rfl = ψ Refl ; sym = ψ Symm ; trans = ψ Trans }
We have collected all the pieces necessary to express the collection of identities satisfied by allalgebras in the class as a congruence relation of the term algebra. We call this congruence ψ Con and define it using the Congruence constructor mkcon . ψ Con : ( K : Pred (Algebra UUU S ) (OV UUU )) → Congruence ( T X ) ψ Con K = mkcon ( ψ Rel K ) ( ψ compatible K ) ψ IsEquivalence
We denote the free algebra by F and construct it as the quotient T X ⧸ ( ψ Con K ). open the-free-algebramodule the-relatively-free-algebra{ UUU XXX : Universe}{ X : XXX (cid:5) }{ K : Pred (Algebra UUU S ) (OV UUU )} where
FFF : Universe – (universe level of the relatively free algebra)
FFF = (
XXX ⊔ (OV UUU )) + F : Algebra FFF S F = T X ⧸ ( ψ Con K ) Here
FFF = ( XXX ⊔ ov uuu ) + happens to be the universe level of F . The domain of the free algebra is | T X | / ⟨ ψ Con K ⟩ , which is Σ C : _ , Σ p : | T X | , C ≡ ( [ p ] ⟨ ψ Con K ⟩ ), by definition;i.e., the collection { C : ∃ p ∈ | T X | , C ≡ [ p ] ⟨ ψ Con K ⟩ } of ⟨ ψ Con K ⟩ -classes of T X . F -free-lift : { WWW : Universe}( A : Algebra WWW S )( h : X → | A | ) → | F | → | A | F -free-lift { WWW } A h (_ , x , _) = (free-lift{ XXX }{ WWW } A h ) x F -lift-hom : { WWW : Universe}( A : Algebra WWW S )( h : X → | A | ) → hom F A F -lift-hom A h = f , fhomwheref : | F | → | A | f = F -free-lift A h
02 8 BIRKHOFF’S HSP THEOREM φ : hom ( T X ) A φ = lift-hom A h fhom : is-homomorphism F A ffhom f aaa = ∥ φ ∥ f ( λ i → ⌜ aaa i ⌝ ) F -lift-agrees-on-X : { WWW : Universe}( A : Algebra WWW S )( h : X → | A | )( x : X ) —————————————– → h x ≡ ( | F -lift-hom A h | ⟦ g x ⟧ ) F -lift-agrees-on-X _ h x = r e f l F -lift-of-epic-is-epic : { WWW : Universe}( A : Algebra WWW S )( h : X → | A | ) → Epic h ——————————– → Epic | F -lift-hom A h | F -lift-of-epic-is-epic A h hE y = γ whereh pre : Image h ∋ y h pre = hE y h y : X h y = Inv h y ( hE y ) η : y ≡ ( | F -lift-hom A h | ⟦ g (h y) ⟧ ) η = y ≡⟨ (InvIsInv h y h pre) ⟩ h h y ≡⟨ ( F -lift-agrees-on-X) A h h y ⟩| F -lift-hom A h | ⟦ ( g h y) ⟧ ■ γ : Image | F -lift-hom A h | ∋ y γ = eq y (⟦ g h y ⟧) η F -canonical-projection : epi ( T X ) FF -canonical-projection = canonical-projection ( T X ) ( ψ Con K ) π F : hom ( T X ) F π F = epi-to-hom ( T X ) { F } F -canonical-projection π F -X-defined : ( g : hom ( T X ) F ) → (( x : X ) → | g | ( g x ) ≡ ⟦ g x ⟧) → ( t : | T X | ) ——————————— → | g | t ≡ ⟦ t ⟧ π F -X-defined g gx t = free-unique gfe F g π F g π F -agree-on-X t whereg π F -agree-on-X : (( x : X ) → | g | ( g x ) ≡ | π F | ( g x ))g π F -agree-on-X x = gx x he Agda Universal Algebra Library 103 X , → F : X → | F | X , → F x = ⟦ g x ⟧ The remainder of §8.2 is not needed for the proof of Birkhoff’s theorem. F -free-lift-interpretation : ( A : Algebra UUU S )( h : X → | A | )( xxx : | F | ) ————————————- → ( ⌜ xxx ⌝ (cid:5) A ) h ≡ F -free-lift A h xxx F -free-lift-interpretation A f xxx = free-lift-interpretation A f ⌜ xxx ⌝ T -canonical-projection : ( θ : Congruence{ov XXX }{ UUU } ( T X )) → epi ( T X ) (( T X ) ⧸ θ ) T -canonical-projection θ = canonical-projection ( T X ) θ ψ ψ lem : ( p q : | T X | ) → | lift-hom F X , → F | p ≡ | lift-hom F X , → F | q———————————————– → ( p , q ) ∈ ψ K ψ lem p q gpgq A sA = γ whereg : hom ( T X ) F g = lift-hom F (X , → F )h : X → | A | h = fst ( X A )f : hom F A f = F -lift-hom A h h φ : hom ( T X ) A h = HomComp ( T X ) A g f φ = T φ (S K ) (mkti A sA ) –(homs from T X to A that agree on X are equal) lift-agreement : ( x : X ) → h x ≡ | f | ⟦ g x ⟧lift-agreement x = F -lift-agrees-on-X A h x fgx ≡ φ : ( x : X ) → ( | f | ◦ | g | ) ( g x ) ≡ | φ | ( g x )fgx ≡ φ x = (lift-agreement x ) h ≡ φ : ∀ t → ( | f | ◦ | g | ) t ≡ | φ | t h ≡ φ t = free-unique gfe A h φ fgx ≡ φ t γ : | φ | p ≡ | φ | q γ = | φ | p ≡⟨ (h ≡ φ p ) ⟩ ( | f | ◦ | g | ) p ≡⟨ r e f l ⟩ | f | ( | g | p ) ≡⟨ ap | f | gpgq ⟩ | f | ( | g | q ) ≡⟨ h ≡ φ q ⟩ | φ | q ■
04 8 BIRKHOFF’S HSP THEOREM T i | = ψ : ( K : Pred (Algebra UUU S ) ooo vvv uuu )( C : Algebra UUU S ) ( sC : C ∈ S{ UUU }{ UUU } K )( p q : | ( T X ) | ) → ( p , q ) ∈ ψ K ————————————————– → | T φ (S K )(mkti C sC ) | p ≡ | T φ (S K )(mkti C sC ) | q T i | = ψ K C sC p q p ψ q = p ψ q C sC This subsection presents the
UALib.Birkhoff.HSPLemmas submodule of the Agda UALib. Thissubsection gives formal statements of four lemmas that we will string together in §8.4 to com-plete the proof of Birkhoff’s theorem.
Warning : not all of these are very interesting! open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Birkhoff.HSPLemmas{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }{ UUU : Universe} { X : UUU (cid:5) }whereopen import UALib.Birkhoff.FreeAlgebra { S = S }{ gfe }{ X } publicopen the-free-algebra { UUU }{ UUU }{ X }module class-inclusions{ K : Pred (Algebra UUU S ) (ov UUU )} – extensionality assumptions: { hfe : hfunext (ov UUU )(ov
UUU )}{ pe : propext (ov UUU )} – truncation assumptions: { ssR : ∀ p q → is-subsingleton (( ψ Rel K ) p q )}{ ssA : ∀ C → is-subsingleton ( C {ov UUU }{ov
UUU }{ | T X | }{ ψ Rel K } C )}where – NOTATION. ovu ovu+ : Universeovu = OOO ⊔ VVV ⊔ UUU + ovu+ = ovu + The first hurdle is the lift-alg-V-closure lemma, which says that if an algebra A belongs to thevariety V , then so does its lift. This dispenses with annoying universe level problems that ariselater—a minor techinical issue, but the proof is long and tedious, not to mention uninteresting. open Liftlift-alg-V-closure – (alias) he Agda Universal Algebra Library 105 VlA : { A : Algebra ovu S } → A ∈ V{ UUU }{ovu} K ——————————— → lift-alg A ovu+ ∈ V{ UUU }{ovu+} K VlA (vbase{ A } x ) = visow (vbase{ UUU }{ WWW = ovu+} x ) (lift-alg-associative A )VlA (vlift{ A } x ) = visow (vlift{ UUU }{ WWW = ovu+} x ) (lift-alg-associative A )VlA (vliftw{ A } x ) = visow (VlA x ) (lift-alg-associative A )VlA (vhimg{ A }{ B } x hB ) = vhimg (VlA x ) (lift-alg-hom-image hB )VlA (vssub{ A }{ B } x B ≤ A ) = vssubw (vlift{ UUU }{ WWW = ovu+} x ) (lift-alg- ≤ B { A } B ≤ A )VlA (vssubw{ A }{ B } x B ≤ A ) = vssubw (VlA x ) (lift-alg- ≤ B { A } B ≤ A )VlA (vprodu{ I }{ A } x ) = visow (vprodw vlA) (sym- ∼ = B ∼ = A)where I : ovu+ (cid:5) I = Lift{ovu}{ovu+} I lA+ : Algebra ovu+ S lA+ = lift-alg ( d A ) ovu+lA : I → Algebra ovu+ S lA i = lift-alg ( A (lower i )) ovu+vlA : ( i : I ) → (lA i ) ∈ V{ UUU }{ovu+} K vlA i = vlift ( x (lower i ))iso-components : ( i : I ) → A i ∼ = lA (lift i )iso-components i = lift-alg- ∼ = B ∼ = A : lA+ ∼ = d lAB ∼ = A = lift-alg- d ∼ = gfe iso-componentsVlA (vprodw{ I }{ A } x ) = visow (vprodw vlA) (sym- ∼ = B ∼ = A)where I : ovu+ (cid:5) I = Lift{ovu}{ovu+} I lA+ : Algebra ovu+ S lA+ = lift-alg ( d A ) ovu+lA : I → Algebra ovu+ S lA i = lift-alg ( A (lower i )) ovu+vlA : ( i : I ) → (lA i ) ∈ V{ UUU }{ovu+} K vlA i = VlA ( x (lower i ))iso-components : ( i : I ) → A i ∼ = lA (lift i )iso-components i = lift-alg- ∼ = B ∼ = A : lA+ ∼ = d lAB ∼ = A = lift-alg- d ∼ = gfe iso-componentsVlA (visou{ A }{ B } x A ∼ = B ) = visow (vlift x ) (lift-alg-iso UUU ovu+
A B A ∼ = B )VlA (visow{ A }{ B } x A ∼ = B ) = visow (VlA x ) (lift-alg-iso ovu ovu+ A B A ∼ = B )lift-alg-V-closure = VlA – (alias)
06 8 BIRKHOFF’S HSP THEOREM K ) ⊆ V( K ) In the
UALib.Varieties module, we proved that SP ( K ) ⊆ V ( K ) holds with fairly general universelevel parameters. Unfortunately, this was not general enough for our purposes, so we prove theinclusion again for the specific universe parameters that align with subsequent applications ofthis result. This proof also suffers from the unfortunate defect of being boring. SP ⊆ V’ : S{ovu}{ovu+} (P{
UUU }{ovu} K ) ⊆ V{ UUU }{ovu+} K SP ⊆ V’ (sbase{ A } x ) = γ wherellA lA+ : Algebra ovu+ S lA+ = lift-alg A ovu+llA = lift-alg (lift-alg A ovu) ovu+vllA : llA ∈ V{ UUU }{ovu+} K vllA = lift-alg-V-closure (SP ⊆ V (sbase x ))llA ∼ = lA+ : llA ∼ = lA+llA ∼ = lA+ = sym- ∼ = (lift-alg-associative A ) γ : lA+ ∈ (V{ UUU }{ovu+} K ) γ = visow vllA llA ∼ = lA+SP ⊆ V’ (slift{ A } x ) = lift-alg-V-closure (SP ⊆ V x )SP ⊆ V’ (ssub{ A }{ B } spA B ≤ A ) = vssubw vlA B ≤ lAwherelA : Algebra ovu+ S lA = lift-alg A ovu+vlA : lA ∈ V{ UUU }{ovu+} K vlA = lift-alg-V-closure (SP ⊆ V spA )B ≤ lA : B ≤ lAB ≤ lA = (lift-alg-lower- ≤ -lift {ovu}{ovu+}{ovu+} A { B }) B ≤ A SP ⊆ V’ (ssubw{ A }{ B } spA B ≤ A ) = vssubw (SP ⊆ V’ spA ) B ≤ A SP ⊆ V’ (siso{ A }{ B } x A ∼ = B ) = visow (lift-alg-V-closure vA) lA ∼ = BwherelA : Algebra ovu+ S lA = lift-alg A ovu+plA : A ∈ S{ovu}{ovu}(P{
UUU }{ovu} K )plA = x vA : A ∈ V{ UUU }{ovu} K vA = SP ⊆ V x lA ∼ = B : lA ∼ = B lA ∼ = B = Trans- ∼ = lA B (sym- ∼ = lift-alg- ∼ = ) A ∼ = B he Agda Universal Algebra Library 107 F ≤ d S( K ) Now we come to a step in the Agda formalization of Birkhoff’s theorem that turns out to besurprisingly nontrivial. We must show that the relatively free algebra F embeds in the product C of all subalgebras of algebras in the given class K . Incidentally, this seems to be the onlystage in the proof of Birkhoff’s theorem that requires the truncation assumption that C be aset.We begin by constructing C , using the class-product types described in §7.3.8. open the-relatively-free-algebra { UUU = UUU }{ XXX = UUU }{ X = X } { K = K }open class-product { UUU = UUU }{ K = K } – NOTATION.– V is HSP( K ) V : Pred (Algebra ovu+ S ) (ovu+ + ) V = V{ UUU }{ovu+} K I s : ovu (cid:5) I s = I (S{ UUU }{ UUU } K ) A s : I s → Algebra
UUU S A s = λ ( i : I s) → | i | SK A : ( i : I s) → ( A s i ) ∈ S{ UUU }{ UUU } K SK A = λ ( i : I s) → ∥ i ∥ – C is the product of all subalgebras of algebras in K . C : Algebra ovu S C = d A s Observe that the elements of C are maps from I s to { A s i : i ∈ I s} .Next, we construct an embedding f from F into C using a UALib tool called F -free-lift . h : X → | C | h x = λ i → (fst ( X ( A s i ))) x φ c : hom ( T X ) C φ c = lift-hom C h g : hom ( T X ) Fg = lift-hom F (X , → F ) f : hom F Cf = F -free-lift C h , λ f aaa → ∥ φ c ∥ f ( λ i → ⌜ aaa i ⌝ ) g -⟦⟧ : ∀ p → | g | p ≡ ⟦ p ⟧ g -⟦⟧ p = π F -X-defined g ( F -lift-agrees-on-X F X , → F ) p– p i is the projection out of the product C onto the i-th factor. p : ( i : I s) → | C | → | A s i | p i aaa = aaa i p hom : ( i : I s) → hom C ( A s i )
08 8 BIRKHOFF’S HSP THEOREM p hom = d -projection-hom { I = I s}{ A = A s} – pf is the composition: F – f –> C – p i –> A s i pf : ∀ i → | F | → | A s i | pf i = ( p i ) ◦ | f | pf hom : ( i : I s) → hom F ( A s i ) pf hom i = HomComp F ( A s i ) f ( p hom i ) We now proceed to the proof that the free algebra F is a subalgebra of the product C of allsubalgebras of algebras in K . The hard part of the proof is showing that f : hom F C is amonomorphism. Let’s dispense with that first. Ψ : Rel | T X | (ov UUU ) Ψ = ψ Rel K mon f : Monic | f | mon f (.( Ψ p ) , p , refl _) (.( Ψ q ) , q , refl _) fpq = γ wherep Ψ q : Ψ p q p Ψ q A sA = γ ’where p A : hom F A p A = pf hom ( A , sA ) f pq : | p A | ⟦ p ⟧ ≡ | p A | ⟦ q ⟧ f pq = | p A | ⟦ p ⟧ ≡⟨ r e f l ⟩| p hom ( A , sA ) | ( | f | ⟦ p ⟧ ) ≡⟨ ap ( λ - → ( | p hom ( A , sA ) | - )) fpq ⟩| p hom ( A , sA ) | ( | f | ⟦ q ⟧ ) ≡⟨ r e f l ⟩| p A | ⟦ q ⟧ ■ h φ : hom ( T X ) A h = HomComp ( T X ) A g p A φ = lift-hom A (( p ( A , sA )) ◦ h ) f gx ≡ φ : ( x : X ) → ( | p A | ◦ | g | ) ( g x ) ≡ | φ | ( g x ) f gx ≡ φ x = | p A | ( | g | ( g x )) ≡⟨ ap | p A | ( g -⟦⟧ ( g x )) ⟩| p A | (⟦ g x ⟧) ≡⟨ ( F -lift-agrees-on-X A (( p ( A , sA )) ◦ h ) x ) ⟩| φ | ( g x ) ■ h ≡ φ ’ : ∀ t → ( | p A | ◦ | g | ) t ≡ | φ | t h ≡ φ ’ t = free-unique gfe A h φ f gx ≡ φ t γ ’ : | φ | p ≡ | φ | q γ ’ = | φ | p ≡⟨ (h ≡ φ ’ p ) ⟩| p A | ( | g | p ) ≡⟨ ap | p A | ( g -⟦⟧ p ) ⟩| p A | ⟦ p ⟧ ≡⟨ f pq ⟩| p A | ⟦ q ⟧ ≡⟨ (ap | p A | ( g -⟦⟧ q )) ⟩| p A | ( | g | q ) ≡⟨ h ≡ φ ’ q ⟩| φ | q ■ he Agda Universal Algebra Library 109 γ : ( Ψ p , p , r e f l ) ≡ ( Ψ q , q , r e f l ) γ = class-extensionality’ pe gfe ssR ssA ψ IsEquivalence p Ψ q With that out of the way, the proof that F is (isomorphic to) a subalgebra of C is all butcomplete. F ≤ C : is-set | C | → F ≤ CF ≤ C Cset = | f | , (emb f , ∥ f ∥ )whereemb f : is-embedding | f | emb f = monic-into-set-is-embedding Cset | f | mon f F ∈ V( K ) With the foregoing results in hand, along with what we proved earlier—namely, that PS ( K ) ⊆ SP ( K ) ⊆ V ( K )—it is not hard to show that F belongs to SP ( K ), and hence to V ( K ). open class-product-inclusions { UUU = UUU }{ K = K } F ∈ SP : is-set | C | → F ∈ (S{ovu}{ovu+} (P{ UUU }{ovu} K )) F ∈ SP Cset = ssub spC ( F ≤ C Cset )wherespC : C ∈ (S{ovu}{ovu} (P{ UUU }{ovu} K ))spC = (class-prod-s- ∈ -sp hfe ) F ∈ V : is-set | C | → F ∈ V F ∈ V Cset = SP ⊆ V’ ( F ∈ SP Cset ) This subsection presents the
UALib.Birkhoff.HSPTheorem submodule of the Agda UALib. It isnow all but trivial to use what we have already proved and piece together a complete proof ofBirkhoff’s celebrated HSP theorem asserting that every variety is defined by a set of identities(is an “equational class”). open import UALib.Algebras using (Signature;
OOO ; VVV ; Algebra; _ ↠ _)open import UALib.Prelude.Preliminaries using (global-dfunext; Universe; _ (cid:5) )module UALib.Birkhoff.HSPTheorem{ S : Signature OOO VVV }{ gfe : global-dfunext}{ X : { UUU XXX : Universe}{ X : XXX (cid:5) }( A : Algebra UUU S ) → X ↠ A }{ UUU : Universe} { X : UUU (cid:5) }whereopen import UALib.Birkhoff.HSPLemmas { S = S }{ gfe }{ X }{ UUU }{ X } publicopen the-free-algebra { UUU }{ UUU }{ X }module Birkhoffs-Theorem{ K : Pred (Algebra UUU S ) ooo vvv uuu } – extensionality assumptions { hfe : hfunext ooo vvv uuu ooo vvv uuu }{ pe : propext ooo vvv uuu }
10 9 CONCLUSION – truncation assumptions: { ssR : ∀ p q → is-subsingleton (( ψ Rel K ) p q )}{ ssA : ∀ C → is-subsingleton ( C { ooo vvv uuu }{ ooo vvv uuu }{ | T X | }{ ψ Rel K } C )}whereopen the-relatively-free-algebra { UUU }{ UUU }{ X }{ K }open class-inclusions { K = K }{ hfe }{ pe }{ ssR }{ ssA } – Birkhoff’s theorem: every variety is an equational class. birkhoff : is-set | C | → Mod X (Th V ) ⊆ V birkhoff Cset { A } α = γ where φ : Σ h : (hom F A ) , Epic | h | φ = ( F -lift-hom A | X A | ) , F -lift-of-epic-is-epic A | X A | ∥ X A ∥ AiF : A is-hom-image-of F AiF = ( A , | fst φ | , ( ∥ fst φ ∥ , snd φ ) ) , refl- ∼ = γ : A ∈ V γ = vhimg ( F ∈ V Cset ) AiF
Some readers might worry that we haven’t quite acheived our goal because what we just proved( birkhoff ) is not an “if and only if” assertion. Those fears are quickly put to rest by noting thatthe converse—that every equational class is closed under HSP—was already established in the
UALib.Varieties.Preservation module. Indeed, there we proved the following identity preservationlemmas:(H-id1) K | = p ∼∼∼ q → H K | = p ∼∼∼ q(S-id1) K | = p ∼∼∼ q → S K | = p ∼∼∼ q(P-id1) K | = p ∼∼∼ q → P K | = p ∼∼∼ qFrom these it follows that every equational class is a variety. Now that we have accomplished our initial goal of formalizing Birkhoff’s HSP theorem in Agda,our next goal is to support current mathematical research by formalizing some recently provedtheorems. For example, we intend to formalize theorems about the computational complexityof decidable properties of algebraic structures. Part of this effort will naturally involve furtherwork on the library itself, and may lead to new observations about dependent type theory.One natural question is whether there are any objects of our research that cannot be rep-resented constructively in type theory. As mentioned in the preface, a constructive version ofBirkhoff’s theorem was presented by Carlström in [4]. We should determine how the two newhypotheses required by Carlström compare with the assumptions we make in our Agda proof.Finally, as one of the goals of the Agda UALib project is to make computer formalization ofmathematics more accessible to mathematicians working in universal algebra and model theory,we welcome feedback from the community and are happy to field questions about the UALib,how it is installed, and how it can be used to prove theorems that are not yet part of the library. he Agda Universal Algebra Library 111References Clifford Bergman.
Universal Algebra: fundamentals and selected topics , volume 301 of
Pure andApplied Mathematics (Boca Raton) . CRC Press, Boca Raton, FL, 2012. G Birkhoff. On the structure of abstract algebras.
Proceedings of the Cambridge PhilosophicalSociety , 31(4):433–454, Oct 1935. Venanzio Capretta. Universal algebra in type theory. In
Theorem proving in higher order logics(Nice, 1999) , volume 1690 of
Lecture Notes in Comput. Sci. , pages 131–148. Springer, Berlin, 1999.URL: http://dx.doi.org/10.1007/3-540-48256-3_10 , doi:10.1007/3-540-48256-3_10 . Jesper Carlström. A constructive version of birkhoff’s theorem.
Mathematical Lo-gic Quarterly , 54(1):27–34, 2008. URL: https://onlinelibrary.wiley.com/doi/abs/10.1002/malq.200710023 , arXiv:https://onlinelibrary.wiley.com/doi/pdf/10.1002/malq.200710023 , doi:https://doi.org/10.1002/malq.200710023 . Martín Hötzel Escardó. Introduction to univalent foundations of mathematics with Agda.
CoRR ,abs/1911.00580, 2019. URL: http://arxiv.org/abs/1911.00580 , arXiv:1911.00580 . Emmanuel Gunther, Alejandro Gadea, and Miguel Pagano. Formalization of universal algebrain Agda.
Electronic Notes in Theoretical Computer Science , 338:147 – 166, 2018. The 12thWorkshop on Logical and Semantic Frameworks, with Applications (LSFA 2017). URL: , doi:https://doi.org/10.1016/j.entcs.2018.10.010 . Ralph N. McKenzie, George F. McNulty, and Walter F. Taylor.
Algebras, lattices, varieties. Vol.I . The Wadsworth & Brooks/Cole Mathematics Series. Wadsworth & Brooks/Cole AdvancedBooks & Software, Monterey, CA, 1987. Ulf Norell. Dependently typed programming in Agda. In
Proceedings of the 6th InternationalConference on Advanced Functional Programming , AFP’08, pages 230–266, Berlin, Heidelberg,2009. Springer-Verlag. URL: http://dl.acm.org/citation.cfm?id=1813347.1813352 . E. Riehl.
Category Theory in Context . Aurora: Dover Modern Math Originals. Dover Publications,2017. URL: . Bas Spitters and Eelis van der Weegen. Type classes for mathematics in type theory.
CoRR ,abs/1102.1323, 2011. URL: http://arxiv.org/abs/1102.1323 , arXiv:1102.1323 . The Agda Team. Agda Language Reference section on Axiom K, 2021. URL: https://agda.readthedocs.io/en/v2.6.1/language/without-k.html . The Agda Team. Agda Language Reference section on Safe Agda, 2021. URL: https://agda.readthedocs.io/en/v2.6.1/language/safe-agda.html . The Agda Team. Agda Tools Documentation section on Pattern matching and equality,2021. URL: https://agda.readthedocs.io/en/v2.6.1/tools/command-line-options.htmlhttps://agda.readthedocs.io/en/v2.6.1/tools/command-line-options.html