Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Unary operation
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Mathematical operation with only one operand}} {{More citations needed|date=March 2010}} In [[mathematics]], a '''unary operation''' is an [[Operation (mathematics)|operation]] with only one [[operand]], i.e. a single input.<ref>{{Cite web|last=Weisstein|first=Eric W.|title=Unary Operation|url=https://mathworld.wolfram.com/UnaryOperation.html|access-date=2020-07-29|website=mathworld.wolfram.com|language=en}}</ref> This is in contrast to ''[[binary operation]]s'', which use two operands.<ref>{{Cite web|last=Weisstein|first=Eric W.|title=Binary Operation|url=https://mathworld.wolfram.com/BinaryOperation.html|access-date=2020-07-29|website=mathworld.wolfram.com|language=en}}</ref> An example is any [[function (mathematics)|function]] {{tmath|f : A \rightarrow A}}, where {{mvar|A}} is a [[Set (mathematics)|set]]; the function {{tmath|f}} is a unary operation on {{mvar|A}}. Common notations are [[prefix notation]] (e.g. [[Β¬]], [[β]]), [[postfix notation]] (e.g. [[factorial]] {{math|''n''!}}), functional notation (e.g. {{math|[[sine|sin]] ''x''}} or {{math|sin(''x'')}}), and [[superscript]]s (e.g. [[transpose]] {{math|''A''{{sup|T}}}}). Other notations exist as well, for example, in the case of the [[square root]], a [[Vinculum (symbol)|horizontal bar]] extending the square root sign over the argument can indicate the extent of the argument. ==Examples== === Absolute value === Obtaining the [[absolute value]] of a number is a unary operation. This function is defined as <math>|n| = \begin{cases} n, & \mbox{if } n\geq0 \\ -n, & \mbox{if } n<0 \end{cases}</math> where <math>|n|</math> is the absolute value of <math>n</math>. ===Negation=== [[Negation (arithmetic)|Negation]] is used to find the negative value of a single number. Here are some examples: :<math>-(3) = -3</math> :<math>-( -3) = 3</math> ===Factorial=== For any positive integer ''n'', the product of the integers less than or equal to ''n'' is a unary operation called [[factorial]]. In the context of [[complex number]]s, the [[gamma function]] is a unary operation extension of factorial. ===Trigonometry=== In [[trigonometry]], the [[trigonometric functions]], such as <math>\sin</math>, <math>\cos</math>, and <math>\tan</math>, 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=== Below is a table summarizing common unary operators along with their symbols, description, and examples:<ref name="summarytable">{{cite web |title=Unary Operators in Programming |url=https://www.geeksforgeeks.org/unary-operators-in-programming/ |website=GeeksforGeeks |access-date=24 April 2024 |date=20 March 2024}}</ref> {| class="wikitable" |- ! Operator !! Symbol !! Description !! Example |- | Increment || <code>++</code> || Increases the value of a variable by 1 || <code>x = 2; ++x; // x is now 3</code> |- | Decrement || <code>β-</code> || Decreases the value of a variable by 1 || <code>y = 10; --y; // y is now 9</code> |- | Unary Plus || <code>+</code> || Indicates a positive value || <code>a = -5; b = +a; // b is -5</code> |- | Unary Minus || <code>-</code> || Indicates a negative value || <code>c = 4; d = -c; // d is -4</code> |- | [[Logical NOT]] || <code>!</code> || Negates the truth value of a Boolean expression || <code>flag = true; result = !flag; // result is false</code> |- | [[Bitwise|Bitwise NOT]] || <code>~</code> || Bitwise negation, flips the bits of an integer || <code>num = 5; result = ~num; // result is -6</code> |} ====JavaScript==== In [[JavaScript]], these operators are unary:<ref>{{cite web |title=Unary Operators |url=https://www.javascripttutorial.net/javascript-unary-operators/}}</ref> *[[Increment and decrement operators|Increment]]: <code>++<span style="color:gray;">x</span></code>, <code><span style="color:gray;">x</span>++</code> *[[Increment and decrement operators|Decrement]]: <code>--<span style="color:gray;">x</span></code>, <code><span style="color:gray;">x</span>--</code> *Positive: <code>+<span style="color:gray;">x</span></code> *Negative: <code>-<span style="color:gray;">x</span></code> *[[Ones' complement]]: <code>~<span style="color:gray;">x</span></code> *[[Negation|Logical negation]]: <code>!<span style="color:gray;">x</span></code> ====C family of languages==== In the [[C (programming language)|C]] family of languages, the following operators are unary:<ref>{{cite book |url=http://www-01.ibm.com/support/docview.wss?uid=swg27002103&aid=1 |page=109 |chapter=5. Expressions and Operators |title=C/C++ Language Reference |version=Version 6.0 |archive-url=https://web.archive.org/web/20121016081612/http://www-01.ibm.com/support/docview.wss?uid=swg27002103&aid=1 |archive-date=2012-10-16}}</ref><ref>{{cite web |url=http://www.sanfoundry.com/c-tutorials-different-unary-operators-operate-operands/ |title=Unary Operators - C Tutorials - Sanfoundry |website=www.sanfoundry.com|date=2 March 2014 }}</ref> *[[Increment and decrement operators|Increment]]: <code>++<span style="color:gray;">x</span></code>, <code><span style="color:gray;">x</span>++</code> *[[Increment and decrement operators|Decrement]]: <code>--<span style="color:gray;">x</span></code>, <code><span style="color:gray;">x</span>--</code> *[[Reference (computer science)|Address]]: <code>&<span style="color:gray;">x</span></code> *[[Indirection]]: <code>*<span style="color:gray;">x</span></code> *Positive: <code>+<span style="color:gray;">x</span></code> *Negative: <code>-<span style="color:gray;">x</span></code> *[[Ones' complement]]: <code>~<span style="color:gray;">x</span></code> *[[Negation|Logical negation]]: <code>!<span style="color:gray;">x</span></code> *[[Sizeof]]: <code>sizeof <span style="color:gray;">x</span>, sizeof(<span style="color:gray;">type-name</span>)</code> *[[Type conversion|Cast]]: <code>(''type-name'') ''<span style="color:gray;">cast-expression</span>''</code> ====Unix shell (Bash)==== In the [[Unix shell]] ([[Bash (Unix shell)|Bash]]/[[Bourne shell|Bourne Shell]]), e.g., the following operators are unary:<ref name="unixbash">{{cite web |title=Shell Arithmetic (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html |website=www.gnu.org |publisher=GNU Operating System |access-date=24 April 2024}}</ref><ref name="unarybash">{{cite web |last1=Miran |first1=Mohammad Shah |title=Unary Operators in Bash |url=https://linuxsimply.com/bash-scripting-tutorial/operator/unary-operators/ |website=LinuxSimply |access-date=24 April 2024 |date=26 October 2023}}</ref> *Pre and Post-Increment: <code>++<span style="color:gray;">$x</span></code>, <code><span style="color:gray;">$x</span>++</code> *Pre and Post-Decrement: <code>--<span style="color:gray;">$x</span></code>, <code><span style="color:gray;">$x</span>--</code> *Positive: <code>+<span style="color:gray;">$x</span></code> *Negative: <code>-<span style="color:gray;">$x</span></code> *Logical negation: <code>!<span style="color:gray;">$x</span></code> * Simple expansion: <code>$<span style="color:gray;">x</span></code> * Complex expansion: <code>${#<span style="color:gray;">x</span>}</code> ====PowerShell==== In the [[PowerShell]], the following operators are unary:<ref name="powershell">{{cite web |title=Expressions - PowerShell |url=https://learn.microsoft.com/en-us/powershell/scripting/lang-spec/chapter-07 |website=learn.microsoft.com |publisher=Microsoft |access-date=23 April 2024 |language=en-us |date=3 September 2021}}</ref> *Increment: <code>++<span style="color:gray;">$x</span></code>, <code><span style="color:gray;">$x</span>++</code> *Decrement: <code>--<span style="color:gray;">$x</span></code>, <code><span style="color:gray;">$x</span>--</code> *Positive: <code>+<span style="color:gray;">$x</span></code> *Negative: <code>-<span style="color:gray;">$x</span></code> *Logical negation: <code>!<span style="color:gray;">$x</span></code> *[[Execution (computing)|Invoke]] in current [[Scope (programming)|scope]]: <code>.<span style="color:gray;">$x</span></code> *Invoke in new scope: <code>&<span style="color:gray;">$x</span></code> *Cast: <code>[''type-name''] ''<span style="color:gray;">cast-expression</span>''</code> *Cast: <code>+<span style="color:gray;">$x</span></code> *Array: <code>,<span style="color:gray;">$array</span></code> ==See also== * [[Unary function]] * [[Binary operation]] * [[Iterated binary operation]] * [[Binary function]] * [[Ternary operation]] * [[Arity]] * [[Operation (mathematics)]] * [[Operator (programming)]] ==References== {{Reflist}} ==External links== *{{Commons category-inline|Unary operations}} {{DEFAULTSORT:Unary Operation}} [[Category:Elementary algebra]] [[Category:Operators (programming)]] [[Category:Unary operations| ]]
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Commons category-inline
(
edit
)
Template:Math
(
edit
)
Template:More citations needed
(
edit
)
Template:Mvar
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Tmath
(
edit
)
Search
Search
Editing
Unary operation
Add topic