What does a sentence actually say?

Language and logic

How they were born together, parted ways and met again in the computer

SEVEN STOPS

Browse the stops with the arrows or by swiping left and right; the timeline stays at the top.

PROLOGUE · TODAY · A PUZZLE TO START

Tea or coffee?

I

QuestionWhere speech and logic don’t match.

Asked “Would you like tea or coffee?”, you answer “both”. The host is taken aback; the logician smiles.

Is “both” a correct answer according to logic? And is the statement “If 2 > 4, then Prague is in Brazil” true?

Reveal the answer

Yes and yes. In everyday speech “or” is often exclusive; in logic and in code (||) it is inclusive: it holds even when both parts hold. And in speech “if” expects a link of cause and effect; in logic it does not: the premise 2 > 4 is false, and an implication with a false premise is true.

II

IdeaThree places where a programmer needs to know this.

  • “Or”: in speech often exclusive (“tea or coffee?”), in logic and in code inclusive.
  • “If”: in speech we expect a link of cause and effect, in logic we don’t.
  • Precedence: language expresses it with intonation and commas, a formal language with brackets and rules. That is why AND binds more tightly than OR, and why it pays to use brackets in conditions.

Logic has always rested on the question of what a sentence says. That is why, throughout its history, it was moved forward by people who studied language. Logic and linguistics were born together, parted ways and met again in the computer. This page is an insert to the chapter Logic.

III

FormulaTwo kinds of “or”.

OR, AND EITHER–OR

or, or both:  p ∨ q

either, or:  (p ∨ q) ∧ ¬(p ∧ q)

Logic does not hear intonation.

STOP I · 3RD CENTURY BCE · ATHENS, THE STOA

The Stoics: grammarians who invented the statement

the Stoic grammarians

I

QuestionGrammar or logic?

Who decides that “Is it raining?” is not a statement – the grammarian or the logician?

Something to think about

For the Stoics, both at once. Telling a statement apart from a question or a command is originally a grammarian’s job: anyone who wants to know of what one can say “it holds” must first sort the kinds of sentences.

II

PersonThe same people, two sciences.

The Stoics were grammarians too. The same people who invented the statement and the connectives (Chrysippus and his school, see the chapter Logic) also worked out the theory of grammatical cases and parts of speech.

We still carry a trace of this today. The Greek ptōsis means “a fall”; the Romans translated it as casus, and English took it over as case. Whenever you talk about the nominative or the genitive case, you are using a Stoic word.

The Stoic grammatical works have not survived in full; we know their teaching mainly from later authors, for example Diogenes Laertius (Lives of the Eminent Philosophers, Book VII).

III

IdeaOf all the kinds of sentences, logic took only one.

Question, command, wish, address, declaration: grammar distinguishes many kinds of sentences. Logic chose only those of which it makes sense to ask “does it hold?”, and called them statements.

FOR THE CURIOUS: SORTING SENTENCES

Which of these sentences are statements?

  1. Prague is the capital of the Czech Republic.
  2. Close the window!
  3. What time is it?
  4. x > 3.
  5. This statement is false.
Solution

Only the first sentence is a statement. A command and a question have no truth value. “x > 3” is an open sentence: it becomes a statement only once we substitute a number for x – like a condition in code, which has a value only once the variable has one. And the last sentence is the liar paradox: declarative, and yet not a statement.

IV

FormulaA statement is what has a truth value.

STATEMENT

“It is raining.”  ↦  0 or 1

“Is it raining?”  ·  “Let it rain!”  ↦  no value

Grammar sorted the kinds of sentences; logic took one of them.

STOP II · 13TH–14TH CENTURY · PARIS, OXFORD

The Middle Ages: what does a word point to?

medieval logicians and the Modistae

I

QuestionThe same word, a different meaning?

In the sentence “A man is running” and in the sentence “Man is a species” the same word appears. Does it point to the same thing in both?

Reveal the answer

No. In the first sentence “man” points to some particular running person. In the second it points to the concept of man: no individual is a species. If we did not tell these apart, we could derive from “Socrates is a man” and “Man is a species” the nonsense “Socrates is a species”.

II

PersonLogicians and Modistae of the medieval universities.

At the universities of Paris and Oxford in the 13th and 14th centuries, logic was taught as the foundation of all study. Medieval logicians (for example Peter of Spain in the 13th century or William of Ockham in the 14th) investigated what exactly a word refers to in a given sentence. They called it suppositio, “standing for”: a word in a sentence stands for certain things, and which ones depends on the sentence.

Alongside them worked the Modistae, grammarians who looked for general “modes” (modi) of expression common to all languages. The best-known Modist work, the Grammatica speculativa of Thomas of Erfurt (early 14th century), is one of the first attempts at a universal grammar.

III

IdeaThree ways a word can stand for something.

  • Personal (suppositio personalis): “A man is running.” The word stands for individuals.
  • Simple (suppositio simplex): “Man is a species.” The word stands for a concept.
  • Material (suppositio materialis): “Man is a noun.” The word stands for itself.

This is a forerunner of today’s distinction between variable and value. A programmer does the same thing every day:

// personal: a concrete value
  man.run()
  // simple: a type, a concept
  class Man { }
  // material: the word itself, a string
  "man".length   // 3
FOR THE CURIOUS: WHAT DO YOU THINK?

How does the word “Prague” stand for something in these sentences: (a) Prague lies on the Vltava. (b) Prague has six letters. (c) Prague is a proper noun.

Solution

(a) personally, it is about the city; (b) and (c) materially, it is about the word. In written text today we solve this with quotation marks: “Prague” has six letters. Quotation marks are exactly what tells a string apart from a variable.

IV

FormulaThe same word, a different notation.

SUPPOSITIO IN TODAY’S NOTATION

A man is running:  ∃x (man(x) ∧ runs(x))

Man is a species:  species(man)

What matters is not the word, but what it stands for in the sentence.

STOP III · 1879 · JENA

Gottlob Frege: a concept script instead of speech

I

QuestionNobody, or somebody?

“Every student doesn’t know Python.” Does that mean that nobody knows it, or that somebody doesn’t?

Something to think about

The sentence can be read both ways, and the language itself does not decide. Exactly this kind of ambiguity is what Frege wanted to drive out of his logic.

II

PersonThe mathematician who distrusted language.

Gottlob Frege (1848–1925), professor of mathematics in Jena, distrusted language. He considered natural language imprecise and ambiguous, and so he created an artificial concept script (Begriffsschrift) – the first formal language with the quantifiers “for all” and “there exists”. Today’s predicate logic comes from it.

1879Gottlob Frege: Begriffsschrift (Concept Script). Fewer than a hundred pages, the first formal language with quantifiers.

The symbols ∀ and ∃ are not Frege’s. Frege wrote two-dimensionally, with lines and hooks; the reversed E (∃) was introduced by Giuseppe Peano, and the inverted A (∀) caught on only in the 20th century.

III

IdeaQuantifiers.

“Every” and “some” are not names of things, but instructions for going through all things: ∀x “for every x it holds that…”, ∃x “there exists an x for which…”. With them the ambiguity disappears from the question:

nobody knows it:  ∀x (S(x) ⇒ ¬P(x))
somebody doesn’t know it:  ¬∀x (S(x) ⇒ P(x))

FOR THE CURIOUS: WHAT DO YOU THINK?

Let S(x) mean “x is a student” and P(x) “x knows Python”. Which formula means “Every student knows Python”: ∀x(S(x) ∧ P(x)), or ∀x(S(x) ⇒ P(x))? And what is its negation?

Solution

The second; the first claims that everybody in the world is a student. The negation: ∃x(S(x) ∧ ¬P(x)), that is, some student doesn’t know Python. The rule: ∀ goes with implication, ∃ with conjunction.

In code you meet quantifiers as every() and some():

people.every(x => !student(x) || python(x))  // ∀x (S(x) ⇒ P(x))
  people.some(x => student(x) && !python(x))   // ∃x (S(x) ∧ ¬P(x))
IV

FormulaNegating a quantifier.

PREDICATE LOGIC

∀x (S(x) ⇒ P(x))

¬∀x (S(x) ⇒ P(x))  ⟺  ∃x (S(x) ∧ ¬P(x))

∀ goes with implication, ∃ with conjunction.

STOP IV · 1932–1934 · VIENNA AND PRAGUE

Rudolf Carnap: cleaning up the language of science

I

QuestionWell-formed, but about what?

The sentence “The Nothing itself nothings” is grammatically fine: subject, verb. But does it say anything at all?

II

PersonThe Vienna Circle and a professor in Prague.

The Vienna Circle, a group of philosophers, mathematicians and physicists in Vienna in the 1920s and 1930s, wanted to “clean up” the language of science: to keep only sentences that are either logically true or verifiable by experience. One of its leading members was Rudolf Carnap (1891–1970), who taught at the German University in Prague from 1931 to 1935.

In 1932 he wrote the article The Elimination of Metaphysics through Logical Analysis of Language. It is famous for its attack on Martin Heidegger’s sentence “The Nothing itself nothings” (from the lecture What Is Metaphysics?, 1929): according to Carnap the sentence looks grammatically correct but violates logical syntax, because it turns “nothing” into a noun.

1934Rudolf Carnap: Logische Syntax der Sprache. Language as a calculus: an alphabet, rules for forming sentences, rules of inference.
III

IdeaLanguage as a calculus.

Carnap’s Logical Syntax of Language treated language as a calculus: an alphabet (which signs we may write), formation rules (which strings are well-formed) and rules of inference (what follows from what). That is exactly how a programming language is built: characters, grammar, evaluation rules.

Carnap’s analysis of Heidegger’s sentence can be shown with an ordinary conversation. “What is outside?” – “Nothing.” Logically this means that there is nothing outside, no x: ¬∃x outside(x). Here “nothing” is not the name of a thing but the negation of a quantifier. Whoever makes it a subject, nothings(Nothing), treats it like a thing, and the sentence loses its meaning even though the grammar is fine.

Programmers know this: code that gets through the parser but fails type checking. Syntactically correct, and still nonsense.

FOR THE CURIOUS: TRY IT!

Write the sentence “Nobody came” in logic. Why may you not conclude from it and from the sentence “Nobody is my friend” that “my friend did not come”?

Solution

¬∃x came(x). “Nobody” is not the name of any person, so it cannot be substituted as x. The inference would turn “nobody” into a person – the same mistake Carnap found in the sentence about the Nothing.

IV

FormulaNothing is not a name.

LOGICAL SYNTAX

There is nothing outside:  ¬∃x outside(x)

The Nothing nothings:  nothings(Nothing)  ✗

Grammatically correct does not yet mean logically meaningful.

STOP V · 1956–1957 · MIT

Noam Chomsky: grammar as a machine

I

QuestionFinitely many rules, infinitely many sentences.

How many rules are enough to produce all correct English sentences, and no incorrect ones?

II

PersonThe linguist whose grammars computer scientists adopted.

Noam Chomsky (born 1928) reversed the direction. Frege and Carnap wanted to replace or clean up language; Chomsky, in 1956–57, did the opposite and used formal grammars to describe natural language, ranking the grammars by their power (the Chomsky hierarchy). Computer scientists adopted it at once: regular expressions, the grammars of programming languages and the parsers in compilers are built directly on it.

1957Noam Chomsky: Syntactic Structures. Formal grammars for natural language; the foundation of compiler theory.

The same book contains the famous sentence “Colorless green ideas sleep furiously”. It is grammatically correct, and yet it makes no sense: the same boundary between form and meaning that Carnap saw.

III

IdeaA grammar is a program that produces sentences.

A formal grammar is a set of rewriting rules. The rule S → ( S ) S | ε says: replace the symbol S either with a pair of brackets with another S inside and after it, or with nothing. A single rule, and out of it come all correctly bracketed expressions.

TypeGrammarsWhere you meet them
3regularregular expressions, lexical analysis
2context-freethe syntax of programming languages, parsers, BNF notation
1context-sensitivethe language anbncn; checking that a variable has been declared
0unrestrictedeverything a Turing machine can compute

Balanced brackets

type some brackets


Why can’t a regular expression do this? A regular grammar remembers only finitely many states, so it cannot count arbitrarily deep nesting. That is why neither HTML nor code can be parsed reliably with regular expressions, and why compilers need a context-free grammar.

IV

FormulaOne rule, infinitely many expressions.

FORMAL GRAMMAR

S → ( S ) S  |  ε

regular ⊂ context-free ⊂ context-sensitive ⊂ unrestricted

A grammar is a program that produces sentences.

STOP VI · 1970 · LOS ANGELES

Richard Montague: English as a formal language

I

QuestionTranslating speech into logic.

Can every English sentence be translated into logic so that a computer can tell what follows from it?

II

PersonThe logician who took language at its word.

Richard Montague (1930–1971), a logician at the University of California, Los Angeles, argued in papers from 1970 (English as a Formal Language, Universal Grammar) that there is no important theoretical difference between natural and formal languages. English can be described just as precisely as the language of logic. He thus founded formal semantics, which computer processing of language draws on today.

Where Frege abandoned language and Carnap wanted to clean it up, Montague claimed that no cleaning was needed: it is enough to find the rules by which the meaning of a sentence is composed from the meanings of its parts.

III

IdeaThe meaning of the whole is composed of the meanings of the parts.

This principle is called compositionality (it is often attributed to Frege). Translating a sentence into logic is then a matter of composition: each word gets its symbol, and the structure of the sentence determines how to combine them. And the structure is exactly where mistakes can happen: try it.

Translate me

click the words

IV

FormulaBrackets matter.

COMPOSITIONALITY

(p ∧ q) ⇒ r

≠  p ∧ (q ⇒ r)

The meaning of the whole is composed of the meanings of the parts – and of the way they are put together.

What we have seen

Logic has always rested on the question of what a sentence says. That is why it was moved forward by people who studied language.

  1. IThe Stoics: the same people invented both the statement and grammatical cases.
  2. IIThe Middle Ages: what a word in a sentence refers to; a forerunner of the distinction between variable and value.
  3. IIIFrege: an artificial concept script instead of ambiguous speech; quantifiers.
  4. IVCarnap: language as a calculus; a grammatically correct sentence need not make sense.
  5. VChomsky: formal grammars and their hierarchy; the foundation of compilers.
  6. VIMontague: natural language as a formal one; computer processing of language.

LANGUAGE AND LOGIC

“Every student knows Python.”

∀x (S(x) ⇒ P(x))

Logic and linguistics were born together, parted ways and met again in the computer.

☜ MAIN CHAPTER Logic How truth became a one: from Aristotle through the Stoics and Boolean algebra to Shannon’s circuits.

Sources and further reading

  • P. Monneret: Séminaire de linguistique théorique, séance 3 (Carnap, Hempel, the Vienna Circle).
  • Stanford Encyclopedia of Philosophy: Ancient Logic, Medieval Theories of Supposition, Frege's Logic, Rudolf Carnap, Montague Semantics.
  • R. Carnap: The Elimination of Metaphysics through Logical Analysis of Language (Überwindung der Metaphysik durch logische Analyse der Sprache), Erkenntnis, 1932.
  • N. Chomsky: Syntactic Structures, 1957.
  • R. Montague: English as a Formal Language and Universal Grammar, 1970.

END OF THE INSERT ON LANGUAGE AND LOGIC

Back to contents