In mathematics, a ternary operation is an n-ary operation with n = 3. A ternary operation on a set A takes any given three elements of A and combines them to form a single element of A.
In computer science, a ternary operator is an operator that takes three arguments as input and returns one output.[1]
T(a,b,c)=ab+c
+
x
In the Euclidean plane with points a, b, c referred to an origin, the ternary operation
[a,b,c]=a-b+c
In projective geometry, the process of finding a projective harmonic conjugate is a ternary operation on three points. In the diagram, points A, B and P determine point V, the harmonic conjugate of P with respect to A and B. Point R and the line through P can be selected arbitrarily, determining C and D. Drawing AC and BD produces the intersection Q, and RQ then yields V.
Suppose A and B are given sets and
l{B}(A,B)
[p,q,r]=pqTr
qT
In Boolean algebra,
T(A,B,C)=AC+(1-A)B
(A\lorB)\land(lnotA\lorC)
In computer science, a ternary operator is an operator that takes three arguments (or operands).[1] The arguments and result can be of different types. Many programming languages that use C-like syntax[3] feature a ternary operator, [[?:]]
, which defines a conditional expression. In some languages, this operator is referred to as the conditional operator.
In Python, the ternary conditional operator reads x if C else y
. Python also supports ternary operations called array slicing, e.g. a[b:c]
return an array where the first element is a[b]
and last element is a[c-1]
.[4] OCaml expressions provide ternary operations against records, arrays, and strings: a.[b]<-c
would mean the string a
where index b
has value c
.[5]
The multiply–accumulate operation is another ternary operator.
Another example of a ternary operator is between, as used in SQL.
The Icon programming language has a "to-by" ternary operator: the expression 1 to 10 by 2
generates the odd integers from 1 through 9.
In Excel formulae, the form is =if(C, x, y).