# Many-sorted logic

Many-sorted logic can reflect formally our intention not to handle the universe as a homogeneous collection of objects, but to partition it in a way that is similar to types in typeful programming. Both functional and assertive "parts of speech" in the language of the logic reflect this typeful partitioning of the universe, even on the syntax level: substitution and argument passing can be done only accordingly, respecting the "sorts".

There are more ways to formalize the intention mentioned above; a many-sorted logic is any package of information which fulfills it. In most cases, the following are given:

The domain of discourse of any structure of that signature is then fragmented into disjoint subsets, one for every sort.

## Example

When reasoning about biological organisms, it is useful to distinguish two sorts: ${\textit {plant}}$  and ${\textit {animal}}$ . While a function ${\textit {mother}}:{\textit {animal}}\longrightarrow {\textit {animal}}$  makes sense, a similar function ${\textit {mother}}:{\textit {plant}}\longrightarrow {\textit {plant}}$  usually does not. Many-sorted logic allows one to have terms like ${\textit {mother}}({\textit {lassie}})$ , but to discard terms like ${\textit {mother}}({\textit {my}}\_{\textit {favorite}}\_{\textit {oak}})$  as syntactically ill-formed.

## Algebraization

The algebraization of many-sorted logic is explained in an article by Caleiro and Gonçalves, which generalizes abstract algebraic logic to the many-sorted case, but can also be used as introductory material.

## Order-sorted logic

While many-sorted logic requires two distinct sorts to have disjoint universe sets, order-sorted logic allows one sort $s_{1}$  to be declared a subsort of another sort $s_{2}$ , usually by writing $s_{1}\subseteq s_{2}$  or similar syntax. In the above example, it is desirable to declare

${\textit {dog}}\subseteq {\textit {carnivore}}$ ,
${\textit {dog}}\subseteq {\textit {mammal}}$ ,
${\textit {carnivore}}\subseteq {\textit {animal}}$ ,
${\textit {mammal}}\subseteq {\textit {animal}}$ ,
${\textit {animal}}\subseteq {\textit {organism}}$ ,
${\textit {plant}}\subseteq {\textit {organism}}$ ,

and so on.

Wherever a term of some sort $s$  is required, a term of any subsort of $s$  may be supplied instead. For example, assuming a function declaration ${\textit {mother}}:{\textit {animal}}\longrightarrow {\textit {animal}}$ , and a constant declaration ${\textit {lassie}}:{\textit {dog}}$ , the term ${\textit {mother}}({\textit {lassie}})$  is perfectly valid and has the sort ${\textit {animal}}$ . In order to supply the information that the mother of a dog is a dog in turn, another declaration ${\textit {mother}}:{\textit {dog}}\longrightarrow {\textit {dog}}$  may be issued; this is called function overloading, similar to overloading in programming languages.

Order-sorted logic can be translated into unsorted logic, using a unary predicate $p_{i}(x)$  for each sort $s_{i}$ , and an axiom $\forall x(p_{i}(x)\rightarrow p_{j}(x))$  for each subsort declaration $s_{i}\subseteq s_{j}$ . The reverse approach was successful in automated theorem proving: in 1985, Christoph Walther could solve a then benchmark problem by translating it into order-sorted logic, thereby boiling it down an order of magnitude, as many unary predicates turned into sorts.

In order to incorporate order-sorted logic into a clause-based automated theorem prover, a corresponding order-sorted unification algorithm is necessary, which requires for any two declared sorts $s_{1},s_{2}$  their intersection $s_{1}\cap s_{2}$  to be declared, too: if $x_{1}$  and $x_{2}$  are variables of sort $s_{1}$  and $s_{2}$ , respectively, the equation $x_{1}{\stackrel {?}{=}}x_{2}$  has the solution $\{x_{1}=x,\;x_{2}=x\}$ , where $x:s_{1}\cap s_{2}$ .

Smolka generalized order-sorted logic to allow for parametric polymorphism.  In his framework, subsort declarations are propagated to complex type expressions. As a programming example, a parametric sort ${\textit {list}}(X)$  may be declared (with $X$  being a type parameter as in a C++ template), and from a subsort declaration ${\textit {int}}\subseteq {\textit {float}}$  the relation ${\textit {list}}({\textit {int}})\subseteq {\textit {list}}({\textit {float}})$  is automatically inferred, meaning that each list of integers is also a list of floats.

Schmidt-Schauß generalized order-sorted logic to allow for term declarations. As an example, assuming subsort declarations ${\textit {even}}\subseteq {\textit {int}}$  and ${\textit {odd}}\subseteq {\textit {int}}$ , a term declaration like $\forall i:{\textit {int}}.\;(i+i):{\textit {even}}$  allows to declare a property of integer addition that could not be expressed by ordinary overloading.