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-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 exa ...
, 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, an internal binary op ...
s, which use two operands. An example is any function , where is a set. The function is a unary operation on . Common notations are prefix notation (e.g. ¬,
− The plus and minus signs, and , are mathematical symbols used to represent the notions of positive and negative, respectively. In addition, represents the operation of addition, which results in a sum, while represents subtraction, result ...
), 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, 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 exa ...
they are evaluated before other operations containing them. Here is an example using
negation In logic, negation, also called the logical complement, is an operation that takes a proposition P to another proposition "not P", written \neg P, \mathord P or \overline. It is interpreted intuitively as being true when P is false, and fals ...
: :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 language ...
−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, the trigonometric functions, 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 Website, websites use JavaScript on the Client (computing), client side ...
, 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: (''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 Invoke may refer to: * Invocation, a form of supplication or prayer * Invoke Solutions, a market research company founded in 1999 and based in the United States * Invoke (smart speaker), developed by Harman Kardon and powered by Microsoft's inte ...
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 * CinemaS ...
: .$x *Invoke in new scope: &$x *Cast: 'type-name''''cast-expression'' *Cast: +$x *Array: ,$array


See also

*
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, an internal binary op ...
* Iterated binary operation * Ternary operation *
Arity Arity () is the number of arguments or operands taken by a function, operation or relation in logic, mathematics, and computer science. In mathematics, arity may also be named ''rank'', but this word can have many other meanings in mathematics. In ...
*
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 operat ...
* Operator (programming)


References

*


External links

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