Talk:Unary operation

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Mathematics (Rated Start-class, Mid-importance)
WikiProject Mathematics
This article is within the scope of WikiProject Mathematics, a collaborative effort to improve the coverage of Mathematics on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Mathematics rating:
Start Class
Mid Importance
 Field: General

I added a phrase on the notion of "single input" which seems not very meaningful to me. An example should be added (e.g. a "binary" (mathematical) function defined on AxB is a unary function defined on E where E=AxB ; a function proc(name,age,address) could as well be written as a function proc(person) where person = struct{name,age,address}, and of course this is already true in a hidden way for several "hidden" complex types (complex number = (real part,imag part), long int = (low word, high word), etc.))

It could be discussed whether this might not apply to functions with various types of "arguments" (in / inout / out) (where the latter are in fact an "improper" way to return the output). — MFH:Talk 12:50, 17 October 2006 (UTC)


Isn't factorial an unary oparation? —Preceding unsigned comment added by (talk) 14:06, 16 November 2006‎

I was just about to ask the same thing! It is probably the example most people know, so I think it would make a good example, unless it actually isn't. Does anybody know? --WikiDonn (talk) 02:25, 25 October 2011 (UTC)

Examples of Unary Operations[edit]

Not all of these are unary:

  • the absolute value operation is a unary operation on the real numbers
    • OK
  • the opposite operation (-x) on the real numbers
    • This is a binary operation. This is the same as multiplying by -1, which is binary operation that requires two operands, x and -1.
  • the power operation (squaring, cubing, etc) on the real numbers
    • Again, this requires two operands. x^n requires both x and n as input values.
  • the factorial operation on the real numbers
    • OK
  • the trigonometric operations (sin x, cos x, tan x, cot x, csc x) on the real numbers
    • OK
  • the natural logarithm (ln x) on the real numbers
    • A logarithm requires a base, which is another operand. In this case, the base is e. Therefore, this has two operands, x and e.
  • the logarithm of base 10 (log x) on the real numbers
    • This requires two operands, x and 10.
  • logical negation on truth values
  • A unary operation on a given set S is nothing but a function SS, also called an endomorphism of S.
    • OK

Pointlessness 16:02, 17 April 2007 (UTC)

All the operations you consider not unary are special cases of binary operations. If one operand in a binary operation is fixed, we have a unary operation on the other operand. So while all these operations can be described by binary operations, the operations as described in the article are unary operations. The negation on real numbers in particular is a good example of this - while it is the same as multiplying by -1, it is quite natural to define this unary operation (taking the additive inverse) without having any notion of multiplication. JPD (talk) 16:25, 17 April 2007 (UTC)

How about the difference operator? Can it also be considered a unary operator? Cako 23:38, 10 October 2007 (UTC)

It can be described as unary, in the sense that it produces one function from a single other function. But operator is traditional nomenclature; I would call it a unary functional. Septentrionalis PMAnderson 02:23, 11 October 2007 (UTC)
"If one operand in a binary operation is fixed, we have a unary operation on the other operand."
Then it all becomes rather arbitrary. If x^n, loge(x), and log10(x) are unitary, you might as well say log4(x), 4throot(x), and 13+x are umitary. (talk) 20:07, 31 March 2009 (UTC)

Usage of Incremental and Decremental operators[edit]

The output of the examples given is clearly wrong. Seth Arlington (talk) 15:25, 1 October 2008 (UTC)

Listen, I just checked the output of the code snippets in question for the 3rd or 4th time now using Borland Turbo C Version 2.01. I don't know which compiler you're using, but unless someone can convince me that there is an error in my compiler, I'm going to correct the article again. Ghettoblaster (talk) 19:42, 1 October 2008 (UTC)
Relying on the output of a single compiler is irresponsible. Seth Arlington (talk) 20:53, 1 October 2008 (UTC)
It appears that C99 leaves order of evaluation for arguments in function calls unspecified. The output of the examples is compiler-specific. It would be best to modify the examples as to avoid confusion. This is almost certainly why your compiler produces different results. Seth Arlington (talk) 21:50, 1 October 2008 (UTC)
What you just found out is already mentioned in the article, so your results are not more correct than the ones that were in the article before you changed it. Remember, these are just examples. I fail to see how your modifications to the examples help to avoid confusion. Ghettoblaster (talk) 23:00, 1 October 2008 (UTC)
"...already mentioned in the article..." Please take a look at the page's history. I am responsible for the text that explains order of evaluation. Additionally, I haven't made any modifications to the examples. Seth Arlington (talk) 23:17, 1 October 2008 (UTC)
I ment the output examples of course. Since there is no single "correct" output, there is no reason for modifying the article to contain the output that you got using your favourite compiler. I also think we should restore the information which compiler/version was used to get the example output. Ghettoblaster (talk) 23:24, 2 October 2008 (UTC)
As an alternative, we could also add the different output one gets using various compilers to the article so that it is possible to compare the different results. Ghettoblaster (talk) 23:29, 2 October 2008 (UTC)

I was just referencing this page and noticed the printf() call with two i++ operations in it. That call invokes undefined behavior in C, not merely implmentation-defined behavior, because it attempts to modify i twice between two sequence points. Thus a compiler can generate any kind of output, including printing nothing, or crashing the program. A compiler is not even required to diagnose instances of undefined behavior, so running this through every compiler won't help settle the question. It's a terrible example.

From the C99 standard:

6.5 Expressions
2 Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.

Here is a much better example which doesn't invoke undefined behavior, yet does generate different results depending on the order the arguments to printf() are evaluated:

int g = 0;

int increment()
     return ++g;

int main( void )
    printf( "%d,%d\n", increment(), increment() );

It can legally print either 1,2 or 2,1, nothing else. I can't think of a shorter one that doesn't invoke undefined behavior or use other language facilities that would require explanation. (talk) 17:28, 14 March 2010 (UTC)

From A to A?[edit]

According to the Operation page an operation is just a function, and a unary operation would thus simply be a function with exactly one operand. In fact, all functions could be seen as unary operations, as taking multiple operands is just a matter of notation: f(x,y) is defined as equal to f((x,y)), i.e. the image of the one single element (x,y). Binary and ternary operations can't be confused this way, as the element (x,y,z) - a 3-tuple - is different from (x,(y,z)) - a 2-tuple. Defining the arity of an operation s.t. f: A->B has arity n iff there exist B1, B2, ..., Bn s.t. A = B1 x B2 x ... x Bn, and for all m and all C1, ..., Cm, A != C1 x ... x Cm - would fix the problem for unary operations. — Preceding unsigned comment added by (talk) 20:28, 30 January 2013 (UTC)

I agree that A to A is incorrect. f: A → A describes an endofunctor instead of a unary operation. Unary operations are not necessarily endofunctors.
For example, the length operator ||v|| produces a scalar value from a vector value. The operator's operand is a value in the set of vectors, and its result is the set non-negative real numbers.
Kodefuguru (talk) 17:53, 29 May 2014 (UTC)
I realize that no one's been here for a long time. I'm going to change the wording to describe f: A → A as an example. After analyzing the text, it appears that may have been the intent.
Kodefuguru (talk) 18:09, 29 May 2014 (UTC)

I'm going to remove from the section on $ shell parameter expansion the examples of `$(command substitution)` and `$((arithmetic expansion))`. In neither of these cases does this reflect anything like a unary operation, as neither need operate on a variable at all, and if they do, the variable needs a second sigil. I.e., `$(echo foo)`, `$(( 4 + $x ))`, etc. Hopefully this makes sense to everyone? Gsnxn (talk) 05:15, 4 January 2015 (UTC)