Skip to content

refactor(FOL): derive Repr and add ToString for the syntax types - #40

Merged
arademaker merged 3 commits into
mainfrom
refactor/fol-tostring
Oct 19, 2026
Merged

arademaker merged 3 commits into
mainfrom
refactor/fol-tostring

Conversation

@arademaker

Copy link
Copy Markdown
Member

Logic/FOL was the one chapter whose syntax types printed through a hand-written Repr over Std.Format, so #eval of a formula showed its notation and there was no way to see its structure. InfEngine and ModelChecking already follow the other pattern: deriving Repr for the constructor tree, plus a ToString instance for the notation.

This moves Variable, Term and Formula to that pattern:

  • deriving Repr on the three types; #eval f shows the tree.
  • Variable.format, Term.format and Formula.format become toText functions to String, with ToString instances; toString f gives the same notation as before (∀x R[x, x]).
  • ToString, how #eval chooses between Repr and ToString, and s! strings are presented at their first use, with Variable; the Formula paragraph becomes a short reminder.
  • The ledger in STYLE-CODE.md moves ToString and s! strings from InfEngine to Logic/FOL and drops Std.Format. InfEngine used ToString without presenting it, so this also closes that gap.
  • ModelChecking: #eval toString (lfSent tr1) in the prose, and the lfDET signature display is dropped.

Needed by the step-by-step example from syntax tree to formula that is being added to ModelChecking (#15), which shows both views of the same formula.

Verified locally: make all builds the four variants (the solutions project compiles standalone).

This change was prepared with the assistance of Claude Code (Anthropic); all edits were reviewed by the author.

Variable, Term and Formula now derive Repr, so #eval shows the
constructor tree, and their notation moves from a hand-written Repr
over Std.Format to ToString instances, so toString shows the formula.
This is the pattern InfEngine and ModelChecking already follow, and it
lets a chapter show both views of the same formula. ToString, its
behaviour under #eval and s! strings are presented at their first use,
with Variable, and the ledger moves them from InfEngine to Logic/FOL.

This change was prepared with the assistance of Claude Code (Anthropic);
all edits were reviewed by the author.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 15:11
`$` appears nowhere else in the book; `<|` is the idiomatic Lean form
and IntroL already uses it. Record `<|` in the ledger under IntroL.

This change was prepared with the assistance of Claude Code (Anthropic);
all edits were reviewed by the author.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Only a minor presentation-before-use convention issue remains; no blocking defects were identified.

1 open issue
What changed in this PR

Separates FOL syntax-tree output from readable logical notation, supporting the planned ModelChecking examples.

Changes:

  • Derives Repr and adds ToString printers for FOL syntax types.
  • Explains both display modes and updates the feature ledger.
  • Adjusts ModelChecking prose and removes a redundant signature display.
File Description
STYLE-CODE.md Updates first-use entries for printing features.
CSwL/​ModelChecking.lean Updates the display example and removes the signature display.
CSwL/​Logic/​FOL.lean Separates structural and notation printing, with explanatory examples.

Review effort: Balanced

Comment thread CSwL/Logic/FOL.lean Outdated

```lean
#eval Variable.mk "x" [1]
#eval toString $ Variable.mk "x" [1]
@arademaker
arademaker merged commit 79b1dee into main Oct 19, 2026
1 check passed
@arademaker
arademaker deleted the refactor/fol-tostring branch October 19, 2026 16:48
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