Sentential Logic/Unique Readability and a Parsing Algorithm

Lesson 2.31,113 words

Unique Readability and a Parsing Algorithm

Parentheses keep a formula from being read two ways. The parenthesis lemmas and a top-down parsing algorithm recover a formula's structure and yield unique readability: every wff has exactly one formation tree, which is what makes the truth recursion well defined.

╌╌╌╌

The truth recursion assigns by climbing the formation tree of , which makes sense only if has one formation tree. It does: the parentheses in the definition of a wff leave no formula ambiguous.

Without parentheses, ambiguity is immediate. The string can be assembled two ways, as or as . Under , the two readings disagree — the first is (its conjunction has a false right conjunct), the second (its disjunction has a true left disjunct) — so would have no well-defined value. The parentheses in every exist to forbid exactly this.1

The parenthesis lemmas

Two facts about how parentheses distribute in a wff are used throughout. The first was proved in the formation lesson.

The consequence follows from the lemma with the parenthesis-balance lemma: a wff is balanced, but a proper initial segment is left-heavy, so a proper initial segment cannot be a wff.

The running count of unmatched left parentheses makes the lemma visual. Scan a wff left to right, adding at each and subtracting at each . The parenthesis-balance lemma says the count returns to at the end; the initial-segment lemma says it stays strictly positive at every proper initial segment along the way.

Unmatched left parentheses while scanning a wff left to right. The count ends at zero (balanced) but is strictly positive at every proper initial segment, so no prefix closes off into a wff of its own.

The parsing algorithm

The initial-segment lemma forces every choice a parser could make. The algorithm reads an expression and either rejects it or builds its formation tree from the top down, splitting each compound at its principal connective.

Algorithm:Parse(ε)\textsc{Parse}(\varepsilon) — build the formation tree of an expression, or reject
  1. 1
    place ε\varepsilon at the root; mark it the only vertex
  2. 2
    repeat
  3. 3
    if every minimal vertex holds a sentence symbol then
  4. 4
    return the tree
    ε\varepsilon is a wff
  5. 5
    select a minimal vertex whose expression μ\mu is not a sentence symbol
  6. 6
    if the first symbol of μ\mu is not "(" then reject
  7. 7
    if the second symbol of μ\mu is "¬\neg" then
  8. 8
    μ\mu must be (¬β)(\neg\, \beta) with β\beta an expression
  9. 9
    attach one child holding β\beta
  10. 10
    else
  11. 11
    scan from the left to the shortest (α(\alpha with α\alpha balanced and nonempty
  12. 12
    the next symbol must be a binary connective
    the principal connective
  13. 13
    the remainder must be β)\beta) with β\beta an expression
  14. 14
    attach children holding α\alpha and β\beta
  15. 15
    until the tree is complete

Four observations establish correctness.1

  • Termination. Each child holds a strictly shorter expression than its parent, so the tree depth is bounded by the length of .
  • Forced choices. In the binary case the first constituent must be exactly : any shorter prefix is unbalanced (violating the parenthesis-balance lemma applied to a would-be constituent), and any longer one contains the balanced as a proper initial segment (violating the initial-segment lemma). The principal connective and the second constituent are then determined.
  • Rejection is sound. If the algorithm rejects, the only possible attempt to build a tree has failed, so was no wff.
  • Acceptance is sound. If it succeeds, working up the finished tree shows every vertex holds a wff, the root included.
The parsing decision flow for one non-atomic vertex; every branch is forced, so the tree it produces is the only tree the expression admits.

Unique readability

Because every choice the parser makes is forced, it constructs the only possible tree for the given wff. This is the central syntactic fact of the language.

The language is unambiguous, and the parser exhibits the tree — what the truth recursion needed. For any wff there is one tree; propagating values up it assigns without ambiguity, and the resulting function meets the recursion clauses. So exists, completing the half of the unique-extension theorem left open under truth assignments. The general form of this unique readability licenses recursion argument is the recursion theorem.

An almost-ambiguous string is pinned to a single reading by its parentheses: the outer conjunction, not the disjunction, is the principal connective, so only the left tree is a legal parse.

The figure shows the two readings of : only the tree whose root is the conjunction is a legal parse, because the outermost matched pair of parentheses encloses with as its principal connective.

Polish notation

Parentheses are one way to avoid ambiguity; they are not the only way. Polish (prefix) notation writes the connective before its arguments and drops the parentheses entirely. In place of one writes , and the P-wffs are generated from the sentence symbols by

The same formula parenthesized (infix) and in parenthesis-free Polish prefix notation; the connective moves ahead of its operands, and no punctuation is needed to recover the structure.

Polish notation is well suited to machine processing; compilers routinely convert input formulas into it. Its own unique readability theorem is proved in the first-order parsing lesson, where the parenthesis-free case reappears.

Omitting parentheses

For readability, some parentheses are dropped by convention when naming wffs, with precedence rules restoring them.

  • Outermost parentheses are omitted: names .
  • Negation binds tightest: is , not .
  • Conjunction and disjunction bind tighter than the conditional and biconditional: is .
  • Repeated connectives group to the right: is .

These abbreviations violate the strict naming rules on purpose; the license is harmless because only wffs are ever named, and each abbreviation restores to exactly one wff.

Footnotes

  1. Enderton, §1.3 — the ambiguity of unparenthesized strings, Lemmas 13A and 13B, the top-down parsing algorithm with its four correctness observations, unique readability, Polish notation, and the parenthesis-omission conventions. 2

╌╌ END ╌╌