# 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 creatures, it is useful to distinguish two sorts: ${\displaystyle {\textit {plant}}}$ and ${\displaystyle {\textit {animal}}}$. While a function ${\displaystyle {\textit {mother}}:{\textit {animal}}\longrightarrow {\textit {animal}}}$ makes sense, a similar function ${\displaystyle {\textit {mother}}:{\textit {plant}}\longrightarrow {\textit {plant}}}$ usually does not. Many-sorted logic allows one to have terms like ${\displaystyle {\textit {mother}}({\textit {lassie}})}$, but to discard terms like ${\displaystyle {\textit {mother}}({\textit {my\_favorite\_oak}})}$ as syntactically ill-formed.

## Algebraization

The algebraization of many-sorted logic is explained in an article by Caleiro and Gonçalves,[1] 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 ${\displaystyle s_{1}}$ to be declared a subsort of another sort ${\displaystyle s_{2}}$, usually by writing ${\displaystyle s_{1}\subseteq s_{2}}$ or similar syntax. In the above example, it is desirable to declare

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

and so on.

Wherever a term of some sort ${\displaystyle s}$ is required, a term of any subsort of ${\displaystyle s}$ may be supplied instead. For example, assuming a function declaration ${\displaystyle {\textit {mother}}:{\textit {animal}}\longrightarrow {\textit {animal}}}$, and a constant declaration ${\displaystyle {\textit {lassie}}:{\textit {dog}}}$, the term ${\displaystyle {\textit {mother}}({\textit {lassie}})}$ is perfectly valid and has the sort ${\displaystyle {\textit {animal}}}$. In order to supply the information that the mother of a dog is a dog in turn, another declaration ${\displaystyle {\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 ${\displaystyle p_{i}(x)}$ for each sort ${\displaystyle s_{i}}$, and an axiom ${\displaystyle \forall x:p_{i}(x)\rightarrow p_{j}(x)}$ for each subsort declaration ${\displaystyle 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.[2]

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 ${\displaystyle s_{1},s_{2}}$ their intersection ${\displaystyle s_{1}\cap s_{2}}$ to be declared, too: if ${\displaystyle x_{1}}$ and ${\displaystyle x_{2}}$ is a variable of sort ${\displaystyle s_{1}}$ and ${\displaystyle s_{2}}$, respectively, the equation ${\displaystyle x_{1}{\stackrel {?}{=}}x_{2}}$ has the solution ${\displaystyle \{x_{1}=x,\;x_{2}=x\}}$, where ${\displaystyle x:s_{1}\cap s_{2}}$.

Smolka generalized order-sorted logic to allow for parametric polymorphism. [3][4] In his framework, subsort declarations are propagated to complex type expressions. As a programming example, a parametric sort ${\displaystyle {\textit {list}}(X)}$ may be declared (with ${\displaystyle X}$ being a type parameter as in a C++ template), and from a subsort declaration ${\displaystyle {\textit {int}}\subseteq {\textit {float}}}$ the relation ${\displaystyle {\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.[5] As an example, assuming subsort declarations ${\displaystyle {\textit {even}}\subseteq {\textit {int}}}$ and ${\displaystyle {\textit {odd}}\subseteq {\textit {int}}}$, a term declaration like ${\displaystyle \forall i:{\textit {int}}.\;(i+i):{\textit {even}}}$ allows to declare a property of integer addition that could not be expressed by ordinary overloading.
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 42, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://en.wikipedia.org/wiki/Many-sorted_logic", "fetch_time": 1495974392000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2017-22/segments/1495463609817.29/warc/CC-MAIN-20170528120617-20170528140617-00194.warc.gz", "warc_record_offset": 929680301, "warc_record_length": 17542, "token_count": 1378, "char_count": 5412, "score": 3.515625, "int_score": 4, "crawl": "CC-MAIN-2017-22", "snapshot_type": "latest", "language": "en", "language_score": 0.8502690196037292, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00007-of-00064.parquet"}