Arity
Inlogic,mathematics,andcomputer science,arity(/ˈærɪti/) is the number ofargumentsoroperandstaken by afunction,operationorrelation.In mathematics, arity may also be called rank,[1][2]but this word can have many other meanings. In logic andphilosophy,arity may also be calledadicityanddegree.[3][4]Inlinguistics,it is usually namedvalency.[5]
Examples
[edit]In general, functions or operators with a given arity follow the naming conventions ofn-basednumeral systems,such asbinaryandhexadecimal.ALatinprefix is combined with the -ary suffix. For example:
- A nullary function takes no arguments.
- Example:
- Aunary functiontakes one argument.
- Example:
- Abinary functiontakes two arguments.
- Example:
- Aternary functiontakes three arguments.
- Example:
- Ann-ary function takesnarguments.
- Example:
Nullary
[edit]Aconstantcan be treated as the output of an operation of arity 0, called anullary operation.
Also, outside offunctional programming,a function without arguments can be meaningful and not necessarily constant (due toside effects). Such functions may have somehidden input,such asglobal variablesor the whole state of the system (time, free memory, etc.).
Unary
[edit]Examples ofunary operatorsin mathematics and in programming include theunary minusand plus, the increment and decrement operators inC-style languages (not in logical languages), and thesuccessor,factorial,reciprocal,floor,ceiling,fractional part,sign,absolute value,square root(the principal square root),complex conjugate(unary of "one"complex number,that however has two parts at a lower level of abstraction), andnormfunctions in mathematics. In programming thetwo's complement,address reference,and thelogical NOToperators are examples of unary operators.
All functions inlambda calculusand in somefunctional programming languages(especially those descended fromML) are technically unary, but seen-arybelow.
According toQuine,the Latin distributives beingsinguli,bini,terni,and so forth, the term "singulary" is the correct adjective, rather than "unary".[6]Abraham Robinsonfollows Quine's usage.[7]
In philosophy, the adjectivemonadicis sometimes used to describe aone-place relationsuch as 'is square-shaped' as opposed to atwo-place relationsuch as 'is the sister of'.
Binary
[edit]Most operators encountered in programming and mathematics are of thebinaryform. For both programming and mathematics, these include themultiplication operator,the radix operator, the often omittedexponentiationoperator, thelogarithmoperator, theadditionoperator, and thedivisionoperator. Logical predicates such asOR,XOR,AND,IMPare typically used as binary operators with two distinct operands. InCISCarchitectures, it is common to have two source operands (and store result in one of them).
Ternary
[edit]The computer programming languageCand its various descendants (includingC++,C#,Java,Julia,Perl,and others) provide theternary conditional operator?:
.The first operand (the condition) is evaluated, and if it is true, the result of the entire expression is the value of the second operand, otherwise it is the value of the third operand.
ThePythonlanguage has a ternary conditional expression,xifCelsey
.InElixirthe equivalent would be,if(C,do:x,else:y)
.
TheForthlanguage 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 Unixdc calculatorhas several ternary operators, such as|
,which will pop three values from the stack and efficiently computewitharbitrary precision.
Many (RISC)assembly languageinstructions are ternary (as opposed to only two operands specified in CISC); or higher, such asMOV%AX,(%BX,%CX)
,which will load (MOV) into registerAXthe contents of a calculated memory location that is the sum (parenthesis) of the registersBXandCX.
n-ary
[edit]Thearithmetic meanofnreal numbers is ann-ary function:
Similarly, thegeometric meanofnpositive real numbersis ann-ary function:Note that alogarithmof the geometric mean is the arithmetic mean of the logarithms of itsnarguments
From a mathematical point of view, a function ofnarguments can always be considered as a function of a single argument that is an element of someproduct space.However, it may be convenient for notation to considern-ary functions, as for examplemultilinear maps(which are not linear maps on the product space, ifn≠ 1).
The same is true for programming languages, where functions taking several arguments could always be defined as functions taking a single argument of somecomposite typesuch as atuple,or in languages withhigher-order functions,bycurrying.
Varying arity
[edit]In computer science, a function that accepts a variable number of arguments is calledvariadic.In logic and philosophy, predicates or relations accepting a variable number of arguments are calledmultigrade,anadic, or variably polyadic.[8]
Terminology
[edit]Latinatenames are commonly used for specific arities, primarily based on Latindistributive numbersmeaning "in group ofn",though some are based on Latincardinal numbersorordinal numbers.For example, 1-ary is based on cardinalunus,rather than from distributivesingulīthat would result insingulary.
n-ary | Arity (Latin based) | Adicity (Greek based) | Example in mathematics | Example in computer science |
---|---|---|---|---|
0-ary | nullary (fromnūllus) | niladic | aconstant | a function without arguments,True,False |
1-ary | unary | monadic | additive inverse | logicalNOToperator |
2-ary | binary | dyadic | addition | logicalOR,XOR,ANDoperators |
3-ary | ternary | triadic | triple product of vectors | conditional operator |
4-ary | quaternary | tetradic | ||
5-ary | quinary | pentadic | ||
6-ary | senary | hexadic | ||
7-ary | septenary | hebdomadic | ||
8-ary | octonary | ogdoadic | ||
9-ary | novenary (alt. nonary) | enneadic | ||
10-ary | denary (alt. decenary) | decadic | ||
more than 2-ary | multary and multiary | polyadic | ||
varying | variadic | sum; e.g., Σ | variadic function,reduce |
n-arymeans havingnoperands (or parameters), but is often used as a synonym of "polyadic".
These words are often used to describe anything related to that number (e.g., undenary chess is achess variantwith an 11×11 board, or theMillenary Petitionof 1603).
The arity of arelation(orpredicate) is the dimension of thedomainin the correspondingCartesian product.(A function of aritynthus has arityn+1 considered as a relation.)
Incomputer programming,there is often asyntacticaldistinction betweenoperatorsandfunctions;syntactical operators usually have arity 1, 2, or 3 (theternary operator?:is also common). Functions vary widely in the number of arguments, though large numbers can become unwieldy. Some programming languages also offer support forvariadic functions,i.e., functions syntactically accepting a variable number of arguments.
See also
[edit]- Logic of relatives
- Binary relation
- Ternary relation
- Theory of relations
- Signature (logic)
- Parameter
- p-adic number
- Cardinality
- Valency (linguistics)
- n-ary code
- n-ary group
- Function prototype– Declaration of a function's name and type signature but not body
- Type signature– Defines the inputs and outputs for a function, subroutine or method
- Univariate and multivariate
- Finitary
References
[edit]- ^Hazewinkel, Michiel(2001).Encyclopaedia of Mathematics, Supplement III.Springer. p. 3.ISBN978-1-4020-0198-7.
- ^Schechter, Eric (1997).Handbook of Analysis and Its Foundations.Academic Press. p. 356.ISBN978-0-12-622760-4.
- ^Detlefsen, Michael; McCarty, David Charles; Bacon, John B. (1999).Logic from A to Z.Routledge. p.7.ISBN978-0-415-21375-2.
- ^Cocchiarella, Nino B.; Freund, Max A. (2008).Modal Logic: An Introduction to its Syntax and Semantics.Oxford University Press. p. 121.ISBN978-0-19-536658-7.
- ^Crystal, David (2008).Dictionary of Linguistics and Phonetics(6th ed.). John Wiley & Sons. p. 507.ISBN978-1-405-15296-9.
- ^ Quine, W. V. O. (1940),Mathematical logic,Cambridge, Massachusetts: Harvard University Press, p. 13
- ^ Robinson, Abraham (1966),Non-standard Analysis,Amsterdam: North-Holland, p. 19
- ^Oliver, Alex (2004). "Multigrade Predicates".Mind.113(452): 609–681.doi:10.1093/mind/113.452.609.
External links
[edit]![](https://upload.wikimedia.org/wikipedia/commons/thumb/9/99/Wiktionary-logo-en-v2.svg/40px-Wiktionary-logo-en-v2.svg.png)
A monograph available free online:
- Burris, Stanley N., and H.P. Sankappanavar, H. P., 1981.A Course in Universal Algebra.Springer-Verlag.ISBN3-540-90578-2.Especially pp. 22–24.