 x Arity Encyclopedia
In logic
Logic
In philosophy, Logic is the formal systematic study of the principles of valid inference and correct reasoning. Logic is used in most intellectual activities, but is studied primarily in the disciplines of philosophy, mathematics, semantics, and computer science...

, mathematics
Mathematics
Mathematics is the study of quantity, space, structure, and change. Mathematicians seek out patterns and formulate new conjectures. Mathematicians resolve the truth or falsity of conjectures by mathematical proofs, which are arguments sufficient to convince other mathematicians of their validity...

, and computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

, the arity of a function
Function (mathematics)
In mathematics, a function associates one quantity, the argument of the function, also known as the input, with another quantity, the value of the function, also known as the output. A function assigns exactly one output to each input. The argument and the value may be real numbers, but they can...

or operation
Operation (mathematics)
The general operation as explained on this page should not be confused with the more specific operators on vector spaces. For a notion in elementary mathematics, see arithmetic operation....

is the number of arguments or operand
Operand
In mathematics, an operand is the object of a mathematical operation, a quantity on which an operation is performed.-Example :The following arithmetic expression shows an example of operators and operands:3 + 6 = 9\;...

s that the function takes. The arity of a relation
Relation (mathematics)
In set theory and logic, a relation is a property that assigns truth values to k-tuples of individuals. Typically, the property describes a possible connection between the components of a k-tuple...

is the dimension of the domain in the corresponding Cartesian product
Cartesian product
In mathematics, a Cartesian product is a construction to build a new set out of a number of given sets. Each member of the Cartesian product corresponds to the selection of one element each in every one of those sets...

. The term springs from such words as unary, binary, ternary, etc.

The term "arity" is primarily used with reference to functions of the form f : VS, where VSn, and S is some set. Such a function is often called an operation on S, and n is its arity.

Arities greater than 2 are seldom encountered in mathematics, except in specialized areas. The Logarithm
Logarithm
The logarithm of a number is the exponent by which another fixed value, the base, has to be raised to produce that number. For example, the logarithm of 1000 to base 10 is 3, because 1000 is 10 to the power 3: More generally, if x = by, then y is the logarithm of x to base b, and is written...

function has an argument and a base: logb(N). Arities greater than 3 are seldom encountered except in theoretical computer science
Theoretical computer science
Theoretical computer science is a division or subset of general computer science and mathematics which focuses on more abstract or mathematical aspects of computing....

. In computer programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...

there is often a syntactical distinction between operators
Operator (programming)
Programming languages typically support a set of operators: operations which differ from the language's functions in calling syntax and/or argument passing mode. Common examples that differ by syntax are mathematical arithmetic operations, e.g...

and functions; syntactical operators usually have arity 0, 1 or 2.

In mathematics, depending on the branch, arity may be called type, adicity or rank.
In computer science, arity may be called adicity, a function that takes a variable number of arguments being called variadic
In computer science, an operator or function is variadic if it can take a varying number of arguments; that is, if its arity is not fixed.For specific articles, see:* Variadic function* Variadic macro in the C preprocessor* Variadic templates...

.
Unary functions may also be called "monadic"; similarly, binary functions may be called "dyadic".

In linguistics
Linguistics
Linguistics is the scientific study of human language. Linguistics can be broadly broken into three categories or subfields of study: language form, language meaning, and language in context....

and in logic, arity is sometimes called valency
Valency (linguistics)
In linguistics, verb valency or valence refers to the number of arguments controlled by a verbal predicate. It is related, though not identical, to verb transitivity, which counts only object arguments of the verbal predicate...

, not to be confused with valency in graph theory.

## Examples

The term "arity" is rarely employed in everyday usage. For example, rather than saying "the arity of the addition
Addition is a mathematical operation that represents combining collections of objects together into a larger collection. It is signified by the plus sign . For example, in the picture on the right, there are 3 + 2 apples—meaning three apples and two other apples—which is the same as five apples....

operation is 2" or "addition is an operation of arity 2" one usually says "addition is a binary operation".
In general, the naming of functions or operators with a given arity follows a convention similar to the one used for n-based numeral system
Numeral system
A numeral system is a writing system for expressing numbers, that is a mathematical notation for representing numbers of a given set, using graphemes or symbols in a consistent manner....

s such as binary
Binary numeral system
The binary numeral system, or base-2 number system, represents numeric values using two symbols, 0 and 1. More specifically, the usual base-2 system is a positional notation with a radix of 2...

In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...

. One combines a Latin
Latin
Latin is an Italic language originally spoken in Latium and Ancient Rome. It, along with most European languages, is a descendant of the ancient Proto-Indo-European language. Although it is considered a dead language, a number of scholars and members of the Christian clergy speak it fluently, and...

prefix with the -ary ending; for example:
• A nullary function takes no arguments.
• A unary
Unary operation
In mathematics, a unary operation is an operation with only one operand, i.e. a single input. Specifically, it is a functionf:\ A\to Awhere A is a set. In this case f is called a unary operation on A....

function takes one argument.
• A binary
Binary operation
In mathematics, a binary operation is a calculation involving two operands, in other words, an operation whose arity is two. Examples include the familiar arithmetic operations of addition, subtraction, multiplication and division....

function takes two arguments.
• A ternary
Ternary operation
In mathematics, a ternary operation is an n-ary operation with n = 3. A ternary operation on a set A takes any given three elements of A and combines them to form a single element of A. An example of a ternary operation is the product in a heap....

function takes three arguments.
• An n-ary function takes n arguments.

### Nullary

Sometimes it is useful to consider a constant
Constant term
In mathematics, a constant term is a term in an algebraic expression has a value that is constant or cannot change, because it does not contain any modifiable variables. For example, in the quadratic polynomialx^2 + 2x + 3,\ the 3 is a constant term....

as an operation of arity 0, and hence call it nullary or point-free.

Also, in non-functional programming
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

, a function without arguments can be meaningful and not necessarily constant (due to side effect
Side effect (computer science)
In computer science, a function or expression is said to have a side effect if, in addition to returning a value, it also modifies some state or has an observable interaction with calling functions or the outside world...

s). Often, such functions have in fact some hidden input which might be global variable
Global variable
In computer programming, a global variable is a variable that is accessible in every scope . Interaction mechanisms with global variables are called global environment mechanisms...

s, including the whole state of the system (time, free memory, ...). The latter are important examples which usually also exist in "purely" functional programming languages.

### Unary

Examples of unary operators in mathematics and in programming include the unary minus and plus, the increment and decrement operators in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

-style languages (not in logical languages), and the factorial
Factorial
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n...

, reciprocal
Multiplicative inverse
In mathematics, a multiplicative inverse or reciprocal for a number x, denoted by 1/x or x−1, is a number which when multiplied by x yields the multiplicative identity, 1. The multiplicative inverse of a fraction a/b is b/a. For the multiplicative inverse of a real number, divide 1 by the...

, floor
Floor function
In mathematics and computer science, the floor and ceiling functions map a real number to the largest previous or the smallest following integer, respectively...

, ceiling, fractional part
Fractional part
All real numbers can be written in the form n + r where n is an integer and the remaining fractional part r is a nonnegative real number less than one...

, sign
Sign (mathematics)
In mathematics, the word sign refers to the property of being positive or negative. Every nonzero real number is either positive or negative, and therefore has a sign. Zero itself is signless, although in some contexts it makes sense to consider a signed zero...

, absolute value
Absolute value
In mathematics, the absolute value |a| of a real number a is the numerical value of a without regard to its sign. So, for example, the absolute value of 3 is 3, and the absolute value of -3 is also 3...

, complex conjugate
Complex conjugate
In mathematics, complex conjugates are a pair of complex numbers, both having the same real part, but with imaginary parts of equal magnitude and opposite signs...

, and norm
Norm (mathematics)
In linear algebra, functional analysis and related areas of mathematics, a norm is a function that assigns a strictly positive length or size to all vectors in a vector space, other than the zero vector...

functions in mathematics. The two's complement
Two's complement
The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of two...

Reference (computer science)
In computer science, a reference is a value that enables a program to indirectly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing those data is called...

and the logical NOT operators are examples of unary operators in math and programming. According to Quine
Willard Van Orman Quine
Willard Van Orman Quine was an American philosopher and logician in the analytic tradition...

, a more suitable term is "singulary", though the term "unary" remains the de facto usage.

All functions in lambda calculus
Lambda calculus
In mathematical logic and computer science, lambda calculus, also written as λ-calculus, is a formal system for function definition, function application and recursion. The portion of lambda calculus relevant to computation is now called the untyped lambda calculus...

and in some functional programming languages (especially those descended from ML) are technically unary, but see n-ary below.

### Binary

Most operators encountered in programming are of the binary
Binary operation
In mathematics, a binary operation is a calculation involving two operands, in other words, an operation whose arity is two. Examples include the familiar arithmetic operations of addition, subtraction, multiplication and division....

form. For both programming and mathematics these can be the multiplication operator
Multiplication operator
In operator theory, a multiplication operator is a linear operator T defined on some vector space of functions and whose value at a function φ is given by multiplication by a fixed function f...

, the addition operator, the division operator. Logical predicates such as OR, XOR, AND, IMP are typically used as binary operators with two distinct operands.

### Ternary

From C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, C#, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

and variants comes the ternary operator ?:?:In computer programming, ?: is a ternary operator that is part of the syntax for a basic conditional expression in several programming languages..., which is a so-called conditional operator, taking three parameters.
Forth also contains a ternary operator, */, which multiplies the first two (one-cell) numbers, dividing by the third, with the intermediate result being a double cell number. This is used when the intermediate result would overflow a single cell.
The dc calculator has several ternary operators, such as |, which will pop three values from the stack and efficiently compute with arbitrary precision.
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

instructions are ternary or higher, such as MOV %AX, (%BX,%CX), which will load (MOV) into register AX the contents of a calculated memory location that is the sum (parenthesis) of the registers BX and CX.

### n-ary

From a mathematical point of view, a function of n arguments can always be considered as a function of one single argument which is an element of some product space. However, it may be convenient for notation to consider n-ary functions, as for example multilinear maps (which are not linear maps on the product space, if n≠1).

The same is true for programming languages, where functions taking several arguments could always be defined as functions taking a single argument of some composite type
Object composition
In computer science, object composition is a way to combine simple objects or data types into more complex ones...

such as a tuple
Tuple
In mathematics and computer science, a tuple is an ordered list of elements. In set theory, an n-tuple is a sequence of n elements, where n is a positive integer. There is also one 0-tuple, an empty sequence. An n-tuple is defined inductively using the construction of an ordered pair...

, or in languages with higher-order function
Higher-order function
In mathematics and computer science, higher-order functions, functional forms, or functionals are functions which do at least one of the following:*take one or more functions as an input*output a function...

s, by currying
Currying
In mathematics and computer science, currying is the technique of transforming a function that takes multiple arguments in such a way that it can be called as a chain of functions each with a single argument...

.

## Other names

• Nullary means 0-ary.
• Unary
Unary operation
In mathematics, a unary operation is an operation with only one operand, i.e. a single input. Specifically, it is a functionf:\ A\to Awhere A is a set. In this case f is called a unary operation on A....

means 1-ary.
• Binary
Binary operation
In mathematics, a binary operation is a calculation involving two operands, in other words, an operation whose arity is two. Examples include the familiar arithmetic operations of addition, subtraction, multiplication and division....

means 2-ary.
• Ternary
Ternary operation
In mathematics, a ternary operation is an n-ary operation with n = 3. A ternary operation on a set A takes any given three elements of A and combines them to form a single element of A. An example of a ternary operation is the product in a heap....

means 3-ary.
• Quaternary means 4-ary.
• Quinary means 5-ary.
• Senary means 6-ary.
• Septenary means 7-ary.
• Octary means 8-ary.
• Nonary means 9-ary.
• Polyadic, multary and multiary mean any number of operands (or parameters).
• n-ary means n operands (or parameters), but is often used as a synonym of "polyadic".

An alternative nomenclature is derived in a similar fashion from the corresponding Greek
Greek language
Greek is an independent branch of the Indo-European family of languages. Native to the southern Balkans, it has the longest documented history of any Indo-European language, spanning 34 centuries of written records. Its writing system has been the Greek alphabet for the majority of its history;...

These words are often used to describe anything related to that number (e.g., undenary chess is a chess variant with an 11×11 board, or the Millenary Petition
Millenary Petition
The Millenary Petition was a list of requests given to James I by Puritans in 1603 when he was travelling to London in order to claim the English throne. It is claimed, but not proven, that this petition had 1,000 signatures of Puritan ministers...

of 1603). 