https://retrocomputing.stackexchange.com/questions/27741/how-were-the-signs-for-logical-and-arithmetic-operators-decided Stack Exchange Network Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange [ ] Loading... 1. + Tour Start here for a quick overview of the site + Help Center Detailed answers to any questions you might have + Meta Discuss the workings and policies of this site + About Us Learn more about Stack Overflow the company, and our products. 2. 3. current community + Retrocomputing help chat + Retrocomputing Meta your communities Sign up or log in to customize your list. more stack exchange communities company blog 4. 5. Log in 6. Sign up Retrocomputing Stack Exchange is a question and answer site for vintage-computer hobbyists interested in restoring, preserving, and using the classic computer and gaming systems of yesteryear. It only takes a minute to sign up. Sign up to join this community [ano] Anybody can ask a question [ano] Anybody can answer [an] The best answers are voted up and rise to the top Retrocomputing 1. Home 2. 1. Public 2. Questions 3. Tags 4. Users 5. Companies 6. Unanswered 3. Teams Stack Overflow for Teams - Start collaborating and sharing organizational knowledge. [teams-illo-free-si] Create a free Team Why Teams? 4. Teams 5. Create free Team Teams Q&A for work Connect and share knowledge within a single location that is structured and easy to search. Learn more about Teams How were the signs for logical and arithmetic operators decided? Ask Question Asked 2 days ago Modified today Viewed 7k times 12 I'm curious as to how exactly some of the logical and arithmetic operator signs were decided? The plus and minus operators make sense, but how was decided that / was the division operator or that * was the multiplication operator? Also how did we get && as the logical AND operator or || as the logical OR operator? Now I know not all languages use them but their use does seem widespread to a large extent. Somebody or something must have decided on there use in computer science. * history * programming Share Improve this question Follow edited 2 days ago Neil Meyer asked 2 days ago Neil Meyer's user avatar Neil MeyerNeil Meyer 5,98388 gold badges2727 silver badges4141 bronze badges 10 * 9 There were only so many characters available to use. And once one language used them one way it was easy for subsequent languages to use them as well. - Jon Custer 2 days ago * 4 This might be a better question for langdev.stackexchange.com - kouta-kun 2 days ago * 5 The vertical bar for 'or' and asterisk for multiplication are probably the most mysterious. The rest seem pretty straightforward too: the ampersand has long been an abbreviation for 'and', the slash has been likewise used for fractions. I think it's also well-known that doubling the symbols for logical operators came from C needing to have separate forms because bitwise operators could not be made to short-circuit. - user3840170 2 days ago * 7 Vertical bar for 'or' has precedent in Backus Naur Form, as used in the Algol 60 report. I imagine Naur just chose from what was available on his typewriter, though it seems perfect for the meaning of 'alternative'. - another-dave 2 days ago * 4 @kouta-kun We have accepted questions about the origin of code notations before; that a new site exists that could also accept this question is not a reason to reject it here. (Also, langdev is an insufferable Bikeshedding Central.) - user3840170 2 days ago | Show 5 more comments 4 Answers 4 Sorted by: Reset to default [Highest score (default) ] 25 Martin Richards, the designer of BCPL (based on Algol-60 and CPL, and the predecessor for B and C), had this to say on the motivation for many such decisions: It was not until July 1967 that a specification of a character set was published that closely resembles the ASCII character set we have today. Prior to that, computers typically had their own character sets and these were often quite limited. For instance, on the first machine on which BCPL ran, namely an IBM 7094 running CTSS, the standard code used 6-bit characters packed in 36-bit words. The characters available were essentially those used in Fortran and did not include square or curly brackets ([ ] { }), semicolon (;), double quote (") or underscore (_) and commonly used terminals such as the Model 35 Teletype only permitted letters in upper case. However, at Cambridge, CPL programs used a much richer character set since they were typically prepared using a Flexowriter which was an electric typewriter that was combined with a 7-track paper tape reader and punch. The available characters included backspace and so overprinting was possible and used to represent symbols such as [?]. System words such as while were underlined to distinguish them from ordinary identifiers. BCPL on the 7094 thus had to represent lexical tokens quite differently. Most of the commonly-used ASCII representations of operators were codified in either B or C. Many two-character tokens seem to have been chosen based on how some terminals could print one character on top of another. For example, on many paper terminals, e would have been represented as e-backspace-^, which on a terminal that didn't support overstriking, would display as e^. When programming languages were transitioning to ASCII in the late '60s, this seems to have inspired several of the two-character operators familiar to us today. So, != would look like a vertical stroke across an equals sign if they were printed on top of each other. Note that =| was already taken in B for the binary operator that became |= in C. Algol and BCPL originally had <= (which some machines could represent as an underlined <, and others replaced with a text mnemonic). This became =< in B and early C, and <= in BASIC, C and languages influenced by them. Probably, C reversed all the equals operators at the same time, so that typos such x=-1 for x = -1 would no longer cause so many bugs. This happened to make the existing != operator look as though x != 0 should be a synonym for x = !0, which the syntax of B did not imply. However, perhaps because all C users knew B and != is never used in a context where anyone would ever suspect it meant if (x = !0), the designers of C saw no need to change it. Multiplication and Exponentiation A recent question on LangDev.SX discussed the history of *. The use of an asterisk for multiplication in printed books goes back at least to Johann Heinrich Rahn in 1659. The first programming language to use it was Fortran. Fortran's preliminary report, in 1954, proposed using x for multiplication and xx for exponentiation.. By 1956, * and ** had been chosen instead. MATH-MATIC (deriving from work by Grace Hopper) was being developed at the same time and also settled on * sometime between 1955 and 1957. John Backus said this was a coincidence, and that he was unaware of much previous work that came to light later. He made this choice because of the very limited 48-character set of the BCD-coded punch cards he needed to support, and even removed comparisons from DO loops because of the lack of a < character (giving rise to .LT.). The convention of ^ for exponentiation derived from Algol's choice of | (perhaps because it represents raising the exponent). Dartmouth BASIC in 1964 originally used this symbol as well, despite being primarily based on Fortran. Some early teletypes and computers displayed character 5E as |, but ASCII standardized it as ^, and BASIC was the first language to officially make exponentiation ^. This symbol was later adopted by AWK and Donald E. Knuth's TeX. The ubiquity of TeX in mathematics is probably what led other languages used primarily by mathematicians to follow suit. Logical Operators The Medieval Latin abbreviation & (originally a stylized et) came to be read as and in many languages that use the Latin script. Algol used [?] for or in the reference language itself, but the hugely influential ALGOL-60 report also was the first to use BNF grammar. Its section 1.1 introduces the syntax of BNF with: The marks ::= and | (the latter with the meaning of or) are metalinguistic connectives. Successor languages designed after ASCII had become dominant used | to mean or within the language itself. B in particular had no short-circuting logical or, only bitwise or, and used | to mean that. BCPL and B had the optimization that a & at the top level of a conditional expression, such as if (p & q), would short-circuit. Algol had used the standard symbol ! for logical not. Since that did not make it into ASCII and B had only bitwise complement (representing false as 0 and true as ~0, or -1 in two's-complement), B used the closest available character to ! in ASCII, ~. Ken Thompson would later call the choice of ^ for exclusive-or in B "a random choice of the characters left," and say, "if i had it to do over again (which i did) i would use the same operator for xor (^) and bit complement (~)" The "(which i did)" is a reference to how he made "the better-known operator" ^ mean both bitwise complement and exclusive-or in Golang. The && and || operators first appeared in C. Dennis Ritchie credits Alan Snyder for them. Rapid changes continued after the language had been named, for example the introduction of the && and || operators. In BCPL and B, the evaluation of expressions depends on context: within if and other conditional statements that compare an expression's value with zero, these languages place a special interpretation on the and (&) and or (|) operators. In ordinary contexts, they operate bitwise, but in the B statement if (e1 & e2) ... the compiler must evaluate e1 and if it is non-zero, evaluate e2, and if it too is non-zero, elaborate the statement dependent on the if. The requirement descends recursively on & and | operators within e1 and e2. The short-circuit semantics of the Boolean operators in such `truth-value' context seemed desirable, but the overloading of the operators was difficult to explain and use. At the suggestion of Alan Snyder, I introduced the && and || operators to make the mechanism more explicit. Speculation The division sign / was probably chosen to represent a fraction slash, as in 2/3. The % symbol for modulus was likely picked as the closest ASCII equivalent of /. Its occasional use for cents might have suggested its use for a remainder. Share Improve this answer Follow edited 2 hours ago Community's user avatar CommunityBot 1 answered yesterday Davislor's user avatar DavislorDavislor 8,4612828 silver badges3434 bronze badges 18 * 1 It's somewhat speculative, but the caret may have been a simplification of the triangle operator used to denote symmetric difference of sets. - user3840170 yesterday * 4 "Note that =| was already taken for the binary operator that became =| in C". Worth pointing out that, in early C iterations, the assignment operators were all the other way around i.e. you didn't have += you had =+. They were changed later (as you alluded) to obviate syntactic ambiguities. - JeremyP yesterday * 3 Actually, BASIC had <= and >= and <> before B or C. BASIC also introduced the ^ operator for exponentiation and seems to have pioneered the apparently radical idea of using AND and OR to represent the AND and OR operators. I've always found it distracting how willing people have been to forget BASIC's contributions to programming history, and how correspondingly willing they are to attribute things to C (or B) that neither invented. - RBarryYoung yesterday * 1 "Emulating AND' is just if A then if B ... but the else's can get tricky. This is necessary in BLISS, for example, which did not possess short-circuit AND. - another-dave yesterday * 2 @RBarryYoung: Didn't Fortran use .OR. and .AND. as the logical operators well before basic? - Flydog57 yesterday | Show 13 more comments 7 but how was decided that / was the division operator or that * was the multiplication operator? Well, in mathematics you write fractions with a horizontal line, and simple fractions that couldn't be multiple lines already used / (and today we have unicode 1/2 etc.), so / is really the obvious choice. Multiplication was already sometimes written as x (and the unicode character is still called "multiplication"), so using an asterisk * was the next best approximation in ASCII. If * is multiplication, then ** as exponentiation is also easy, as is ^ to denoate the superscript notation for exponentiation. Using & (literally ampersand or and-per-se-and, "and by itself") for "and" is also obvious. If you want to use & for bitwise and, then && for logical "short-circuit" and isn't that mysterious. I don't know where | for or comes from. As far as I know the C inventors tried to stay as far away from Algol as possible. Share Improve this answer Follow answered 2 days ago dirkt's user avatar dirktdirkt 25.6k33 gold badges6969 silver badges105105 bronze badges 2 * 3 Both & and | come from BCPL. This was a change from its predecessor CPL, largely due to the desire to limit the character set to ASCII, which was standardized about the same time BCPL was being developed. Interesting history here - Chris Dodd 2 days ago * | came to C from BCPL via B. | is not a symbol in the Algol 60 reference language, though it may be used in some implementation. | is used as a delimiter in if and case clauses in Algol 68 (the brief forms). - another-dave 2 days ago Add a comment | 4 With respect to && and ||, there are two issues at play. Firstly, what symbols shall be used for 'and' and 'or'? Many choices have been made: [?] [?] (Algol 60) .AND. .OR. (Fortran) & | (BCPL) It comes down to a consideration of what will be available on the expected input devices. Secondly, what are the semantics? In 'A and B', should B be evaluated if A is known to be false? In 'A or B', should B be evaluated if A is known to be true? If you answer in the negative, it follows that 'A and B' differs from 'B and A' - the operator is no longer commutative. One workaround is to say that the meaning is context-dependent: 'if' conditions are different to assignments (as in BCPL). But that's not nice. The alternative is to introduce different syntax for the short-circuit cases. C in particular did this. Now the question is, what symbols to choose for the new operators? I'd suggest that doubling-up (&&, ||) nicely conveys both that they are related to 'and' and 'or' (&, |) but different. I can't think of any better within C's self-imposed restriction to the ASCII character set. Since then, many other languages, particularly 'brace languages', have followed suit on the grounds of familarity. Share Improve this answer Follow edited 2 days ago answered 2 days ago another-dave's user avatar another-daveanother-dave 32.5k55 gold badges7373 silver badges147147 bronze badges 3 * Back in the 1970s, I used to really dislike FORTRAN's relational operators since they were written in allcaps and often without spaces, but I think writing an expression as x = foo .rdiv. bar; to perform e.g. rounding integer division would be clearer than trying to understand all the other ways someone might try to write similar constructs. - supercat 2 days ago * The choices made for BCPL seem to be due to character set limitations, so choosing ASCII replacements for things that use other symbols in traditional notation. This is also where ~ instead of ! comes from - Chris Dodd 2 days ago * 3 Re FORTRAN - not a lot of choices in the 026 character set +-0123456789ABCDEFGHIJKLMNOPQR/STUVWXYZ ='.)$*,( ! - another-dave 2 days ago Add a comment | 3 The vertical bar was in use as a kind of a binary Boolean operation since the 1910s: In 1913, Sheffer described non-disjunction using | and showed its functional completeness. Sheffer also used [?] for non-disjunction. Many people, beginning with Nicod in 1917, and followed by Whitehead, Russell and many others, mistakenly thought Sheffer has described non-conjunction using |, naming this the Sheffer Stroke. While the train of thought leading to the use of | for disjunction in the B language is unclear, its established use in mathematical logic notation likely had an influence. Share Improve this answer Follow answered yesterday Leo B.'s user avatar Leo B.Leo B. 18.1k55 gold badges4444 silver badges130130 bronze badges 4 * But the Sheffer Stroke is NAND, and not OR. - dirkt yesterday * @dirkt That's exactly why I've said that the train of thought leading to its use for OR is unclear. Note, however, that | and [?] which Sheffer used for NOR, are effectively the same symbols as | and ^ for OR and XOR, so "Look, here's characters which look like ASCII, being used for some Boolean functions! Let's use them for the Boolean functions that we need in our language!" does not seem too far-fetched. - Leo B. yesterday * 1 @LeoB.: I find it a bit curious that programming languages never seem to have a bitwise operator for "AND NOT", which would be to "OR" what "-" is to "+". It would for many purposes be semantically superior to using separate bitwise "AND" and "NOT" operators because the type of the right operand would be balanced with the left operand before negation, so 0x987654321uLL __andnot__ 0x80000000u would yield 0x907654321 even though on a 32-bit or 64-bit system 0x987654321uLL &~ 0x80000000u would yield 0x07654321uLL. - supercat yesterday * The PDP-11 and VAX of course have 'AND NOT' instructions in their repertoire: "bit clear'. 'BIC R1,R2` means R2 := R2 & ~R1 - another-dave 23 hours ago Add a comment | You must log in to answer this question. Not the answer you're looking for? Browse other questions tagged * history * programming . * The Overflow Blog * Like Python++ for AI developers * Being creative with math: The immersive artist who traded a sketchpad for a... * Featured on Meta * Alpha test for short survey in banner ad slots starting on week of September... * What should be next for community events? * Should we avoid the low rep voting experiment? Linked 11 Why is the BBC Micro's Mode 7 so different to the other display Modes? Related 7 When were the analogs of the C operators "break" and "continue" introduced in Pascal? 12 How did most fifth-generation consoles avoid wobbly graphics? 3 What is the layout of the directory track on a TRS-80 Model I/Model III disk? 11 Was there an input device capable of entering all Algol 60 symbols with correct appearance? 14 Origin of "arithmetic" and "logical" for signed and unsigned shifts 9 Besides the IBM 709 and its descendents, did any other machine have "slightly longer" registers? 24 What accounted for the cost of ENIAC? 17 What was the first programming language to use `+` for string concatenation? 9 Historical installed base figures for early lines of personal computer? Hot Network Questions * Is a passenger who is flying the aircraft liable for regulations that they violate? * My Medieval kingdom has birth control, why is the population so high? * How were the signs for logical and arithmetic operators decided? * I have a distribution block buried under my center console. Would getting 12v from that line vs directly from the battery present any fire hazard? * Iteration counts of AMG solver changes in parallel * What does this sentence mean in Stephen King's IT? * Is this revision of the level 2 Transmutation Wizard feature balanced? [Version 3] * How would you deal with an (actual) etymology that makes no sense in-game? * Geometrical verifications for Algebraic formulae * Is it illegal to have a product delivered to a different ZIP code to pay less sales tax? * Is Goddess Durga Brahman or Maya? Why is she termed as Brahman in some places and maya in others? * How do I screw through a metal bathroom fan box to affix it to the joist? * Is Ming Zhao a typo for Zao Zhao ? * "Premove" in OTB game * Same flight taking one hour longer with same aircraft on different dates * How to find the font file in macOS 13.3 * Why does Robin Williams have a dark beard in the poster? * "bieten" with the meaning of "to ensure" * What does "(which see)" means in various Emacs help docstrings? * Why does English use the French "sans" for sans serif? * How to describe the Sun's location to an alien from our Galaxy? * How do I properly address and handle work burnout? * What would be the range of a cargo 777 full of usable fuel up to MTOW? * Low-noise/Stable power source options more hot questions Question feed Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. [https://retrocomputi] * Retrocomputing * Tour * Help * Chat * Contact * Feedback Company * Stack Overflow * Teams * Advertising * Collectives * Talent * About * Press * Legal * Privacy Policy * Terms of Service * Cookie Settings * Cookie Policy Stack Exchange Network * Technology * Culture & recreation * Life & arts * Science * Professional * Business * API * Data * Blog * Facebook * Twitter * LinkedIn * Instagram Site design / logo (c) 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.9.28.43651 Your privacy By clicking "Accept all cookies", you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Accept all cookies Necessary cookies only Customize settings