Section12.6

]>
Book Contents Previous Section 12.5 Membership Next Section 12.7 Axioms Book Index

## 12.6 Defaults

We actually omitted the last category:defaults part of the definition of default definitions SemiGroup in ugCategoriesHier . Here now is its complete Axiom definition.

SemiGroup(): Category == SetCategory with
"*": ($, $) -> $
"**": ($, PositiveInteger) -> $
add
import RepeatedSquaring($)
x: $ ** n: PositiveInteger == expt(x,n)

The add part at the end is used to give ``default definitions'' for add exported operations. Once you have a multiplication operation *, you can define exponentiation for positive integer exponents using repeated multiplication:

This definition for ** is called a default definition. In general, a category can give default definitions for any operation it exports. Since SemiGroup and all its category descendants in the hierarchy export **, any descendant category may redefine ** as well.

A domain of category SemiGroup (such as Integer) may or may not choose to define its own ** operation. If it does not, a default definition that is closest (in a ``tree-distance'' sense of the hierarchy) to the domain is chosen.

The part of the category definition following an add operation is a capsule, as discussed in the previous chapter. The line

import RepeatedSquaring($)

references the package RepeatedSquaring($), that is, the package RepeatedSquaring that takes ``this domain'' as its parameter. For example, if the semigroup Polynomial (Integer) does not define its own exponentiation operation, the definition used may come from the package RepeatedSquaring (Polynomial (Integer)). The next line gives the definition in terms of expt from that package.

The default definitions are collected to form a ``default package'' for the category. The name of the package is the same as the category but with an ampersand (&) added at the end. A default package always takes an additional argument relative to the category. Here is the definition of the default package SemiGroup& as automatically generated by Axiom from the above definition of SemiGroup.

SemiGroup_&($): Exports == Implementation where
$: SemiGroup
Exports == with
"**": ($, PositiveInteger) -> $
Implementation == add
import RepeatedSquaring($)
x:$ ** n:PositiveInteger == expt(x,n)
Book Contents Previous Section 12.5 Membership Next Section 12.7 Axioms Book Index