In
mathematics
Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
, a unary operation is an
operation with only one
operand
In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on.
Unknown operands in equalities of expressions can be found by equation solving.
Example
The following arithmetic expres ...
, i.e. a single input. This is in contrast to ''
binary operation
In mathematics, a binary operation or dyadic operation is a rule for combining two elements (called operands) to produce another element. More formally, a binary operation is an operation of arity two.
More specifically, a binary operation ...
s'', which use two operands. An example is any
function , where is a
set
Set, The Set, SET or SETS may refer to:
Science, technology, and mathematics Mathematics
*Set (mathematics), a collection of elements
*Category of sets, the category whose objects and morphisms are sets and total functions, respectively
Electro ...
; the function is a unary operation on .
Common notations are
prefix notation
Polish notation (PN), also known as normal Polish notation (NPN), Łukasiewicz notation, Warsaw notation, Polish prefix notation, Eastern Notation or simply prefix notation, is a mathematical notation in which operators ''precede'' their oper ...
(e.g.
¬,
−),
postfix notation
Reverse Polish notation (RPN), also known as reverse Łukasiewicz notation, Polish postfix notation or simply postfix notation, is a mathematical notation in which Operation (mathematics), operators ''follow'' their operands, in contrast to pr ...
(e.g.
factorial
In mathematics, the factorial of a non-negative denoted is the Product (mathematics), product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial:
\begin
n! &= n \times ...
), functional notation (e.g. or ), and
superscript
A subscript or superscript is a character (such as a number or letter) that is set slightly below or above the normal line of type, respectively. It is usually smaller than the rest of the text. Subscripts appear at or below the baseline, wh ...
s (e.g.
transpose
In linear algebra, the transpose of a Matrix (mathematics), matrix is an operator which flips a matrix over its diagonal;
that is, it switches the row and column indices of the matrix by producing another matrix, often denoted by (among other ...
). Other notations exist as well, for example, in the case of the
square root
In mathematics, a square root of a number is a number such that y^2 = x; in other words, a number whose ''square'' (the result of multiplying the number by itself, or y \cdot y) is . For example, 4 and −4 are square roots of 16 because 4 ...
, a
horizontal bar extending the square root sign over the argument can indicate the extent of the argument.
Examples
Absolute value
Obtaining the
absolute value
In mathematics, the absolute value or modulus of a real number x, is the non-negative value without regard to its sign. Namely, , x, =x if x is a positive number, and , x, =-x if x is negative (in which case negating x makes -x positive), ...
of a number is a unary operation. This function is defined as
where
is the absolute value of
.
Negation
Negation
In logic, negation, also called the logical not or logical complement, is an operation (mathematics), operation that takes a Proposition (mathematics), proposition P to another proposition "not P", written \neg P, \mathord P, P^\prime or \over ...
is used to find the negative value of a single number. Here are some examples:
:
:
Factorial
For any positive integer ''n'', the product of the integers less than or equal to ''n'' is a unary operation called
factorial
In mathematics, the factorial of a non-negative denoted is the Product (mathematics), product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial:
\begin
n! &= n \times ...
. In the context of
complex number
In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the for ...
s, the
gamma function
In mathematics, the gamma function (represented by Γ, capital Greek alphabet, Greek letter gamma) is the most common extension of the factorial function to complex numbers. Derived by Daniel Bernoulli, the gamma function \Gamma(z) is defined ...
is a unary operation extension of factorial.
Trigonometry
In
trigonometry
Trigonometry () is a branch of mathematics concerned with relationships between angles and side lengths of triangles. In particular, the trigonometric functions relate the angles of a right triangle with ratios of its side lengths. The fiel ...
, the
trigonometric functions
In mathematics, the trigonometric functions (also called circular functions, angle functions or goniometric functions) are real functions which relate an angle of a right-angled triangle to ratios of two side lengths. They are widely used in all ...
, such as
,
, and
, can be seen as unary operations. This is because it is possible to provide only one term as input for these functions and retrieve a result. By contrast, binary operations, such as
addition
Addition (usually signified by the Plus and minus signs#Plus sign, plus symbol, +) is one of the four basic Operation (mathematics), operations of arithmetic, the other three being subtraction, multiplication, and Division (mathematics), divis ...
, require two different terms to compute a result.
Examples from programming languages
Below is a table summarizing common unary operators along with their symbols, description, and examples:
JavaScript
In
JavaScript
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
, these operators are unary:
*
Increment
Increment or incremental may refer to:
*Incrementalism, a theory (also used in politics as a synonym for gradualism)
* Increment and decrement operators, the operators ++ and -- in computer programming
* Incremental computing
* Incremental backup ...
:
++x
,
x++
*
Decrement:
--x
,
x--
*Positive:
+x
*Negative:
-x
*
Ones' complement
The ones' complement of a binary number is the value obtained by inverting (flipping) all the bits in the Binary number, binary representation of the number. The name "ones' complement" refers to the fact that such an inverted value, if added t ...
:
~x
*
Logical negation
In logic, negation, also called the logical not or logical complement, is an operation that takes a proposition P to another proposition "not P", written \neg P, \mathord P, P^\prime or \overline. It is interpreted intuitively as being true ...
:
!x
C family of languages
In the
C family of languages, the following operators are unary:
*
Increment
Increment or incremental may refer to:
*Incrementalism, a theory (also used in politics as a synonym for gradualism)
* Increment and decrement operators, the operators ++ and -- in computer programming
* Incremental computing
* Incremental backup ...
:
++x
,
x++
*
Decrement:
--x
,
x--
*
Address
An address is a collection of information, presented in a mostly fixed format, used to give the location of a building, apartment, or other structure or a plot of land, generally using border, political boundaries and street names as references, ...
:
&x
*
Indirection:
*x
*Positive:
+x
*Negative:
-x
*
Ones' complement
The ones' complement of a binary number is the value obtained by inverting (flipping) all the bits in the Binary number, binary representation of the number. The name "ones' complement" refers to the fact that such an inverted value, if added t ...
:
~x
*
Logical negation
In logic, negation, also called the logical not or logical complement, is an operation that takes a proposition P to another proposition "not P", written \neg P, \mathord P, P^\prime or \overline. It is interpreted intuitively as being true ...
:
!x
*
Sizeof
sizeof is a unary operator in the C and C++ programming languages that evaluates to the storage size of an expression or a data type, measured in units sized as char. Consequently, the expression sizeof(char) evaluates to 1. The number of b ...
:
sizeof x, sizeof(type-name)
*
Cast
Cast may refer to:
Music
* Cast (band), an English alternative rock band
* Cast (Mexican band), a progressive Mexican rock band
* The Cast, a Scottish musical duo: Mairi Campbell and Dave Francis
* ''Cast'', a 2012 album by Trespassers William ...
:
(''type-name'') ''cast-expression''
Unix shell (Bash)
In the
Unix shell
A Unix shell is a Command-line_interface#Command-line_interpreter, command-line interpreter or shell (computing), shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command languag ...
(
Bash/
Bourne Shell
The Bourne shell (sh) is a shell command-line interpreter for computer operating systems. It first appeared on Version 7 Unix, as its default shell. Unix-like systems continue to have /bin/sh—which will be the Bourne shell, or a symbolic lin ...
), e.g., the following operators are unary:
*Pre and Post-Increment:
++$x
,
$x++
*Pre and Post-Decrement:
--$x
,
$x--
*Positive:
+$x
*Negative:
-$x
*Logical negation:
!$x
* Simple expansion:
$x
* Complex expansion:
$
PowerShell
In the
PowerShell
PowerShell is a shell program developed by Microsoft for task automation and configuration management. As is typical for a shell, it provides a command-line interpreter for interactive use and a script interpreter for automation via a langu ...
, the following operators are unary:
*Increment:
++$x
,
$x++
*Decrement:
--$x
,
$x--
*Positive:
+$x
*Negative:
-$x
*Logical negation:
!$x
*
Invoke in current
scope:
.$x
*Invoke in new scope:
&$x
*Cast:
'type-name''''cast-expression''
*Cast:
+$x
*Array:
,$array
See also
*
Unary function
*
Binary operation
In mathematics, a binary operation or dyadic operation is a rule for combining two elements (called operands) to produce another element. More formally, a binary operation is an operation of arity two.
More specifically, a binary operation ...
*
Iterated binary operation
In mathematics, an iterated binary operation is an extension of a binary operation on a set ''S'' to a function on finite sequences of elements of ''S'' through repeated application. Common examples include the extension of the addition operation ...
*
Binary function
*
Ternary operation
*
Arity
In logic, mathematics, and computer science, arity () is the number of arguments or operands taken by a function, operation or relation. In mathematics, arity may also be called rank, but this word can have many other meanings. In logic and ...
*
Operation (mathematics)
In mathematics, an operation is a function from a set to itself. For example, an operation on real numbers will take in real numbers and return a real number. An operation can take zero or more input values (also called "'' operands''" or "arg ...
*
Operator (programming)
In computer programming, an operator is a programming language construct that provides functionality that may not be possible to define as a user-defined function (i.e. sizeof in C) or has syntax different than a function (i.e. infix additio ...
References
External links
*
{{DEFAULTSORT:Unary Operation
Elementary algebra
Operators (programming)