Skip to content

Simplify randltl exercise formulas within the tutor grammar#173

Open
sidprasad wants to merge 2 commits into
mainfrom
simplify-randltl-formulas
Open

Simplify randltl exercise formulas within the tutor grammar#173
sidprasad wants to merge 2 commits into
mainfrom
simplify-randltl-formulas

Conversation

@sidprasad

Copy link
Copy Markdown
Contributor

What

Random exercise formulas from SPOT's randltl are now simplified before becoming questions, without ever leaving the tutor's operator set (X F G U & | ! -> <->).

Why

randltl freely emits redundant nestings such as F G F G d (≡ F G d), which rendered as absurd English in english-to-LTL questions:

"Eventually, eventually, the document is open, and it stays that way forever, and it stays that way forever."

How

  • gen_rand_ltl generates with simplify=3 (randltl's own CLI default level), collapsing redundant nestings like FGFG d → FG d.
  • SPOT's simplifier normalizes into operators the tutor grammar can't parse (W/M/R/xor — e.g. !(a U b) → !a R !b). These are rewritten back via exact identities instead of SPOT's unabbreviate(), whose chained R→W→U expansion can triple subterms:
    • a R b ≡ !(!a U !b) — the exact inverse of the negated-until normalization, so !(a U b) shapes survive simplification verbatim rather than being lost from the pool
    • a W b ≡ (a U b) | G a, a M b ≡ b U (a & b), a xor b ≡ !(a <-> b)
  • Formulas that simplify to constants (1/0) are skipped and redrawn to fill the batch.
  • gen_rand_ltl now passes a random seed to spot.randltl. Previously the default seed (0) plus a fresh generator per call meant every call with the same atoms/tree-size returned the identical formula sequence — the same exercise pool per complexity band, and constant "random" subformulas in misconception templates.

Reviewer notes

  • SPOT landmine, documented in a comment: SPOT's priority parser tokenizes the priority string buffer in place, corrupting the immutable Python string it was handed (afterwards the string reads 'ap\x005\x00G\x00…'). The code is only safe because to_priority_string builds a fresh string per call — that string must never be hoisted into a shared constant.
  • Each rewrite identity was verified semantically equivalent with SPOT containment in both directions; a 320-formula sweep parses cleanly against the ANTLR grammar with no W/M/R/xor in any output, negated-until shapes present (~9%), and no size blowups (avg 21 chars, max 123).
  • Skipping out-of-grammar formulas instead of rewriting was considered and rejected: it silently removed the whole negated-until family (~20% of the pool).
  • Full suite: 328 tests pass.

Version bumped to 2.1.3 with changelog entries.

randltl freely emits redundant nestings like F G F G d (== F G d),
which rendered as absurd English ("Eventually, eventually, the document
is open, and it stays that way forever, and it stays that way forever").

gen_rand_ltl now generates with simplify=3 and rewrites the operators
the simplifier introduces but the tutor grammar lacks (W/M/R/xor) back
into the supported set via exact identities, chosen over SPOT's
unabbreviate() because its chained R->W->U expansion can triple
subterms. The R identity is the exact inverse of the simplifier's
negated-until normalization, so !(a U b) shapes survive unchanged.
Constants are skipped and redrawn.

Also pass a random seed to spot.randltl: the default seed is 0 and a
fresh generator was built per call, so every call with the same
atoms/tree-size returned the identical formula sequence (same exercise
pool per complexity band, constant template subformulas). And document
that SPOT's priority parser tokenizes the passed string buffer in
place, so the priority string must be rebuilt on every call.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sidprasad

Copy link
Copy Markdown
Contributor Author

@codex please review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fed150d75

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/spotutils.py Outdated
Skipped constants and generator exhaustion could leave gen_rand_ltl
returning fewer than num_formulae. Reseed a fresh generator when the
unique-formula space at the given tree size runs out (duplicates across
generators are fine — callers ask for a pool, not a set), bounded by a
generous draw budget for pathologically tiny spaces.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant