Skip to content

§7.3 CFL closure under union / concatenation / Kleene star (Lean, from scratch) - #105

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/v2-grammar-proofs-audit-1yqgxh
Jun 26, 2026
Merged

hyperpolymath merged 1 commit into
mainfrom
claude/v2-grammar-proofs-audit-1yqgxh

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Closes the last open item from grammar-proofs.md §7.3 (positive direction):
the class of context-free languages is closed under union, concatenation, and
Kleene star
— machine-checked from scratch (no Mathlib).

WokeGrammarCFL.lean (Lean 4.30.0, CI-gated, sorry-free, propext-only)

  • A general CFG: a production relation P : N → List (N ⊕ T) → Prop with a mutual
    derivation relation Gen/GenL; IsCFL L := ∃ grammar generating exactly L.
  • One reusable core lemma embGen_iff: embedding a grammar's nonterminals
    into a larger disjoint grammar preserves the generated language. This is the
    load-bearing result — a lift direction plus a generalized-index structural
    reflection
    (the index is generalized to a variable + equation so Lean's mutual
    brecOn accepts the recursion).
  • The three closures as grammar constructions, each with a full language-equality
    proof:
    • cfl_union — none → S1 \| S2
    • cfl_concat — none → S1 S2
    • cfl_star — none → ε \| S1 S (the self-recursive one; handled via a mutual
      Gen/GenL forward pass)
    • cfl_single — {[t]} is context-free (non-vacuity).

#print axioms → propext only. The WokeLang surface grammar is context-free, so
it inhabits this class and these operations apply to it.

Still scoped (honestly)

§7.3 non-closure under intersection / complement needs the pumping lemma for
CFLs
(e.g. to show aⁿbⁿcⁿ is not context-free) — a separate larger development,
recorded in GRAMMAR-PROOF-INVENTORY.md rather than stubbed.

Status of the whole grammar-proofs effort

With this PR, every prose claim in grammar-proofs.md is now machine-checked
except the §7.3 negative-closure results: parser metatheory (Lean + Coq),
no-left-recursion (+ the guard-pattern bug found), lexer munch/priority,
LL(1)✗/LL(2)✓, §7.1 not-regular, and §7.3 positive closure.

🤖 Generated with Claude Code

https://claude.ai/code/session_015oyMquf4daB6hMhmqB1wAL


Generated by Claude Code

…(Lean)

WokeGrammarCFL.lean proves grammar-proofs.md §7.3 (positive direction) without
Mathlib: the class of context-free languages is closed under union,
concatenation, and Kleene star.

- A CFG production relation P : N -> List (N + T) -> Prop with a mutual
  derivation relation Gen/GenL; IsCFL L := some grammar generates exactly L.
- One reusable core lemma embGen_iff: embedding a grammar's nonterminals into a
  larger disjoint grammar preserves the generated language (lift + a generalized-
  index structural reflection).
- Union/concat/star grammar constructions (none -> S1 | S2 ; none -> S1 S2 ;
  none -> eps | S1 S) with full language-equality proofs: cfl_union, cfl_concat,
  cfl_star. Plus cfl_single (non-vacuity).

sorry-free; #print axioms shows propext only. CI-gated via lean-proofs.yml.

The WokeLang surface grammar is context-free, so it inhabits this class and these
operations apply. Only §7.3 non-closure under intersection/complement remains
scoped (needs the CFL pumping lemma). Inventory + prose §7 notes updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015oyMquf4daB6hMhmqB1wAL
@hyperpolymath
hyperpolymath marked this pull request as ready for review June 26, 2026 23:17
@hyperpolymath
hyperpolymath merged commit dfcec84 into main Jun 26, 2026
25 of 28 checks passed
@hyperpolymath
hyperpolymath deleted the claude/v2-grammar-proofs-audit-1yqgxh branch June 26, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants