Ternary Operations outside of coding?

In summary: The ternary operator is used to make a choice between two values, based on a condition. If you skip the condition, you would always get the same result. In summary, the ternary operation is a shorthand for if...else statements in web development, but it does not have any mathematical properties. It is used to make a choice between two values based on a condition, and cannot be skipped without always getting the same result.
  • #1
OMGCarlos
28
0
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
 
Mathematics news on Phys.org
  • #2
OMGCarlos said:
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.
 

Related to Ternary Operations outside of coding?

1. What are ternary operations?

Ternary operations refer to operations that involve three operands or inputs. In simple terms, it is a mathematical operation that takes three values and produces a result based on a certain condition.

2. How are ternary operations different from binary operations?

Ternary operations are different from binary operations in that they involve three operands instead of two. This allows for more complex and conditional calculations to be performed.

3. What are some examples of ternary operations?

Some examples of ternary operations include the conditional operator (also known as the ternary operator) in programming languages, such as the ?: operator in C++, and the if/else statement in Excel formulas.

4. What are the advantages of using ternary operations?

One advantage of using ternary operations is that they can make code more concise and easier to read. They can also allow for complex conditional logic to be implemented in a single line of code.

5. Are ternary operations used only in coding?

No, ternary operations can be used in a variety of fields and disciplines, not just in coding. They can be used in mathematics, logic, and even in decision-making processes in everyday life.

Similar threads

Replies
3
Views
385
  • Programming and Computer Science
2
Replies
53
Views
3K
  • Programming and Computer Science
Replies
23
Views
2K
Replies
14
Views
1K
  • Advanced Physics Homework Help
Replies
12
Views
1K
  • Precalculus Mathematics Homework Help
Replies
3
Views
840
  • Nuclear Engineering
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
930
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
2
Views
6K
Back
Top