Order Sorted Computer Algebra

and Co ercions

submitted by

Nicolas James Doye

for the degree of PhD

of the

University of Bath

COPYRIGHT

Attention is drawn to the fact that copyright of this thesis rests with its author This

copy of the thesis has b een supplied on the condition that anyone who consults it is

understo o d to recognise that its copyright rests with its author and that no quotation

from the thesis and no information derived from it may b e published without the prior

written consent of the author

This thesis maybemadeavailable for consultation within the University and

may b e photo copied or lent to other libraries for the purp oses of consultation

Signature of Author

Nicolas James Doye

Abstract

Computer algebra systems are large collections of routines for solving mathematical

problems algorithmically eciently and ab ove all symb olically The more advanced

and rigorous computer algebra systems for example Axiom use the concept of strong

typ es based on ordersorted algebra and to ensure that op erations are

only applied to expressions when they make sense

In cases where Axiom uses notions whichare not covered by current mathematics we

shall present new mathematics which will allow us to prove that all such cases are

reducible to cases covered by the current theory On the other hand we shall also

p oint out all the cases where Axiom deviates undesirably from the mathematical ideal

Furthermore we shall prop ose solutions to these deviations

Strongly typ ed systems esp ecially of mathematics b ecome unusable unless the system

can change the typ e in a way a user exp ects We wish any typ e change exp ected by

a user to be automated natural and unique Co ercions are normally viewed as

natural typ e changing maps this thesis shall rigorously dene the word co ercion

in the context of computer algebra systems

We shall list some assumptions so that wemayprove new results so that all co ercions

are unique this concept is called coherence

We shall give an algorithm for automatically creating all co ercions in typ e system

which adheres to a set of assumptions We shall prove that this is an algorithm and

that it always returns a co ercion when one exists Finallywe present a demonstration

implementation of this automated co ercion algorithm in Axiom

Contents

Intro duction

Intro duction

Computer algebra

Strong typ es categories varieties and theories

Abstract datatyp es in general

The problem

Examples of how Axiom co erces

Mathematical solution overview

Constructing co ercions algorithmically

Background of Axiom

OBJ

Aims of the thesis

Typ es in computer algebra

Intro duction

Mathematica

Reduce

Axiom

Economyofeort

Interest

Contents

Functoriality

Newsp eak

OBJ

Ob jects

Theories

Views

Comparison

Category theory

Intro duction

Category theory

Categories and Axiom

Functors and Axiom

Co ercion and category theory

Conclusion

Order sorted algebra

Intro duction

Algebras

Ordersorted algebras

Extension of signatures

The equational calculus

Signatures theories varieties and Axiom

Conclusion

Extending order sorted algebra

Intro duction

Contents

Partial Functions

Conditional varieties

A Category theory approach

Co ercion

Conclusion

Coherence

Intro duction

Web ers work I denitions

Web ers work I I assumptions and a conjecture

The coherence theorem

Extending the coherence theorem

Conclusion

The automated co ercion algorithm

Intro duction

Finitely generated algebras

Constructibility

The algorithm

Existence of the co ercion

Proving co erciveness

Conclusion

Implementation details

Intro duction

Bo ot and Axiom

The top level

Lab elling op erators

Getting information from domains

Contents

Checking information from domains

Flaws in the implementation

Conclusion

Making Axiom algebraically correct

Intro duction

Explicitly dened theories

Op erator symb ols and names

Moving certain op erators

Retyping certain sorts

Sorts and their order

Altering Axioms databases

Conclusion

Conclusions

Intro duction

Summary of work done

Formalising strongly typ ed algebra systems

Representation and syntax issues

On coherence

The automated co ercion algorithm

Future work and extensions

A Extra category theory

A Intro duction

A Extra denitions

B Set theory

B Intro duction

B Basics

Contents

B Inductive class approximation

B Inductive classes and category theory

B Inductive classes categories and Axiom

Bibliography

Structure of the Thesis

Structure of the Thesis

The thesis can b e viewed as decomp osable into the following topics

Background and existing theory

Chapter intro duces computer algebra systems in general strong typing and abstract

datatyping We intro duce some of the problems that can occur in a strongly typ ed

language which uses abstract datatyp es We present an analogy of the solution to one

of the problems in such a system

In chapter we discuss and compare the typ e systems in several mo dern computer

algebra systems We also mention OBJ a computer language which implements a typ e

system based on abstract datatyp es

Both category theory chapter and universal algebra chapter may be used as

the basis for systems of abstract datatyp es In these chapters we state all the current

theory whichwe shall require in the later chapters

W e shall also compare how many of these theoretical notions are represented in the

Axiom

New theory

Chapter details some extra mostly new mathematics which allows for certain ex

tensions to the theory of abstract datatyp es as currently implemented in Axiom to

b e formalised in the language of ordersorted algebra

We briey lo ok at the corresp ondence b etween the twoapproaches to abstract datatyp

ing This allows us to use either terminology when one may b e more appropriate than

the other

Finally we formalise the meaning of the word co ercion which is used widely in Axiom

without any strict denition

In chapter we lo ok at the work of Web er in the area of coherence We adjust and

extend his work so that w e may sensibly restrict the typ e system of Axiom and still

have unique co ercions

Chapter intro duces new denitions and assumptions on the typ e system whichallow

us to create co ercions automatically Weprovide a function to do so and provethatit

is an algorithm which creates a unique co ercion if and only if one exists

Structure of the Thesis

Demonstration implementation

In chapter we detail how the automated co ercion algorithm may b e implemented in

Axiom We mention where this prototyp e implementation disagrees with the theoretical

algorithm

Conclusions and future extensions

In chapter we list the dierences b etween Axioms currenttyp e system and the formal

theoretical typ e system wehavespecied

We draw conclusions from this work in chapter We also state future directions

research may take towards the aim of creating the p erfect computer algebra system

based on abstract datatyp es

Acknowledgements

Acknowledgements

None of this work would have b een p ossible without the original input and ideas of my

sup ervisor Professor James H Davenp ort

The implementation would have b een imp ossible without the help from the following

Lisp andor Axiominternals exp erts Professor James H Davenp ort again Mike

Dewar Russell Bradford Pete Broadb erry

Mathematical issues were discussed at length with Professor James H Davenp ort yet

again Tracy Gardner Russell Bradford Mark Beanz Hindess

My thanks go out to both Professor James H Davenp ort and Russell Bradford for

pro of reading various versions of this thesis

In addition to all the intellectual supp ort there are two p eople without whom none of

this would have been p ossible I refer of course to my wife Deb orah and my father

Mr Georey Doye

thank Professor John tch for giving me this chance in the rst place Id Id liketo

also b etter thank all the p ostgrads in the computing group in the last few years for

putting up with me

My thanks go to NAG for supplying the Axiom Bo ot source co de Also to the follow

ing computing services departments for the use of their systems University of Bath

Department of Mathematical Sciences computing services BUCS Universityof Bath

Computing Services NISS National Information Services and Systems

This research was funded by the EPSRC previously known as SERC Much needed

p ersonal nancial assistance came from my father and parttime employment from

b oth BUCS and the Department of Mathematical Sciences In the overrun I have

b een employed by both the Department of Mathematical Sciences and more recently

by NISS

Finally I ought to thank the authors of XEmacs for making editing everything just so

A

easy and the authors of L T X for the layout of this thesis Diagrams were pro duced

E

using Paul Taylors diagrams package

Dedication

For Deborah

Chapter

Intro duction

Intro duction

This chapter intro duces the reader to the main ideas b ehind this thesis Wegive some

background information explain the context of the work and say why the work is a

go o d idea

This work centres on typ es in computer algebra

Computer algebra

Computer algebra DST is an allencompassing term that covers p erforming anysort

of mathematics on a computer Numerical analysis mathematics involving oating

p ointnumb ers and a certain degree of error is often excluded from this term though

most mo dern computer algebra systems are at the very least comp etent in this area

Computer algebra systems may excel in various areas of mathematics Some are masters

of discrete mathematics groups rings monoids etc the more common systems deal

with more mainstream concerns such as indenite integration solving dierential

equations matrices etc

The imp ortant feature of all computer algebra systems is their abilitytosolve equations

like dierential equations symbolical ly In other words they maysolve equations for

the general case they need not substitute values for the variables

Mo dern computer algebra systems are large collections of routines and algorithms

These algebra systems often come with their own languages for user input The user

Chapter Intro duction Computer algebra

is usually supplied with an which can usually read both input from the

keyb oard and from les The more advanced computer algebra systems come with a

to o

Common computer algebra systems are Axiom JS Derive Der GAP GAP

Macsyma Mac Magma Pla Maple CGG Mathematica Wol and Re

duce Hea We discuss the relevant details of some of these systems in chapter

The user of a computer algebra system is usually someone who wishes to solve a math

ematical problem Mathematics is a formal sub ject and as such there is a need for

rigour Hence computer algebra systems need a rigorously dened language to avoid

confusion and incorrect results

this Many of the more popular commercial computer algebra systems do not provide

rigour Instead they trade rigour and strictness for easeofuse and hence massmarket

app eal This is not to say that they consistently supply incorrect results merely that

if the user has not given all the input that they can or are allowed to by constraints

of the system then the system may misinterpret their input

Being able to restrict the domain over which a variable may range or from where a

function may take its arguments can reduce the amount of confusion and ambiguityin

any mathematics a user mayenter

For example if a user enters a then a computer algebra system has to judge whether

this is the from the integers a constant p olynomial the identity of some group a

from the integers mo dulo some n the distance which is not zero in a discrete metric

space etc

Restricting variables to various sets of values is a useful concept and is called typing

For example if one says that x is an integer and then declares x to b e then there is

no confusion as to what x is We are free to add x to x safe in the knowledge that the

answer is the integer If we did not know that x were an integer then the answer

could havebeen in Z in a group where is the identity and the binary op erator

is or any other value in some contrived example

Such restrictions on variables are usually called typ es For example declaring x to b e

an integer is the same as saying that the typ e of x is an integer

Mathematics written in b o oks is usually stated formally with all the context and

meaning of certain symb ols stated in the text When mathematicians talk to one

another they may and in practice do drop some of this formality since they can infer

text from extramathematical factors such the meaning of certain symb ols and the con

Chapter Intro duction Strong typ es categories varieties and theories

as with whom they are holding a conversation previous conversations they mayhave

had etc They mayeven correct eachother

Computer algebra systems are not p eople and can fail to infer the typ e and meaning

of terms successfully They also can not understand paragraphs of English or other

natural languages to gain the context from there They are highly unlikely to correct

the user This is why their languages should b e strictly dened and yet fully expressive

Guessing the typ e intelligently is called typ e inference All the untyp ed systems

eectively guess the typ e internally whenever a function is applied to any data

Entering will result in simply this is b ecause this is the most common case

etyp e inference in Axiom is to allowthe user to say A more intelligent approach lik

which function they require Axiom will then infer the typ es of the two s from the

fact it knows whichtyp es that is exp ecting Alternatively the user may state which

stheyhave inputted and what typ e they exp ect in return Axiom will then use the

function uniquely determined by this information

Strong typ es categories varieties and theories

In this thesis we are mainly concerned with the typing mechanisms in mo dern computer

algebra systems However this work is also relevant to typ e systems in general Many

languages principally the socalled ob jectoriented languages use a typ e system which

may o ccasionally b e viewed in a mathematical fashion

Axiom and Magma are two of the b est computer algebra systems and what sets them

apart from their p eers is the concept of categories chapter or varieties sp ecied by

theories section Some other algebra systems do possess the concept of typ es

and Reduce Hea will allownewtyp es to b e intro duced section GAP GAP

also claims to have a concept of categories though they are not so deeply ingrained

in the typ e system as they are in Axiom section and Magma section GAP

will also allow new typ es to b e intro duced

Certain forms of inheritance found in ob jectoriented languages follow the paradigms

used in Axiom and Magma However most ob jectoriented languages C Str

Eiel Eif Java Gra youto o Kin etc are more exible and allow many

dierent ways for typ es to reuse bits of co de from each other However automated

co ercion in any sense is not a feature of these languages OBJ GWM is not a

computer algebra system however this work is wholly suited to it since it uses a similar

typ e paradigm to Axiom and Magma We discuss OBJ further in sections and

Chapter Intro duction Abstract datatyp es in general

The category or variety mechanism found in Axiom and Magma is a way of abstracting

a further level away from mere typ es The categories are used to typ e the typ es and

provide a standard interface andor implementation for eachtyp e in a category

Magma also abstracts one further level away by allowing the existence of varieties of

categories in a similar way

The concept of strong typing is that every thing must haveatyp e Axiom and Magma

are both strongly typ ed Most of the other systems are not strongly typ ed Indeed

some do not even have any notion of typ es at all

e The categories or varieties of Axiom Magma and OBJ are abstract datatyp es W

shall detail this more in the next section

Abstract datatyp es in general

Abstract datatyp es provide a way of sp ecifying a typ e As a useful side eect an

abstract datatyp e can express how a whole collection of typ es mayact

An incredibly sp ecic sp ecication will only sp ecify typ es which are all the same

isomorphic A less exacting sp ecication may result in typ es which are similar but

not the same

This side eect of using a less exacting sp ecication to collect similar typ es together

forms the basis of strict categorical typ e systems likethat in Axiom and many ob ject

oriented languages

For example we may say which op erations are available on a certain family of typ es

We may also state certain facts ab out the structure of all typ es in a certain family

Most imp ortantly of all we can enforce relationships b etween various typ es of dierent

families how they interact and howtheymay dep end up on each other or not

See section for howwemay sp ecify typ es and what op erations are available to them

Lo ok at section for the relationships between dierent typ es Section details

howwemay restrict the structure of certain typ es using sets of equations

As a simple example a p olynomial ring dep ends for its sp ecication on the underlying

ring from which the co ecients are taken

As amore complicated example a p olynomial ring could also dep end up on the typ e

from which it takes its variables the typ e of the exp onents a b o olean algebra an

often a ordered free monoid with one generator the natural numb ers adjoin fg is

Chapter Intro duction The problem

go o d choice and mayb e a few others

Another factor is the actual relationship between the various typ es In our ab ove

example of the p olynomial ring weknowthat

there is a ring monomorphism from the underlying ring to the p olynomial ring

there is an injection from the variable typ e to the p olynomial ring In fact an

orderedset monomorphism

Other typ es often have more complicated lattices of relationships These relationships

are often able to be abstracted out to apply all the instance typ es of a particular

abstract data typ e

The problem

A commonly encountered diculty in languages which utilise typ es is the following

Given thing of typ e Type can we change the typ e of thing to be that of

Type More accuratelycanwe create an elementof Type which corresp onds

in some natural waytothing of typ e Type

If so how do we go ab out p erforming such an op eration Can we p erform this

task algorithmically

Do es there exist a way of abstracting this question or must every TypeType

pair be considered Moreover can we abstract such an algorithm as mo oted

in ab ove out to cover all cases

Such typ e changes are often called coercions conversions or castings with all three

words having slightly dierent meanings

versions to mean any typ e change In this work we shall consider castings and con

regardless of mathematical rigour We shall call a typ e change a co ercion if it is in

some way natural We will dene this more rigorously later in denition

The typ e from which all the variables are taken In Axiom the variables are usually elements such

as X Y and Z which are from the typ e Symbol



This is an injective function which is b oth a set which is just a total function

and preserves order So if a b then a b Mathematicians often utilise the order on the

variables and extend it to an order on p olynomials

Chapter Intro duction The problem

Computer algebraists often need to use co ercions since informally most mathematicians

alter the domain of computation without saying phrases like in the monomorphic

image of A in B or forgetting that x is a T and viewing it as a U

For example we often view the integers Z as p olynomials in Zx rather than

considering the constant p olynomials of Zx as b eing a monomorphic copyofZ This

is the co ercion Z Zx

Other simple examples of this sort of co ercion are

Z Q Zx Zy x Z Qx y S S Zx Zx

where S n is the symmetric group on a set of n symb ols

Co ercions are useful when creating elements of quotient structures suchas Z Z

n

ZnZ where n N Other epimorphic surjective examples include

Z Z G GG

where G is any group and G is the commutator subgroup of G

Under certain circumstances co ercions can be lifted into other constructors We

refer to these as structural co ercions later in this work As examples consider

ListZ ListQ ListZ ListZ Z x Z x

Z M Zx M

Examples of typ econversions which are not co ercions include

Q Float ListN S n Z Z Z Z Zx Zy

Natural typ e changes co ercions can b e created in the Axiom interpreter at the moment

using a series of ad hoc measures All of this o ccurs transparently to the user and works

for most common typ es However it is not algorithmic One of the aims of this thesis

is to provide an algorithm algorithm to create unique theorems

co ercions

Chapter Intro duction Examples of how Axiom co erces

Examples of how Axiom co erces

Axiom knows or b elieves that all functions called coerce are co ercions and will use

them to build other co ercions using certain rules and sp ecial cases dened in the

interpreter Here we give examples of how Axiom co erces between certain common

typ es

Simple examples

Example Z Q

In Axiom Z is the typ e Integer and Q is the typ e FractionInteger The typ e

constructor FractionR Ring exp orts a function

coerce R

which is the natural monomorphism including the ring R in its fractional eld

FractionR

Example Z ZX

In Axiom the typ e UnivariatePolynomialXInteger typically represents ZX

This is constructed bythetyp e constructor

UnivariatePolynomial S Symbol R Ring PolynomialCategoryR

NonNegativeInteger Symbol

UnivariatePolynomial exp orts a function

coerce R

which is the natural monomorphism including the ring R in the p olynomial ring as the

constant p olynomials

Example ZX ZX Y where ZX Y ZX Y

This is the same as the previous example Y is acting as a morphism ZX ZX Y



Actually dened in a Category to which Fraction b elongs

Chapter Intro duction Examples of how Axiom co erces

Example ZX ZY X whereZY X ZY X

Axiom knows that Z ZY is a co ercion and that the map X ZY ZY X

ie UnivariatePolynomial lifts this co ercion

Example Z QX Y

This is built by the chain of co ercions

Z Q QX QX Y

Example S S

These do not exist as domains in Axiom

Example ZX ZX

the co ercion from Fraction discussed ab ove since ZX is represented in This uses

Axiom by FractionUnivariatePolynomialXInteger

Example Z Z

This uses the function

coerce Z

dened in IntegerModn PositiveInteger

Example Z Z

Axiom cannot co erce from IntgerMod to IntegerMod

Structural co ercions

The structural co ercions are lifts of other co ercions In the case of Lists one may

p erform a structural co ercion as follows

coerce x ListA ListB

map coerce x ListB

map f ListA ListB x ListA ListB

nullpx nilListB

cons fcarx map f cdrx

Chapter Intro duction Mathematical solution overview

In the case of Polynomials a similar map function exists which uses instead of cons

In the case of Matrix a similar map function can be used though since matrices are

of xed sizes unlike sets lists and p olynomials a default valued matrix has to b e

created then all the values substituted into added to it

Mathematical solution overview

The solution to the questions raised in of section rely on abstract datatyp es

These collect large numbers of typ es into collections of similar typ es We shall be

considering abstract datatyp es in the language of universal algebra sp ecically order

sorted algebra section

Universal algebra has close links with the ideas of category theory See chapter for

category theory and section for the links b etween the two theories Indeed Axiom

algebraic design Thus we shall uses the language of category theory to describ e its

also discuss the fundamentals of category theory in relation to this work

Using the ordersorted algebra framework we shall show that there is indeed a strict

mathematical denition denition which we may use to tell us which typ e

changes are natural and therefore in our denition co ercions

Moreover we shall show that this approach allows us to create such co ercions algo

rithmically algorithm

In section we shall show an analogy with moving buildings to the solution of chang

ing the typ e of ie co ercing something

Constructing co ercions algorithmically

Consider the following analogy

Supp ose you have been given the job of moving London Bridge from one lo cation to

another The bridge is to o large to move in one piece

You will merely be sup ervising the work and will not have to carry any of the bricks

yourself hence eciency is not your concern

You are also planning to move other dierent bridges in the future and once you have

a metho d for moving one bridge you would like to b e able to apply that metho d to the

next This means that next time a bridge needs moving you wont have to do much

Chapter Intro duction Constructing co ercions algorithmically

work at all

Luckily for you someone has already worked out a way of moving any of the bricks

at the very b ottom of the bridge to their new lo cation regardless of any obstruction

whichwould normally leave civil engineers crying This p erson was clearly a magician

So here is your algorithm for moving London bridge and hence any future bridge

If the original bridge has no bricks left then finished

Else

take a brick from the top of the original bridge

If this brick is a bottom brick then

use the magical bottom brick mover to place

the brick in the corresponding location of

the new bridge

Else

the brick in place in the corresponding hold

location in the new bridge

Endif

Endif

Repeat

Indeed you realize that this metho d will work for other brickbased constructions or

indeed anything that is built Obviously there are other considerations is the new

lo cation for the bridge a natural one For example Is it long or tall enough

The analogue of the bridge is a thing or item in our computer algebra system The

original lo cation of the bridge is the original typ e of the item and the new lo cation

for the bridge is the analogue of the typ e to whichwe are co ercing the item

Thus what weneedtoknoware

what are the foundations of a bridge

Analogue what are the constants of our typ e

what is the length width strength of a bridge

Analogue what are the parameters of the typ e

howdoyou alter the bricks to b e of a new shap ematerial

Analogue we need to be able to recursively call the co ercion algorithm on

typ es whichare recursively required for co ercion cf Denition That

is typ es whic h form the bits of the item once wehavechopp ed it up

Chapter Intro duction Background of Axiom

This is our analogy to algorithm and we may consider many data typ es to

be constructed or built similarly For example lists in the Lispsense are always

constructed either by b eing the empty list or by b eing the cons of something on

to the front of another list

As a more complicated example p olynomials are constructed via one of the following

mechanisms

by being a member of the included monomorphic copy of the underlying ring

a constant p olynomial

by b eing a symbol exp onentiated to some p ositive power a univariate monic

monomial

y b eing the pro duct of a monic monomial and a univariate monic monomial a b

monic monomial

by b eing the pro duct of a monic monomial and a memb er of the underlying ring

a monomial

by adding a monomial to a p olynomial

So we see that at least two of the most basic typ es in computer algebra are constructed

in this way

Background of Axiom

Computer algebra is a sub ject which dates back to and has b een describ ed as

constructive algebra plus ecient algorithms Bra Towards the late s large

collections of routines or programs were starting to b ecome what one might think of

as the rst computer algebra systems

Scratchpad I GJ was b orn in ab out the principal architect b eing RD Jenks

JS Scratchpad I to ok the best ideas from Reduce Hea and Mathlab and

with new ideas and a new language b ecame IBMs research computer algebra system

In Jenks initiated the Scratchpad II pro ject Over the next couple of years

he along with JH Davenp ort and Barton designed and implemented prototyp es of

a suciently clever algebra system one which used the concept of categories

An idea which apart from research pro jects suchas Newsp eak Fod up until the

Chapter Intro duction OBJ

release of Magma Pla November made Scratchpad II unique amongst

computer algebra systems

The category inheritance mechanism is based on an original abstract datatyp e design

by Jenks and BM Trager The algebraic category hierarchy has subsequently b een

redesigned byDavenp ort with Trager

The implementation of Scratchpad I I commenced in and in supp ort for the

system transfered to NAG and the name of the system changed to Axiom

OBJ

The sub ject of data abstraction has not been monop olised by the computer algebra

community Indeed much of the ma jor work has been done by those who are almost

completely disjoint from the computer algebra eld

Akey player in the area has b een Joseph A Goguen In Goguen designed OBJ as

a language for dealing with algebraic abstract data typ es errors and partial functions

in a simple and more imp ortantly uniform way See GWM for more details

The current version of OBJ is OBJ Release and is implemented in

OBJ is based on ordersorted equational whichprovides a notion of subsort

OBJ also provides parameterised programming Both of these notions are found

in Axiom and Magma but OBJs idea of subsort is far more rigorous that that of

Axiom We shall discuss OBJ in more detail in section

Aims of the thesis

We shall lay down a strict mathematical foundation for a typ e system in a computer

algebra system like Axiom We state the mathematics which inspired Axioms typ e

system chapter

Axioms typ e system uses ideas which are not explained using this basic mathematics

we explain some current mathematics which mo dels how we shall be In section

viewing Axioms partial functions In we state some new mathematics to deal

with Axioms conditional categories In section we formalise what is meant by a

co ercion In chapter we state the dierences b etween Axiom and the mathematical

theory

However the greater part of this work is dedicated to stating sections and and

Chapter Intro duction Aims of the thesis

creating sections and chapter enough mathematics to state an algorithm

for automatically creating mathematically correct co ercions

In Axiom co ercions are dened by

b eing a rare sp ecial case handco ded in the interpreter

b eing an explicitly written coerce function from a Category Domain or o cca

sionally a Packageor

b eing created via sp ecial interpreter tricks whichcombine the ab oveinanad hoc

manner

These sp ecial interpreter tricks cover most cases but not all Users can not guarantee

that co ercions entered in the interpreter will exist

It is also imp ortant to note that these sp ecial interpreter tricks are not available in the

Axiom for Spad and

We shall present an algorithm which builds co ercions for a very large sub class of typ es

which should exist from a p otentially but not necessarily minimal set This algorithm

is implementable chapter in the Axiom interpreter Sub ject to a set of conditions

b eing met bythetyp e system these co ercions are unique

We draw some conclusions ab out this work in chapter



The interpreter is the interactiveinterface to the Axiom system



Sp ecial handwritten pieces of co de which execute b ehind the scenes in the interpreter

Chapter

Typ es in computer algebra

Intro duction

In this chapter we shall go into more detail ab out typ es in various computer algebra

systems We shall discuss how the dierent systems view the concept of typing in

formation from the simplest nontyp ed languages in the socalled MMsystems

through Reduces typ e system to the fullblown mathematical b eauty of systems such

as Magma and Axiom

Mathematica

Mathematica is one of the most popular computer algebra systems on the market

to day Priced very reasonably and with an attractive user interface it is easy to see

why ordinary PC owners are attracted to this pro duct

In chapter of Mathematica a System for Doing Mathematics by Computer Wol

Wolfram states

At a fundamental level there are no data typ es in Mathematica Every

ob ject you use is an expression

Typ es may be created in Mathematica but they are merely tags on which one can

p erform switches For example the tag List This is an obvious approach since

Mathematica uses rulebased programming

In JT Mathematica and Maple are referred to as MM



The ability to extend the typ e system of Reduce was inspired by Axiom then called Scratchpad

Chapter Typ es in computer algebra Maple

Abstract data typ es for Mathematica are discussed in Mae and inheritance for such

a system in Har However this approach is only marginally more sophisticated than

that used in Reduce describ ed in BHPS There is some form of abstraction in

this Mathematica abstract data typ e mo del but function metho d selection is just as

primitive as in the Reduce mo del

Maple

Maple CGG is a small fast p opular computer algebra system and is well re

sp ected both by users and exp erts in the area of symb olic computation Maple ver

sion V release do es have some concept of typ e but as you can see this is not

particularly well founded

xarray abcd

x array

a

b

c

d

mlinalgmatrixxyzabc

x y z

m

a b c

evalm

array

a

b

c

d



Maple V release is nowavailable

Chapter Typ es in computer algebra Maple

typemmatrix

true

Notice that m is now a matrix in Maples view whose th element is an

array of symbols Three of these symb ols are also in the second rowof m The array

typ e do es not form a ring and moreover the elements of m are from dierenttyp es

It is ridiculous that one may create matrices over anytyp e whichdoesnotformaring

One learns at scho ol that given two matrices A and B with the same number of rows

p and the same numb er of columns q onemay calculate

the p q additive identity matrix

if p q I thep p multiplicative identity matrix

p

the negation of a matrix A

their sum A B

T T

the pro duct AB where B represents the transp ose of T

However should one create matrices over typ es which do not form rings then one of

the ab ovemaynotbewell dened A in case and A B in cases and This is

the situation in Maple it lets one create ob jects of the typ e matrix which are not

matrices in the mathematical sense

Maple will now also let one assume certain prop erties ab out or typ es for elements

but these are entirely at the users discretion This mechanism is based on the alge

bra of prop erties as describ ed in WG WG One can think of this assumption

mechanism as an advanced way of declaring the typ e of a variable

The algebra of prop erties is a fascinating and extremely clever way of assuming certain

facts ab out a given symbol and works very well in the context of saying We assume

that is real and greater than zero and then deducing various facts ab out f



Admittedly Axiom do es not always get these things p erfectly correct Martin Mar p oints out

that Axiom allows MatrixFloat as a typ e yet the Float typ e do es not really form a ring

Chapter Typ es in computer algebra Reduce

However the algebra of prop erties do es not work particularly well for typing sym

b olsdata Typ e inference for example is problematic given real and greater

p

than zero what are the typ es of and log

Inserting new elements in the prop erty lattice is inherently dicult and in a dynamic

system means that binding op erations to implementations is imp ossible at compilation

time

It could be argued that this metho d could run along side of Axioms more advanced

notion of typ es Part of the problem with the Maple system is a confusion between

dierent classes of unknowns There is no distinction between the imp ortance of

b eing a real numb er and that of b eing greater than zero Surely b eing a real should

b e far more imp ortant than some statement regarding a symb ols p ossible values

Much work has been done on this sub ject with sp ecial emphasis on Axiom and the

denitivework is DF which denes the dierent classes of unknowns and provides

details of an implementation for Axiom

Reduce

Reduce current release is Str Neu is a wellestablished Lisp based

computer algebra system and although the user interface is archaic until recentlyits

algebra system was still one of the very b est around

Reduce has a welldened concept of typ e and indeed new datatyp es may b e added

and included at will BHPS

Reduce prototyp es have also been develop ed HS which take an ordersorted ap

proach to algebra This implementation seems to take some of the Axiom ideas and

some of the algebra of prop erties ideas It app ears to be far cleaner and clearer than

the mo del used in Maple

However in this prototyp e it is still stated in HS that

Mathematical structures can have several isomorphic representations A

go o d example is the representation of p olynomials in a distributed or re

cursive form For the simultaneous use of multiple representations



Being greater than zero is not just a prop osition restricted to real numb ers or subsets thereof

Polynomial typ es are often ordered and zero is a constant p olynomial



The commercial success of some of the other systems has forced them and gained them the capital

to correct many of the bizarre bugs that used to ab ound in earlier releases Thus the commercial systems

nowwork as well as Reduce have a friendly GUI and maywell have consigned Reduce to history

Chapter Typ es in computer algebra Axiom

explicitly dened co ercions are necessary My emphasis

This is not currently the case in Axiom where co ercions can b e built in the interpreter

by clever tricks in the underlying co de Furthermore it is the aim of this thesis to

demonstrate that using an ordersorted approach to algebra one can build manyof

these co ercion functions without explicitly dening the co ercions themselves

Axiom

Axiom JS nee Scratchpad II is a Lispbased general computer algebra system

Axioms main view of things is that everyobjecthasatyp e and that there are osten

sibly four layers

items Domains Categories Category

For example

Integer Ring Category

and the top layer is the unique distinguished symbol Category In general this top

layer is never referred to and the three lower layers are all that are ever considered

Strictly sp eaking if one considers Axioms Categories to b e categories and Axioms

Category symb ol to signify the category of all the Categories then one should write

Integer Integer Ob jRing Ring Ob jCategory

where Integer means is an element of the carrier of the principal sort of the

to which Integer b elongs

Users may extend the Axiom system by writing new Domains and Categories in the

Axiom extension language called Aldor WBD a They may also be written in

an older Axiom language called Spad This is the language describ ed in JS

Aldor can b e complied into many languages for use inside Axiom to Lisp currently

AKCL AKC or CCL to C WBD b This makes Axiom far more than



Category is not one of the Categories in Axiom



This language was sometimes referred to as A in internal do cuments and has often b een referred

to as AxiomXL

Chapter Typ es in computer algebra Axiom

just an algebra system Aldor is also a rst class language for writing fast ecient

standalone applications

A category is a collection of domains all of which are similar In DT the authors

state that they designed the Scratchpad system of categories or abstract algebras

qv chapter for the following reasons

economy of eort section

interest section

functoriality section

Economy of eort

The most obvious reason for this is the view of inheritance A category in Axiom is

said to extend another if it inherits all the others functions attributes and equations

This allows for a signicantamount of reuse

A more imp ortant issue in an algebra system is that if one can prove a theorem in some

generality ie for all the ob jects in a category then one do es not have to go around

proving the theorem for each ob ject of the category

Interest

Some categories are interesting and some are not For example Ring and Field are

particularly interesting Many theorems can b e proved for al l Fields

However to borrow an example from DT the category of all rings which when

viewed as Ab elian groups have an involution with precisely one xed point is not

particularly interesting

One may think of the designers concept of interest as congruent to useful usually

to the user but o ccasionally to the designers

Functoriality

This is called higher order Polymorphism in Cro There are op erators which

t given ob jects of a category can create new ob jects of a given p otentially dieren

Axioms Categories can also be thought of as ordersorted algebras but the order on sorts is

never explicitly dened and there are some diculties in the denition of the op erator symbols This

is discussed in more detail in section

Chapter Typ es in computer algebra Newsp eak

category For example List is a functor from SetCategory to ListAggregate

List SetCategory ListAggregate

S ListS

Indeed this target category mayeven b e the distinguished symbol Category

In Axiom the Category constructors often called functors are functors from

Y

Category Category

nN

For example the Ring functor takes no arguments and returns the Category of Rings

Ring Category

Ring

The sp ecial Category creation op eration Join is also a functor Join is used to declare

a new Category to be a sub category of the intersection of two or more Categories

Here we illustrate the case of Join acting on two Categories

Join Category Category Category

A B A B

More commonly in Axiom and Axioms own use of the word functor covers cases

as follows This is similar to the case of Ring only less trivial ListAggregate is the

Category of all typ es of nite lists

ListAggregate SetCategory Category

S ListAggregateS

Here we see the sub category ListAggregateS of the Category ListAggregate

When using Axiom one usually thinks of ones typ e as b elonging to the smaller con

crete subCategory ListAggregateS Mathematically one usually thinks of ones

typ e as b eing in the larger more abstract ListAggregate

Newsp eak

As an aside from the main computer algebra systems listed in this chapter a research

system called Newsp eak Fod or more correctly Newspeak will now be dis

cussed

Chapter Typ es in computer algebra Newsp eak

Newsp eak was a language written at the University of California at Berkeley in the

early s

It diered from Axiom then in the early stages of b eing Scratchpad I I otherwise called

Newspad by discarding the category mechanism and making a list of improvements

most of which are now in Axiom

The dierences are listed in Fod and are summarised below We shall also p oint

out whether the dierences still hold or not

It should be pointed out that Barton of the Scratchpad II design team also had

an implementation of Scratchpad II called Andante Andante grew in parallel with

Scratchpad I I but this chapter will refer mainly to Scratchpad I I

of Newsp eak over Axiom which have not yet b een incorp orated Sp ecic advantages

into Axiom are

Axioms implementation language is not itself Newsp eak however was written

in Newsp eak This allowed the authors of Newsp eak to write dedicated garbage

collection and fast function selection routines

Function lifting If one writes a Category in Axiom which has parameters from

avery generic Category suchasRing then for certain functions to b e available

in the typ e one has to write co de such as the following from the denition of

FiniteAbelianMonoidRingRRing EOrderedAbelianMonoid

if R has IntegralDomain then

exquo R Unionfailed

exquopr returns the exact quotient of

polynomial p by r or failed

if there is none exists

if R has GcdDomain then

content R

contentp gives the gcd of the

coefficients of polynomial p

primitivePart

primitivePartp returns the unit

normalized form of polynomial p

divided by the content of p

Newsp eaks parameterised representationless typ es equivalent to Axioms

Chapter Typ es in computer algebra Magma

Categories get around this problem by extending or in their doublethink word

ing restricting the Polynomial constructor Poly to PolyId Polyno

mials over Integral domains etc

To this author this do es not app ear to solve the problem of having to know the

category hierarchy of ones parameters It merely abstracts it and moves the

problem to a less satisfactory place

Problems Scratchpad I IAxiom then had whichhave since b een xed

A domain could only b elong to one Category This was not true even then for

Andante

Functions declared in Categories wereonlyabletohave their sources and targets

from a sp ecic domain an arbitrary typ e of this Category the value of a

parameter of this Category

Although Newsp eak allowed functions between categories which it called pa

rameterised representationless typ es which cannot b e written in Axioms Spad

or Aldor languages one could do this in Axioms Bo ot language but this is not

a desirable option

Axioms items did not know their own typeorthattyp es p osition in the hierarchy

In conclusion Newsp eak was a brave attempt at Scratchpad I IAxiom with

out explicit categories and solved many of the problems that the language then had

Fortunately mayb e thanks to Newsp eak these problems have since been redressed

and Axiom is all the more exible and easier to use for it

Magma

Magma the system to replace Cayley isanewandpowerful computer algebra system

As with Cayley the main purp ose of Magma is to deal with discrete algebraic ob jects

While Cayley was useful as a to ol for investigating groups Magma can deal with many

diering discrete algebraic ob jects

Magma users are p eople more interested in branches of mathematics such as Semigroup

theory Group theory Galois theory or other areas of mo dern algebra Magma do es

It should b e noted that Axiom has some comp etence in all these areas but for discrete mathematics

it can not match the pure sp eed of Magma

Chapter Typ es in computer algebra Magma

have some ability to deal with the mainstream areas of computer algebra p olynomials

etc but this is not Magmas raison detre

The design philosophy of Magma BCM takes its cues from Axiom but go es further

supp orting algebraic structures as rst class ob jects This makes Magma far more

powerful than Axiom when dealing with algebraic structures Indeed manipulating

algebraic structures is as easy as dealing with their elements in Magma In Axiom this

is simply not the case

A fundamental design dierence b etween Axiom and Magma is the following Axioms

designers to ok their cue from ordersorted algebra Thus their denitions of typ es and

their metho d of collecting them Categories fo cus on the op erations whicharevalid

on those typ es

The Magma metho dology is more representation centred A category in Magma consists

of all ob jects with a similar representation the category of all p ermutation groups

for example However all the categories of dierent representations of an algebraic

idea are collected together in a varietythevariety of groups for example

This is a subtle dierence b etween Axiom and Magma since Axiom views varieties as

categories At some future date should Axiom ever supp ort algebraic structures as

rst class ob jects then the noticeable dierence would b e minimal

Magma also supp orts the idea of ordersorted algebra more concretely than Axiom

do es From the Magma WWW page Pla

The primary concept in the design of the Magma system is magma Fol

lowing Bourbaki a magma can b e dened as a set with a law of comp osition

Thus typ es corresp ond to magmas a collection of magmas sharing a

common representation forms a category eg the category of p ermuta

tion groups a collection of categories satisfying the same set of identical

relations forms a variety eg the variety of groups Functors may be

used to movebetween categories and the variety op erations substructure

ailable as uniform con homomorphic image and Cartesian pro duct are av

structors across all categories

While every value in Magma b elongs to a unique parent magma the system

provides a mechanism for automatic and forced co ercion to move a value

from one magma to another To take a simple example when an integer

is added to a rational Magma automatically co erces the integer into the

rational eld so that the addition op eration can be carried out on two

Chapter Typ es in computer algebra OBJ

values with the same parent

This automatic co ercion also implemented in Axiom is from the order on the sorts

RRing FractionR in the theory of fractional quotient elds as we shall

dene in section roughly means that there is some sort of natural way of mapping

every elementofR to one in FractionR

OBJ

In this section we shall discuss how OBJ implements the ideas of order sorted algebra

in a more concrete way than Axiom or Magma Much of the information in this section

can b e found in GWM

It should b e noted that OBJ is not marketed as a computer algebra system but as a

comprehensive language with a strong mathematical foundation

OBJ provides a strongly typ ed language based more closely on order sorted algebra

than any other

At OBJs top level there exist three typ es of entity

ob jects These are describ ed in the literature as an encapsulation of executable

co de or an algebra Though it should be noted that an OBJ algebra need not

be a mo del of any theory Note OBJ do cumentation sometimes refers to the

ob jects as Mo dules

theories In the literature theories are describ ed as varieties but in our language

OBJs theories are indeed theories

views Views showhow ob jects algebras satisfy or mo del certain theories

In the next few sections we shall investigate these entities in more detail so that we

may compare them with Axioms top level forms

Ob jects

An OBJob ject is an executable algebraic sp ecication for an abstract data typ e That

is to say an OBJob ject denes a sorted signature or indeed a theory since equations

are allowed and provides the initial ob ject of that theory

The initial ob ject of a theory is the term algebra factored out by the equations This is equivalent

to the category theory notion of initiality

Chapter Typ es in computer algebra Comparison

The parameters of an OBJob ject can b e typ ed and forced to b e mo dels of particular

theories Indeed OBJob jects can b e viewed as algebras mo delling particular theories

themselves as we shall see in section

Theories

OBJtheories are indeed order sorted signatures with sets of equations Semantically

OBJob jects and OBJtheories are very similar However one imp ortant dierence

is that the equations presented in a theory do not have to have to satisfy the same

restrictions as those in an OBJob ject

OBJob jects must have equations whichcanbeconverted into rewrite rules however

this restriction do es not apply to OBJtheory equations This is b ecause the OBJ

ob jects are executable whereas OBJtheories are not Remember that OBJ is

based up on a rewriting system

Views

Views are the most exciting feature of OBJ A view in OBJ is a metho d for stating

that a particular OBJob ject mo dels a particular OBJtheory

What makes OBJ unique is not the fact that the carriers mayhave dierent names to

the sorts but that the op erator names may b e dierent to the op erator symb ols

Comparison

So howdo our denitions of higher order entities OBJs and the other systems com

pare



The current implementation of OBJ is called OBJ

Chapter Typ es in computer algebra Comparison

Universal Category OBJ Magma Axiom

Algebra Theory abstract concrete

Variety Variety

Theory Category Theory Theory

dened

in an

ob ject

Signature Category Category

Algebra Ob ject View Ob ject Magma Domain

In the Universal Algebra column wehave written variety in a dierentrow to theory

This is not quite correct yet the two are dierent A theory is a sp ecication of a typ e

and a variety is the collection of all typ es with satisfy or mo del that sp ecication

There is a dierence b etween theories and signatures since signatures contain no infor

mation ab out equations However the dierence is small a theory with no equations

is a signature

We have slotted categories in as the equivalent of universal algebras theories Yet

since everything may b e thoughtofasacategory this decision is merely arbitrary The

sp ecication of a category could be the same as a theory indeed this is the case in

Axiom but the collection of all ob jects of that category would form a variety

In the OBJ abstract column we refer to genuine OBJ theories declared to b e theories

as opp osed to those mentioned in the OBJ concrete column OBJs theories are

most certainly theories and the collection of views of a particular theory forms a

variety A view of an OBJtheory is most certainly a mo del satisfying that theory

and hence an algebra of the signature of the theory by denition

In the OBJ concrete column the theories are those which exist by inference from an

ob ject denition OBJob jects dene a singleton variety dened by the inferred theory

which the ob ject mo delsThis inferred theory is not an OBJtheory However it is still

a mathematical theory

Magma has a view of varieties and categories matching in with the mathematical variety

and signature denition It should be noted that Magmas categories neither have

an explicit notion of sortedness nor one for equations Though certain assertions

assumptions and statements maybemade

Chapter Typ es in computer algebra Comparison

Axioms categories written Categories elsewhere in this thesis are discussed at length

in other chapters of this work

Chapter

Category theory

Intro duction

As we have already hinted at category theory is one of the main foundations of b oth

Magma and Axiom In this chapter we shall give the necessary denitions to investigate

this claim We shall also investigate the claim in itself

The denitive text on Category Theory is Mac Lane ML The amount of theory

we require is relatively small We dene categories without worrying ab out Russells

Paradox Men In app endix B wehave a brief lo ok at the complications which arise

when one do es

Category theory

Denition A category C consists of two col lections The rst col lection is

cal ledtheob jects of the category or Ob jC The second col lection is cal led the arrows

of the category or ArrC

Also for each arrow f there exists two special objects with which it is associated The

rst is the source of f cal led sourcef The second is cal led the target of f cal led

target f

There also exists a law of comp ositionfor arrows

g f arrowssource g target f

source f target g f target g g f arrow source g f

Chapter Category theory Category theory

Next for each object c there exists a unique arrow cal led the identity arrowonc or

id

c

Final ly the fol lowing two axioms must hold

k g f arrowsg f k g arrows

k g f k g f arrows k g f k g f

f arrowsid f f f id f

target f sourcef

Here endeth the denition

Tointro duce the concept here are some simple nite categories

Example is the empty category it has no ob jects and no arrows

Example is the category with one ob ject and one arrow

Example is the category with two ob jects a b and one nonidentity arrow

f a b

Example is the category with two ob jects a b and two nonidentity arrows

f g a b

Now let is consider some more useful categories The collection of ob jects in the

following examples do not always form a set ML Ber Dev BHFL

Example Set is the category which has as ob jects all sets and has as arrows

all total functions b etween sets

Example Grp is the category which has as ob jects all groups and has as

arrows all group b etween them

Example Ring is the category which has as ob jects all rings and has as arrows

all ring homomorphisms b etween them

Example Poly is the following category An ob ject of Poly is a set of all

p olynomials with variables from a xed ordered set V co ecients from a xed ring

R and the exp onents of the variables from an ordered free monoid with one generator

E

Chapter Category theory Category theory

An arrow of Poly is a Polynomialhomomorphism That is a Ringhomomorphism

which also acts homomorphically on a certain set of functions which act on p olynomials

Some texts call the arrows of a category the morphisms of a category Examples

show us that for some naturally o ccurring categories the arrows or morphisms

are just the homomorphisms of the category Indeed an arrowofSet a total function

is really just a homomorphism b etween sets

So we see that the arrows preserve a certain set of prop erties for each element of the

ob ject

We also see that every ob ject of Grp is an ob ject of Set every ob ject of Ring is an

ob ject of Grp and every ob ject of Poly is an ob ject of Ring

Now similarly replace the word ob ject with the word arrow in the previous para

graph and it still holds true

algebra system there is a certain amount of inheritance Hence we see that in an

amongst the categories The categories are the socalled abstract datatypes since they

typ e the usual datatyp es

We can also see how the categories can collect together all similar typ es This function

ality can be used for the three design goals of Axiom economy of eort the co de

for many similar typ es need only be written once interest collecting similar typ es

together gives the user an identical interface to similar typ es and functoriality which

is b est left to b e discussed after the following denition

Denition Let B C be categories then a functor T C B consists of two

functions

C Ob jB the ob ject function T Obj

T ArrC ArrB the arrow function

These must obey the fol lowing

Which has an entirely dierent yet identical meaning in Java Gra Java do es not allowmultiple

inheritance from classes due to the usual problems Towork around this Javaprovides interfaces

An interface is just like a class although declared using dierent syntax except that it can not

provide a metho d for any op eration It may declare many signatures of op erations available to any

class which implements the interface

This is similar to abstract typ es classes with all functions pure virtual and no data memb ers in

C Str

Chapter Category theory Category theory

f arrowT source f source T f

f arrowT target f target T f

c ob ject T id id

c

T c

g f arrowssource g target f T g f T g T f

This is a very useful denition It shows us that when we have two ob jects and an

arrowbetween them in one category then a sensible map of these ob jects to another

category will induce the obvious map b etween these image ob jects

fact one can see that if one were to dene a category which had as ob jects all In

categories and as arrows all functors then wewould set theoretical concerns aside

haveawelldened category

Categories just like many other mathematical constructs may form pro ducts

Denition For two categories B and C we may construct a new category de

noted B C cal led the pro duct of B and C

Anobject of B C is a pair hb ci where b is an object of B and c an object of C

An arr ow of B C is a pair hf gi where f b b is an arrow of B g c c is an

arrow of C the source of hf gi is hb ci and the target of hf gi is hb c i

Composition of arrows hf g i hb c ihb c i and hf gi hb cihb c i is dened

via

hf g ihf gi hf f g g i

Axiom makes use of such pro ducts implicitly in its functor denitions For example

see the discussion of PolynomialCategory b elow

Natural transformations are another imp ortant part of category theory They are to

functors as functors are to categories Here is a more formal denition

Denition For two functors S T C B a natural transformation S T

is a function which assigns to every c Ob jC an arrow c Sc Tc of B such

c

that

c Ob jC f c c ArrC Tf c c Sf

Nowwemay dene the following interesting category

C

Denition For two categories B C the functor category B is the category

Chapter Category theory Category theory

with objects the functors T C B and arrows the natural transformations between

two such functors

As another fairly abstract denition consider the following

Denition Let S D C be a functor and c Ob jC An universal arrow

c S is a pair hruiOb jD ArrC where u c Sr such that

hd f iOb jD ArrC wheref c Sd f r d ArrD Sf u f

Functoriality in a computer algebra system allows us to view ob jects of one category

as ob ject of another

As wehave already seen an ob ject of Poly is an ob ject of Ring and hence an ob ject

of Grp and thus an ob ject of Set Wehave also seen this is true for their arrows This

relationship is called the sub category relationship dened formally as follows

Denition A category C is a sub category of a category B i every object of

C is an object of B and every arrow of C is an arrow of B

Functors from sub categories to the categories of which they are sub categories are often

called forgetful functors This is more often true when the target of the functor is

Set

Axioms designers also use functors to create instances of abstract datatyp es

PolynomialCategory Axioms equivalentof Poly is in Axioms view a func

tor

Ring OrderedAbelianMonoid OrderedSet PolynomialCategory

REV PolynomialCategoryREV

This functorialityprovides the glue for Axioms typ e mechanism

Now trivially for categories A B if F A B a forgetful functor then B is a sub

category of A Equally triviallya concrete instance of PolynomialCategoryREV

is a sub category of PolynomialCategoryR which is a sub category of Poly

inheritance mecha It is this rst form of sub category relation that provides Axioms

nism

Chapter Category theory Categories and Axiom

Categories and Axiom

Notation To distinguish between Axioms internal structures and those com

monly used in mathematics things which belong to Axiom wil l be written in this

font Specical ly

Category wil l always refer to Axioms distinguished symbol to which al l Axioms

Categories belong

Hence a Category is an Axiom object declared to be such an object eg Ring

PolynomialCategoryREV

A Domain is an Axiom object declared to bea member of a particular Category

eg Integer PolynomialInteger

An item is an element of a Domain eg x

As stated in section Axioms main view of things is that every ob ject has a typ e

and that there are four layers

items Domains Categories Category

Categories also may inherit from or extend other Categories forming an inheritance

lattice Thanks to the higher order p olymorphism available in Axiom Categories

may also b e parameterised by items or Domains

This parameterisation may cause some confusion For example

ListS ListAggregateS

declares for each and every S ListS is in the category ListAggregateSFor exam

ple ListInteger is an ob ject of ListAggregateInteger However

ListAggregateInteger is a mere sub category of the category of all ob jects which

are domains of linked lists This is ListAggregateS

So ListAggregateS contains for example both ListInteger and

ListFractionInteger as ob jects but what are the arrows of this category This



One may view a domain as a category whose ob jects are the items and whose arrows are either triv

ial ie solely the identityarrows or some other natural o ccurring meaning eg In PositiveInteger

one may think that there is a natural map since j This would then mean that this map

could b e lifted to IntegerMod IntegerMod

Chapter Category theory Functors and Axiom

is something which is not made explicit in the Axiom literature and is indeed the core

of this thesis

We shall discuss what it means to b e a natural map and how this relates to categorical

arrows section

Functors and Axiom

Axiom describ es its domain constructors as functors and this is true After all ne

glecting diculties with constructors which take domain elements for arguments these

constructors are maps from a cross pro duct of categories to another category

The diculties with constructors whichtake domain elements for arguments disapp ear

when considering the argument used in fo otnote of section

Co ercion and category theory

If coerce A Bthenwe are going to have that A and B are ob jects of the same

category ACatandthat coerce is an arrow of that category See denition

Also if T is a functor from ACat to TCat whichinAxiomwould lo ok like

TAACat TCat

then T lifts the arrows of ACat to TCat and in particular

T coerceA B coerceTCatA TCatB

In manytyp es and some other languages T is acting like the familiar map op erator

on the coerce function

Conclusion

We have seen in this chapter how category theory and abstract datatyping esp ecially

with resp ect to Axioms Category mechanism are ideologically similar

We have also shown how Axioms functors interact with co ercions from a category

theoretical p ersp ective

Chapter

Order sorted algebra

Intro duction

In this chapter we shall intro duce the concepts of universal algebra We shall lo ok at

the unsorted case to start with and then move on to the sorted case

We then follow up with the equational calculus which allows us to consider sets of

equations whichmust hold in a concrete instance of an algebra

All the work in this chapter is taken from Dav except example the Perl

example in section and section

Universal Algebra

Universal algebra will provide us with a natural way of representing categories of typ es

which p ossess certain functions In the following lengthy section of denitions keep

in mind that what we shall dene as a signature will b e equivalent in some sense

to our notion of a category or abstract datatyp e An algebra will b e the ideological

equivalent of an ob ject or typ e

Denition A sortlist S is a nite sequenceofsymbols cal led sorts normal ly

denoted s s

m

Denition Given a sortlist of size m a set A of S carriers is an ordered m

tuple of sets A indexed by S

s

i

Chapter Order sorted algebra Universal Algebra

Example One may consider the sortlist of a vector space to be K V where

K is to be identied with the underlying eld and V is to be identied with the set of

al l points in the vector space Then considering C to be a vector space over R the

K V carriers of C are R C

So we see that the carriers of a particular typ e are a list of typ es which have something

in question The sort list is a list of the same length where the to do with the typ e

ith element is a symb ol corresp onding to a particular abstract datatyp e to which the

ith carrier b elongs

Denition Given a sortlist S and n N fg an S arity of rank n is an

ordered ntuple of elements of S

An arity is merely a list of elements of the sort list This will b e useful when we wish

to typ e p olymorphic or abstract functions

Denition Given a sortlist S n N fg q q q an S arity of rank

n

n and a set A of S carriers we dene

Y

q

A A

q

i

ifng

This is the map of an arity to the list of carriers

q

Denition An S op erator of arity q is a function from A to one of the elements

of A

Denition An S op erator set or S sorted signature is a set of sets

nq s

S

is a indexed by n N fg q an S arity of rank nand s S such that

nq s

nq s

is cal led operator symbol subset of some alphabet An element of some

nq s

The usual notation for such a signature is hSi

So this denes us a set of sets of p olymorphic functions for a particular sortlist A

signature is like a category in that it is an abstract datatyp e

A signature collects together all typ es which share a similar family of op erators

Notice that the sort list is dened rst and that the carriers dep end on the sort list Onedoesnot

dene a list of carriers and then x a list of abstract datatyp es post facto



Functions without metho ds

Chapter Order sorted algebra Universal Algebra

Example Monoids N fg is an additive monoid whereas N is a multiplicative

monoid

The signature for monoids could beviewed as being

hUi hM B e id ep b i

where M is the monoid sort B is the sort of boolean logic types The operator symbol

e is a member of and corresponds to the function which always returns the

M

identity constant of the monoid

id is the operator symbol in which corresponds to the identity function

M M

ep is the operator symbol in which corresponds to the is this the identity

M B

element function

Last in our example but by no means least b is the monoids binary operator from

MM M

So in N fg e id ep b correspond to id respectively Whereas in N e id ep b

correspond to id respectively

Denition A multisorted total algebra is an ordered pair hA i where A

is an Scarrier set and

f jn N fgq an arity of rank n s S g

nq s

q

A g f A

s nq s nq s

nq s

So if hUi is the monoidal signature then

hN Boolean id i

is an algebra

Notation Let hA i be a algebra For an operator symbol of the sig

nq s

nature hSi the function associated with this symbol in hA i is represented by either

or

nq s

nq s



Constants are often represented by if not compiled in the same way as functions in programming

languages such as Axioms Spad language This gives a homogeneous interface for providing constants

Chapter Order sorted algebra Term Algebras

This second form of notation is useful for when we refer to op erator symb ols by names

other than those in the form For example if then

nq s nq s

nq s

nq s

Denition Given hA i hB i both algebras then a homomorphism

hA i hB i is an S indexed family of functions A B for each s in S

s s s

such that

q

s S n N fgq arities of rank na a A

nq s n

we have

a a a a

s nq s n nq s q q n

n

As an example of a homomorphism let us consider our monoidal case once more The

n

map from N fgN which maps n is a homomorphism

Term Algebras

Term algebras provide us with at least one example of an algebra for each signature

In some sense it is the freest algebra of the signature and all other algebras are

isomorphic to quotients of the term algebra

Notice that given hUi the denition of the monoidal signature from example

the term algebra is not the free monoid since we have not added in any laws or

equations to the algebra Thus we do not have asso ciativity in the term algebra

whereas we do in the free monoid

Thus we see that as yet universal algebra do es not mo del real mathematics p erfectly

However this situation will b e remedied somewhat in section

Notation We shal l dene the set to be the set containing threespecial symbols

fgfgf g

is a just a piece of notation that will make the following denition less verb ose



Wehavent provided an exp onentiation function in our monoidal algebra but adding an extra sort

and a function it is p ossible Otherwise think of the map as taking to to to to

and so on

Chapter Order sorted algebra Ordersorted algebras

Denition Let X bean S indexed family of sets disjoint from each other from

S

the set and from We dene T X to be the S indexed family of sets

nq s

nq s

S S

of strings of symbols from X each set as smal l as possible

s nq s

sS nq s

satisfying these conditions

s S T X

s

s

S X T X s

s s

i f ngt T X t t T X

nq s i q n s

i

We make T X into a algebra by dening operators on T X for each

T

via

nq s

If n then Guarante ed to be in T X by

T s

Else dene t t to be the string t t

T n n

T X is cal led the term algebra and an element of T X is cal led a term

Ordersorted algebras

Order sorted algebras extend the concept of of universal algebras by imp osing an order

on the elements of the sortlist This can b e useful if weknow that all algebras of our

signature hSi have the carrier of S as a subset of S say

The ordering of sorts imp oses a subtyp e lattice on the sorts and hence their carriers

This can then be used in any algebra of the signature to either restrict a function

already dened on one typ e to a subtyp e of that typ e or extend a function on a typ e

to a partial function on a sup ertyp e Partial functions and order sorted algebra are

discussed in section

Firstlywe had b etter dene what we mean by an order

Denition A strict partial order on a set S is a relation on S which is

transitive antisymmetric and irreexive

A weak partial order on a set S is a relation such that a b a b a b

Such a relation is transitive

Chapter Order sorted algebra Ordersorted algebras

Notation Let S be a set of sort symbols such that there is a partial order

dened on S and a top element u of S such that s u for al l s in S

u provides us with a universe see app endix B in which to work Equivalently we

could set u to be any class which is big enough The term class is dened in

app endix B

Denition Extend from S to the S arities of r ank n by dening s s

n

t t i i f ngs t

n i i

Denition An ordersorted total algebra is an ordered triple hA fA s

s

S g where A is a class known as the universe fA s S g is an S indexed family

s

of subsets of A known as the carriers of the algebra and is a set of sets of functions

S

q

A g such that f A

nq s s nq s

nq s

A A

u

If s s in S then A A

s

s

If with s s and q q then j

q

nq s nq s

nq s nq s

A

Strictly sp eaking that last condition should b e

j

q

A A nq s

nq s

s

A

s

where is the inclusion op erator A A since otherwise the target of the

A A s

s s

s

s s

left hand side would b e A and of the right hand side would b e A

This is typical of the sort of abuse of notation that computer systems often have to

implement

In a language like C KR there is not much scop e for such abuse The compiler will

complain if we attempt to change the typ e of anyvariable

However in a language likePerl WCS where typ e changes are p erformed automat

ically abuse is everything For example to convert the string to a number one

simply adds to it

The following command line session shows the abuse Perl allows

Chapter Order sorted algebra Ordersorted algebras

nicpangurban Tmp perl e

astring

anumber

print astring

print n

print anumber

print n

print astring anumber

print n

astring text

print astring

print n

text

print n means print carriage return linefeed as in C See how astring is

treated as a number when added to anumber and a string when we app end using

the op erator some text to it

Notice that the opp osite can b e p erformed to o Wemay treat numb ers as strings We

have already seen this with the line print anumber but as a more explicit example

e can app end text to a number w

nicpangurban Tmp perl e

anumber

anumber text

print anumber

print n

text

Perl is incredibly go o d at all such built in typ e changes However Perl is not a computer

algebra system and do es not have the vast number of typ es that Axiom has

Perl also has a xed universe see app endix B and denition and knows how

to retract any variable back to the universe typ e From this it can see how to co erce

Chapter Order sorted algebra Ordersorted algebras

anytwo ob jects to typ es over which an op erator suchasprint or isvalid

The denition of order sortedness ensures some conuence amongst op erators on sub

typ es However it do es not provide enough for most sensible applications The follow

ing denition ensures a more conuent system

Denition The ordersorted signature is regular if whenever q is an arity and

with q q there is a least pair q s such that and q q and

nq s

nq s

s s

Now we shall extend the denition of term algebras to the order sorted case

om each other from Denition Let X bean S indexed family of sets disjoint fr

S

We dene T X to be the S indexed family of sets the set and from

nq s

nq s

S S

each set as smal l as possible X of strings of symbols from

nq s s

nq s sS

satisfying these conditions

s S T X

s

s

s S X T X

s s

s s S s s T X T X

s

s

i f ngt T X t t T X

nq s i q n s

i

We make T X into a algebra by letting the rst component be T X and dening

u

operators on T X for each via

T nq s

If n then Guaranteed to be in T X by

T s

Else dene t t to be the string t t

T n n

T X is cal led the term algebra and an element of T X is cal led a term

The following theorem proves the freeness of term algebras That is to say all algebras

are isomorphic to a quotient of the term algebra In this waywe see that all algebras

ted as a term algebra and a set of rewrite rules are easily implementable once represen

in a rewrite system suchasOBJ



Perhapsthisiswhy OBJ is a rewriting system



With the usual caveats on b eing able to check whether two elements are equal or not and other

unsolvable problems

Chapter Order sorted algebra Extension of signatures

S

It also says something ab out the constructibilityoftyp es That is if is nite

nq s

nq s

then clearly only a nite number of functions in each and every algebra construct

the whole algebra

Moreover supp ose in every real algebra whichwe wish to study a certain set of equa

tions hold see section Then all our algebras are isomorphic to factors of the term

algebra factored out by that set of equations

Then if every element of this freest factor algebra is equal to one constructed by a

S

p otentially very small nite subset of a p otentially innite we may

nq s

nq s

utilise this to construct elements of our algebra

In the automated co ercion algorithm section we utilise a small but not necessarily

minimal set to construct all or some of the elements of one of the sorts of an algebra

any algebra any Theorem First universality theorem Let hA i be

map S indexed family of maps from X into A Then there exists a unique

homomorphism from T X to A such that s S x X

s

x x

s

s

The pro of may b e found in Dav

Extension of signatures

In this section we shall formalise what wemean for one algebra to be an extension of

another or more imp ortantly from our p oint of view for one algebratobea p ortion

of another

More formally we are saying how the abstract datatyp es or categories or signatures

may inherit from each other This sometimes corresp onds to algebras dep ending on

each other

First a piece of notation

Notation If S and T are two sets of sets both indexed by the same set I we

say that S T i i I S T

i i

This extends the denition of subsets to ntuples of sets

Denition Let S S betwo sortlists such that as sets of symbols S S and

Chapter Order sorted algebra The equational calculus

that s t S s t s t Let be an S sorted signature and T be a

S

S

S sorted signature If T we say that is a subsignature of T and that T is a

sup ersignature of

Thus we have the obvious denition of subsignature As an example the monoidal

signature is a subsignature of the signature for groups The notion of subsignature

corresp onds directly with that of subcategory

Denition With S S T as in the previous denition let hA i be an S

sorted T algebra Dene hA i j cal led hA i restricted to to be the S sorted

algebra with carriers those carriers of hA i which are indexed by sort symbols from

S and operators nary operators of arity q and result sort s for every

nq s

This is applying the forgetful functor from the category corresp onding to T to that

corresp onding to to hA i

The equational calculus

Again we borrow heavily from Davenp orts lecture notes Dav Throughout this

section we assume that S fs s g is our indexing family of sort symb ols and

n

f g is a S sorted signature

nq s

The equational calculus presented here applies to multisorted algebra The reader will

see that it clearly may b e extended to the ordersorted case

The equational calculus allows us to add equations to our signatures and hence

algebras This will allow us to assert facts ab out all the algebra in a signature For

example we may wish note that one of the binary op erators is always asso ciative

Other more complicated expressions are available also

The equational calculus do es not allow us to dene everything that weneed only those

things that are easily denable as equations

Denition A S indexed family of relations R fR R g on a algebra

s s

n

hA i is cal led a congruence if it satises the fol lowing four families of conditions

a A aR a R

s s

i i

aR b bR a S

s s

i i

aR b and bR c aR c T

s s s

i i i

b a R b a a R b b C a R

n q n n s n nq s q

n

Chapter Order sorted algebra The equational calculus

The rst three conditions imply that R is an equivalencerelation on the set A while

s s

i i

the conditions C explain how R relates to the various op erators of The op erators

of are welldened on the equivalence classes

nq s

Denition Let hA i be a algebra and bea congruence on hA i De

ne hA i to be the algebra hB i where the carrier set B of B is the set of

s

i

and is the operator equivalence classes of A under the equivalence relation

s s

i i

dened by

a a a a a a

n n

for every operator symbol in every

nq s

This is merely the quotient algebra and to b e sure the following is a theorem

Theorem The operators in the above denition are wel ldened

The following denition actually turns out to b e very imp ortant

Denition We say that a sort s is void in the signature if T

s

Basically having a void sort s in the signature means that there are no constants of

that typ e and that one of the following is true

s

no op erators have s as a return typ e q n where q is an arity of

nq s

rank n

every op erator withs as a return typ e has an argument whose sort is either void

or s q n i f ngq is a void sort or s where q is

nq s i

an arity of rank n

Lemma If s is not void in the signature thenineveryalgebrahA i A

s

Goguen Meseguer suggest the following rules of deduction for a sound multisorted

equational calculus

Notation Let X be a S indexed family of sets of variable symbols such that

each X is disjoint from al l the others from the operator symbols of and from any

s

i

symbols in any particular algebras we may be reasoning over

Chapter Order sorted algebra The equational calculus

We wil l bereasoning frequently with S indexed families of sets and wishing to perform

operations on them Let X hX X i and Y hY Y i be two S indexed

n n

families of sets and dene X Y to be the S indexed family hX Y X Y i

n n

Similarly we wil l write X Y to indicate that each component of X is a subset of the

corresponding element of Y

A nal piece of notation is that the indexed family of empty sets wil l bedenoted by

Denition A multisorted equation for the signature consists of a triple

Y t t where Y X t and t are terms from the same carrier set of T X or

i and every T X A if we are dealing with equations in a particular algebra hA

variable occurring in t and t occurs in the appropriate member of Y t t T Y

Such equations are written Y t t

If t and t come from the same carrier set of T X we say that the equation is

generic

One should read the symbol Y as meaning for all values of all the variables of Y in

the appropriate sorts and there had b etter b e some values in those sorts It is this

interpretation that will solve the paradoxmentioned earlier

system for the signature is a set of equations for Denition An equational

T X or T X A if we are dealing with equations in a particular algebra hA i

We will tend to write e f for an equation from an equational system meaning

Y e f where Y is the S indexed family of sets of variables consisting precisely of

those variables o ccurring in e and f

Notation x t means substitute the variable x with the term t We cal l this

i i i i

a instance

Denition A pro of in the multisorted equational calculus of the equation

Y e f from the equational system E is a nite set of equations Y e f such

i i i

that each equation is justied by one of the seven fol lowing rules of inference

Y ex t x t f x t x t E

n n n n

where X e f is an equation of E thet are terms of the appropriate sort of T X

i

and Y is the S indexed family of sets whose sth component is the set of al l variables

Chapter Order sorted algebra The equational calculus

of sort s in al l the t and those variables of X which have not been substituted for ie

i s

which are not one of the x

i

Y e e R

where Y is the S indexed family of sets whose sth component is the set of al l variables

of sort s in e

Y f e S Y e f

Y Y e g T Y e f Y f g

Y e f Y e f Y Y e e f f

n n n n n n

C

where is any symbol of and each e is a term of sort q

nq s i i

Y e f A Y e f

where Y Y

Y e f hY Y Y nfy gY Y i e f Q

i i i n

where y does not occur in e or f and the sort i is nonvoid for

We use the notation Y e f or Y e f if we wish to make clear which

E

equational system is b eing considered to mean that e f is provable in the equational

system using the ab ove rules of inference

Denition If Y e f is an S sorted equation c al l it E and hA i is

a algebra then we say that hA i satises E or that hA iis a mo del for E if for

al l S sorted maps from Y to A e f where is the map from T X A

A

to hA i whose existence is guaranteed by theorem We extend the notation to

sets of equation E by insisting that hA i bea model for each equation in E

Theorem The Soundness Theorem If hA i is a model for E and

E

Y e f then hA i is a model for EfY e f g

The pro of of the soundness theorem may b e found in GM

Denition Let hA i be a algebra and let E be an equational system for

d by A B if hA i The congruence induced by E denoted on hA i is dene

E E

and only if Y a b where Y is the S indexed family of empty sets

E

Chapter Order sorted algebra The equational calculus

The following two denitions are very imp ortant A theory sp ecies a typ e and we

dene a varietyto b e the collection of all typ es which mo del that theory

Denition We dene a theory to be the ordered pair hhSi Si where is

an S sorted signature and S is a set of S sorted equations We say that a algebra

mo dels or satises the theory i it is a model for S

Denition The col lection of al l models of a particular theory is cal led a vari

ety

Clearly since a signature hSi may b e viewed as the theory hhSi i the collection

of all algebras forms a variety

When referring to the variety of all mo dels of a particular signature for example

hhSi Si we usually say the variety dened by or sp ecied by the signature

hhSi Si

Theorem Second universality theorem Let X beaS sorted set of vari

ables an S sorted op erator set E a set of equations for hA i a algebra which

is a model for E and a S sorted mapping from X to A Then there is a unique

homomorphism from T X to A such that

E

x x

for al l x X where is the map from X into T X dened by x x

E

Theorem The Completeness Theorem If every algebra which satis

es the equation E also satises the equation Y e f then Y e f

E

Again the pro of of this may b e found in GM

Finallywe state the denition of an extension and a protecting extension Extensions

are selfexplanatory

Denition Suppose that and T are signatures where is S sorted and

T is S sorted where S S

e an extension of Then T is said to b

A protecting extension is an extension which preserves the equational system for a the

ory Combining the second universality theorem with the denition of protecting

Chapter Order sorted algebra Signatures theories varieties and Axiom

extension allows us to view a mo del of a theory as a mo del of a protecting extension

of that theory

More imp ortantlyifwehave an algebra which is a mo del for a protecting extension of

a theory then wemay view the algebra as a mo del of that theory unextended

For example if the Ring theory is dened to be a protecting extension of the Group

theory then wemay view anyringRingalgebra as a group Groupalgebra

Denition With T S and S as in denition

Let E bean equational system on Also let EF bean equational system on T

cal led a protecting extension if Such an extension is

T X j

EF

T

is isomorphic to T X isomorphism meaning isomorphism as algebras

E

Notice that the denition of protecting extension is equivalent to the notion of enrich

ment given in Pad although this do es not allow for the existence of S Thus a

theory is a protecting extension of another i is complete and consistent

with resp ect to

Signatures theories varieties and Axiom

Axioms typ e system uses the terminology from category theoryyetitsdesignisbased

on order sorted signatures

A Category denition in Axiom ie the source co de that denes the Category is

equivalent to a signature or theory b eing a sp ecication of a typeortyp es

The Category viewed as a collection of ob jects Domains is the variety sp ecied by

the theory which denes the Category in the Category denition

The sorts are for the principal sort see denition and the argument and

return typ es of all the op erator symb ols of the Category

For example PolynomialCategoryREV is a Category is the principal sort

Other sorts include R E V a sort each for the Boolean and PositiveInteger typ es

The equations of a theory in an Axiom Category denition are either dened in the



Unless they are concrete typ es Domains See section

Chapter Order sorted algebra Conclusion

comments or as certain attributes of op erators For example commutative means

that is commutative and the traditional commutativity equation for the op erator

is an equation of the theory There is currently no metho d for enforcing the equations

to hold in any mo del

An algebra or mo del for a theory in Axiom is a Domain Declaring a Domain to be

in a Category is equivalenttosaying that is an algebra of that signature or mo del of

that theory Or in other words a memb er of the variety dened by the theory which

sp ecies the Category

For example PolynomialInteger is a mo del for PolynomialCategoryREV

An op erator symbol in Axiom is a function declaration in a Category An op erator

name in Axiom always corresp onds to the op erator symbol

the For example is an op erator symbol in Ring In Integer a mo del for Ring

op erator name of is and has to b e

A carrier is the concrete typ e substituted for a parameter in any instantiation of a

Domain

In PolynomialInteger PolynomialInteger is the carrier Whereas Integer

NonNegativeInteger and Symbol are the carriers of R E and V resp ectively No sort

is given for the Boolean and PositiveInteger typ es

All of Axioms extensions are protecting extensions That is if a Category is declared

to extend another then it is always a protecting extension of that Category

In chapter we shall discuss how Axiom diers from order sorted algebra and howwe

may remedy this situation

Conclusion

In this chapter wehaveintro duced all the basics of order sorted algebra and the equa

tional calculus Wehave also shown how these notions are represented in Axiom

Wehave demonstrated that order sorted algebra combined with the equational calculus

provides a sound basis for a computer algebraic typ e system

Amulti sorted signature is a sp ecication for a typ e and hence is an abstract datat yp e

Adding an order on the sorts to obtain an order sorted signature enforces relations

between the sorts It also guarantees sensible interaction between these carriers of

these sorts and op erators thereon in any algebra of the signature

Chapter Order sorted algebra Conclusion

Combining signatures with the equational calculus yields theories Theories further

enhance the usefulness of signatures by ensuring certain equations will hold in any

mo del algebra of the theory signature

Chapter

Extending order sorted algebra

Intro duction

In this chapter we shall discuss how partial functions and conditional signatures may

tiein with traditional order sorted algebra This will mean that any facts that we

mayprove for or use from traditional order sorted algebra will also apply when partial

functions andor conditional signatures are considered to o provided certain extra facts

hold

Next we shall lo ok at the similarities b etween order sorted algebra and category theory

This will demonstrate why computer algebra systems such as Axiom use category theory

terminology whereas most of this thesis uses order sorted algebra as its framework

Lastly we dene what we mean by a co ercion This denition is fundamental to the

rest of this thesis

All the work in this chapter is the authors own except for section which is based

almost entirely on Bro after a suggestion by Ric and Mar

Partial Functions

In this section we ask the question How do partial functions interact with classical

universal algebra We need this in case some of the functions used to create our

co ercions later are only partial This can happ en see denition For example the

division op erator in any quotient eld is partial but could b e viewed as a constructor

function

Chapter Extending order sorted algebra Partial Functions

In our previous chapter on universal algebra we dened an S op erator of arity q to

q

be a total function from some A to some element of A Where A is a set of S

carriers Is it p ossible to redene this so that the S op erators are partial Indeed is

this necessary One of the original reasons for the invention of ordersorted algebra

denition rather than multisorted algebra denition was so that all

functions could b e considered total See for example GM

i A A were a partial function in an algebra hA For example if

P T

P T

A A were a total then we could insert a new sort N P such that

N T

N T

function

In the example of a quotient eld one would intro duce a subsort of the integral domain

whichwould represent all the nonzero elements of the domain

Wemay pro ceed by either attempting to redene all of universal algebra using partial

functions or through some dierentmechanism The following mechanism which uses

virtual sorts turns out to b e awed Virtual sorts are an onthey way of generating

sorts to representthingslike the nonzero elements of an integral domain or nonempty

stacks

Denition Let hSi dene an ordersorted signature If we dene hLi to be

the signature where

L S f u u g a set of symbols distinct from al l those in S

m

i f mgs S u s

u i L u

i i

n

n N fgs S q S

nq s nq s

n n

e than n Nq L n S s S Note that there may be mor

nq s

one such triple hn q si

then we say that the u are virtual sorts of hSi and n Nq

i nq s nq s

n n

L n S s S a virtual op erator symbol of hSi

Unfortunately virtual sorts virtual op erators and homomorphism do not interact in a

satisfactory manner The intro duction of a virtual sort in the source of a homomor

phism may b e meaningless in the target or vice versa

For traditional examples like the nonempty stack they are ne since this has some

meaning in all stackalgebras But for typ es like all the elements which do not map

Chapter Extending order sorted algebra Partial Functions

to under a particular co ercion then it may be meaningless to create a virtual sort

which attempts to representthis

Broy Bro denes algebras as having either partial or total op erators A partial

homomorphism is then dened as follows

Denition Partial homomorphism If hA i and hB i are hSi al

gebras and is a family of partial maps A B then is a partial

s s s

homomorphism hA ihB i i the fol low two conditions are full led

Firstly

n N fgq arities of rank ns S

nq s

q

a a A

n

if b oth a a and a a are dened then

s n q q n

nq s nq s n

a a a a

s n q q n

nq s nq s n

Second ly

n N fgq arities of rank ns S

nq s

a a A a a A

q n q

n n

a a

q i strong q

i

i i

ifng

a a a a

s n strong s

nq s nq s

n

Where is the strong equality dened via

strong

dened a dened a b a b a dened b

strong

Broys denition of homomorphism denition is as he states rather lib eral A

sp ecial factor whichhe notes is that the comp osition of partial homomorphisms need

not b e a homomorphism again

The following two denitions turn out to b e useful in distinguishing b etween typ es of

partial homomorphism

Denition Let h S i bea subsignatureof hSi A algebra hA i is said

to be a subalgebra of the algebra hB i i

with partial op erators in our terminology

Chapter Extending order sorted algebra Partial Functions

s S A B

s s

q

n N fgq arities of rank ns S j

nq s A

Denition Let h S i bea subsignatureof hSi A algebra hA i is said

to be a weak subalgebra of the algebra hB i i

A B s S

s s

q

n N fgq arities of rank ns S j

nq s  A

where is dened via



f g xf x is not dened f xg x



Broy notes that any partial homomorphism may be decomp osed using the following

eak subalgebra A of A metho dology A partial homomorphism A B denes a w

dened via

s S A fa A a denedg

s s

a a a a ifi with the functions taking the meanings

n n

nq s

nq s

a a is dened Otherwise f nga are dened and

n i

nq s

a a is not dened

n

nq s

By we denote the weak partial identity function A A Then we dene A B

to b e the total homomorphism which is the restriction of to A

Being total induces a weak subalgebra B of B dened via

s S B fb B a A abg

s s s

with the functions dened via a a a a where b

n n i

nq s

nq s

a and a a is dened

i n

nq s

This then induces a total surjective homomorphism A B Also by con

struction B is a weak subalgebra of B Therefore there also exists a total injective

homomorphism B B which is the natural inclusion op erator

As examples consider the following co ercions We are only lo oking at the carrier of

the principal sort denition in these examples

Example Q Z

Chapter Extending order sorted algebra Partial Functions

Fraction Integer PrimeField

A Q nfq j q Q nfgg

B B

Example Qx ZxQx

Polynomial Fraction Integer Fraction Polynomial Integer

A A

B Qxfp j p Qx q Qxp q denomq Qg

Example Qx Z x

Polynomial Fraction Integer Fraction Polynomial PrimeField

i

A Qx g nf q x Qx j i N fgs Q nfg q s

i i

iNfg

B Z xfp j p Z x q Z xp q denomq Z g

These show that real examples of co ercions may indeed cause A and A to dier as well

as B and B

Notice that in example ab ove we are considering a eld homomorphism and

that A is a weak subeld of A For example is undened on the pair in A

Clearly B is a subeld of B

In example it is an integral domain homomorphism that concerns us So although

B is only a weak subeld of B this do es not matter as it is subintegral domain of B

Similarly in example we are again considering an integral domain homomorphism

and b oth A and B are subintegral domains of A and B respectively

As Broy notes this denition of partial homomorphism allows the everywhere undened

function to be a partial homomorphism Thus this denition is to o weak for our

purp oses

Denition Apartial homomorphism is cal led strict i

q

n N fgq arities of rank ns S a a A

nq s n

Chapter Extending order sorted algebra Conditional varieties

a a a a

n strong n

Broy notes that a strict homomorphism ensures that B is a subalgebra of B and

not just a weak subalgebra is always strict and if is strict then B is indeed

a subalgebra of B

Our requirements for homomorphism are that it act strictly on a certain set of partial

functions the constructors denition In other words we shall require that our

C

co ercion b e a strict partial homomorphism again see denition

In the rest of this work we shall not in general concern ourselves with the partiality

of homomorphisms op erators or strictness Since provided our homomorphisms act

ely required for construc strictly on the constructors of the typ e and anytyp e recursiv

tion denition then the strong equality in the denition of strictness puts us

in go o d shap e

Conditional varieties

Axiom contains the notion of conditional Categories or in the language of universal

algebra conditional varieties In this section we dene and reconcile the notions of

conditional and nonconditional varieties This means that in future sections we shall

b e able to ignore the existence of conditional varieties in Axiom

Notice that our choice of the word conditional here is similar to that used in the

phrase conditional algebraic sp ecications The dierence b eing that our conditions

are predicates evaluated over arities not terms Ours is a higher order notion and

should not b e confused with the ordinary lower order work

We extend the denition of signature to conditional signature via the following deni

tion

Denition A S sorted conditional signature is a set C of sets C indexed

nq s

by n N fg q an S arity of rank nands S Each element of C is of the form

if P w then

nq s

where P is a wel lformed proposition in some language and w is an arity of nite



Unconditional may have been a better choice of word from an English language point of view

However we are not saying that an algebra is unconditionally an algebra of a variety we are saying

that it is an algebra of a variety which has no conditions

Chapter Extending order sorted algebra Conditional varieties

rank if it is a tautology it is always represented by T The are the conditional

nq s

op erator symbols

Firstlywe need to dene a conditional term algebra

Denition Let X bean S indexed family of sets disjoint from each other from

S

the set the set fifPtheng and from f j arity w if P w then g

nq s

nq s

We dene T X to be the S indexed family of sets of strings of symbols from

C

S S

fifPtheng X each set as smal l as possible satisfying these

s nq s

sS nq s

conditions

s S T X

C s

s

s S X T X

s C s

if P w then C i f ngt T X if P w then

nq s i C q

i

t t T X

n C s

We make T X into a conditional C algebra by dening conditional operators if

C

P w then on T X for each if P w then C via

T C nq s

If n then if P w then if P w then Guaranteed to be in

T

T X by

C s

Else dene if P w then t t tobethe string if P w then t t

T n n

T X is cal led the conditional term algebra and an element of T X is cal led a

C C

conditional term

Asso ciated with the notion of conditional signature are the notions of conditional the

require a new denition for equations and ory and conditional variety However we

equational systems

Denition A conditional multisorted equation for the conditional signature

C consists of a quadruple P w Yt t where P is a wel lformed proposition in

some language and w is an arity of nite rank if it is a tautology it is always

representedbyT where Y X t and t are terms from the same carrier set of T X

C

or T X A if we aredealing with equations in a particular algebra hA i and every

C

Chapter Extending order sorted algebra Conditional varieties

variable occurring in t and t occurs in the appropriate member of Y t t T Y

C

Such equations are more usual ly written if P w Y t t

If t and t come from the same carrier set of T X we say that the equation is

C

C generic

Note that this denition of conditional equation should not be confused with that

found in work such as KR In that context a conditional equation is a clause such

as if P tY t t where t is a subterm of t for example

Denition An conditional equational system for the signature is a set of

conditional equations for T X or T X A if we aredealing with equations in a

C C

particular algebra hA i

Asso ciated with denition are two sp ecial signatures and The former is the

extension of all the C s the latter is extended byallC s More formally

Denition Using the denitions of denition we dene to be the S

sorte d signature where n q s n N fg q an S arity of rank nand s S

f j if P w then C g

nq s nq s nq s nq s

Now similarly we dene to be the S sorted signature where n q s n N fg q

an S arity of rank n and s S

T then C g f j if

nq s nq s nq s nq s

where S is the largest subset of S such that has no void sorts

The algebras of conditional signatures are the same as ordinary algebras except that

w

the prop osition P is evaluated over A and i this is true there is an op erator

nq s

in that algebra More formally

Denition An ordersorted total conditional C algebra is an ordered triple

hA fA s S gi where A is a class known as the universe fA s S g is an

s s

S indexed family of subsets of A known as the carriers of the algebra and is a set

S

q w

of sets of functions f A A j P A g such that

nq s nq s s

nq s

A A

u

Chapter Extending order sorted algebra Conditional varieties

If s s in S then A A

s

s

If if P w then C and if P w then C with s s and

nq s

nq s

w w

q q and also P A and P A then j

q

nq s

nq s

A

Clearly if all the P are tautologies then a conditional signature C is identical to its

nonconditional partner Therefore all conditional C algebras are nonconditional

algebras in this case

In any case a C algebra is a algebra Thus wecanseethat is a minimal signature

for C

Denition We dene a conditional theory to be the ordered pair hhC Si Si

where C is an S sortedconditional signatureandS is a set of S sortedconditional

equations We say that a C algebra hA i mo dels or satises the conditional theory

i it is a model for Sj where Sj is dened as fol lows

hAi hAi

w

Sj fY t t j P w Yt t S P A g

hAi

A theoretical interpretation of a conditional theory hhC Si Si is a theory hh Si S i

equivalent to hhC Si Si with al l the propositions P w evaluated in some consistent

manner

Final ly we demand that for al l possible pairs of theoretical interpretations hh Si S i

hh Si S i where and S S that hh Si S i is a protecting extension of

hh Si S i

Denition The col lection of al l models of a particular conditional theory is

cal led a conditional variety

In fact the conditional variety dened by hhC Si Si is equivalent to the variety dened

by hh S i Si

Also the variety sp ecied by any theoretical interpretation of the conditional theory

hhC Si Si forms a sub class of the the conditional variety Moreover for a pair of theo

retical interpretations hh Si S i hh Si S i where and S S thevariety

sp ecied by hh Si S i forms a sub class of the variety sp ecied by hh Si S i



Minimal in the sense that it has fewest op erator symbols and sorts The variety it sp ecies is

maximal if you consider the numb er of algebras that mo del it

Chapter Extending order sorted algebra Conditional varieties

If we consider two conditional algebras from the same conditional varietythenwe wish

to know whether there is a homomorphism from one to the other For this we need to

dene conditional homomorphism

Atechnical denition which will allow us to dene homomorphisms more easily

Denition Let hA i and hB i be C algebras For al l n q swe dene

nq s nq s nq s

to be the map

nq s nq s

Similarly dene for hB i

nq s

The family of maps as we show in notation map an algebra hA i to a

nonconditional signature which it mo dels

Denition hA ihB i is a conditional C homomorphism i it is a

AB

nonconditional homomorphism where

AB

ff j gf j gj

nq s nq s nq s nq s nq s nq s nq s

nq s

n N fgq an S arity of rank n s S g

AB AB

is a S sorted signature where S is the largest subset of S such that has no

void sorts

In fact if we use the following piece of notation

NCA

Notation If hA i is a conditional C algebra we dene to be the

nonconditional signature

ff j gjn N fgq an S arity of rank n s S g

nq s nq s nq s nq s

NCA NCA

is a S sorted signaturewhere S is the largest subset of S such that has

no void sorts

As an aside notice that for each C algebra hA i there is an asso ciated nonconditional

T X This term algebra is the equivalentofevaluating each P w term algebra

NC A

over A in T X

C

Chapter Extending order sorted algebra A Category theory approach

NCA

Then hA i is a nonconditional algebra and

AB NCA NCB

f j n N fgq an S arityof rank n s S g

nq s nq s

So for any two conditional algebras of the same conditional signature there exists

a xed maximal nonconditional signature of which they are both nonconditional

algebras Wemayhave to forget some op erators and even some sorts whichmay only

exist in conditions

Our denition of conditional homomorphism is that of the nonconditional homomor

phism from this xed nonconditional signature

one for non Hence the concept of conditional signatures can always be reduced to

conditional signatures and therefore any results we prove or use need only b e for non

conditional signatures

As we have seen in denition this concept may also be extended to theories In

addition to adding new op erators when certain prop ositions hold we also allow for new

equations to be added conditionally However we demand that any such extension

is a protecting extension of the minimal nonconditional theory the theory over the

signature h S i

More explicitly let us dene S to be all those equations from S which only involve

NCA

arities from as well as all equations not involving arities Similarly dene

S to be all those equations from S which only involve arities from as well as all

equations not involving arities

NCA

If hA i is a conditional C mo del then hh S i Si must b e a protecting exten

sion of hh S i Si

A Category theory approach

This section is an aside from the rest of the chapter We are not extending the theory

of order sorted algebra nor category theory merely explaining whywecover b oth

There is a great deal of corresp ondence b etween category theory sp ecically categor

ical typ e theory and universal algebra There is not enough ro om here to cover this

huge topic but the reader is pointed to Cro whichcovers categorical typ e theory

in great depth



Alternatively dene S to b e those equations from S for which hA i is a mo del since it maynot

mo del all the equations in the denition of S in the main text

Chapter Extending order sorted algebra Co ercion

As usual Mac Lane ML also contains a great deal of information on the corresp on

dence between universal algebra and adjoint functors in the chapter on Monads and

Algebras

All the ideas from multisorted algebra theory may be represented in the categorical

typ e theory framework although an equivalent for ordersorted algebra app ears not to

be covered However the author b elieves that the notion could b e intro duced

One area which we shall discuss here is the concept of algebraic homomorphism and

the arrows morphisms of a given category

The corresp ondence between a categorical typ e theory C and its asso ciated algebraic

typ e theory hhSi Si is the following

Ob jC all the algebras for a giv en which mo del S

ArrC all or a xed subcollection of the homomorphisms

The category of all algebras of a given signature hSi has as an initial ob ject the term

algebra T X

The category of all algebras which mo del a given theory hhSi Si has as an initial

ob ject the free algebra T X This is why the second universality theorem

E

holds

So we see that both categories and theories collect together similar typ es This ab

straction of information forms the basis of abstract datatyping

Co ercion

In this work we are interested in co ercions whichso far have been explained as being

natural typ echanging maps Wemay dene them in a far more strict fashion

The following w ould seem to be a go o d denition for co ercion However in practice

this denition is not welldened enough since it do es not state which theory a co ercion

should come from

Denition Let hA i and hB i be algebras from the variety specied by some

theory hhSi Si The map hA ihB i is a coercion if it is a homomorphism

of that theory

Using the category theory corresp ondence ab ove we see that a function b etween two

Chapter Extending order sorted algebra Co ercion

typ es of the category of all algebras which mo del a particular theory is a co ercion i

it is an arrow of the category

The only problem with this denition of co ercion is that it do es not sp ecify from which

theory or equivalently category from which we should demand the homomorphism

be taken In general we would like this to be the most sp ecic or smallest category

to which b oth algebras b elong

If we just used the denition of co ercion ab ove denition then any total map

between typ es would b e a co ercion Any small category may b e forgotten backto Set

via the forgetful functor and any total function is an arrow of Set Most typ es in

computer algebra system are ob jects of Set which is equivalent to SetCategory in

Axiom the second most basic Category in Axiom

Richardson Ric notes that we also require a xed framework in which we dene

our co ercions If we were to attempt to dene a co ercion hA i to hB i to be any

map which is a homomorphism for all theories which both algebras mo del then the

denition would not b e welldened Weneedto state a context

We are attempting to reect the situation that app ears in a system like Axiom Th us

wemust state that wehavebeengiven a priori a xed collection of theories and that

given anytyp e we know precisely which theories it mo dels

This precludes a user from adding another theory which the algebras mo del which could

redene what co ercion means for those algebras

In the category theory corresp ondence we say that Axioms Category is a xed col

lection of categories and given anytyp e weknow of which categories it is an ob ject

Denition Co ercion Let bea xed col lection of theories

Let hA i be a model for theories for i in some indexing set I where i I

i i

is a theory from

hB i be a model for theories for j in some indexing set J where Similarly let

j

j J is a theory from

j

Then we cal l a map hA i to hB i a co ercion i it is a homomorphism for al l the

theories in

f j i I gf j j J g

i j

In Axiom Domains are only memb ers of a xed set of Categories



A user could reimplement one of these Categories and ruin everything

Chapter Extending order sorted algebra Conclusion

In fact in Axiom we are in a slightly b etter p osition If a Domain is an ob ject of two

Categories then there must exist a Category which extends p otentially trivially

b oth these Categories of whichthe Domain is an ob ject

Thus in Axiom denition reduces to

A co ercion in Axiom from a typ e A toatyp e B is a homomorphism of the

most restrictive Category to which b oth A and B b elong

It would be useful to have a name for maps which are co ercions in the sense of

denition These maps are in a sense natural and may b e the nextmost natural

map b etween twotyp es However as wehave shown in the example using Set the map

need not particularly natural from a realistic p ointofview

with our current terminology maps which satisfy denition which As it stands

are not co ercions are merely homomorphisms which are not co ercions

If no co ercion existed b etween twotyp es but a homomorphism which is not a co ercion

existed and a user required that homomorphism then either the user only required a

conversion or the theory lattice for the algebra system has not b een designed correctly

Conclusion

In this chapter we have shown how classical order sorted algebra may b e extended to

encompass the notion of partial functions and conditional signatures We have also

stated how these notions interact with the equational calculus These are imp ortant

extensions due to the fact that these notions are used extensively in Axiom

Wehave also mentioned some of the correlation b etween category theory and universal

algebra Finally wehav e made the imp ortant denition of a co ercion and demonstrated

why the denition is necessarily strict

Chapter

Coherence

Intro duction

In this chapter we will lo ok at a conjecture of Web er which is imp ortant to our work

We shall state his assumptions and pro of which is incorrect

We shall then add in some extra assumptions and truly prove the theorem Finally we

shall relax one of Web ers assumptions and prove that the theorem still holds

The assumptions made byWeb er provide a strict formal setting for typ es in an algebra

system The theorem in itself proves conuence for co ercions in this setting

All the work in section except the explanation of nary typ e constructor which

is by this author and section is taken from Webb Weba Web All the

rest of the work is the authors own

Web ers work I denitions

This section contains the denitions from Web ers thesis Webb Weba Web

required for the statement and Web ers pro of of Web ers co ercion conjecture

His assumptions are in the next section

These statements will also b e used when we correctly prove the coherence theorem

in section

It should b e noted that Web ers co ercion conjecture only makes up part of one chapter

of his thesis Webb which also covers various areas of typ e classes typ e inference

and co ercion in great depth and detail

Chapter Coherence Web ers work I denitions

Web er uses the phrase typ e class where we would use the terms category or va

riety

Denition A base typ e is any type which is not a parametrical ly dened type

ie a ary operator in the term algebra of type classes

So for example the Integer and Boolean typ es are base typ es

Denition A ground typ e is any type within the system which is either a base

type or a parametrical ly dened type with al l the parameters present Any nonground

e is cal led a p olymorphic typ e typ

As examples we have Integer and PolynomialFractionInteger As a non

example wehave PolynomialRRing

Denition If there exists a coercion from t to t we say that t t

This denition places an order on the ground typ es

Web er uses the phrase nary typ e constructor to mean a functor from the pro duct

of n categories to a sp ecic category

Equivalently it is a function from the pro duct of n varieties sp ecied resp ectively

by the theories to a variety sp ecied by the theory hhSi Si This

n

is a function which for all i maps the carrier of the principal sort and p otentially

the carriers of some of the nonprincipal sorts of a mo del of to one for each sort

i

mapp ed of the nonprincipal sorts of a mo del of hhSi Si

If the mo del returned is hA i this function must map one and only one sortcarrier

to each and every member of A nfA g where S is the principal sort

S

we dene com t to be if t is a base type Denition For a ground type t

or if t f t t an nary type constructor then comt is dened to be

n

max fcom t ji f ngg

i

This denes the complexity of a ground typ e to b e how far up the typ e lattice it is

Denition Coherence A is coherent if the fol lowing condition

is satised

Chapter Coherence Web ers work I denitions

ground types t t t t coercions

This guarantees that there only exist one co ercion from one ground typ e to another

This is a highly desirable feature of anytyp e system The main results of this chapter

the coherence theorem and the extended coherence theorem are that we

may be able to guarantee that our typ e system is coherent providing some sensible

assumptions hold true

In the following denitions all the and are typ e classes

type t is an object of the type class Notation t means that the

Denition The nary typeconstructor f n N induces a structural co ercion

if thereare sets A f ng and M f ng such that the fol lowing condition

f f

is satised

If f and f and i f ng

n

n

i A M t t and there exist ground types t and t

i i i

f f

i i i

coercions

if i M t t

i i

f

i

t if i A t

i i

f

i

id id if i A M

i t

f f

t

i

i

then there exists a uniquely dened coercion

F t t t t f t t f t t

n n n

f

n n

The type constructor f is covariant or monotonic in its ith argument if i M f

f

is contravariant or antimonotonic in its ith argument if i A

f

t Note that if i A M then t

i

f f

i

As an example of covariance the list constructor in Axiom List a functor Set

ListAggregatetakes one argument in whichit is covariant Given typ es A and B

h that there exists a co ercion A B then suc

F A B ListA ListB

List

Chapter Coherence Web ers work I denitions

Since Axioms typ e constructors are functors then category theory states this more

simply as

F A B List

List

Contravariance is a rarer case However Axioms Mapping functor is contravariant in

its rst argument and covariant in its second Mapping takes two typ es A and B and

returns the typ e of all mappings from A to B

As a concrete example for Mapping supp ose we wish to nd the uniquely dened

co ercion

MappingFractionIntegerFractionInteger

MappingIntegerFractionInteger

There exists a co ercion

Integer FractionInteger

the inclusion op erator There also exists a co ercion

id FractionInteger FractionInteger

which is the identity op eration The uniquely dened co ercion is as follows

F FractionInteger FractionInteger Integer FractionIntegerid

Mapping

MappingFractionInteger FractionInteger

MappingInteger FractionInteger

which sends f id f

The following denitions shows that there is a homomorphic image of a parameter in

the created typ e For example there is a homomorphic image of the underlying ring in

any p olynomial ring

Denition Let f be an nary type constructor If i

n

f ng for some ground types t such that there exists a coercion

i i

i

t f t t

i n

ft t

n

then we say that f has a direct emb edding at its ith p osition

Chapter Coherence Web ers work I I assumptions and a conjecture

Moreover let

D fijf has a direct embedding at its ith position g

f

be the set of direct emb edding p ositions of f

The denition of D is a technical denition of Web ers needed for one of his assump

f

tions

Web ers work II assumptions and a conjecture

This section provides all the assumptions and results whichWeb er uses in his pro of

of Web ers coherence conjecture which we shall state and at the end of this

section The assumptions and results are also required in our pro of of the coherence

theorem

Assumption For any ground type t the identity on t wil l be a coercion The

wel ldened composition of two coercions is also a coercion

This is clearly a sensible if notoften implemented statement Since our co ercions are

always to b e arrows of a category then the ab ove assumption must hold

Lemma If assumption holds then the set of ground types as objects to

gether with their coercions as arrows form a category

Proof Immediate 

The following assumption will provide us with the basis for a coherent typ e system

y ensuring conuence amongst dierent paths leading to the Our coherence is built b

same co ercion If we do not have coherence at the base typ es then we shall not have

coherence amongst the general typ es

Assumption The subcategory of base types and coercions between base types

forms a preorder ie if t t are base types and t t are coercions then

The following condition states that F is a functor o ver the category of all f s

f

Chapter Coherence Web ers work I I assumptions and a conjecture

Assumption Let f bean nary typeconstructor which induces a structural co

ercion and let f t t ft t ft t beground types Assume that the

n

n n

fol lowing are coercions

i M t t t t

i i

f

i i i i

t i A t t t

i i

f

i i i i

i A M t t t and id

i i t

f f

i i i

i

Then the fol lowing conditions are satised

id F t t t t id id

n n t t

f

f t t

n

n

F t t t t

n n

f

n n

F t t t t F t t t t

n n

f f

n n n n

This is a condition which stops direct emb eddings b ecoming confused FirstlyWeb er

declares that anytyp e constructor can only have one direct emb edding We shall show

how to relax this condition in a later section Secondly he states that direct

emb eddings where they exist are unique

Assumption Let f beannary typeconstructor Then the fol lowing conditions

hold

jD j

f

i

Direct embedding coercions are unique ie if t f t t and

i n

ft t

n

i

t f t t then

i n

ft t

n

i i

ft t ft t

n n

The following assumption is highly technical and shows how direct emb eddings interact

with structural co ercions Basically they commute

Assumption Let f beannary typeconstructor which induces a structural coer

cion and has a direct embedding at its r th position Assume that f

n

and f and i f ngt and t If there are

i i

n

i i

r r

coercions t t if the coercions and are dened and if f is

r r

r

ft t

ft t

n

n

th argument then the fol lowing holds covariant in its r

r r

F t t t t

r n n

f

n ft t

ft t

n

n

Chapter Coherence Web ers work I I assumptions and a conjecture

or equivalently the fol lowing diagram commutes

r

t t

r

r

r r

ft t

ft t

n

n





F t t t t

n n

f

n

f t f t t t

n

n

However if f is contravariant in its r th argument then

r r

F t t t t

n n r

f

n ft t

ft t

n

n

or equivalently the fol lowing diagram commutes

r

t t

r

r

r r

ft t

ft t

n

n





t F t t t

n n

f

n



f t t t f t

n

n

We are now in a p osition to state Web ers coherence conjecture and his pro of This

attempts to show that when the aforementioned assumptions hold true then wehavea

coherenttyp e system We shall give more assumptions and a prop er pro of in section

Conjecture Web ers coherence conjecture Assume that al l coercions be

tween ground types are only built by one of the fol lowing mechanisms

coercions between base types

coercions induced by structural coercions

direct embeddings in a type constructor

composition of coercions

coercions identity function on ground types as

If assumptions and are satised then the set of ground

types as objects and the coercions between them as arrows form a category which is a

preorder

Chapter Coherence The coherence theorem

This is the pro of of this conjecture given in Webb Weba Web

Webers Proof By assumption and lemma the set of ground typ es

as ob jects and the co ercions b etween them form a category

For anytwogroundtyp es t and t we will proveby induction on max com t com t

that if t t are co ercions then

If maxcom t com t then the claim follows by assumption Now assume

that the inductivehyp othesis holds for k and let max com t com t k Assume

t t are co ercions wlog that t t and that

Now t t com t comt So we may assume that t f u u for some

n

nary typ e constructor f

By assumption and the induction hyp othesis we can assume that there are ground

typ es s s and unique co ercions t s and t s such that either

F ts

f

or

i

f s

Similarly either

ts F

f

or

j

fs



If is of form and is of form then by assumption and the

uniqueness of F

f

If is of form and is of form then by assumption

Analogously if is of form and is of form

If is of form and is of form then assumption implies that i j and

s s Because of the induction hyp othesis wehave and hence again

by assumption 

The coherence theorem

In the ab ove pro of there seem to b e some irregularities

Chapter Coherence The coherence theorem

On co ercibility and complexity

Web er states in the pro of that

t t comt com t

Web er do es not prove this and indeed it is not true

Supp ose that f is an nary typ e constructor and that it is contravariant in its ith

p osition If

F s s t t f s s f t t

n n n n n

f

and t s with

i i i

coms maxcom s com s com s com s

i i i n

In other words coms istheuniquemaximum memb er of the set

i

fcom s j j f ngg

j

Then if com t com s and for all j in f ngnfig we have that s t we

i i j j

haveacounterexample Web ers claim that

comf s s comf t t

n n

Thus Web ers assertion is invalid

Structural co ercions in the pro of

In equation and similarly equation is given as a function

f t f s

however is supp osed to b e a function from t

Chapter Coherence The coherence theorem

Structural co ercions syntax

Web er calls the structural co ercion function from f s s to f t t

n n

F s s t t

n n n

f

where is from s to t or t to s dep ending on whether f is covariantorcontravariant

i i i i i

in its ith argument resp ectively

However this is merely the functorial action of f on the maps and could b e

n

represented more compactly as

f

n

The source and target of each and knowledge of the sets A and M uniquely de

i

f f

termine the source and target of f This also demonstrates the uniqueness

n

of f and guarantees that assumption holds

n

Identity co ercions

Web er states in assumption that the identity function is a co ercion However

he never proves this to b e unique Indeed automorphisms are p erfectly natural maps

t t

In a computer algebra system like Axiom many automorphisms are not automorphisms

of the smallest category to whichatyp e b elongs

For example the ringautomorphism ZX Y ZY X isnotaPolynomialCategory

homomorphism since for instance the leadingMonomial function is not preserved

under the map

For some categories like the category of groups this may not b e so easy to implement

We add the following sensible assumption

Assumption The only co ercion from a type to itself is the identity function

We shall of course allowanynumb er of functions from a typ e to itself including con

versions It is merely the numb er of co ercions whichwe are restricting

Chapter Coherence The coherence theorem

Comp osition of co ercions

It is p ossibly symptomatic of the previous errors that Web er has neglected to cover all

the p ossible cases of and

All our co ercions are comp ositions of co ercions or just a single co ercion from the list

co ercions b etween base typ es

co ercions induced by structural co ercions

direct emb eddings in a typ e constructor

identity function on ground typ es as co ercions

Supp ose that and that where and are single co ercions and

and are also comp ositions of co ercions may b e the identity co ercion as may

be

For a pro of by induction on com weneedtocover all the cases of pairs Thus

the list whichwe need to consider is

is a co ercion b etween base typ es is a co ercion b etween base typ es

is a co ercion b etween base typ es is a structural co ercion

is a co ercion b etween base typ es is a direct emb edding

is a co ercion b etween base typ es is an identity function

is a structural co ercion is a co ercion b etween base typ es

is a structural co ercion is a structural co ercion

is a structural co ercion is a direct emb edding

is a structural co ercion is an identity function

is a direct embedding is a co ercion b etween base typ es

is a direct embedding is a structural co ercion

is a direct embedding is a direct emb edding

is a direct embedding is an identity function

is an identity function is a co ercion b etween base typ es

Chapter Coherence The coherence theorem

is an identity function is a structural co ercion

is an identity function is a direct emb edding

is an identity function is an identity function

Firstly notice we are only interested in the pairs as unordered entities Thus some of

these cases are duplicates

Indeed case is case case is case case is case case is case case is

case case is case So wemay discard cases and

Now notice that a base typ e can not haveadirect emb edding neither can it induce a

structural co ercion If either or is co ercion b etween base typ es then the target of

and is a base typ e Hence the other can not be a direct emb edding nor can it

i

b e a structural co ercion

tly Thus wemay All the cases of this form are equivalently and equivalen

ignore these to o

Our remaining cases are and

To really prove the coherence theorem we are going to require some more assumptions

Only one of them is dicult to justify

We shall replace this rst assumption which uses Web ers denition of a direct

emb edding presently with our own denition In our denition assumption

shall always hold trivially

Assumption If a type constructor f has a direct embedding at its ith position

i

and f t t exists then t f t t

n i n

ft t

n

Web er denes a f to hav e a direct emb edding denition at a particular p osi

tion if there exists some ntuple of typ es t t for which t directly emb eds in

n i

f t t

n

This seems sensible if we consider a typ e constructor to be a function which returns

the carrier of the principal sort of the algebra Wearesaying that direct emb edding of

atyp e in a constructor is equivalenttosaying that a sort the principal sort

It is true that an Axiom typ e constructor returns the carrier of the principal sort of

the algebra but Axiom is more sp ecic than that The typ e constructor furnished with

full complement of arguments is the principal sort of the algebra

Chapter Coherence The coherence theorem

In fact it would be b etter to replace denition and assumption with the

following denition

Denition Let f be an nary type constructor If i

n

f ng ground types t there exists a coercion

i i

i

t f t t

i n

ft t

n

then we say that f has a direct emb edding at its ith p osition

eover let Mor

D fijf has a direct embedding at its ith position g

f

be the set of direct emb edding p ositions of f

The next assumption is undesirable due to its diculty to guarantee in any implemen

tation However it is provable in the more common covariant case and we shall prove

it in the pro of of the coherence theorem

We are assuming that structural co ercions b ehave conuently The assumption b elow

is stated to o strongly We shall state the assumption we really need

which is more complicated immediately after Assumption gives the idea of what

we require whereas assumption gives us what is necessary It is an assumption

ab out typ e constructors

Assumption Let the typeconstructor f induce a structural coercion If t

then if there t f s s t f u u are coercions and t f t

n n

n

exists

F s s t t f s s t

n n n

f

n

t F u u t t f u u

n n n

f

n

the fol lowing holds

F s s t t F u u t t

n n n n

f f

n n

Chapter Coherence The coherence theorem

or equivalently the fol lowing diagrams commute

f s s t

n

F s s t t

n n

f

n





F u u t t

n n

f

n

f u u t f t t

n

n

Now what we actually require Supp ose that a typ e t is not constructed bythenary

typ e constructor f which is contravariantinitsith p osition at which it also has a direct

emb edding

Supp ose also that t is co ercible to twotyp es whichmay b e directly embedded in f at

the ith p osition Let us directly embed them to gain two new typ es constructed by

f If these new typ es constructed by f can b oth b e structurally co erced to the same

typ e t also constructed by f then the two comp ositions of co ercions t t are the

same

Succinctly A structural co ercion of a direct emb edding of any other co ercion is unique

Assumption Let f be a type constructor c ontravariant at its ith position at

which it also has a direct embedding and let t be a type not constructed by f

If t a and t b are coercions and f a a f t t and

i i a n

a n

b

are structural coercions then f b b f t t

n

b

n

i i

a

b

b fb b a fa a

n n

or equivalently the fol lowing diagram commutes

Chapter Coherence The coherence theorem

t

a

b



a b

i i

i i

fb b fa a

n n

 

f a a f b b

n n

b

a



f t t

n

Notice that assumption is provable in the case that f is covariant at i and we

shall prove this in the pro of of the coherence theorem In the contravariant case

there is no link b etween t and t and it is this whichmake it an assumption

i

The following assumption is more easily ensurable We merely require that for two

typ es constructed by the same typ e constructor if there exists a co ercion between

them then it equals the structural co ercion between them which we now assume to

exist This is also an assumption on typ e constructors

Assumption If f s s f t t then there exists a structural coer

n n

cion f s s to f t t and it is the unique coercion f s s to

n n n

f t t

n

We are now nally in a p osition to state and prove the co ercion theorem

Theorem Coherence theorem Assume that al l coercions between ground

types are only built by one of the fol lowing mechanisms

coercions between base types

coercions induced by structural coercions

direct embeddings denition in a type constructor

composition of coercions

identity function on ground types as coercions

Chapter Coherence The coherence theorem

If assumptions and are satised

then the set of ground types as objects and the coercions between them as arrows form

a category which is a preorder

Proof By assumption and lemma the set of ground typ es as ob jects and

the co ercions b etween them form a category

All our co ercions are either an individual co ercion or a comp osition of nitely many

co ercions from the list co ercions b etween base typ es structural co ercions direct em

b eddings denition in a typ e constructor and identity functions

Thus wemay decomp ose any co ercion into such a nite comp osition We dene len

co ercions in any decomp osition of the length of to be the minimum number of

Clearly there are innitely manyvaluesoflen but there is a minimum value

For any two ground typ es t and t we will prove by induction on the length of the

co ercions b etween them that any co ercions b etween them are unique

Let t t b e co ercions

If the length of and is then replacing the unordered pair with we

need to lo ok at our eight cases and dened ab ove

Cases and If isabasetyp e co ercion then t and t are base typ es and co ercions

between base typ es are unique by assumption

Case and If is an identity function on a ground typ e then t t then by

assumption

Case If and are structural co ercions then and are equal by assumption

Case If is a direct emb edding and is a structural co ercion then there are two

cases

Case a is covariant Then by assumption

Case b is contravariant Thus t f t t and there exists i and a co ercion

n

t t This can not happ en since no comp osition of our four basic co ercions can create

i

such a co ercion

y assumption Case If and are direct emb eddings then b

Wenowmay assume that any co ercions of length less than or equal to k are unique

Supp ose that t t are co ercions and maxlen len k Also supp ose

that and where for i in f g we have s t are single

i i

atomic co ercions Also t s and t s are unique co ercions since their

Chapter Coherence The coherence theorem

lengths are less than or equal to k

If the length of or is then we dene or resp ectively to be the identity

function on t

As stated b efore there are eight cases and Wemay transp ose

and if we wish since their order is unimp ortant

Case is a co ercion b etween base typ es is a co ercion b etween base typ es Then

t s s are all base typ es Base typ es may only b e the targets of base typ e co ercions

hence t is a base typ e Thus and are co ercions between base typ es and are thus

equal by assumption

Case is a co ercion b etween base typ es is an identity function Again t and t

must b oth b e base typ es and and are equal by assumption

Case is a structural co ercion is a structural co ercion Let t f t t

n

If t is equal to some f t t then and are structural co ercions f t t to

n n

t f t t and hence are equal by assumption

n

Else we may assume that t f t t Since all our co ercions are built from

n

comp ositions of the four basic typ es of co ercion wemay consider and to b e chains

of comp ositions Without loss of generality assume that the length of is k and

the length of is l where l k

k

t h h h h t

k k

and

l

s s s t t s

l l

In b oth the comp osition chains of co ercions from t to t there must exist a minimal

elementofthechain which is constructed by f and this by assumption can not b e s

or h Also b ecause and are structural co ercions these minimal elements are not

h or s

k l

In the chain we shall assume that this elementish In the chain we shall assume

a

that this elementiss

b

Since h is constructed by f and h is not and is one of the four basic co ercions

a a a

it must be a direct emb edding It can not be a structural co ercion since h is not

a

constructed by f It is not a co ercion b etween base typ es b ecause h is constructed by

a

It is not an identity co ercion since h is not constructed by f whereas h is f

a a

Chapter Coherence The coherence theorem

Similarly is also a direct emb edding

b

Now by assumption the direct emb eddings must be at the same p osition We

shall assume that this p osition is the ith

Let h f a a and s f b b Call the unique structural co ercions

a n n

b

h t and s t Notice that h a and s b

a a a i i

b b b

Call the maps t h and t s where

a

b

a

b

a

a

and

b

b

If a or b equal then wemay insert an initial identity co ercion and lengthen the chain

byone This do es not aect our induction on length since we are always in go o d shap e

with identity co ercions Neither a nor b maybeby our assumption on t

Thus wehave the following diagram and we wish to prove that it commutes

t

a

b



h a s b

a i i

b

i i

fa a fb b

n n

 

s f b b h f a a

n a n

b

b

a



f t t

n

Case a f is covariant in the ith p osition

Consider the co ercions a t and b t Recall that t f t t

i i

n

i i

These must exist b ecause and lift them covariantly resp ectively

a

b

i

The denition of direct emb eddings guarantees the existence of

ft t

n

Chapter Coherence The coherence theorem

Nowby the denitions ab ove

i

a

fa a a

n

By assumption

i i

a

fa a

ft t

n

n

Thus

i

a

ft t

n

By induction on length we know that the co ercion t to t is unique Hence

i

a b

So

i

b

ft t

n

Assumption gives us

i i

b

fb b

ft t

n

n

Thus

i

b

b fb b

n

whichby denition means

Graphically the following is a commutative diagram

t

a

b



h a s b

a i i

b



i i

t

i

fa a fb b

n n

 

i

h f a a s f b b

a n n

b

ft t

n

b

a





t f t t

n

Case b f is contravariant in its ith p osition

Chapter Coherence The coherence theorem

There is nothing to link t and t in this case and wemust resort to assumption

i

t

a

b

t

i





h a s b

a i i

b

i i

fa a fb b

n n

 

h f a a s f b b

a n n

b

b

a



t f t t

n

Case is a direct emb edding is a structural co ercion

Case a is covariant Then bycaseaabove

If t Case b is contravariant Let s f s s and t f t

n n

s is the co ercion lifted contravariantly by where t

i i

F s t

f

i

i

Also

i

ft t

n

The uniqueness of implies that

i

fs s

 

n

By assumption wehave

i i

F s t

f

i fs s

i

ft t

 

n

n

Thus

i i

F s t

f

i fs s

i

ft t

 

n

n

Chapter Coherence The coherence theorem

and therefore

i

F s t

f

i

i

ft t

n

Hence

Case is a structural co ercion is an identity function Let t f t t

n

By viewing as the identity function

F t t t t id id

f

t

t

n n

n

Thus by case

is a direct emb edding is a direct emb edding Assumption implies Case

that the direct emb eddings must b e at the same p osition i Therefore s s So by

the inductivehyp othesis By assumption Hence

Case is a direct emb edding is an identity function Let t f t t

n

By viewing as the identity structural co ercion

id F t t t t id

f

t

t

n n

n

Thus by case ab ove

Case is an identity function is an identity function Thus and

However since s s by the inductivehyp othesis Hence

Thus wehaveproved for all co ercions of length less than or equal to k Hence

the result hold for all co ercions by induction 

In case b of the case when the length is we claimed that there can not be built a

co ercion from a typ e constructor to one of its arguments

From our description so far of Axiom one might think that Axiom would p ermit the

construction of the following typ e

FractionFractionInteger

which is the quotient eld of the quotienteldofintegers However the quotient eld

of a quotient eld is itself and hence

FractionInteger FractionFractionInteger

The quotienteldoftheintegers Z is more commonly known as the rationals Q

Chapter Coherence Extending the coherence theorem

For this reason Axiom contains sp ecial co de in the interpreter to stop such pathological

typ es b eing instantiated A Bo ot function isValidTypechecks to see if one is trying

to create a typ e liketheoneabove or

PolynomialPolynomialInteger

But this is handcrafted sp ecial co de covering afewcases and mentions the typ es by

name It is conceivable that a user could create a new typ e called MyFraction which

is identical to Fraction This would not b e picked up b e isValidType and thus

MyFractionMyFractionInteger

could b e instantiated Since the typ e is then isomorphic to one of its arguments it is

feasible that a co ercion between the two could be dened contradicting our claim in

case b of the case when the length is

This co ercion can still not be built from our four basic typ es thus dening such a

co ercion contradicts our assumptions for the coherence theorem

Extending the coherence theorem

Firstly Web ers pro of of his conjecture relies on induction on com t This

assumes that there are no typ es of innite complexity in our system This is not the

case in Axiom since one could dene the following typ es in one le

Rr Ring Ring r

D Ring RD

D Ring RD

though calling D would b e disastrous So we add the following extra assump

tion

Assumption There do not exist any types of nonnite complexity

The pro of of the coherence theorem do es not rely on typ e having nite complexity

wever it is still a sensible assumption to make and can b e easily guaranteed in a real Ho

implementation It is also imp erative that this assumption holds if the automated

co ercion algorithm is to terminate



This would try to create the constant from the ring D which can not b e evaluated

Chapter Coherence Extending the coherence theorem

Assumption states that wemayhave only one direct emb edding into an algebra

However in Polynomial Integer one would wish to p erform the direct emb eddings

of b oth of Integer and Symbolyet this violates assumption and thus wewould

not b e able to prove that our algebra system is coherent

The reason for Web ers assumption is to stop co ercions like the following o ccurring

If A is a group then b eing able to co erce A A A whilst p otentially useful is

ambiguous As he points out in Webb Weba Web A can be co erced into

A A via the isomorphisms A A I or A I A where I is the trivial subgroup

of A

In this example the inclusions are ambiguous since using either co ercion the target of

the inclusion is a group However in many cases the typ es are incomparable eg

Integer and Symbol and thus the assumption seems to be to o strong The question

is what do wemeanby incomparable

Certainly there is no co ercion function Integer Symbol or Symbol Integer But

for two distinct nontrivial prop er normal subgroups G H of A such that G H I

then there is no co ercion function AG AH or AH AGyet there then exists

AG is the two distinct co ercion functions A AG AH and coherency is lost

quotient group A factored out by G and is the set faG j a Ag where aG a G i

a a G Thus the condition of there not existing a co ercion function b etween our

twotyp es is not sucient for our denition of incomparability

However we notice that there exists no typ e which can b e co erced to b oth Symbol and

Integer but there do es exist homomorphisms A AG and A AH So if we

cho ose the statementTyp es A and B are incomparable if there do es not exist a typ e S

whichcan b e co erced to b oth A and Basa denition of incomparability then we are

in go o d shap e

We state this in the language of Web er as follows To replace the assumption we

rst need to alter denition our previous replacement of denition to the

following

Denition Let f be an nary type constructor If i

n

f ng ground types t there exists a coercion

i i

i

t f t t

i n

ft t

n

then we say that f has a direct emb edding at its ith p osition

Chapter Coherence Extending the coherence theorem

Moreover let s bea ground type and i f ng and dene

i

P i s s t t f t t

i i n

ft t

n

where is a coercion and also dene

D fi sjP i sg

f

Note then that D fijsP i sg Wenow alter assumption to the following

f

Assumption L et f beannary typeconstructor Then the fol lowing conditions

hold

i s j s D i j

f

i

Direct embedding coercions are unique ie if t f t t and

i n

ft t

n

i

t f t t then

i n

ft t

n

i i

ft t ft t

n n

So wemaynow extend the coherence theorem theorem by altering the assump

tion list to our new relaxed set of assumptions It is not necessary to reprove the entire

theorem but merely the cases whichinvolved assumption

Theorem Extended coherence theorem Assume that al l coercions between

ground types are only built by one of the fol lowing mechanisms

coercions between base types

coercions induced by structural coercions

direct embeddings denition in a type constructor

composition of coercions

identity function on ground types as coercions

If assumptions and are satis

ed then the set of ground types as objects and the coercions between them as arrows

form a category which is a preorder

Chapter Coherence Conclusion

Proof The entire pro of of theorem is valid except where assumption was

used

First we deal with the length of and b eing The only case which relied on

assumption was case

Case If and are direct emb eddings then by assumption

Now the induction case The only cases which relied on assumption were cases

and

Case In the pro of of theorem in this case we relied on assumption to

show that the two direct emb eddings h h and s s were at the same

a a

b b

p osition

h and t s by assumption the direct emb eddings must be Now since t

a

b

at the same p osition

Thus the rest of the pro of of this case holds

Case is a direct emb edding is a direct emb edding Since t s and t s

assumption implies that the direct emb eddings must be at the same p osition

i Therefore s s So by the inductive hyp othesis By assumption

Hence

Inserting the rest of the pro of of theorem completes the pro of 

Th us wehave relaxed an imp ortant one of the conditions of the coherence theorem

and proved that the theorem still holds

Conclusion

In this chapter we stated all the mathematics needed to state Web ers coherence con

jecture and give his pro of

Wehave also stated extra mathematics to correct the statement of the conjecture and

then prove it hence promoting it to a theorem We have then relaxed one of the

conditions and shown that the theorem still holds

This theorem is the cornerstone for ensuring correct co ercions

By having a coherent typ e system then provided we are careful in how we imple

ment our typ e constructors the must satisfy the assumptions and howwe create our

co ercions comp ositions of the four basic typ es all our co ercions are then unique

Chapter

The automated co ercion

algorithm

Intro duction

In this chapter we shall intro duce some extra mathematics which will allowustostate

the automated co ercion algorithm Furthermore this sound foundation will allowusto

demonstrate that all co ercions generated by the algorithm are in fact homomorphisms

Indeed wemayeven guarantee that these are co ercions in the sense of denition

All the work in this chapter is the authors own

Finitely generated algebras

In this section we shall dene what it means to say that an algebra is nitely generated

and also what it means to say that a nitely generated algebra is decomp osable

Denition Let beanordersorted S signature We say that S has a principal

sort if hSi denes an algebra which has one sort which without loss of generality

we shal l always assume to be S which is the most interesting of the algebra

By most interesting wemeanthata more nav e algebraist would consider this sort

to dene the entire algebra

For example if we dene to b e the Group algebra with sorts

the group a boolean sort an integer number system

Chapter The automated co ercion algorithm Finitely generated algebras

then the most interesting sort is the one for the group whichwould b e carried by

a set of all the group elements

All Axiom algebras must have a principal sort referred to as in the source co de One

can think of S as the sort that the Axiom co de constructs In the terminology

of chapter it is the typ e constructed by the typ e constructor Axiom views base

typ es as typ e constructors with no arguments

Denition We say that a theory hhSi Si is nitely generated i S has a

principal sort S and the fol lowing set is nite

nq S

nq

This states that given a nitely generated algebra hA i whichis a mo del for S

then there are a nite numb er of op erators which can return an element of the carrier

of the principal sort

This means that only nitely many functions directly construct the carrier of the

principal sort

The next denition allows us to decomp ose any element of such a algebra into at least

two pieces Moreover there exists such a decomp osition for each one of the nitely

many constructors Furthermore decomp osing such an element and recombining using

the corresp onding constructor is equivalent to the identity function

Denition A nitely generated theory hhSi Si is decomp osable i

nq S

i f ng

i i S q n

i

id S

S

For example in a an algebra of lists cons is a constructor The corresp onding functions

which decomp ose an elementarecar and cdr The following equation holds

conscarxcdrx x

Notice that this equation is only well formed when x is not the empty list For the

empty list which is constructed by the ary function nil there are no decomp osers

and the equation is as follows

Chapter The automated co ercion algorithm Constructibility

nil x

It is imp ortant to note that the part functions are usually partial functions For

i

example car is not dened on the empty list

Notice that wehave not yet dened a way of dierentiating b etween which constructors

construct which element We shall do this in the following section

Constructibility

We now come to the most imp ortant concept of this thesis The aim of this thesis is

to provide a metho d for creating co ercions constructively We now supply the means

do so

As usual weneedtomake some denitions rst We will state what wemeanbyan

algorithmically reconstructible algebra What we really mean is that an algebra is

algorithmically reconstructible if some subset of the elements of the most interesting

sortcarrier of that algebra can b e built up from a nite family of op erators

This nite family consists of constructors used to create increasingly large elements

of the principal sort

W e shall also have equations in the theory linking the constructors to part functions

whichwe shall use to split large elements into an ntuple of smaller elements The con

structor applied to its asso ciated part functions acting on an element will b e equivalent

to the identity function

We shall b e able to tell how an element is constructed by using a query function That

is to say we mustbeable to know which constructors may construct any particular

element of the principal sort

We require these denitions so that if an algebra is a mo del of some algorithmically

reconstructible theory and another algebra contains some of the constructors of the

rst algebra then some subset of the elements of the most interesting sortcarrier

We shall show this to be a can be co erced from the rst typ e to the second

homomorphism where is a particular signature to which b oth algebras b elong

We demand our extensions to be protecting extensions so that p erforming op erations

on an algebra or lo oking at equations of elements of that algebra when viewed as a

mo del of the original theory or the extension of the theory yield the same result

Denition We cal l a theory hhSi Si constructible i is a protecting exten

Chapter The automated co ercion algorithm Constructibility

sion of a nitely generated theory We then cal l a constructing signature and any

model for the theory a constructible algebra

Similarly

Denition We cal l a theory hhSi Si reconstructible i is a protecting ex

tension of a decomposable theory We then cal l a reconstructing signature and any

model for the theory a reconstructible algebra

Moreover

Denition If hhXi Xi is the decomposable theory extended by the recon

structible hhSi Si we dene the constructors of hhSi Si to be

C

We dene the constant constructors to be the constructors of arity denoted by

and the nonconstant constructors to betheconstructors of al l other arities We denote

C C

this set by n

C

We also dene the part functions of hhSi Si associatedwith to bethe

i

Constant constructors have no associated part functions

Final ly we dene the constructor equations to be the fol lowing set and demand it to be

a subset of S and hence X given by

C

f id j g

n S

We also need to ensure that certain other relationships between constructors which

hold in our source algebra hold in our target algebra

If an element of the source algebra may b e constructed in more than one waywe require

that reconstructing that element in the target algebra using any of those metho ds yields

the same result

Notice that since our theories are protecting extensions we are in go o d shap e since

any equation that holds in the protecting extension which concerns only the sorts from

must hold in the original signature Thus these the original unextended signature

equations will hold in the target algebra

We call these equations that link dierent constructors together the secondary con

structor equations

Chapter The automated co ercion algorithm Constructibility

Denition We cal l a reconstructible theory hhSi Si algorithmically recon

structible i S contains a boolean sort B contains a set of symbols cal led the

query functions denoted and dened by

Q C

f j g

S B

and S contains the fol lowing equations cal led the query equations

C

a a T

n nq S nq S

nq S

C

We also demand that for each in

nq S

a a a a F

n nq S n

nq S

Final ly we demand that al l secondary constructor equations are dened in the theory

A secondary constructor equation is any equation which has a constructor as the nal

symbol on both right and left sides

Wesay nal symb ol to mean this is op erator applied last In our notation functions

written on the left a nal symbol is written to the left of all the other elements of a

formula

For example and e e e b oth have as a nal symbol

In the algorithm we shall demand that the decomp osable theory whichbothtyp es mo del

is the smallest theory which they b oth mo del This is to ensure that the algorithm not

only creates a homomorphism but that it is a co ercion denition The pro of of

this is given in corollary

Example We shall take the varietyof Lists as our example and we shall assume

that List is a memb er of this variety Then the constructors for the mo del are nil and

cons where nil is a constant constructor whereas cons is a nonconstant constructor

cons asso ciated partfunctions are car and cdr Thus we have the constructor equa

tion

conscarx cdr x id x

The query functions are null and consp and our query equations are

Chapter The automated co ercion algorithm Constructibility

nullnilT

and for any list l and any element of the underlying typ e i

conspconsi l T

Notice also that conspnilF and also for the same l and i nullconsi l F

It is nowworth discussing some of the ner p oints of homomorphism

For to be a homomorphism we require that the constructor functions are preserved

by homomorphism We do not require that the part or query functions are homomor

phically preserved indeed wedonoteven require that they are in the signature of the

algebra of the target of

Thus we do not require that b oth the source and target of are mo dels of the same

algorithmically reconstructible theory but that the source is mo del of an algorithmically

reconstructible theory T and that all the constructors of T are functions of the target

of inherited from the same signature theory

This is an imp ortant point As an example we shall consider p olynomial rings A

p olynomial is a function suchas

x y xy x y

That is a sum of pro ducts of an element of the underlying ring which in the ab ove

example might b e the integers and variables raised to nonnegativepowers A mono

mial is a p olynomial which is a pro duct of a nonzero element of the underlying ring

and variables raised to nonnegativepowers

A p olynomial ring is ordered by an extension of the order on the variables In particular

is greater than another m if the exp onent of in Zx y if xy then a monomial m

x is greater in m than in m Should the exp onent of x be equal in both then the

exp onentofy is compared in the same manner

The leading monomial of a p olynomial is the largest monomial of a p olynomial If

xy in the ab ove p olynomial then x y is the leading monomial Should yxthen

the leading monomial would b e xy

The reductum of a p olynomial is the p olynomial less its leading monomial

Chapter The automated co ercion algorithm The algorithm

Co ercions between two p olynomial rings need only use leadingMonomial as a part

function which is not preserved via homomorphism since it dep ends on the order

ing given to the variables instead of some unnatural xed for all p olynomial rings

with variable from a xed domain mostimp ortantmonomial function whichwould

cho ose the same monomial regardless of variable ordering

Also this allows us to form the natural monomorphism from Qx to Zx which in

Axiom is

Polynomial Fraction Integer to Fraction Polynomial Integer

which are in Axioms view without clever hackery in the interpreter two unrelated

s This may be constructed without having to force to be a constructor of Ring

Fraction Polynomial Integer or indeed leadingMonomial etc to be available in

Fraction Polynomial Integer

The algorithm

We are now in a p osition to state the automated co ercion algorithm

The algorithm to create the co ercion will b e stated in English It is to o implementation

dep endent to state any ner

The actual algorithm to co erce will b e stated as Lisp pseudoco de In Lisp a b c

means apply the function a to the arguments bc cond is the like the switch

statement in C or Java

condsor switches are equivalent to ifthenelse statements if a condition is true

then we evaluate and return the following statement and leave the cond blo ck else

go to the next condition and rep eat

For example the line

x

S

S

means

if x then

S

S

The nal statement t is the default statement since t is always true This line will

only b e reached when all the other conditions have not b een satised and shows that

wehave failed to build a total automated co ercion function

Chapter The automated co ercion algorithm The algorithm

This could happ en if one fails to list all the constructors and their queries for a typ e

The lines of the form

x

S

S

check for the constants of the typ e For example the constant p olynomial can

not be constructed using a nonzero number of parts using any normal construction

metho dology thus co ercing from Qxto Zxwe mightsay

if zeroxPolynomial Fraction Integer

then zeroFraction Polynomial Integer

returning the appropriate in Zx

The lines of the form

x x x

q q

n n

nq S

nq S nq S

nq S

are the constructing lines For example in a p olynomial ring wemightwrite

if x is the sum of a monomial and a p olynomial

then coerceleadingMonomialx coercereductumx

where the addition function is that taken from the target domain

In this case leadingMonomialx and reductumx are b oth p olynomials In general

the parts of the element need not b e of the same typ e as the original element

For example in List algebras co ercing from ListA to ListB where there exists

or we can build a co ercion from A to B then wehave back in Lisp terminology

consp x cons coerce car x coerce cdr x

car x is the rst element of the list and is of typ e A rather than ListA the typ e

ybeconsed on to the frontof of x So coerce car x is of typ e B and thus ma

coerce cdr x whichisoftyp e ListB

Algorithm The Automated Co ercion Algorithm Let hA i be a model

for the algorithmical ly reconstructible theory hhSi Si

Chapter The automated co ercion algorithm The algorithm

Let hB i be a model of hhDi Di where hhSi Si is a protecting extension of

hhDi Di and some or al l of the constructors of hhSi Si are in fact in hhDi Di

Also we demand that theredoes not exist an extension of hhDi Di which both hA i

and hB i model

Then the fol lowing is an algorithm to coerce from hA i to hB i

The for i are the potential ly automated coercions from A to B from the

i i i

abstract type of S

i

The entire morphism created thus is cal led and not only is it a homomorphism it is

a coercion denition

x cond

x

S

S

Repeat for each in

S

x x x

q q

n n

nq S

nq S nq S

nq S

C

Repeat for each in

nq S

t error

The algorithm to create the coercion is

createCoercehA ihB i

determine hhDi Di error if doesnt exist

determine hhSi Si error if doesnt exist

determine

for

determine

determine

C

determine

C

for

determine

determine

determine for all relevant i

i

construct and return as defined above

So the algorithm presented ab ove allows us to algorithmically reconstruct elements of

one typ e as elements of another

Chapter The automated co ercion algorithm Existence of the co ercion

Existence of the co ercion

Before we prove that the automated co ercion algorithm constructs a co ercion when one

exists wemust prove that it do es not create some unnatural function when no co ercion

exists

We shall use the terminology of algorithm in this section

In the simplest case some of the functions will not exist in the target typ e and the

algorithm will error at an early stage This will be b ecause there is no hhDi Di

which b oth hA i and hB i mo del

If a homomorphism exists but not a co ercion then this means that there exists an

extension of hhDi Di whichboth hA i and hB i mo del In this case the algorithm

will error at an early stage

A i are available in hB i but no homomorphism co ercion If all the constructors of h

exists then this could b e b ecause of the at least one of the following causes

One of the co ercions to be used do es not exist

At least one of typ es which is required for construction or recursively required for

construction and whichisnot the carrier of the principal sort may not be co ercible

to its counterpart in the target Provided the algorithm checks at construction time

that every co ercion used directly or indirectly by exists or is constructible then we

i

may rep ort an error at an early stage

Nonhomomorphic constructors

The fact that hhSi Si is a protecting extension of hhDi Di and that all sec

ondary constructor equations hold in hhSi Si guarantees that these equations hold

in hhDi Di and hence in hB i

This not only ensures that the order of the lines in is unimp ortant but also that if

a certain relationship holds in hA i it must hold in hB i

For example if someone denes that all nite eld algebras are constructed by and

succ the successor function the automated co ercion algorithm will not attempt to

create the co ercion Z Z This is b ecause there exists a secondary constructor

equation in the theory of nite elds of size n

Chapter The automated co ercion algorithm Proving co erciveness

n

succ

So in this example hA i Z and hB i Z The equation succ holds in

the theory of nite elds of size Z is a obviously a mo del for this theory

This equation is not true in any theory whichtheab ove theory extends and of which

Z is a mo del Otherwise the equation would hold in Z and that patently is not true

Thus the automated co ercion algorithm will error at an early stage from not b eing able

to nd hhDi Di

Proving homomorphicity and co erciveness

We now make some notational denitions so that we may prove the nal result of

That is we shall show that algorithm constructs a homomorphism the chapter

theorem which is a co ercion corollary

Recall notation Thus for any constructor symbol the asso ciated construc

nq S

the query function is and for i f ng tor function in hA i is

nq S

nq S

the part functions are

i

nq S

Denition For a term t in a term algebra T X if

t X then lengtht

s

t then lengtht

s

t t t then lengtht lengtht lengtht

n n

This denition of length of an element will form the basis of our inductive pro of of the

automated co ercion algorithm However in general we shall not b e dealing with term

algebras but their homomorphic images

Denition For x an element of a algebra we dene

lengthx min ft T X j txg

where is the unique homomorphism given in the rst universality theorem

Chapter The automated co ercion algorithm Proving co erciveness

corresponds to Assumption If one of the part functions

i

S S

nq S

thus q S then we demand that

i

t length t t T X length

i

nq S

where is the unique homomorphism given in the rst universality theorem

A couple of technical denitions to make the next assumption easier to understand

Denition Suppose hA i is a constructe d algebra constructed by the S sorted

signature If for any i f jS jg we have that S appears in the arity of any of

i

the constructors of we say that A is required for construction by A

i

So for example in ListInteger we have that Integer is required for construction

since it is an argument of cons Notice that ListInteger is not required for con

struction itself since it is the carrier of S

Denition Suppose hA i is a constructed algebra c onstructed by the S sorted

signature Let A berequiredforconstruction by A Now consider A as the carrier

i i

of the principal sort of hB i a constructed algebra

If B is required for construction by B A hence j then we say that B is

j i j

recursively required for construction by A

Now suppose that the carrier D of the principal sort of aconstructed algebra hD i is

recursively required for construction by A If D is required for construction by D

k

then we also say that D is recursively required for construction by A

k

So for example in ListListInteger the only typ e which is required for construc

tion is ListInteger since this is the only argumentof cons which is not the carrier

of the principal sort ListListInteger

Thus the only typ es which are recursively required for construction are ListInteger

and the typ es which are recursively required for construction by ListInteger

Since Integer is the only typ e required for construction by ListInteger it is the

only typ e recursively required for construction by ListInteger

ListListInteger Thus the typ es which are recursively required for construction by

are ListInteger and Integer

The following assumption is required so that wemayprove that the automated co ercion

algorithm terminates

Chapter The automated co ercion algorithm Proving co erciveness

Assumption We demand that A is not recursively required for construction

Theorem Let hhSi Si be an algorithmical ly reconstructible theory which is a

C

protecting extension of the theory hhXi Xi such that

Let hB i bea model for hhXi Xi and hA i be a model for hhSi Si

is a homomorphism hA i hB i Then the function given in algorithm

Proof

Let b e the correct homomorphism which is attempting to emulate

Since contains nitely many cases and covers all cases of constructors for we

need only consider one line from Also by induction on com twe can assume that

i f jS jg

i i

Since covers all cases of constructor for we do not need to consider the error line

since it will never b e reached

For we may induct on length and we are in go o d shap e by assumption on

length and on the interaction b etween length and com

Here is one line from

if a a a

c p c p

q c n n

Now assuming awe knowthat

q

a a a

p p

c n

then since is a homomorphism

a a a a

c p p p c p

n n c n c

Now we knowthatby our induction argument

a a a

c p c p c p c p

c n n c n n

a

whence for this line and therefore every line and the entire function a

a So by induction and thus is a homomorphism 

Now by adding one extra condition we may prove that the automated co ercion algo

rithm generates co ercions in the sense of denition

Chapter The automated co ercion algorithm Conclusion

Corollary Let hhSi Si be an algorithmical ly reconstructible theory which is

C

a protecting extension of the theory hhXi Xi such that

Let hB i be a model for hhXi Xi and hA i be a model for hhSi Si such that

there does not exist any extension of hhXi Xi which both hA i and hB i model

Then the function given in algorithm is a coercion hA i hB i

Proof No other theories extend hhXi Xi whichboth hA i and hB i mo del so

the only thing which could stop b eing a co ercion would b e for there to exist a theory

which b oth hA i and hB i weretomodelwhichwas not extended by hhXi Xi

So supp ose for a contradiction hA i and hB i were to mo del a theory which

hhXi Xi do es not extend then wemaymanufacture a new theory containing all the

sorts op erator symb ols and equations of b oth theories

We may have some duplication of sorts and op erators so this manufacturing pro cess

would need to be p erformed intelligently Explicitly and hhXi Xi may b oth be

extensions of some theory We might but not always only wish our manufactured

theory to contain the sorts op erator symb ols and equations of once not twice

This new theory would clearly extend hhXi Xi and hA i and hB i would b oth

mo del this new theory Hence wehave a contradiction and such an can not exist

So hhXi Xi m ust sp ecify the unique smallest variety to which both hA i and

hB i b elong We already know by theorem that is a homomorphism by

denition it must b e a co ercion 

This is why algorithm lo oks for hhDi Di since it must sp ecify the smallest

variety to whichboth hA i and hB i b elong

Conclusion

In conclusion we have shown that it is p ossible to create a homomorphism between

yp es twotyp es from an imp ortant subset of t

Moreover this homomorphism may b e constructed algorithmically and hence the gen

eral construction of homomorphisms is implementable on a computer

Furthermore if the typ e system adheres to all the assumptions made and the homo

morphism is from the theory which sp ecies the smallest variety to whichbothtyp es

b elong then it is the unique coercion between the twotyp es

The theory of rings inherits from the theory of monoids twice

Chapter

Implementation details

Intro duction

In this chapter we shall discuss the implementation details of the automated co ercion

algorithm Axiom version a was chosen as the computer algebra system for this

work The only other options would have been

Magma

writing an entirely new computer algebra system from scratch

extending another computer algebra system eg Reduce

These were the only options since a computer algebra system with a notion of typ es

and typ es of typ es falling either into a category theorylike framework or a universal

algebra set up was required

Axiom and Magma are the only two systems which are currently based on these sound

principles and it was thought that either extending Reduce to be Axiomesque or

writing a new ordersorted algebra system were beyond the scop e of the pro ject

Since the source co de for Axiom a was made available byNAG to the author this

was the soundest choice

Bo ot and Axiom

Versions to a of Axiom were based on Austin Kyoto Common Lisp AKCL

Previous versions of Scratchpad were built on top of other Lisps and since AKCL is

Chapter Implementation details The top level

now GNU Common Lisp GCL and covered by the GNU Public Licence GPL future

versions of Axiom including the current version are to be based on Co demist

Common Lisp CCL

This has had a useful side eect CCL is a far smaller faster and more mo dern

implementation of Common Lisp This means that Axioms fo otprintisnow far smaller

than it has b een in the past

Axiom has b een said to have been b orn big it initially only ran on large IBM

mainframes With the advent of CCL based Axiom it now runs on the humble PC

This is true whether the PC is running an op erating system likeLinux or whether it is

running Windows or NT

AKCLbased The hardware This research was p erformed on Axiom a which is

used was usually an IBM RS running AIX and o ccasionally a Sparc Server

running Solaris

Axiom is built in the following manner Bo ot is a syntacticallysugared interpreted or

compiled form of Lisp Bo ot retains all the functionality of AKCL with a lot more

thrown in A lot of these extra features are there for historical reasons for example

there are plenty of functions to allow co de written in VMLisp to continue to run Some

are there to genuinely extend the usability of the language

The Axiom interpreter is written in Bo ot and hence any alteration to the Axiom world

must b e written in Bo ot

Compiled libraries of co de Packages Domains Categories are either written in Spad

or Aldor These are the strict languages which dene the typ es algebras and theories

of Axiom They may b e compiled and loaded into the Axiom interpreter

The Axiom interpreter itself contains many features not available to the Package etc

writer In b oth Spad and Aldor strong typ es are the order of the day The interpreter

is meant to b e a bit more userfriendly Hence typ e inference and onthey co ercions

are available to the user in the interpreter

So for this research the co de had to b e written in Bo ot

The top level

The basic design was as follows To p erform a co ercion from a Domain A to a Domain

B one needs to be able to ascertain which constants queries constructors and part

functions are available to b oth A and B These functions should all come from the same

Chapter Implementation details Lab elling op erators

algorithmically reconstructible theory Category

The automated co ercion function should be created and then compiled and stored

away ready for fast access in case of future use Such items are called cached lamb

das or clams for short and are already part of the Axiom system Thus this was

implemented

The automated co ercion function should b e integrated with the current co ercion mech

anism in Axiom This was done by inserting the relevant line at the correct p oint of

the Bo ot function coerceInteractive

Lab elling op erators

part We had to decide on a mechanism to mark which op erators were constructors

functions etc

One metho d would have been to create subtyp es of the Axiom Domain Mapping

which would have b een infeasible requiring much rewriting of the Spad and Aldor

compilers This is also true of the metho d given in a later section

A Spad Domain contains the following parts

the name of the typ e constructor

a variable name Category pair for each of the parameters of the typ e con

structor

a Category or Join intersection of Categories to whichthe Domain b elongs

a list of additional op erator symb ols functions for the typ e

a list of metho ds for some of or all the op erator symb ols of the typ e

Every op erator symbol denition in a Domain or Category and hence available in a

Domain of that Category has a certain number of sp ecial comments called com

ments

These comments as opp osed to ordinary comments in most languages and Axioms

other style of comments comments are parsed by the compiler to pro duce the

Occasionally a variable name Domain pair For example IntegerModpPositiveInteger



This is not the same as all the sorts of the signature One may declare extra unused sorts Also

wemay declare a function where the source or the target maycontain a ground typ e For example

functions which return a b o oleanliketyp e are usually declared to return Boolean rather than a pair

where the Category is the Category of b o oleanliketyp es

Chapter Implementation details Getting information from domains

do cumentation for Axioms sophisticated online help system Hyp erDo c Hyp erDo c

was one of the rst hyp ertext systems

This parsing of the comments allowed us to enter sp ecial keywords for each sp ecial

function whichwere read and stored at compile time for each Domain We could then

read them at runtime using the Axiom interpreters built in comments reader

Getting information from domains

The comments were gathered for a Domain by recursion up the Category inher

itance lattice using the GETDATABASE function We asked the database for all the

do cumentation for each Category and then asking which Categories it extended

The do cumentation includes all the functions and their resp ective comments This

allowed the automated searc hing for keywords and hence the sp ecial functions of a

Domain

Note that we only needed the comments for functions op erator symb ols declared in a

Category Functions declared in Domains are of no interest to the automated co ercion

algorithm This is b ecause these do not corresp ond to any of the sp ecial functions

constructors part functions or queries of a signature or theory

The keywords were checked quite simply b eing memb ers of the following list

listconstantconstructorpartquery

Part number checking was only slightly more dicult with each number having to be

converted from a Lisp string to a Lisp integer A restriction was placed on queries

that they must be called the same as their asso ciated constant or constructor but

with a app ended This restriction was not necessary and could havebeenworked

around easily

The sp ecial function lists from b oth Domainswere compared and the required functions

were extracted from b oth

Checking information from domains

For each sp ecial function a check was p erformed to see whether that function was

really available in the Domain

Chapter Implementation details Flaws in the implementation

The envisaged problem was that Axioms Categories can be conditional that is to

say some function denitions only exist if certain relationships hold for the Categorys

parameters

GETDATABASE ignores the parameters to a Category and returns all the functions which

may b e exp orted byaDomain of that Category Hence the extra checkwas necessary

to ensure that the automated co ercion function did not try to include these unavailable

functions

Thus the homomorphism created by the automated co ercion algorithm was always

equivalent to denition of a conditional homomorphism given in section

Flaws in the implementation

The implementation was originally envisaged as a fully working piece of co de of pro

duction standard and hence shippable with a commercial release of Axiom For various

reasons outlined b elow only a working prototyp e was implemented

Delib erate restrictions placed by the author on the design were

Query function names were restricted to b e the name of their asso ciated constant

function with a app ended

The numb er of non ary constructors was limited to one

Recursion through coerceInteractive was achieved using nave means

Neither the existence of hhSi Si nor hhDi Di were checked See algo

rithm for the meaning of these

Both the rst two items could have easily b een worked around but would have required

a more complex comment reader This was considered to b e a minor detail which

would have required to o much implementation time

The third item was more problematic Attempts were made to remedy this situation

e re However the depth of knowledge needed to implement this correctly would hav

quired to o much time to learn This was the main factor in the downgrading of the

implementation to mere prototyp e status

It was a certain amount of navety on the authors part to assume that a pro duction

standard implementation of the automated co ercion Bo ot package was within the scop e

of this pro ject

Chapter Implementation details Flaws in the implementation

The metho d to work around the complexities of Axioms evaluation lo op was to add a

Spad Package which exp orted a function whichthencalledthe Bo ot function The

co de for this Package called NCoerce follows

Coercion Package

abbrev package NCOERCE NCoerce

NCoerceSource Type Target Type Exports Implementation where

Exports with

nCoerce Source Target

Implementation add

nCoercex Source Target

nCreateCoercexSourceTargetLisp

To call a function from a Package is relatively easy in Bo ot and uses the same syntax

as calling a function from a Domain

The function nCoerce ab ove then uses the Axiom Lisp syntax for calling a function

dened in Bo ot This breaking out of the Bo ot co de to call a Spad function which

then in turn calls Bo ot co de is most undesirable

However should an exp ert in the Axiom interpreter be given the Bo ot co de for the

automated co ercion algorithm then it is merely a matter of changing one line This

one line currently calls a function which creates lines of the form

nCoercexNCoerceSourceTarget

This somehow needs to b e changed to something which p erforms

coercexTarget

is the Axiom syntax meaning the previous function should return the following

typ e In this case coerce x to the typ e Target

The automated co ercion Bo ot package was only implemented to deal with Spad co de

and not Aldor co de This is b ecause Bo ot handles co de written in the two dierent

Chapter Implementation details Flaws in the implementation

languages in a dierent way There are dierent interfaces to the two internal repre

sentations of a Domain or a Category or Package

This again could have b een remedied but would have required to o much time com

pared with the prosp ective gain in functionality

Occasionally Axioms mo demap selection can get confused Mo demap selection is

Axioms metho d for selecting metho ds from an overloaded op erator name This causes

the automated co ercion package to fall over at a premature stage

The fourth item is a bit more dicult to solve The existence of hhSi Si is implicit

if a Domain has sp ecial functions It would also b e p ossible to check if b oth source and

target are b oth memb ers of a common Category using GETDATABASE It would even

to check that all the constructors of the source are from this Category be p ossible

Finallyitwould b e p ossible to ensure that this is the smallest such Category

However it would b e most problematical to determine whether hhSi Si is a protect

ing extension of hhDi Di or not

This is a more general problem than one which just applies to the automated co ercion

algorithm This is due to the fact that Axiom b elieves everything that you say One

may pro duce a Category and claim that it extends another Yet if Axioms Categories

were really varieties sp ecied by theories there would need to b e some wayofchecking

whether the equations in the original Category still held in the new one Similarly

Domains need not mo del the theory sp ecifying the variety Category to which they

have b een declared to b elong

The current situation in automated theorem proving means that Axiom will b elieveany

false assertions like those mentioned in the previous paragraph This is not a design

aw of either Axiom or the automated co ercion algorithm neither Axioms designers

nor I had any choice automated theorem proving has not yet advanced suciently

for us to take advantage of it Similarly and moreover Axiom will b elieve that any

function whichonemay implement called coerce is a valid co ercion

algorithm in the This means that in this implementation of the automated co ercion

current release of Axiom it would b e p ossible to create new co ercions b etween p o

tentially unrelated typ es or nonhomomorphically between similar typ es Using the

example from section we could create a co ercion Z Z

The present state of automated theorem proving technology with sp ecial reference

to Axiom is detailed in MS This pap er details recent research and nearfuture

directions for the sub ject

Chapter Implementation details Conclusion

Other aws which shall b e dealt with in chapter include

Some Axiom Categories do not agree with our notion of varieties sp ecied by

signatures or theories Sections

Axiom Domains have to o much in common with their Categories There is a

lack of distinction between op erator symbols and op erators Similarly between

sorts and carriers Sections

Conclusion

We conclude that the automated co ercion algorithm is probably implementable in the

Axiom interpreter It is certainly p ossible to create a version whichworks However it

would take someone with deep er knowledge of the co de to force a complete integration

of the current implementation with the Axiom interpreter

What wedohave is a pro of of concept If Category authors correctly lab el their op er

ators then the co ercion function do es the right thing It is only the p erfect integration

into the Axioms kernel that has not b een demonstrated

Chapter

Making Axiom algebraically

correct

Intro duction

In this chapter we shall discuss various details which need to be changed to make

a computer algebra system in this case Axiom more algebraically correct By

this we mean so that Axioms Categories behave more like our concept of varieties

sp ecied by ordersorted theories and that the Domains act more like our notion of

ordersorted algebras more correctly

Explicitly dened theories

In Axiom the Categories were originally intended to b e akin to varieties sp ecied by

signatures The Domainswere then meanttobelike algebras of those signatures This

seems in retrosp ect to have beenanoverambitious aim

The Categories do b ehave and lo ok to the casual observer liketheywere sp ecied by

multisorted algebraic typ e theories but there are some clear dierences

Op erator symbols and names

In Axiom if a category denes an op erator symbol then for all domains in that

nq s

of will b e category that op erator name

nq s nq s

nq s

Chapter Making Axiom algebraically correct Op erator symb ols and names

It may app ear to be not that much of a disadvantage to have such a restriction on

op erator names but an imp ortant case in mind is that of the monoid A ring has two

binary op erators over which it forms a monoid The only way in Axiom that we can

ensure this is to havetwo dierent monoidal categories A distinct disadvantage

If we allowed op erator symb ols to dier from op erator names then another Category

could extend Monoid in two dierentways

Syntactically this would be most dicult We would need a way of declaring the

two op erator symbols in Ring traditionally and as b eing from dierent op erator

symb ols in Group which extends Monoidand Monoid

For example we could write something like the following

Ring Category with M Monoid G Group

Operators from Monoid

M

M

Operators from Group

G

G

inv inv G

This would identify and with the binary op erator and identity element resp ectively

from Monoid Whereas and inv would be identied with the binary op erator

identity element and inverse function from Group

Notice that both the op erator symbol eg and both the source arity eg

and target eg sort are needed to uniquely identify the op erator These corresp ond

to q and s resp ectively We do not need to know n since this is deducible from q

A function in Axiom in either a Domain or Category is currently represented by name

target source comments Function declarations in Categories are normally of

the form

comments s q

s and q are reversed in Axioms internal representation of a function

Chapter Making Axiom algebraically correct Op erator symb ols and names

and once exp orted by a ground typ e ie genuine Axiom Domain with all parameters

to the Domain xed it b ecomes

s q

A A comments

nq s

where

nq s

For the co ercion algorithm we inserted sp ecial words in the comments eld to try and

mimic an op erator symb ol

Another approachmighthave b een to declare other typ es eg Constructorab which

are subtyp es of Mappingab

A far b etter approach is to extend the information contained within the function con

struct For initial denitions in Categories that is new op erators whichhave come

from this Category not ones which this Category may extend then the current

declaration metho d suces

However as in the ab ove Ring example for Categories whic h extend others then a

b etter metho d maybe

s q comments

where is the new op erator symb ol corresp onding to amember of where this

nq s

signature extends

We haveusedvariable names to avoid confusion One may wish to dene a Category

called DoubleMonoid where G is a Monoid instead of a Group Obviously no inv

op erator would b e available to sucha Category

The same terminology could also be used to dene sp ecic algebras Domains For

Zg is an additive example for all n in N nZ whose elements is the set fnz j z

group whereas S n the symmetric group on n elements is usually considered to b e

amultiplicative group

So for nZ wemight write

IntegersTimes n PositiveInteger Group

inv

Chapter Making Axiom algebraically correct Op erator symb ols and names

However for S nwe might write

SymmetricGroup n PositiveInteger Group

inv inv

In this example we can see the following prop osed metho dology for declaring op erator

names which corresp ond to op erator symbols

s q comments

nq s

The signature do es not need to be mentioned in each function denition since the

algebra is only declared to b e a mo del of one signature

This do es create more unnecessary confusion for DomainCategory writers but cor

rectness should overrule easeofuse It is also conceivable that this will have a negative

wever this is true of all eect on the amount of time it takes to compile a Domain Ho

typ echecking compilers

More imp ortantly it should not have any eect on runtime sp eed of execution This

should denitely b e the case if the internal representation is moved to something ap

proximating Axioms current order

s q comments

nq s

This puts the target and source closer and less op erations away from b eing discovered

Clearly in this prop osed metho dology the carriers of the source and target are not

mentioned explicitly in the function representation

To sp eed up functiontyp e lo okups mo demap selection each Domain could provide a

hash of sorts and carriers Indeed then the internal representation could b e

s q

A A comments

nq s

and then mo demap selection would b e as fast as in the currentversion of Axiom but

the hash could be used going in the other direction to determine s and q for the

automated co ercion algorithm

Chapter Making Axiom algebraically correct Moving certain op erators

Moving certain op erators

Another factor which stops Axiom acting totally homomorphically is that certain op er

ators app ear in Categories to o far up the inheritance lattice This is b est illustrated

by an example

In Axiom one often would like to b e able to convert Liststo Sets The Domain whose

items are nite sets or actually sometimes classes over some particular typ e is called

Set in Axiom

Sets and Lists in Axiom are both certainly nite collections which can be built by

adding in another elementatatime In List this maybeachieved using either cons or

append though obviously cons is far more ecient whereas Setscan b e built using

the sometimes noneective command insert

Axiom knows that Lists are sorted whereas Sets are not The problem which is

vious is that adding in a new element to a List will always increase immediately ob

the length of the List This is not true of Axioms nite Sets They b oth however get

the same elementcountingop erator from the same Category This function comes

from the the Category Aggregate whichis the most general typ e of collection in

Axiom

ListS for some xed S is a mo del of ListAggregate and SetS is a mo del of

FiniteSetAggregate Both of these theories are extensions of the theory Aggregate

Therefore if we had a homomorphism from Liststo Sets then the following equation

should hold yet it clearly do es not

since the left hand side is

and the right hand side is

fg

and unless the carrier sort of collection length is not NonNegativeInteger but a dif

ferent typ e one in which all elements are equal we will not be able to create any

homomorphisms from List to Set



This op eration inserts a p otentially new elementinto a set insertx s s fxg s x

Chapter Making Axiom algebraically correct Retyping certain sorts

In section we demanded that if the automated co ercion algorithm was to b e appli

cable in this case from ListS to SetS then ListAggregate would need to be a

protecting extension of Aggregate

It is clear that in ListAggregate the following equation holds

consab b

If this were a protecting extension then this equation would hold in Aggregate How

ever as wehave already observed

insertab b

when a b

Thus ListAggregate is not a protecting extension of Aggregate and the automated

co ercion algorithm can not b e applied

There are three obvious solutions

Disallow co ercions from List to Set Although we would still allow a non

homomorphic convert op erator

Move the elementcountingop eration further down the Category inheritance lat

tice until it do es not app ear in any Categories to which both List and Set

b elong Or if they do b oth b elong to this Category ensure that none of the part

functions constants queries or constructors are from this Category or anyofits

ancestors

Move the addingnewelementop eration further down the lattice in a similar

manner Thus cons and insert would not know anything ab out each other In

this case the automated co ercion algorithm would still not b e applicable

This is merely one example of manysuch op erators which could require moving

Retyping certain sorts

As in section this is b est illustrated by an example

In Axiom the Category Ring exp orts a function



Or an extension of Aggregate which b oth ListAggregate and FiniteSetAggregate extends

Chapter Making Axiom algebraically correct Sorts and their order

characteristic NonNegativeInteger

rememb ering that Axiom do es not dierentiate b etween sorts and carriers So imagine

the natural ringepimorphism Z Z Then the following equation should hold

characteristic characteristic

yet this is clearly is not the case since must send the Void sort to Void and thus the

left hand side must equal the characteristic of Z which is Whereas for the right

hand side wehave This is the natural map from N fg to itself This is of

course the identity map and hence the right hand side has the value

There is clearly something very wrong here There are two solutions the rst of which

is highly unsatisfactory

Stop characteristic b eing a function One could p ersuade it to b e an attribute

of the Ring

Alter the carrier of the return typ e of characteristic from NonNegativeInteger

to b eing a typ e with the same elements but a dierent idea of equality

This is one of many such cases in Axiom

Sorts and their order

We have b een discussing Axioms Category inheritance system as if it were a true

attempt at mo delling ordersorted algebra There are however two areas which are

distinctly missing from the Axiom mo del these are the sorts and their order

There is a distinct confusion in Axiom b etween sorts and carriers The author b elieves

that all Category denitions the signatures or theories whichspecifyvarieties should

not use genuine typ es at any p oint in the signatures or any other p oint These should

only o ccur in the Domainsofthat Category

For example many Categories assume that the only b o oleanlike typ e is Boolean

Similarly the typ es NonNegativeInteger PositiveInteger and Integer are often

assumed and are not parameters of a typ e

For the typ es Boolean NonNegativeInteger and PositiveInteger this is not nor

mally a complete disadvantage There are not likely to b e other algebras in our system

which b ehave similarly enough to replace these typ es

Chapter Making Axiom algebraically correct Sorts and their order

However there are co ercions between NonNegativeInteger PositiveInteger and

Integer in the obvious directions This then imp oses some order on the sorts of the

typ e which is not explicitly mentioned

Some of the sorts of an algebra are dened is always the principal sort and any

parameters of the Category are there to o Others however are merely mentioned in

function prototyp es signatures All should b e listed in a sortlist andor sortlattice

see b elow

Neglected sorts normally include those which are carried by the four typ es mentioned

ab ove However other typ es are often neglected to o These include List which is often

present so that elements of the typ e may b e constructed The underlying representa

tion of most typ es in a Lispbased system are often lists More seriously particular

p olynomial representations are sometimes present

There is no real mechanism built into Axiom to order the sorts of an signature Category

The order is implicit in Categorical inheritances such as CoercibleTo and

RetractibleTowhich give information on how the principal sort relates to some other

sorts

I b elieve that a more sensible waywould b e to declare a lattice like arrangementwith

the declaration of a Category Indeed this would then make the sortlist clear to o

since this is never explicitly dened either

For example we could add the syntax SortOrder to b e used as follows

ACategoryaAbB Category

with SortOrder

a

b

exportedFunction List A

or b etter SortOrder could b e a Category which could b e dened as assuming this

is compilable



According to Bro One problem is that it may not b e p ossible for the compiler to gure out

exactly what this construct will exp ort but it might still b e implementable

Chapter Making Axiom algebraically correct Altering Axioms databases

SortOrderls List Pair Type Category

for pr in ls repeat

coerce first pr second pr

This for lo op would not build the entire sort lattice for any particular category This

would b e b etter done by the compiler at compile time on a p erCategory or p erType

basis

Thus any Category which do es not extend SortOrder would be a nonordersorted

signature

Altering Axioms databases

Axiom has many built in databases for lo oking up comments functions attributes etc

from each Category or Domain These are usually text les with character number

keys for faster crossreferencing

Database and hashtable technology has certainly improved in vast amounts over re

cent years and is in fact quite an evolving area of computing Magma utilises many

dierent handwritten in C databases for the large number of precomputed tables

of facts needed by the mo dern discrete mathematician

Each Magma database utilises the fastest lo okup metho d available to the authors for

that particular task While Axioms metho d is not excessively slow it is also not

particularly fast

More imp ortantly from our p oint of view Axiom could have some extra databases to

aid the automated co ercion algorithm Sp ecically there could b e a database contain

ing for each Category a list of lists of sp ecial functions exp orted by that algebra

but not its ancestors This could just be also be a compiled fact ab out each algebra

but the lo okup overhead would b e greater

The restriction on only having functions from that Category and not its ancestors

sp ecial functions allows for the dynamic nature of Axioms Category system Without

this restriction altering a Category further up the lattice could cause the database

information to b ecome outdated for all of its descendants

Chapter Making Axiom algebraically correct Conclusion

Conclusion

Axiom behaves very similarly to a language based on order sorted theories and the

algebras that mo del them However there are some key areas in which Axiom diers

to the mathematical notions

We summarise these areas in the following table

Mathematical Notion Axiom

Op erator names need not be the Op erator names are always the

same as op erator symbols same as op erator symb ols

Co ercions are homomorphisms and Co ercions need not act like ho

hence act homomorphically on all momorphisms at all If it were

op erators p ossible to implement a univer

sal equationchecker then Axiom

would b e alright

A signature dep ends on its sort Category denitions do not explic

list and hence a sortlist is part itly list their sorts

of its denition

No algebras are mentioned in a sig Category denitions do dep end on

nature denition only sorts sp ecic Domains

The order on the sorts is part of Category denitions do not explic

the denition of a signature itly order their sorts

Wehave presented metho ds for addressing all of these dierences

Chapter

Conclusions

Intro duction

In this chapter we shall summarise the work wehave done and what problems wehave

managed to overcome We shall also saywhatfuturework may b e p erformed to extend

the ideas presented here

Summary of work done

In this section we shall summarise the work done in this thesis and what problems

these ideas overcome We shall split this down into the following sections

Category theory and order sorted algebra bases for computer algebra systems

Section

Representation and syntax of order sorted algebra Section

Coherence of a typ e system Section

The automated co ercion algorithm Section

Category theory and order sorted algebras as the bases for

sound strongly typ ed computer algebra systems

W ehaveshown why b oth category theory and order sorted algebra b oth provide solid

mo dels for the typ es systems found in computer algebra

Chapter Conclusions Summary of work done

In sections and wehave demonstrated the correlation b etween a computer

algebra typ e system and category theory See also app endix B

In sections and we have shown how a computer algebra typ e system corre

lates with order sorted algebra In section we extended the notion of order sorted

signatures to cover conditional signatures which o ccur in Axiom

We have mentioned some of the corresp ondence between category theory and order

sorted algebra section We have usually used order sorted algebra as our mo del

This is b ecause order sorted algebra more readily corresp onds to the algebraic inheri

tance mechanism This is mainly due to the order on the sorts whichisnot available

higher order in category theory Also category theory has more diculty expressing

p olymorphism

Representation and syntax issues of an order sorted algebra

based typ e system

In chapter we demonstrated various metho dologies for extending Axioms current

typ e system so that it may more closely mo del order sorted signatures and algebra

In section we showed how Axioms syntax may be extended so that a signature

may extend another more than once We also showed that this syntax could b e used

to uniquely identify op erator names with op erator symbols This then allows op erator

symb ols to dier from op erator names

In section we discussed how b oth the sort list and the order on the sorts could b e

intro duced to Axioms signatures

Sections and commented on how the Axiom signature tree may b e altered to

allow co ercions to act more homomorphically

Finallywe discussed how Axiom signatures could b e compiled to contain extra informa

tion whichwould enhance the sp eed of the automated co ercion algorithm section

On coherence

In chapter we rst stated all the mathematics used by Web er to state and prove

Web ers coherence conjecture sections and

In section we then showed that this pro of is not correct Weshowed that altering

a denition and adding a couple of new assumptions that let us prove the co ercion

Thus this solves an interesting class of multiple inheritance problem

Chapter Conclusions Future work and extensions

theorem

In section we then showed that it was p ossible to relax one of the assumptions

which Web er made and still have a coherent typ e system The extended coherence

theorem

The automated co ercion algorithm

In sections and we provided enough mathematics to show that the auto

mated co ercion algorithm section is an algorithm which returns a function

which is not only a homomorphism but a co ercion whichwe dened in denition

This homomorphism is unique in a coherent typ e system which we can guarantee

providing we can satisfy all the assumptions of the extended co ercion theorem

four basic typ es of co ercion given The homomorphism created may be built from the

in the statement of that theorem

In chapter we showed that a demonstration implementation of this algorithm is

p ossible in Axiom

Future work and extensions

Wehave presented in this thesis the basis for a mathematically sound computer algebra

system We have also shown that it would be p ossible to implement the automated

co ercion algorithm in such a system

At present there is no such system though Axiom and Magma come close

We have shown how Axioms syntax could be extended to allow it to mo del an order

sorted algebra system the author would b e most interested in implementing either a

future release of Axiom or mayb e a freeware Axiomlik e system

To implement a totally new Axiomlike system it would be nice to take advantage

of a language which already supp orts ob jects Thus such a system could be written

in C Str youto o Kin an implementation of EuLisp Level Pad or

Java Gra

However note that Java do es not allowmultiple inheritance amongst classes It do es

allow multiple inheritance from interfaces though Interfaces are always eectively

abstract classes

Thus a Java implementation of an Axiomlike computer algebra system would haveall

Chapter Conclusions Future work and extensions

Domains as classes and all Categories as interfaces

Axioms categories are not always abstract that is they maycontain implementations

of functions This is a go o d thing as it enforces certain truths ab out a particular

function

Forcing any imp ortant facts by making a class which implements a particular interface

would then ruin anychance of reattaining multiple inheritance This eectively means

that Javawould not make a sensible implementation language

A more serious omission of Java is that functions are not rst class ob jects This means

that the automated co ercion algorithm would b e unimplementable in an algebra system

with Java classes for ob jects

C is a tempting choice but the time for one p erson to implementtheentire system

in suchalowlevel language might make it infeasible The source co de for the Axiom

interpreter alone takes up over lines of Bo ot and Lisp co de

Youto o is an implementation of EuLisp Level whichdoes allow some forms of mul

a with tiple inheritance So while the temptation of using a fashionable language Jav

p otentially many more users is there to implement the new algebra system correctly

we see that Lisp is still the sensible choice

Access to OBJ and the Magma source co de would also prove interesting The author

would liketo see if the automated co ercion algorithm is easily implementable for any

system other than Axiom whichprovided all the original inspiration

Sticking with the current release of Axiom it would be nice to sp end a few hours

with one of the few exp erts who truly understand the Axiom interpreter This would

undoubtedly lead to a successful integration of the automated co ercion algorithm with

Axiom

However this would b e only available in the interpreter An implementation inside the

Aldor compiler would b e far more dicult and hence makeavery interesting research

pro ject

Future research by Martin MS and research students of Davenp ort should ensure

that Axioms theory lattice is guaranteed to b e mathematically correct Eventuallywe

mayeven b e able to prove that one theory is a protecting extension of another though

this may b e some years from now

Until such research is completed the accuracy of the automated co ercion algorithm

dep ends on the abilityof Category and Domain authors to adhere to to the assumptions



The not equals function is dened to b e notequals

Chapter Conclusions Future work and extensions

made in this thesis

App endix A

Extra category theory

A Intro duction

This app endix merely lists some extra category theory needed by app endix B

A Extra denitions

Denition A The constant functor c sends al l objects of J to c and al l arrows

to

c

J

Denition A The diagonal functor C C sends each object c c the

constant functor al l arrows f c c of C to the natural transformation f c

c A limit for F J C is a universal arrow hr ui from to F

Denition A Acategory is complete if given any smal l category J and any func

tor F J C then F has a limit

App endix B

Set theory

B Intro duction

The work in this section and sections B B and B is not strictly necessary for the

rest of this thesis however the author b elieves that it is necessary if one wishes to have

a strict foundation to ones computer algebra system

I also b elieve this work to b e necessary if one wishes to form categories of categories in

Axiom See section B

B Basics

We need not go into a precise axiomatisation of set theory or indeed class theory in

this thesis but merely p oint the reader towards some suitable references Dev for

ZermeloFraenkel set theory Ber for von NeumannBernays and BHFL for a

deep exp osition on many formulations of set theory

Mac Lane ML avoids this by letting categories only form over small and large

sets also known as sets and classes in von NeumannBernays set theory Briey

to formulate set theory in this fashion one tak es nave set theory and app ends the

existence of a xed set U called the Universe The universe has the following prop erties

x u U x U

u v U fu v g hu v iu v U

x U Px y U

y x

App endix B Set theory B Basics

the set of all nite ordinals is in U

if f a b is a surjective function with a U and b U thenb U

One then denes a set to b e a smal l set i it is a member of U

Thus he refers to the category with all categories as ob jects and all functors as

arrows as the metacategory of al l categories Metacategories are in his b o ok are

what would b e called categories if only their ob jects and arrows formed small or large

sets

Mac Lanes book b eing the denitive volume on category theory also refers to other

formulations of set theoryandeven mentions in passing Lawveres pap er Law In

that pap er Lawvere formulates eight axioms for categories and proves that if one has

a complete category denition A satisfying those axioms then it is equivalentto

the category of sets and mappings and moreover is unique

Lawvere continues further down this abstract path in his pap er Law which

attempts to axiomatise all of mathematics without recourse to any form of set theory

Herrlich and Strecker HS use von NeumannBernays to overcome the diculties

of having categories and metacategories They consider as we have that a category

may b e dened over any collection of ob jects and arrows

von NeumannBernays set theory intro duces the notion of class in an attempt to over

come the problems asso ciated with trying to form the set of all sets Any collection of

sets is a class but if A is a proper class that is a class which is not representable as a

set then there exists no class which has A as a memb er

It is for this reason that the authors of HS intro duce the notion of a conglomerate

They lo osely dene conglomerates to b e collections of classes of conglomerates and

say that they require that

Every class is a conglomerate

Conglomerates are closed under formation of ordered pairs unions intersections

complements disjoint unions and Cartesian pro ducts

However they also state that there is no conglomerate of all conglomerates and thus

they intro duce the term cartel for collections of conglomerates

It should b e noted that Lawveres pap er is extremely abstract in content and that it do es not even

formulate a traditional form of the relationship Indeed A B is dened to mean that there exists

a monomorphism A with co domain B and x A is dened via B Ax B xAxx



I b elievethattheymay only mean collections of classes or conglomerates representable by classes

and will take this meaning from here on

App endix B Set theory B Basics

Indeed we see that if we dene the authors concept of inductive classes as follows

we will be in good shape

Denition B Inductive classes An entity X is cal led a class i X is

a set

An entity X is cal ledaclass where is any ordinal number i an ordinal

numberal l members of X are class s

ordinal numbers X is a class X is a class

There is no reason for the following not to hold but the author can not prove it from

the denitions alone Thus we state it here as an axiom

Axiom B A nite col lection of class s is a class

So if wenow dene Cat as follows we will always b e able to nd a category in which

we can work rather than a metacategory Unless of course one still wishes to form

a category of al l categories or a category with itself as an ob ject We are just saying

that we can always nd a category large enough in whichwe can work

Many theoretical computer scientists do not b elieve that there really exists a problem

at all Davenp ort states in Dav

many mathematical sets are not represented in computing languages

quite as we would like For example the set Z and more seriouslyno

computer can really represent R

yet we often pretend that they can For example in most computer algebra systems

allow the existence calculation and manipulation of bignums integers larger than

the largest representable within one machine word In a lazily evaluated system one

might even allow the creation of integers larger than the number of molecules in the

universe let alone the usable workspace of any current computer Indeed this is already

commonplace

So just b ecause ones computer cannot representevery elementof Z do es not mean we

cannot have atyp e of al l integers

Davenp ort also states in Dav

One might think of the universe U as b eing the set of all p ossible data

ob jects or bitpatterns

App endix B Set theory B Inductive class approximation

Hence since everything with which we work is nite we would not be required to

do any more work at this p oint The author disagrees simply b ecause ones machine

contains only nitely may states do es not mean that we may assume that all of our

collections are small sets

B Inductive class approximation

In Axiom

S Set Any f g S insertSS

denes S to be a nite collection with itself as its sole element however it most

umber such certainly is not a small set In fact there do es not exist an ordinal n

that S is a class

So what use is the idea of inductive classes in this situation The metho d of inductive

class approximation allows us to identify the Ss on each side of a dening equation

with dierent approximations to the value of S

To demonstrate the metho d of inductive class approximation let us x C to b e a class

Now alter C by letting

C C fC g

The op eration on the right hand side is the traditional function and should be

familiar to set theorists from one of the rst three axioms of general set theory Ber

It is also used to dene successors in ordinal theory

As b efore there do es not exist an ordinal suchthat C is now a class What wemay

do is identify the C sontheright hand side with a copy of the original C andthus the

C on left is now a class For those myself included who do not like the idea of

the same symbol having dierentvalues in the same equation then here is a dierent

version

C C fC g

We now have an approximation to C Given any ordinal suchthatC is

an approximation to C then we dene C the th approximation via

C C fC g



An ordinal is an ordinal numberifitisasetMen

App endix B Set theory B Inductive classes and category theory

Thus we can always nd an approximation to C containing a large enough but

dierent approximation to C

In traditional notation

Od C C C

If we could continue inductively approximating ad innitum then we would reach a

limit ordinal Limc However C may still not b e equal to C

Limc

At rst glance this app ears to be neither a usable nor implementable idea however

for dealing with categories on a computer it is in fact a useful concept as we shall see

w b elo

B Inductive classes and category theory

The following mathematics presented here for the rst time denes a way for us to

always have a category of all the categories in whichwe currently wish to work It

allows for Axioms Category to b e a category and indeed by lazy representation to

b e a member of Category

Denition B For any ordinal number Cat is the category which has as ob

jects any category C for which both Ob jC and ArrC are representable as class s

The arrows of Cat are the functors between these categories

Prop osition B Cat is an object of Cat

Proof ordinal numb ers X is a class X is a class

Hence trivial 

So for example is an ob ject of Cat and Set is an ob ject of Cat

B Inductive classes categories and Axiom

tity functor for the category of all Categories in Supp ose we wish to dene the iden

Axiom We shall call this functor CopyCat

If we assume that Axioms Category is normally a Cat andwe wished for a category

whichwas parameterised bya Category then the mathematical way of representing

CopyCatC Category Category C

App endix B Set theory B Inductive classes categories and Axiom

is that CopyCat takes C a Cat but the CopyCat category is a Cat

Thus wenowhave Category as b oth a Cat and a Cat dep ending on whether we

have any instantiations of CopyCat or not We may carry on inductively changing

the approximation of Category to the category of all Categories should we have

CopyCatCopyCatCopyCat etc ad innitum and beyond but we shouldnt

need that on a computer

Obviously this is only a trivial example This mathematics is a neat trick and would

allow category theorists to p erform their research in Axiom

However Join is a functor from

Y

Category Category

nN

in Axiom so CopyCat dened ab ove is equivalent to Join acting on one argument

Axiom do es not consider Join to b e a functor since it is only dened in the compilers

and acts solely as syntax in the construction of new Categories

Bibliography

AKC GNU httpwwwgnuorg GNU the copyright owners of

AKCLGCL homepage on WWW

BCM W Bosma J Cannon and G Matthews Programming with algebraic

structures Design of the Magma language In Proceedings of the ISSAC

Conference pages ACM

Ber P Bernays Axiomatic Set Theory with a historical introduction by AA

Fraenkel Dover

BHFL Y BarHillel AA Fraenkel and Y Levy Foundations of set theory

Elsevier Science Publishing BV

BHPS RJ Bradford AC Hearn JA Padget andESchrufer Enlarging the

REDUCE domain of computation In Proceedings of the Symposium

on Symbolic and Algebraic Computation pages ACM

Bra RJ Bradford C Computer algebra Lecture Notes for nal

year undergraduate and masters course in computer algebra given at

the UniversityofBath

Bro M Broy Equational sp ecication of partial higherorder algebras Theo

retical Computer Science pages

Bro PA Broadb erry Private communication August

CGG BW Char KO Geddes GH Gonnet BL Leong MB Monagan and

SM Watt Maple V Language Reference Manual SpringerVerlag

Cro RL Crole Categories for types Cambridge University Press

Dav JH Davenp ort C Computing foundations Lecture Notes for a

second year undergraduate course in computing foundations given at the

UniversityofBath

Bibliography

Dav JH Davenp ort C Universal algebra Lecture Notes for second

year undergraduate and masters course in universal algebra given at the

UniversityofBath

Der Soft Warehouse Inc httpwwwderivecom Derives parent

companys homepage on WWW

Dev KJ Devlin Fundamentals of Contemporary Set Theory SpringerVerlag

DF JH Davenp ort and CR Faure The unknown in computer algebra

Programmirovanie pages pages January

DST JH Davenp ort Y Siret and E Tournier Computer Algebra Systems

and Algorithms for Algebraic Computation Academic Press second edi

tion

DT JH Davenp ort and BM Trager Scratchpads view of algebra I Basic

commutative algebra Technical Rep ort Computing Group Scho ol

of Mathematical Sciences University of Bath Bath England January

Eif Eiel httpwwweiffelcom Eiel homepage on WWW

JP tch Co demist Ltd httpwwwcodemisttc Co demist

Ltd homepage on WWW

JP tch Co demist REDUCE distribution information

httpwwwcodemisttcreduceJanuary Co demist Reduce

homepage on WWW

Fo d JK Fo deraro The Design of a Language for Algebraic Computation

Systems PhD thesis University of California at Berkeley

GAP The GAP Team Lehrstuhl D fur Mathematik RWTH Aachen Germany

and Scho ol of Mathematical and Computational Sciences U St Andrews

ogramming Version Scotland GAP Groups Algorithms and Pr

GJ JH Griesmer and RD Jenks SCRATCHPAD An interactive facility

for symbolic mathematics In SR Petrick editor Proceedings of the

Second Symposium for Symbolic and Algebraic ManipulationACM

Bibliography

GM JA Goguen and J Meseguer Completeness of manysorted equational

logic ACM Sigplan Notices pages January

GM JA Goguen and J Meseguer Ordersorted algebra I equational deduc

tion for multiple inheritance overloading exceptions and partial op era

tions Theoretical Computer Science pages

Gra M Grand Java Language Reference OReilly and Asso ciates second

edition

GWM Joseph A Goguen Timothy Winkler Jose Meseguer Kokichi Futatsugi

and JeanPierre Jouannaud Intro ducing OBJ Octob er

Har JF Harris Inheritance of rewrite rule structures applied to symb olic

computation In Proceedings of the ISSAC Conference pages

CM A

Hea AC Hearn Reduce a system and language for algebraic manipulation

In SR Petrick editor Proceedings of the Second Symposium for Symbolic

and Algebraic ManipulationACM

Hea AC Hearn Reduce Users Manual Version Numb er CP RAND

rev edition

HS H Herrlich and E Strecker Category Theory Allyn and Bacon Inc

HS AC Hearn and E Schrufer A computer algebra system based on order

sorted algebra Journal of Symbolic Computation pages

JanuaryFebruaryMarch Article received Septemb er

JS RD Jenks and J Sutor Axiom the scientic computation system

SpringerVerlag

JT RD Jenks and BM Trager How to make Axiom in to a Scratchpad In

Proceedings of the ISSAC Conference pages ACM

Kin A Kind youto o home page

httpwwwmathsbathacukakyoutoo youto o homepage

on WWW

KR BW Kernighan and DM Ritchie The C Programming Language

PrenticeHall second edition

Bibliography

KR E Kounalis and M Rusinowitch A pro of system for conditional alge

braic sp ecications In S Kaplan and M Okada editors Conditional

and Typed Rewriting Systems nd International CTRS Workshop Mon

treal Canada June Proceedingsnumb er in LNCS pages

SpringerVerlag

Law FW Lawvere An elementary theory of the category of sets In Pro

ceedings of the National Academy of Sciences USA volume pages

Law FW Lawvere The category of categories as a foundation of mathematics

dings of the conference on categorical algebra pages In Procee

Mac Inc httpwwwmacsymacom Macsyma homepage on

WWW

Mae RE Maeder Abstract data typ es The Mathematica Journal no

pages

Mar U Martin Private communication December

Men E Mendelson Introduction to Wadsworth and

Bro oksCole third edition edition

ML S Mac Lane Categories for the Working Mathematician Number in

Graduate Texts in Mathematics SpringerVerlag

MS U Martin and D Shand Investigating some emb edded

verication techniques for computer algebra systems In

Pr oceedings of THEOREMA Workshop volume of

RISCLinz technical report Also available at

httpwwwtheorydcsstandacukddshandPaperspubhtml

Neu W Neun REDUCE information httpwwwzibdeSymbolikreduce

Octob er ZIB Reduce homepage on WWW

Pad P Padawitz New results on completeness and consistency of abstract

data typ es In Mathematical Foundations of Computer Science Pro

ceedings of the th Symposium Held in Rydzyna Poland number in

LNCS pages SpringerVerlag

Bibliography

Pad JA Padget EuLisp FAQ

httpwwwbathacukmasjapEuLispeulisphtml EuLisp

homepage on WWW

Pla C Playoust The Magma system for al

gebra number theory and geometry

httpwwwmathsusydeduaucompmagmaOverviewhtml

Magma homepage on WWW

Ric DS Richardson Private communication December

Str A Strotmann REDUCE Home Page

httpwwwrrzunikoelndeREDUCE September Reduce

homepage on WWW

Str B Stroustrup The C Programming Language AddisonWesley third

edition

WBD a SM Watt PA Broadb erry SS Do oley P Iglio SC Morrison JM

Steinbach and RS Sutor Axiom Library Compiler User Guide Number

NP NAG st ed edition Novemb er

WBD b SM Watt PA Broadb erry SS Do oley P Iglio SC Morrison JM

Steinbach and RS Sutor A rst rep ort on the A compiler In Proceed

ings of the ISSAC Conference pages ACM

WCS L Wall T Christiansen and RL Schwartz Programming Perl OReilly

and Asso ciates second edition

Weba A Web er On coherence in computer algebra In

DISCO number in LNCS Also available at

httpwwwcainformatikunituebingendePEOPLEweber

ENTRIESpapershtml

Webb A Web er Type Systems for Computer Algebra

PhD thesis Tubingen Also available at

httpwwwcainformatikunituebingendePEOPLEweber

ENTRIESpapershtml

Web A Web er On coherence in computer algebra Journal of Symbolic

Computation JanuaryFebruaryMarch Also available at

httpwwwcainformatikunituebingendePEOPLEweber

ENTRIESpapershtml

Bibliography

WG T Weib el and G Gonnet An algebra of prop erties In Proceedings of the

ISSAC conference pages July Bonn

WG T Weib el and G Gonnet An assume facility for CAS with a sample

implementation for Maple In DISCO Conference Proceedings April

Bath

Wol S Wolfram Mathematica A System for doing Mathematics By Com

puter AddisonWesley nd edition