# Binary operation

In mathematics, a

**binary operation**or

**dyadic operation**is a calculation that combines two elements to produce another element. More formally, a binary operation is an operation of arity two.

More specifically, a binary operation

*on a set*is an operation whose two domains and the codomain are the same set. Examples include the familiar arithmetic operations of addition, subtraction, multiplication. Other examples are readily found in different areas of mathematics, such as vector addition, matrix multiplication and conjugation in groups.

An operation of arity two that involves several sets is sometimes called also a

*binary operation*. For example, scalar multiplication of vector spaces takes a scalar and a vector to produce a vector, and scalar product takes two vectors to produce a scalar. Such binary operations may be called simply binary functions.

Binary operations are the keystone of most algebraic structures, that are studied in algebra, in particular in semigroups, monoids, groups, rings, fields, and vector spaces.

## Terminology

More precisely, a binary operation on a set*S*is a mapping of the elements of the Cartesian product to

*S*:

Because the result of performing the operation on a pair of elements of

*S*is again an element of

*S*, the operation is called a

**closed**binary operation on

*S*. If

*f*is not a function, but is instead a partial function, it is called a

**partial binary operation**. For instance, division of real numbers is a partial binary operation, because one can't divide by zero:

*a*/0 is not defined for any real

*a*. However, both in universal algebra and model theory the binary operations considered are defined on all of.

Sometimes, especially in computer science, the term is used for any binary function.

## Properties and examples

Typical examples of binary operations are the addition and multiplication of numbers and matrices as well as composition of functions on a single set.For instance,

- On the set of real numbers
**R**, is a binary operation since the sum of two real numbers is a real number. - On the set of natural numbers
**N**, is a binary operation since the sum of two natural numbers is a natural number. This is a different binary operation than the previous one since the sets are different. - On the set M of matrices with real entries, is a binary operation since the sum of two such matrices is a matrix.
- On the set M of matrices with real entries, is a binary operation since the product of two such matrices is a matrix.
- For a given set
*C*, let*S*be the set of all functions. Define by for all, the composition of the two functions*h*and*h*in*S*. Then*f*is a binary operation since the composition of the two functions is again a function on the set*C*.

*a*and

*b*in

*S*, or associative, satisfying for all

*a*,

*b*and

*c*in

*S*. Many also have identity elements and inverse elements.

The first three examples above are commutative and all of the above examples are associative.

On the set of real numbers

**R**, subtraction, that is,, is a binary operation which is not commutative since, in general,. It is also not associative, since, in general, ; for instance, but.

On the set of natural numbers

**N**, the binary operation exponentiation,, is not commutative since, , and is also not associative since. For instance, with, and,, but. By changing the set

**N**to the set of integers

**Z**, this binary operation becomes a partial binary operation since it is now undefined when and

*b*is any negative integer. For either set, this operation has a

*right identity*since for all

*a*in the set, which is not an

*identity*since in general.

Division, a partial binary operation on the set of real or rational numbers, is not commutative or associative. Tetration, as a binary operation on the natural numbers, is not commutative or associative and has no identity element.

## Notation

Binary operations are often written using infix notation such as,, or*ab*rather than by functional notation of the form. Powers are usually also written without operator, but with the second argument as superscript.

Binary operations sometimes use prefix or postfix notation, both of which dispense with parentheses. They are also called, respectively, Polish notation and reverse Polish notation.

## Pair and tuple

A binary operation,*ab*, depends on the ordered pair and so

*c*and then operate on the result of that using the ordered pair ) depends in general on the ordered pair. Thus, for the general, non-associative case, binary operations can be represented with binary trees.

However:

- If the operation is associative,
*c*=*a*, then the value of*c*depends only on the tuple. - If the operation is commutative,
*ab*=*ba*, then the value of*c*depends only on, where braces indicate multisets. - If the operation is both associative and commutative then the value of
*c*depends only on the multiset. - If the operation is associative, commutative and idempotent,
*aa*=*a*, then the value of*c*depends only on the set.## Binary operations as ternary relations

*f*on a set

*S*may be viewed as a ternary relation on

*S*, that is, the set of triples in

*S*×

*S*×

*S*for all

*a*and

*b*in

*S*.

## External binary operations

An**external binary operation**is a binary function from

*K*×

*S*to

*S*. This differs from a

*binary operation on a set*in the sense in that

*K*need not be

*S*; its elements come from

*outside*.

An example of an external binary operation is scalar multiplication in linear algebra. Here

*K*is a field and

*S*is a vector space over that field.

An external binary operation may alternatively be viewed as an action;

*K*is acting on

*S*.

The dot product of two vectors maps from

*S*×

*S*to

*K*, where

*K*is a field and

*S*is a vector space over

*K*. It depends on authors whether it is considered as a binary operation.