Unary operation
   HOME

TheInfoList



OR:

In
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern 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-Man ...
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 , 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 (e.g. ¬, ), postfix notation (e.g. factorial ), functional notation (e.g. or ), and superscripts (e.g. transpose ). 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 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 a ...
, 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: ++x, x++ * Decrement: −−x, x−− *Positive: +x *Negative: x * Ones' complement: ~x * Logical negation: !x


C family of languages

In the C family of languages, the following operators are unary: * Increment: ++x, x++ * Decrement: −−x, x−− * Address: &x * Indirection: *x *Positive: +x *Negative: x * Ones' complement: ~x * Logical negation: !x * Sizeof: 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 * Cinema ...
: .$x *Invoke in new scope: &$x *Cast: 'type-name''''cast-expression'' *Cast: +$x *Array: ,$array


See also

* Binary operation * Iterated binary operation * Ternary operation * 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)


References

*


External links

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