arity
Pronunciation
UK
- /ˈærɪtɪ/
US
- /ˈærɪti/
Description
- number of arguments
- number of operands
- input count
Imagine you're building with LEGO bricks. Some pieces only connect to one other piece—they have an "arity" of one. Others snap together with two, three, or even four. In math and computer science, "arity" describes the number of inputs (arguments/operands) a function or operation needs to work. A plus sign (+) is usually treated as a binary operator: it has an arity of two because it combines two numbers (like 2 + 3). Unary minus (as in -5) has an arity of one because it takes a single input. So, arity is all about how many things something "wants" to operate on.
"Arity" is a term borrowed from logic and mathematics, but it's become increasingly important in computer science too. It refers to the number of arguments or inputs that a function, operation, or predicate requires. Think of it as its "input capacity."
Originally, arity described how many places (arguments) a logical predicate takes. For example, "loves(John, Mary)" is a binary relation (arity of two) because it takes two arguments: John and Mary. "IsRed(apple)" is unary (arity of one).
In programming, functions have an arity based on the number of parameters they accept. A function that calculates the area of a rectangle might take two inputs—length and width—giving it an arity of 2. A function to print "Hello" might take no input at all, having an arity of 0.
Understanding arity is crucial for writing correct code and ensuring functions are called with the right number of arguments. If you try to call a function with fewer or more arguments than its defined arity allows, you'll usually get an error! It's also important in database design when defining relationships between tables—specifically, determining how many entities participate in a relationship.
So, while it might sound technical, arity is simply about counting the number of inputs needed for something to do its job—whether that "something" is a mathematical operation, a logical statement, or a piece of computer code.
Examples
- 1
Programming languages
In this language, every function has an arity, so the compiler can check your calls.
- 2
Operators
The `+` operator usually has an arity of two, but some languages also allow a one-argument version.
- 3
Function arguments
Our parser handles both fixed-arity and variable-arity functions.
Domain
in programming, variable-arity functions can take different numbers of arguments
Forms and spellings
1 form open this card.
Main spelling
- aritynoun