Section13.9

]>
Book Contents Previous Section 13.8 Add Domain Next Section 13.10 Origins Book Index

## 13.9 Defaults

In Chapter ugPackages we saw that categories can provide default implementations for their operations. How and when are they used? When Axiom finds that QuadraticForm(2, Fraction Integer) does not implement the operations *, +, and -, it goes to SquareMatrix(2,Fraction Integer) to find it. As it turns out, SquareMatrix(2, Fraction Integer) does not implement any of these operations!

What does Axiom do then? Here is its overall strategy. First, Axiom looks for a function in the capsule for the domain. If it is not there, Axiom looks in the add-domain for the operation. If that fails, Axiom searches the add-domain of the add-domain, and so on. If all those fail, it then searches the default packages for the categories of which the domain is a member. In the case of QuadraticForm, it searches AbelianGroup, then its parents, grandparents, and so on. If this fails, it then searches the default packages of the add-domain. Whenever a function is found, the search stops immediately and the function is returned. When all fails, the system calls error to report this unfortunate news to you. To find out the actual order of constructors searched for QuadraticForm, consult Browse: from the QuadraticForm, click on Cross Reference, then on Lineage.

Let's apply this search strategy for our example 3*q-q+q. The scalar multiplication comes first. Axiom finds a default implementation in AbelianGroup&. Remember from ugCategoriesDefaults that SemiGroup provides a default definition for x n by repeated squaring. AbelianGroup similarly provides a definition for n x by repeated doubling.

But the search of the defaults for QuadraticForm fails to find any + or * in the default packages for the ancestors of QuadraticForm. So it now searches among those for SquareMatrix. Category MatrixCategory, which provides a uniform interface for all matrix domains, is a grandparent of SquareMatrix and has a capsule defining many functions for matrices, including matrix addition, subtraction, and scalar multiplication. The default package MatrixCategory& is where the functions for + and - (from QuadraticForm) come from.

You can use Browse to discover where the operations for QuadraticForm are implemented. First, get the page describing QuadraticForm. With your mouse somewhere in this window, type a ``2'', press the Tab key, and then enter ``Fraction Integer'' to indicate that you want the domain QuadraticForm(2, Fraction Integer). Now click on Operations to get a table of operations and on * to get a page describing the * operation. Finally, click on implementation at the bottom.

Book Contents Previous Section 13.8 Add Domain Next Section 13.10 Origins Book Index