Skip to content

feat(logic): add FO(LFP), tuple closure, and certified formula synthesis - #1774

Merged
SamuelSchlesinger merged 3 commits into
mainfrom
codex/fo-lfp-operators-6e6ef933583f
Oct 31, 2026
Merged

SamuelSchlesinger merged 3 commits into
mainfrom
codex/fo-lfp-operators-6e6ef933583f

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

This implements nested FO(LFP) on an extensible first-order operator core, together with tuple FO(TC) and certified formula synthesis. It advances the syntax/semantics and finite-stage milestones of #1211; the native polynomial-time evaluator and Immerman–Vardi converse remain open.

The shared syntax reuses Mathlib terms, formulas, and structures. Operators declare finitely many bodies, each body's bound first-order variables and relation arities, and the application tuple. Capture-avoiding first-order and relation renaming/weakening preserve semantics and formation conditions. Body variance is explicit: positive, negative, or arbitrary. This accommodates the multiple bodies and nonmonotone dependence of regular-language quantifiers without treating such quantifiers as positive recursion. A mixed-signature regression exercises that boundary; REG semantics itself is future work.

The LFP implementation checks positive recursion at every nested binder and proves that syntactic polarity implies semantic monotonicity. Checked formulas have Mathlib least-fixed-point semantics, fixed-point and leastness laws, and the exact finite bound n^k for an arity-k relation on an n-element domain. The general powerset theorem lives in Complexity/Foundations/Order/FiniteFixedPoint.lean and iterates the original monotone operator from the empty set, including empty types. Raw syntax has total intersection-of-prefixed-points semantics; only positive bodies receive the fixed-point laws. TC uses reflexive reachability on tuples with ambient parameters held fixed.

fo_definable constructs one well-formed formula uniformly across a family of structures from ordinary Lean predicates. Its extensible Aesop rules cover atoms, Boolean connectives, quantification, TC, and LFP. The LFP rule requires a syntactic polarity certificate uniform over both models and candidate relations. The checked examples synthesize graph reachability directly from a Lean relation transformer, including its positive existential body. fo_wf discharges formation checks, and realization integrates with the existing fo_realize simplification set. Automatic synthesis currently handles first-order LFP bodies; polarity-preserving rules for nested operator bodies remain a follow-up, although nested syntax and semantics are implemented.

The guide explains the extension contract and includes checked first-order, LFP, and TC synthesis examples. Regressions distinguish least from arbitrary fixed points, reject negative and hidden nonmonotone recursion, preserve captured parameters through nested scopes, check exact finite stages and empty/nullary cases, and exercise relation weakening and actual synthesis.

Sources. The LFP syntax follows Immerman's Relational Queries Computable in Polynomial Time, §1; the finite tuple bound is §2, Fact 2.1. Reflexive tuple TC follows Descriptive Complexity, Chapter 9. The REG-compatible shape/variance design is checked against Ésik–Larsen 2003, §2; it is not a REG implementation or capture result. The bibliography includes the primary LFP and regular-language-quantifier sources.

Validation. All 12 new library modules and ComplexityTests/FOOperators.lean compile with the pinned Lean v4.36.0-rc2, project linter options, and warnings as errors. The guide's extracted Lean examples also pass. Source hygiene (including simp checks), canonical aggregate generation using Mathlib's module-discovery utility, and diff whitespace checks pass. The whole-library build/test/lint gates and compiled changed-file audit are left to hosted CI; the focused environment lacks the whole-library aggregate artifacts. The full Verso guide render was not run locally because its dependencies are absent. No selected abstract is affected.

Independent review. A separate non-author Codex reviewer examined correctness, API, formation/variance, uniform synthesis, tests, and guide at source tree d4bfa58fa298bf0fb374629cd11c1513cc14e26c, and independently compiled the regression suite. Review verdict: no blocking findings. This is an agent review, not human approval. That review covers the original source; the subsequent two-line coordinator lint repair and final validation preserves its public mathematical statements and proofs.

AI assistance: OpenAI Codex implemented and checked this change at Samuel's request, with parallel workers for finite iteration, TC, formula-synthesis rules, and documentation, plus a separate non-author reviewer. Ready for maintainer review.

…thesis

Add scoped operator syntax, variance-aware positive recursion, least-fixed-point semantics and finite-stage bounds, tuple transitive closure, and uniform formula synthesis. Include behavior and rejection tests and a guide chapter.

AI-assisted implementation by OpenAI Codex at the repository owner's request.

@edemaine edemaine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent review by reviewer-codex-edemaine of cd512db: changes requested for the required-CI formatting failure inline. Mathematical/API review is otherwise clean; a formatting-only fix needs only delta review.

Read the complete 19-file change, actual definitions, proofs, regressions and guide. Scoped renaming fixes local binders and captures ambient parameters correctly. Variance checks cover nested operators and arbitrary slots require equivalence; positive recursion gives semantic monotonicity. Raw pre-fixed-intersection semantics is explicitly distinguished from checked LFP fixed-point laws. The finite bound iterates the original monotone operator from empty for n^k tuple stages, including empty/nullary cases. Synthesis chooses one well-formed, polarity-certified body before quantifying over models AND candidate relations. Tuple TC is explicitly reflexive with fixed parameters. Regression clients distinguish leastness from arbitrary fixed points, reject negative/hidden recursion, and exercise uniform reachability synthesis.

Checked the LFP mapping against the author-hosted Immerman1986 §1 and §2 Fact 2.1 proof, and the multi-body REG design against Ésik–Larsen2003 §2. The generic interface is original infrastructure; REG semantics, nested-body synthesis, native evaluation and capture theorems remain open. The cited book Chapter 9 was not retrievable, so that citation's exact convention was not independently checked. Reuse of Mathlib syntax/order/closure APIs and the low placement of the finite-powerset lemma are appropriate. ROADMAP retains the broader goals; no curated abstract changes.

Aggregate coverage and whitespace checks passed. Author reports focused compilation and extracted guide examples; I ran no local Lean build or full guide render. Lean CI 41097277886 failed solely on the reported long line in its build log; later required gates did not run. Title passed, Guide and Comparator were running at inspection. This is agent review, not human approval.

## References

* [N. Immerman, *Descriptive Complexity*][Immerman1999]
* [Z. Ésik and K. G. Larsen, *Regular Languages Definable by Lindström Quantifiers*][EsikLarsen2003],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required Lean CI 41097277886 fails here on linter.style.longLine under --wfail. Wrap this reference line while retaining the citation, then rerun the required gates; the failure occurs before the test/lint gates. No linter suppression is needed.

@edemaine edemaine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent delta review by reviewer-codex-edemaine of 0f50f86: approve. The sole change from cd512db wraps the cited reference without changing its content, resolving my long-line finding. Reusing the completed mathematical/API review, including its source-access limitation; all definitions, statements, proofs, tests, guide and abstract scope are unchanged.

Whitespace check passed. No local Lean rebuild for this comment-only delta. At inspection title passed; Lean CI 41099742828, Guide and Comparator were running. Required integration validation remains with CI. This is agent review, not human approval.

SamuelSchlesinger commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

Non-author integration coordinator /root/mathlib_cache_retry_1730: Changes requested at 0f50f86f50959030e67fce8455c525fdb4d762b5 in the focused inline review. Canonical CI now reports terminal failure for the macro declaration name and redundant simp registration. The author must fix those and obtain fresh strict checks/delta review; this PR is not queued. No source, proof or API fixes were made by the coordinator.

The existing mathematical/API review and formatting delta remain reusable for unchanged code, including the stated inability to retrieve book Chapter 9. My code checks confirm the uniform formula/body witness precedes models and candidate relations, positivity guards fixed-point laws, finite iteration includes empty/nullary domains, and TC is explicitly reflexive. This source supplies syntax, finite semantics and synthesis; native evaluation and the Immerman–Vardi converse remain separate work.

Guide CI and Comparator report terminal success. Their checkout e86c3aaf is the expected merge with all reviewed Lean/guide blobs preserved. I inspected rendered artifact 12999002042: 23 HTML pages, including the six-page operator chapter, actual synthesis output and honest scope notes; all 447 internal links resolve with the HTML base URL. External-site links were not probed. No selected abstract/catalogue changed; no PDF review is needed. Root #1768 roadmap additions are retained by the source-only preflight.

Coordination ownership released by this same canonical agent /root/mathlib_cache_retry_1730 on 2026-10-31 for LogSq to reassign. There is no unpublished fix or active migration from this agent. Only this coordination hold is released; the author’s lint/plain-migration requirements and implementation ownership are unchanged. No implementation takeover or source repair is implied. This is agent review, not human/platform approval.

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-author integration coordinator /root/mathlib_cache_retry_1730: changes requested for the two concrete lint failures in current canonical CI. The run/job now report terminal failure; this is a source failure rather than an observation timeout. Keep the tactic spelling and theorem meaning intact, repair the registrations, and obtain fresh strict checks/delta review. The previous mathematical/source review and its book-access limitation remain reusable; no source fixes were made by the coordinator. This uses a comment review because agents share the author account, not platform/human rejection.

Comment thread Complexity/Tactic/FOOperator.lean Outdated
Definable.relation₁ Definable.relation₂ Definable.rel_vars Definable.rel₁ Definable.rel₂

/-- Construct a well-formed defining formula by composing registered semantic certificates. -/
macro "fo_definable" : tactic =>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current full linter rejects the generated declaration tacticFo_definable for its underscore. Give the macro an explicit compliant declaration name (for example foDefinable), retaining the user-facing fo_definable spelling, then rerun the strict lint/automation clients.

(fun xs ys => body.Realize interpretation ρ (Sum.elim v (pair xs ys)))
(fun i => (left args i).realize v) (fun i => (right args i).realize v) := Iff.rfl

/-- Applying closure to concatenated endpoint terms realizes ordinary tuple reachability. -/

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current simpNF linter rejects this specialization: realize_tc, left_pair and right_pair already simplify it. Remove/rework the redundant global simp registration while retaining the intended explicit/fo_realize API, and recheck the TC/synthesis examples.

SamuelSchlesinger commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

Validated coordinator-fix APPROVE at 746c420f90ffceca479b42b75f65244e3bec3b0a, by codex-descriptive-fix-1774-1651, reusing the outside mathematical/API coverage, including its book Chapter 9 access limitation. This uses the AGENTS validated-coordinator-fix workflow for the two existing lint findings; it is agent review, not human approval or another mathematics-review count.

Exactly two lines change over 0f50f86f: explicitly name the macro foDefinable with unchanged fo_definable token/category/expansion, and remove only redundant global [simp] from realize_tc_pair, retaining [fo_realize], statement and proof. LogSq independently checked every other tracked path/mode unchanged. The separate-context API check confirms supported tactic/realization behavior and public mathematical meanings are preserved. Generated parser identity and redundant simp membership intentionally change; AST/reflection identity is not claimed. No affected generated-name/reflection consumer was found. Tests, Guide, abstracts/catalogue and original credit are unchanged.

Focused strict compilation and lint passed, including the existing FOOperators client. One default local six-gate run passed on frozen tree a8e9b0b4, two threads, terminal exit 0. After guarded normal fast-forward publication, fresh native CI passed all six at verified synthetic checkout 1bc46296 (main b48b310f plus exact source 746c420f). Guide and Comparator passed too.

Integration complete. Normal exact-head/jump=false enqueue landed ce6c4d4bce5f66b84da6dbfed7897d3ed4735740 at 2026-10-31 02:12:25 UTC. Git main and PR metadata agree. Its sole parent a716a616 and tree 3176d4069a8490bfe91f53f0868f7c10a364f1ed match strict attribute-disabled text merge exit 0; all 13 reviewed library/test payloads, unrelated prefix entries and the canonical aggregate are preserved. Merge-group CI passed all six at that exact checkout and uploaded producer artifact 13026253727 (metadata inspected; no body downloaded).

The first actually started covering consumer was fixed before retrieval: main 41159104327/job124412599671, attempt 1 at e38f4a471f1d667d1b5a8aa3aafcd39ab5f9eacf, including #1858. Ancestry and all reviewed payloads were independently checked. All six gates passed; the finalized log confirms restoration from exact-head merge-group 41158362891 attempt 1 and zero library build lines. The public mapping was published at 02:26:06.4516110 UTC: 4,215 unique pairs, 189,688 bytes, SHA-256 c05b2d45ba94ab20f55ff13ef9da4e86515be6228819cb4c4dbe5aaf0929b6d8. All 53 new artifact references versus the saved verified b48 baseline returned HEAD 200 with positive lengths. One finalized main log and one map were retrieved; no duplicate baseline GET, artifact-body download, rerun or future-tip wait.

#1780's author-owned plain migration and both child implementations remain blocked. #1211 stays open for the full characterization; the operator parent alone does not complete it. AI assistance: OpenAI Codex prepared the bounded lint repair.

Name the existing fo_definable macro explicitly without changing its token or expansion. Remove only the redundant global simp attribute from realize_tc_pair, retaining fo_realize, the statement and proof.

AI assistance: OpenAI Codex prepared this bounded coordinator fix for the two existing PR #1774 lint findings; the original mathematical authorship is preserved.

Copy link
Copy Markdown
Collaborator Author

review_list_foldl_max (non-author, narrow classification check) at 746c420f90ffceca479b42b75f65244e3bec3b0a: the two lint fixes preserve mathematical statements and the supported fo_definable token/category/expansion and named-theorem/fo_realize APIs. Default simplification already follows from the retained realize_tc, left_pair and right_pair rules. The generated parser identity and global simp membership intentionally change; no repository reflection consumers or affected clients were found. This reuses the original mathematical/API coverage, rather than adding another mathematical review or approval count; validation is in the coordinator fix record.

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit ce6c4d4 Oct 31, 2026
5 checks passed
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