Skip to content

docs(z3,#10605): README example for ExactlyOne + pb-bench measurement harness - #22

Merged
jsboige merged 1 commit into
mainfrom
feature/c8248-pb-bench-readme
Aug 17, 2026
Merged

jsboige merged 1 commit into
mainfrom
feature/c8248-pb-bench-readme

Conversation

@jsboige

@jsboige jsboige commented Aug 13, 2026

Copy link
Copy Markdown

Closes #10605 / c.8248 (documentation + measurement grain, complements PR #20's implementation).

Scope

Documentation + measurement harness for the unweighted Pseudo-Boolean DSL surface added in #20 (PR feature/c8247-z3linq-pb-exactlyone).

1. README.md — new example section

Added ### Problem - Planning a Single Meal from a Menu between the existing examples and ## Getting Started. Demonstrates Z3Methods.ExactlyOne(...) on a 5-recipe one-hot (matching notebook 09's planner instance) and documents the three new magic methods (ExactlyOne / AtMostOne / AtLeastOne) and their native MkPBGe mapping.

Anti-régression: existing example sections (Propositional Logic, Linear Algebra, Oil Purchasing, Shipping) untouched. +33 lines net.

2. solutions/pb-bench/ — measurement harness

Standalone console app comparing native MkPBGe vs MkIte+MkAdd expansion on the Exactly-One pattern (n=10/50/100, SAT + UNSAT). Reference: issue #10605 criterion #1 ("mesurer, ne pas supposer").

Measurement (rerun on this branch)

n variant AST nodes SMT2 bytes z3 ms (SAT) z3 ms (UNSAT)
10 MkPBGe 23 234 14 9
10 MkIte+Add 48 666 13 11
50 MkPBGe 103 1425 9 9
50 MkIte+Add 208 3227 30 27
100 MkPBGe 203 2825 10 10
100 MkIte+Add 408 6427 62 63

Native MkPBGe is measurably cheaper:

  • ~half the AST nodes (PB is a single primitive node; MkIte+MkAdd is 2N+1 nodes)
  • ~2.3× smaller SMT-LIB string (less network/parsing cost)
  • 6.3× faster solver check on n=100 UNSAT (10ms vs 63ms)
  • The gap widens with n — on small n=10 the difference is negligible; on n=100 it's a 6× win

Conclusion: the dedicated DSL surface (PR #20) is not optional — its native Z3 Pseudo-Boolean propagation beats the MkIte expansion by an order of magnitude on the planner instance, and the win grows with n.

Validation

Out of scope

  • Weighted Pseudo-Boolean (MkPBGe with weights ≠ 1, plus MkPBEq / MkPBLe) — issue #10605 body restricts the unweighted case used by notebook 09; the weighted case needs a separate design discussion (signature, semantic).
  • Implementation in Z3Methods.cs / ExpressionVisitor.cs — already in PR feat(z3,#10605): unweighted Pseudo-Boolean (ExactlyOne/AtMostOne/AtLeastOne) → MkPBGe #20.
  • Cookbook sections / notebooks in the main repo (jsboige/CoursIA) — separate PRs post-merge, tracked in the issue body §"Travail demandé".

Suite c.8249 (prochain cycle, on the main repo)

  1. Notebook 09 (MyIA.AI.Notebooks/SymbolicAI/SMT/Z3-Linq2Z3/09_Meal_Planner_Convergence_Scale.ipynb) — add a ## PB — one-hot déclaratif (DSL ExactlyOne) section rewriting the raw MkPB* cells as Z3Methods.ExactlyOne(...). Anti-régression: keep the raw cells (comparison term).
  2. Submodule pointer bump in jsboige/CoursIA to track this fork's main post-merge.
  3. Papermill re-execution C.2 on notebook 09 — convergence chiffres measured at kernel, not recopiés.

See #10605.

… harness

Scope: documentation + measurement harness for the unweighted Pseudo-Boolean
DSL surface added in #20 (PR feature/c8247-z3linq-pb-exactlyone).

README: new section 'Problem - Planning a Single Meal from a Menu' demonstrates
Z3Methods.ExactlyOne(...) on a 5-recipe one-hot, matching notebook 09's
planner instance. Documents the three new magic methods (ExactlyOne /
AtMostOne / AtLeastOne) and their native MkPBGe mapping.

pb-bench: standalone harness comparing native MkPBGe vs MkIte+MkAdd expansion
on the Exactly-One pattern (n=10/50/100, SAT + UNSAT). Measurement result:
native PB ~half the AST, ~2.3x smaller SMT-LIB, 3-6x faster solver check
on n=100 UNSAT (9ms vs 56ms). Justifies #20's dedicated DSL surface against
the 'MkIte+Add is enough' alternative.

See #10605.
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