New Reply

Ternary Operations outside of coding?

 
Share Thread
Feb21-13, 11:08 PM   #1
 
Blog Entries: 3
Recognitions:
Gold Membership Gold Member

Ternary Operations outside of coding?


I use the ternary operation in web development all the time, eg:
x = y > z ? a : b

Which reads, if x > y then a, otherwise b

I realize that it is just a shorthand for if...else statements, but even still, are there any mathematical properties associated with it? I know inequalities have special properties - for example, dividing both sides by a negative.

I recently picked up an elementary book on set theory and I keep thinking about this. It would be interesting to know that in certain cases, I can just skip the operation and automatically assign x to a-something
PhysOrg.com mathematics news on PhysOrg.com

>> Pendulum swings back on 350-year-old mathematical mystery
>> Bayesian statistics theorem holds its own - but use with caution
>> Math technique de-clutters cancer-cell data, revealing tumor evolution, treatment leads
Feb22-13, 09:25 AM   #2
 
Mentor
Quote by OMGCarlos View Post
I use the ternary operation in web development all the time, eg:
x = y > z ? a : b

Which reads, if x > y then a, otherwise b

I realize that it is just a shorthand for if...else statements, but even still, are there any mathematical properties associated with it? I know inequalities have special properties - for example, dividing both sides by a negative.

I recently picked up an elementary book on set theory and I keep thinking about this. It would be interesting to know that in certain cases, I can just skip the operation and automatically assign x to a-something
There aren't any mathematical properties associated with this operator. As you note, it's just a short hand way of writing if ( ... ) then (...).

Your explanation of your example is not quite right.

x = y > z ? a : b

means if y > z, then set x to a. Otherwise, set x to b.

This is equivalent to the following C code:
Code:
if (y > z)
{
   x = a;
}
else
{
   x = b;
}
In answer to your question, no, you can't skip the comparison.
New Reply

Similar discussions for: Ternary Operations outside of coding?
Thread Forum Replies
Ternary operator in C Programming & Comp Sci 13
ternary expansion General Math 2
ternary phase diagram Materials & Chemical Engineering 1
Ternary phase diagram Biology, Chemistry & Other Homework 0
A Ternary Cantor Set proof... Calculus & Beyond Homework 3