Ternary operation

Last updated

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.

Contents

In computer science, a ternary operator is an operator that takes three arguments as input and returns one output. [1]

Examples

Given A, B and point P, geometric construction yields V, the projective harmonic conjugate of P with respect to A and B. Volledige vierhoek.PNG
Given A, B and point P, geometric construction yields V, the projective harmonic conjugate of P with respect to A and B.

The function is an example of a ternary operation on the integers (or on any structure where and are both defined). Properties of this ternary operation have been used to define planar ternary rings in the foundations of projective geometry.

In the Euclidean plane with points a, b, c referred to an origin, the ternary operation has been used to define free vectors. [2] Since (abc) = d implies ab = cd, these directed segments are 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 is the collection of binary relations between A and B. Composition of relations is always defined when A = B, but otherwise a ternary composition can be defined by where is the converse relation of q. Properties of this ternary relation have been used to set the axioms for a heap. [3]

In Boolean algebra, defines the formula .

Computer science

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 [4] 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]. [5] OCaml expressions provide ternary operations against records, arrays, and strings: a.[b]<-c would mean the string a where index b has value c. [6]

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).

See also

Related Research Articles

<span class="mw-page-title-main">Associative property</span> Property of a mathematical operation

In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement for expressions in logical proofs.

<span class="mw-page-title-main">Logical disjunction</span> Logical connective OR

In logic, disjunction, also known as logical disjunction or logical or or logical addition or inclusive disjunction, is a logical connective typically notated as and read aloud as "or". For instance, the English language sentence "it is sunny or it is warm" can be represented in logic using the disjunctive formula , assuming that abbreviates "it is sunny" and abbreviates "it is warm".

First-order logic—also known as predicate logic, quantificational logic, and first-order predicate calculus—is a collection of formal systems used in mathematics, philosophy, linguistics, and computer science. First-order logic uses quantified variables over non-logical objects, and allows the use of sentences that contain variables, so that rather than propositions such as "Socrates is a man", one can have expressions in the form "there exists x such that x is Socrates and x is a man", where "there exists" is a quantifier, while x is a variable. This distinguishes it from propositional logic, which does not use quantifiers or relations; in this sense, propositional logic is the foundation of first-order logic.

<span class="mw-page-title-main">Logical conjunction</span> Logical connective AND

In logic, mathematics and linguistics, and is the truth-functional operator of conjunction or logical conjunction. The logical connective of this operator is typically represented as or or (prefix) or or in which is the most modern and widely used.

<span class="mw-page-title-main">Logical connective</span> Symbol connecting sentential formulas in logic

In logic, a logical connective is a logical constant. They can be used to connect logical formulas. For instance in the syntax of propositional logic, the binary connective can be used to join the two atomic formulas and , rendering the complex formula .

Propositional calculus is a branch of logic. It is also called propositional logic, statement logic, sentential calculus, sentential logic, or sometimes zeroth-order logic. It deals with propositions and relations between propositions, including the construction of arguments based on them. Compound propositions are formed by connecting propositions by logical connectives. Propositions that contain no logical connectives are called atomic propositions.

<span class="mw-page-title-main">Quasigroup</span>

In mathematics, especially in abstract algebra, a quasigroup is an algebraic structure resembling a group in the sense that "division" is always possible. Quasigroups differ from groups mainly in that the associative and identity element properties are optional.

In logic, mathematics, and computer science, arity is the number of arguments or operands taken by a function, operation or relation. In mathematics, arity may also be called rank, but this word can have many other meanings. In logic and philosophy, arity may also be called adicity and degree. In linguistics, it is usually named valency.

A mathematical symbol is a figure or a combination of figures that is used to represent a mathematical object, an action on mathematical objects, a relation between mathematical objects, or for structuring the other symbols that occur in a formula. As formulas are entirely constituted with symbols of various types, many symbols are needed for expressing all mathematics.

<span class="mw-page-title-main">Exclusive or</span> True when either but not both inputs are true

Exclusive or or exclusive disjunction or exclusive alternation, also known as non-equivalence which is the negation of equivalence, is a logical operation that is true if and only if its arguments differ.

In mathematics, a Kleene algebra is an idempotent semiring endowed with a closure operator. It generalizes the operations known from regular expressions.

In mathematics, the Cayley–Dickson construction, named after Arthur Cayley and Leonard Eugene Dickson, produces a sequence of algebras over the field of real numbers, each with twice the dimension of the previous one. The algebras produced by this process are known as Cayley–Dickson algebras, for example complex numbers, quaternions, and octonions. These examples are useful composition algebras frequently applied in mathematical physics.

Relevance logic, also called relevant logic, is a kind of non-classical logic requiring the antecedent and consequent of implications to be relevantly related. They may be viewed as a family of substructural or modal logics. It is generally, but not universally, called relevant logic by British and, especially, Australian logicians, and relevance logic by American logicians.

In mathematics, a subset of a given set is closed under an operation of the larger set if performing that operation on members of the subset always produces a member of that subset. For example, the natural numbers are closed under addition, but not under subtraction: 1 − 2 is not a natural number, although both 1 and 2 are.

<span class="mw-page-title-main">Commutative property</span> Property of some mathematical operations

In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. Most familiar as the name of the property that says something like "3 + 4 = 4 + 3" or "2 × 5 = 5 × 2", the property can also be used in more advanced settings. The name is needed because there are operations, such as division and subtraction, that do not have it ; such operations are not commutative, and so are referred to as noncommutative operations. The idea that simple operations, such as the multiplication and addition of numbers, are commutative was for many years implicitly assumed. Thus, this property was not named until the 19th century, when mathematics started to become formalized. A similar property exists for binary relations; a binary relation is said to be symmetric if the relation applies regardless of the order of its operands; for example, equality is symmetric as two equal mathematical objects are equal regardless of their order.

In logic, a truth function is a function that accepts truth values as input and produces a unique truth value as output. In other words: The input and output of a truth function are all truth values; a truth function will always output exactly one truth value; and inputting the same truth value(s) will always output the same truth value. The typical example is in propositional logic, wherein a compound statement is constructed using individual statements connected by logical connectives; if the truth value of the compound statement is entirely determined by the truth value(s) of the constituent statement(s), the compound statement is called a truth function, and any logical connectives used are said to be truth functional.

In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality and inequalities.

In computing, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another.

In abstract algebra, a semiheap is an algebraic structure consisting of a non-empty set H with a ternary operation denoted that satisfies a modified associativity property:

A truth table is a mathematical table used in logic—specifically in connection with Boolean algebra, boolean functions, and propositional calculus—which sets out the functional values of logical expressions on each of their functional arguments, that is, for each combination of values taken by their logical variables. In particular, truth tables can be used to show whether a propositional expression is true for all legitimate input values, that is, logically valid.

References

  1. 1 2 MDN, nmve. "Conditional (ternary) Operator". Mozilla Developer Network. Retrieved 20 February 2017.
  2. Jeremiah Certaine (1943) The ternary operation (abc) = a b−1c of a group, Bulletin of the American Mathematical Society 49: 868–77 MR 0009953
  3. 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
  4. Hoffer, Alex. "Ternary Operator". Cprogramming.com. Retrieved 20 February 2017.
  5. "6. Expressions — Python 3.9.1 documentation". docs.python.org. Retrieved 2021-01-19.
  6. "The OCaml Manual: Chapter 11 The OCaml language: (7) Expressions". ocaml.org. Retrieved 2023-05-03.