Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Ternary operation
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 that combines three elements to produce another element}} In [[mathematics]], a '''ternary operation''' is an ''n''-[[arity|ary]] [[operation (mathematics)|operation]] with ''n'' = 3. A ternary operation on a [[set (mathematics)|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 (computer programming)|operator]] that takes three [[parameter (computer programming)|arguments]] as input and returns one output.<ref name = "MDM nmve">{{cite web |last1=MDN |first1=nmve |title=Conditional (ternary) Operator |website=Mozilla Developer Network |url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator |accessdate=20 February 2017}}</ref> ==Examples== [[File:Volledige vierhoek.PNG|thumb|right|Given ''A'', ''B'' and point ''P'', geometric construction yields ''V'', the projective harmonic conjugate of ''P'' with respect to ''A'' and ''B''.]] The [[function (mathematics)|function]] <math>T(a, b, c) = ab + c</math> is an example of a ternary operation on the [[integer]]s (or on any structure where <math>+</math> and <math>\times</math> are both defined). Properties of this ternary operation have been used to define [[planar ternary ring]]s in the foundations of [[projective geometry]]. In the [[Euclidean plane]] with points ''a'', ''b'', ''c'' referred to an origin, the ternary operation <math>[a, b, c] = a - b + c</math> has been used to define [[free vector]]s.<ref>Jeremiah Certaine (1943) [https://www.ams.org/journals/bull/1943-49-12/S0002-9904-1943-08042-1/S0002-9904-1943-08042-1.pdf The ternary operation (abc) = a b<sup>−1</sup>c of a group], [[Bulletin of the American Mathematical Society]] 49: 868–77 {{MR|id=0009953}}</ref> Since (''abc'') = ''d'' implies ''b'' – ''a'' = ''c'' – ''d'', the [[directed line segment]]s ''b'' – ''a'' and ''c'' – ''d'' are [[equipollence (geometry)|equipollent]] and are associated with the same free vector. Any three points in the plane ''a, b, c'' thus determine a [[parallelogram]] with ''d'' at the fourth vertex. 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 <math>\mathcal{B}(A, B)</math> is the collection of [[binary relation]]s between ''A'' and ''B''. [[Composition of relations]] is always defined when ''A'' = ''B'', but otherwise a ternary composition can be defined by <math>[p, q, r] = p q^T r</math> where <math>q^T</math> is the [[converse relation]] of ''q''. Properties of this ternary relation have been used to set the axioms for a [[heap (mathematics)|heap]].<ref>Christopher Hollings (2014) ''Mathematics across the Iron Curtain: a history of the algebraic theory of semigroups'', page 264, History of Mathematics 41, [[American Mathematical Society]] {{ISBN|978-1-4704-1493-1}}</ref> In [[Boolean algebra]], <math>T(A,B,C) = AC+(1-A)B</math> defines the formula <math>(A \lor B) \land (\lnot A \lor C)</math>. ==Computer science== In computer science, a ternary operator is an [[operator (computer programming)|operator]] that takes three arguments (or operands).<ref name="MDM nmve"/> The arguments and result can be of different types. Many [[programming language]]s that use [[C syntax|C-like syntax]]<ref>{{cite web |last1=Hoffer |first1=Alex |title=Ternary Operator |website=Cprogramming.com |url=https://www.cprogramming.com/reference/operators/ternary-operator.html |accessdate=20 February 2017}}</ref> feature a ternary operator, <code>[[?:]]</code>, which defines a [[conditional (programming)#If expressions|conditional expression]]. In some languages, this operator is referred to as the ''conditional operator''. In [[Python (programming language)|Python]], the ternary conditional operator reads <code>x if C else y</code>. Python also supports ternary operations called [[array slicing]], e.g. <code>a[b:c]</code> return an array where the first element is <code>a[b]</code> and last element is <code>a[c-1]</code>.<ref>{{cite web |title=6. Expressions — Python 3.9.1 documentation |url=https://docs.python.org/3/reference/expressions.html |access-date=2021-01-19 |website=docs.python.org}}</ref> [[OCaml]] expressions provide ternary operations against records, arrays, and strings: <code>a.[b]<-c</code> would mean the string <code>a</code> where index <code>b</code> has value <code>c</code>.<ref>{{cite web |title=The OCaml Manual: Chapter 11 The OCaml language: (7) Expressions |website=ocaml.org |url=https://v2.ocaml.org/manual/expr.html |access-date=2023-05-03}}</ref> The [[multiply–accumulate operation]] is another ternary operator. Another example of a ternary operator is ''between'', as used in [[SQL]]. The [[Icon (programming language)|Icon programming language]] has a "to-by" ternary operator: the expression <code>1 to 10 by 2</code> generates the [[parity (mathematics)|odd]] integers from 1 through 9. In Excel formulae, the form is =if(C, x, y). ==See also== * [[Unary operation]] * [[Unary function]] * [[Binary operation]] * [[Iterated binary operation]] * [[Binary function]] * [[Median algebra]] or [[Majority function]] * [[Ternary conditional operator]] for a list of ternary operators in computer programming languages * Ternary [[Exclusive or]] * [[Ternary equivalence relation]] ==References== {{Reflist}} ==External links== *{{Commons category-inline|Ternary operations}} [[Category:Ternary operations| ]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite web
(
edit
)
Template:Commons category-inline
(
edit
)
Template:ISBN
(
edit
)
Template:MR
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)