HOME

TheInfoList



OR:

In mathematics, an unary operation is an
operation Operation or Operations may refer to: Arts, entertainment and media * ''Operation'' (game), a battery-operated board game that challenges dexterity * Operation (music), a term used in musical set theory * ''Operations'' (magazine), Multi-Ma ...
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. Example The following arithmetic expression shows an example of operators and operands: :3 + 6 = 9 In the above exam ...
, i.e. a single input. This is in contrast to binary operations, which use two operands. An example is any
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-oriente ...
, 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 or simply prefix notation, is a mathematical notation in which operators ''precede'' their operands, in contrast t ...
(e.g. ¬, ), postfix notation (e.g. factorial ), functional notation (e.g. or ), and superscripts (e.g.
transpose In linear algebra, the transpose of a 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 notations). The tr ...
). 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 ; in other words, a number whose ''square'' (the result of multiplying the number by itself, or  ⋅ ) is . For example, 4 and −4 are square roots of 16, because . ...
, a
horizontal bar The horizontal bar, also known as the high bar, is an apparatus used by male gymnasts in artistic gymnastics. It traditionally consists of a cylindrical metal (typically steel) bar that is rigidly held above and parallel to the floor by a syste ...
extending the square root sign over the argument can indicate the extent of the argument.


Examples


Unary negative and positive

As unary operations have 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. Example The following arithmetic expression shows an example of operators and operands: :3 + 6 = 9 In the above exam ...
they are evaluated before other operations containing them. Here is an example using negation: :3 − −2 Here, the first '−' represents the binary subtraction operation, while the second '−' represents the unary negation of the 2 (or '−2' could be taken to mean the
integer An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign ( −1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the languag ...
−2). Therefore, the expression is equal to: :3 − (−2) = 5 Technically, there is also a unary + operation but it is not needed since we assume an unsigned value to be positive: :+2 = 2 The unary + operation does not change the sign of a negative operation: :+(−2) = −2 In this case, a unary negation is needed to change the sign: :−(−2) = +2


Trigonometry

In
trigonometry Trigonometry () is a branch of mathematics that studies relationships between side lengths and angles of triangles. The field emerged in the Hellenistic world during the 3rd century BC from applications of geometry to astronomical studies ...
, 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 al ...
, such as \sin, \cos, and \tan, 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, require two different terms to compute a result.


Examples from programming languages


JavaScript

In
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
, 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 backu ...
: ++x, x++ * Decrement: −−x, x−− *Positive: +x *Negative: x *
Ones' complement The ones' complement of a binary number is the value obtained by inverting all the bits in the binary representation of the number (swapping 0s and 1s). The name "ones' complement" (''note this is possessive of the plural "ones", not of a sin ...
: ~x * Logical negation: !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 backu ...
: ++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 political boundaries and street names as references, along ...
: &x *
Indirection In computer programming, indirection (also called dereferencing) is the ability to reference something using a name, reference, or container instead of the value itself. The most common form of indirection is the act of manipulating a value throug ...
: *x *Positive: +x *Negative: x *
Ones' complement The ones' complement of a binary number is the value obtained by inverting all the bits in the binary representation of the number (swapping 0s and 1s). The name "ones' complement" (''note this is possessive of the plural "ones", not of a sin ...
: ~x * Logical negation: !x *
Sizeof sizeof is a unary operator in the programming languages C and C++. It generates the storage size of an expression or a data type, measured in the number of ''char''-sized units. Consequently, the construct ''sizeof (char)'' is guaranteed to be ' ...
: 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/Linux shell (bash/sh), '$' is a unary operator when used for parameter expansion, replacing the name of a variable by its (sometimes modified) value. For example: * Simple expansion: $x * Complex expansion: $


Windows PowerShell

*Increment: ++$x, $x++ *Decrement: −−$x, $x−− *Positive: +$x *Negative: $x *Logical negation: !$x * Invoke in current
scope Scope or scopes may refer to: People with the surname * Jamie Scope (born 1986), English footballer * John T. Scopes (1900–1970), central figure in the Scopes Trial regarding the teaching of evolution Arts, media, and entertainment * Cinem ...
: .$x *Invoke in new scope: &$x *Cast: 'type-name''''cast-expression'' *Cast: +$x *Array: ,$array


See also

* 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 ...
*
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''. In computer science, a ternary operator i ...
* Arity *
Operation (mathematics) In mathematics, an operation is a function which takes zero or more input values (also called "'' operands''" or "arguments") to a well-defined output value. The number of operands is the arity of the operation. The most commonly studied opera ...
*
Operator (programming) In computer programming, operators are constructs defined within programming languages which behave generally like functions, but which differ syntactically or semantically. Common simple examples include arithmetic (e.g. addition with ), c ...


References

*


External links

* {{DEFAULTSORT:Unary Operation Elementary algebra Operators (programming)