Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

To Trinary or not to Ternary

by rendler (Pilgrim)
on Dec 05, 2003 at 17:32 UTC ( #312569=perlquestion: print w/replies, xml ) Need Help??

rendler has asked for the wisdom of the Perl Monks concerning the following question:

As I was chatting with some friends, the subject of my recent knowledge of Unary, Binary and Trinary operators that had read from the Camel popped up. I was instantly corrected for using Trinary with Ternary. I was momentarily a-taken back that I had made such a mistake, when I had only just read about it. But the two people to whom I was chatting have a more vast knowledge of computer science that I conceded to the correction, until I check the book again. At which point they still did not believe that Trinary was the term that was used in the book. Only after I had offered to take a photo of the pages did they relent that this wasn't some sort of joke.

These friends, each knowing their fair share of languages (Java, C, C++, Cobol plus many more) with one being very proficient in Perl, said they had never heard of the term Trinary and that it must be some sort of made up word. And the fact that it was used when Ternary already existed and both seemingly having the exact same meaning, when used to describe an operator in a programming language. Their lack of knowledge pertaining to existence of the term Trinary and their utter disregard to accept it as a real term, even a real English word, surprises me.

So what I would like to know is:

  1. Is there a difference between Trinary, Ternary (in operator specific context).
  2. Why is Trinary used primarily in the Camel.
  3. How could two very knowledgeable people not know of such a term.
  4. Possibly some background history on the terms themselves.

Replies are listed 'Best First'.
Re: To Trinary or not to Ternary
by hardburn (Abbot) on Dec 05, 2003 at 17:42 UTC

    Look in the Camel's glossary under 'trinary':

    Not a stellar system with three starts, but an operator taking three operands. Sometimes pronounced ternary.

    "Trinary" seems like the natural way to spell it (given the logical progression "unary", "binary", . . . ), but I find it more awkward to pronounce. "Ternary" is better in that regard, though less phonetic.

    They really mean the same thing. I'm sure an astronomer would gasp at the thought of "trinary" not being a real word, as your CS-majors claim. (See the Camel's note about a stellar system with three stars).

    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Re: To Trinary or not to Ternary
by Anonymous Monk on Dec 05, 2003 at 17:49 UTC

    Trinary logic is three-level digital logic, with states represented by the numbers -1, 0, and 1. Alternatively, the three states can be represented by the numbers 0, 1, and 2. The smallest number corresponds to logical falsity, the highest number to logical truth, and the middle value to logical neutrality (neither truth nor falsity). Trinary logic is not often used. Binary logic, in which there are only two states represented by 0 and 1, is the most common in computer science and electronics.

      What kind of programming structure would support trinary logic?

      if (<<expr>>) { # true } else { # false } otherwise { # nuetral?? }

      Sounds like fun to me :-)

      Eric Hodges

        A friend and myself sat down and played with trying to create a trinary based system (hardware and software). On the hardware level it was nice, as it seemed to simplify a few things.

        We never did get to an actual OS implementation. I fought with the if/else structure, and still do. The simple if/else is a binary concept, and it was wrong to try and kludge it into a trinary system. We had to figure out a control structure that did the same thing, yet has 3 possible states. I just couldn't quite seem to get "out of the box" and figure out the right concept to implement. Consequently the project has been collecting dust for about a year now.

        The farthest I ever got was something along the lines of almost a multiple test structure, but its really just a renamed if/else, with a builtin elsif. Pseudocode below

        true( test_var for truth_value ) { } false ( test_var for not other_values ) { } neither { # something else }

        Maybe some other monks have insight into how to really leverage this at the software level, but at this point I don't. Maybe if I had a CS degree and knew more of the fundamentals of computing I might have gotten further along. The hardware side though was really impressive. Play with the numbers. Take the possible values for a single byte, and instead of it being base 2 take it to base 3.

        use perl;

        Check out the <=> and cmp operators... :-)
Re: To Trinary or not to Ternary
by jweed (Chaplain) on Dec 05, 2003 at 17:43 UTC

    In fact, my edition of the Camel mentions Trinary as well as Ternary as names for the conditional operator (?:). I know that when I used C++, we used the word ternary.

    Some very brief research reveals that the word Trinary does not "exist," per se. But I believe that lwall & co. actually make a brief joke about the fact that trinary does not exists.

    Who is Kayser Söze?
      Some very brief research reveals that the word Trinary does not "exist," per se.

      Some very brief research on my part reveals that the word "trinary" does exist :-)

      It's in my Chambers Dictionary. It's in my Longman Dictionary of the English Language (which defines it as a synonym of "ternary"). And it's even in my Collins Robert French-English English-French Dictionary.


        And... it's a valid Scrabble™ word.

        "My two cents aren't worth a dime.";
        Well, I gues that the 1913 edition of Webster's Unabrigded and the Free online dictionary of computing just aren't "in the know" ;)

        Who is Kayser Söze?
Re: To Trinary or not to Ternary
by Anonymous Monk on Dec 05, 2003 at 17:47 UTC
    Unary. Binary. Unicycle. Bicycle. Tricycle. Trinary.

    1. Is there a difference between Trinary, Ternary (in operator specific context).

    Trinary is a synonim for Ternary.

    2. Why is Trinary used primarily in the Camel.

    Why do people write Color instead of Colour? It doesn't really matter now does it.

    3. How could two very knowledgeable people not know of such a term.


    4. Possibly some background history on the terms themselves.

    What? Get a thesaurus.

      Trinary is a synonim for Ternary.

      Much like "synonim" is a synonym for 'synonym'. :p


Re: To Trinary or not to Ternary
by Art_XIV (Hermit) on Dec 05, 2003 at 18:46 UTC

    Is there a difference between Trinary, Ternary (in operator specific context).

    No. Ternary is the more common term for the ? : operator, though.

    Why is Trinary used primarily in the Camel.

    I suspect that one of the writers of the Camel book was engaging in some word-play, or was taking a 'dig' at someone/something, or it was an expression of a pet peeve. Maybe merlyn will see this node and can shed some light on this.

    How could two very knowledgeable people not know of such a term.

    People with expansive vocabularies can still not know of the word 'trinary'. Just because a person doesn't know it doesn't mean that it is not a 'real' word, though. An entomologist may not know the etymology of 'entomologist'. You can google it or check Or one of those dead-tree word-looker-upper thingies at the library or bookstore. ;)

    Possibly some background history on the terms themselves.

    The two words are pretty much synonymous, though 'ternary' enjoys more popular use. Both words have Latin roots... 'tri-' and 'tern-' both mean 'three'. Blame it on those darned Romans.

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
Re: To Trinary or not to Ternary
by Ninthwave (Chaplain) on Dec 05, 2003 at 18:09 UTC

    Perl operators come in three arities: unary, binary, and trinary (or ternary, if your native tongue is Shibboleth).
    From the Camel Book. Chapter 3 Unary and Binary Operators.
    It is a play on words

    One entry found for ternary.
    Main Entry: ternary

    Function: adjective
    Etymology: Middle English, from Latin ternarius, from terni three each; akin to Latin tres three -- more at THREE Date: 15th century
    1 a : of, relating to, or proceeding by threes b : having three elements, parts, or divisions : THREEFOLD c : arranged in threes <ternary petals>
    2 : using three as the base <a ternary logarithm>
    3 a : being or consisting of an alloy of three elements b : of, relating to, or containing three different elements, atoms, radicals, or groups <sulfuric acid is a ternary acid>
    4 : third in order or rank

    What the great one is saying is that the word is ternary but logically in English language it is similiar to unicycle, bicycle and tricycle. Plus it sounds like tried any but all and all just a play with the words for humour.

    "No matter where you go, there you are." BB

    Edit by tye, change some < to &lt; -- esp. <a ...>

Re: To Trinary or not to Ternary
by BrowserUk (Patriarch) on Dec 05, 2003 at 20:04 UTC

    It would be interesting to know when, by whom and in what context, ?: first started being termed as either 'the trinary operator' or 'the ternary operator'?

    I just dug through a bunch of old language references including a Kernighain & Ritchie from 1978, Stoustrup from 1986, the Waite's Group ANSI C from 1989 and several others including a Java manual from the late 90's and it is universally referred to as 'the conditional expression'.

    Does anyone else know or have a reference on this?

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail

      FWIW, the actual op used in perl is OP_COND_EXPR, implemented in pp_cond_expr.
Re: To Trinary or not to Ternary
by allolex (Curate) on Dec 05, 2003 at 20:50 UTC

    I think they use "trinary" in the Camel book because most English speakers can immediately grasp the meaning of the word, especially when it is listed alongside "unary" and "binary".

    The prefix tern- came into English from Latin, via Old (Norman) French. The prefix tr(e)i- is a direct borrowing (by scientists) from Latin or Greek.

    This is excerpted from the Oxford English Dictionary, 2nd Ed.:

    trinary, a. and n. rare.
    ad. late L. trinari-us of three kinds (Isidore Orig. iii. vi): cf. L. ternarius ternary.
    A. adj. Consisting or composed of a set of three; threefold; triple; ternary.
    1474 Caxton Chesse iv. ii. (1883) 166 For the trynary nombre conteyneth iii parties whiche make a perfect nombre.
    1884 M. Boole in Athenĉum 23 Aug. 238/1 Ascribing to the Eternal a dividedness projected from the trinary nature of the human faculties.


    ternary, a. and n.
    ad. late L. ternarius consisting of three, f. tern-: see ternal and -ary1. Cf. F. ternaire (15th c.).
    A. adj.
    1. a. Pertaining to, consisting of, compounded of, or characterized by a set (or sets) of three; threefold, triple. ternary system (of classification), one in which each division is into three parts.
    1430 Art Nombryng 19 Some vsen forto distingue the nombre by threes, and ay begynne forto wirche vndre the first of the last ternary other uncomplete nombre.
    1909 Cent. Dict. Suppl. s.v. Symmetry, If (the angle is) 120°, or the crystal repeats itself three times, the symmetry is threefold or ternary and the axis is a triad axis.

    40 years isn't a lot of time in the history of English. I'd say it's just misplaced snobbism.


Re: To Trinary or not to Ternary
by delirium (Chaplain) on Dec 05, 2003 at 22:10 UTC
    I'm not a big fan of either of those words, as they don't sound obscure enough for the wierd a ? b : c of that kind of function. I've always borrowed "tertiary function" from type theory, which generates many pleasing puzzled looks.

    Maybe we should design a word that doesn't have other roots. Let's see... Question mark, Colon.. Que - Co.... Quacko?

      Maybe it could be called an "interrothorpe", sort of like an interrobang and sort of like an octothorpe. Sort of.

      -- Mike

      XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
      -- grantm, perldoc XML::Simpler

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://312569]
Approved by Grygonos
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2023-12-02 05:58 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (13 votes). Check out past polls.