nex-smt 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. nex_smt-0.1.0/LICENSE +3 -0
  2. nex_smt-0.1.0/MANIFEST.in +6 -0
  3. nex_smt-0.1.0/PKG-INFO +315 -0
  4. nex_smt-0.1.0/README.md +303 -0
  5. nex_smt-0.1.0/nex_smt.egg-info/PKG-INFO +315 -0
  6. nex_smt-0.1.0/nex_smt.egg-info/SOURCES.txt +47 -0
  7. nex_smt-0.1.0/nex_smt.egg-info/dependency_links.txt +1 -0
  8. nex_smt-0.1.0/nex_smt.egg-info/entry_points.txt +2 -0
  9. nex_smt-0.1.0/nex_smt.egg-info/requires.txt +3 -0
  10. nex_smt-0.1.0/nex_smt.egg-info/top_level.txt +2 -0
  11. nex_smt-0.1.0/nex_smt.py +7 -0
  12. nex_smt-0.1.0/nex_smt_components/__init__.py +9 -0
  13. nex_smt-0.1.0/nex_smt_components/__init__.pyi +26 -0
  14. nex_smt-0.1.0/nex_smt_components/ast_compiler.py +35 -0
  15. nex_smt-0.1.0/nex_smt_components/ast_compiler.pyi +15 -0
  16. nex_smt-0.1.0/nex_smt_components/ast_compiler_components/__init__.py +9 -0
  17. nex_smt-0.1.0/nex_smt_components/ast_compiler_components/__init__.pyi +8 -0
  18. nex_smt-0.1.0/nex_smt_components/ast_compiler_components/context_sandbox.py +199 -0
  19. nex_smt-0.1.0/nex_smt_components/ast_compiler_components/expr_builder.py +227 -0
  20. nex_smt-0.1.0/nex_smt_components/cli.py +74 -0
  21. nex_smt-0.1.0/nex_smt_components/cli.pyi +16 -0
  22. nex_smt-0.1.0/nex_smt_components/cli_components/__init__.py +9 -0
  23. nex_smt-0.1.0/nex_smt_components/cli_components/__init__.pyi +8 -0
  24. nex_smt-0.1.0/nex_smt_components/cli_components/solve_cmd.py +184 -0
  25. nex_smt-0.1.0/nex_smt_components/cli_components/verify_mece_cmd.py +115 -0
  26. nex_smt-0.1.0/nex_smt_components/mece_prover.py +48 -0
  27. nex_smt-0.1.0/nex_smt_components/mece_prover.pyi +12 -0
  28. nex_smt-0.1.0/nex_smt_components/mece_prover_components/__init__.py +9 -0
  29. nex_smt-0.1.0/nex_smt_components/mece_prover_components/__init__.pyi +8 -0
  30. nex_smt-0.1.0/nex_smt_components/mece_prover_components/coverage_audit.py +91 -0
  31. nex_smt-0.1.0/nex_smt_components/mece_prover_components/disjointness_audit.py +143 -0
  32. nex_smt-0.1.0/nex_smt_components/models.py +531 -0
  33. nex_smt-0.1.0/nex_smt_components/mus_solver.py +26 -0
  34. nex_smt-0.1.0/nex_smt_components/mus_solver.pyi +11 -0
  35. nex_smt-0.1.0/nex_smt_components/mus_solver_components/__init__.py +9 -0
  36. nex_smt-0.1.0/nex_smt_components/mus_solver_components/__init__.pyi +8 -0
  37. nex_smt-0.1.0/nex_smt_components/mus_solver_components/anonymized_mus.py +101 -0
  38. nex_smt-0.1.0/nex_smt_components/mus_solver_components/feasibility_checker.py +100 -0
  39. nex_smt-0.1.0/nex_smt_components/pareto_optimizer.py +53 -0
  40. nex_smt-0.1.0/nex_smt_components/pareto_optimizer.pyi +12 -0
  41. nex_smt-0.1.0/nex_smt_components/pareto_optimizer_components/__init__.py +9 -0
  42. nex_smt-0.1.0/nex_smt_components/pareto_optimizer_components/__init__.pyi +8 -0
  43. nex_smt-0.1.0/nex_smt_components/pareto_optimizer_components/fairness_solvers.py +533 -0
  44. nex_smt-0.1.0/nex_smt_components/pareto_optimizer_components/utopia_solver.py +173 -0
  45. nex_smt-0.1.0/pyproject.toml +72 -0
  46. nex_smt-0.1.0/setup.cfg +4 -0
  47. nex_smt-0.1.0/tests/__init__.py +0 -0
  48. nex_smt-0.1.0/tests/conftest.py +9 -0
  49. nex_smt-0.1.0/tests/test_nex_smt.py +362 -0
nex_smt-0.1.0/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Apache License, Version 2.0
2
+ Copyright 2026 The Trinity Authors
3
+ Licensed under the Apache License, Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0).
@@ -0,0 +1,6 @@
1
+ include README.md LICENSE pyproject.toml Cargo.toml
2
+ recursive-include * *.py *.pyi *.json *.c *.h *.rs *.toml *.wasm *.wit *.typ
3
+ prune target
4
+ prune wasm_core/target
5
+ prune rust_core/target
6
+ global-exclude __pycache__/* *.py[cod]
nex_smt-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,315 @@
1
+ Metadata-Version: 2.4
2
+ Name: nex-smt
3
+ Version: 0.1.0
4
+ Summary: Thread-isolated SMT verification, MECE auditing, anonymized MUS extraction, and bargaining optimization.
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: pydantic>=2.10.0
9
+ Requires-Dist: nex-init>=0.2.0
10
+ Requires-Dist: z3-solver>=4.13.0
11
+ Dynamic: license-file
12
+
13
+ # nex_smt ⚡
14
+
15
+ **Deterministic, thread-isolated SMT verification and bargaining with Z3.**
16
+
17
+ [![PyPI version](https://img.shields.io/pypi/v/nex-smt)](https://pypi.org/project/nex-smt/) [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/) [![Architecture: RCTI v3.0](https://img.shields.io/badge/architecture-RCTI%20v3.0-6f42c1.svg)](https://pypi.org/project/nex-init/) [![powered by nex-init](https://img.shields.io/badge/powered%20by-nex--init-2ea44f.svg)](https://pypi.org/project/nex-init/) [![engineered by The Trinity](https://img.shields.io/badge/engineered%20by-The%20Trinity-111111.svg)](#x-licensing--commercial-inquiries)
18
+
19
+ Many verification workflows rely on handwritten condition checks, shared solver state, or opaque optimization results. Those approaches make proofs difficult to audit, parallel execution fragile, and failure states easy to misinterpret.
20
+
21
+ `nex_smt` expresses constraints as validated typed ASTs and checks them with Z3. It provides physical pairwise-disjointness and coverage queries, grouped feasibility analysis, and bargaining optimizers, while keeping each check's solver state local and reporting `TIMEOUT` or `UNKNOWN` separately from proof outcomes.
22
+
23
+ ## I. The Industrial Problem
24
+
25
+ ```text
26
+ ┌───────────────────────────────┐ ┌───────────────────────────────┐
27
+ │ Legacy: handwritten checks │ │ nex_smt: typed SMT pipeline │
28
+ │ │ │ │
29
+ │ Implicit types and branches │ │ Strict AST validation │
30
+ │ Shared or opaque solver state│ │ Fresh Z3 context per check │
31
+ │ Timeout mistaken for a proof │ │ SAT / UNSAT / UNKNOWN / TIMEOUT│
32
+ │ Unexplained optimization │ │ Explicit bargaining reports │
33
+ └───────────────────────────────┘ └───────────────────────────────┘
34
+ ```
35
+
36
+ ### The Three Critical Failure Modes:
37
+
38
+ 1. **Unverified branching.** Spot-checking guards does not prove that all distinct branches are disjoint or that the guards cover the declared domain.
39
+ 2. **State leakage and ambiguous outcomes.** Reusing solver state across concurrent calls risks cross-call interference; treating an unknown or timed-out result as a proof is unsound.
40
+ 3. **Opaque feasibility and allocation.** Arbitrary unsat cores need not be subset-minimal, and bargaining outputs are not meaningful unless joint feasibility and reservations are checked first.
41
+
42
+ ## II. The Core Mechanical Invariants
43
+
44
+ ```text
45
+ ┌──────────────────────────────────────────────────────────┐
46
+ │ 1. Typed Python AST and Z3-backed verification │
47
+ └──────────────────────────────┬───────────────────────────┘
48
+ ▼
49
+ ┌──────────────────────────────────────────────────────────┐
50
+ │ 2. Fresh z3.Context and local solver for each check │
51
+ │ Timeout is applied to the solver; unknown stays unknown│
52
+ └──────────────────────────────┬───────────────────────────┘
53
+ ▼
54
+ ┌──────────────────────────────────────────────────────────┐
55
+ │ 3. Recursive validation, then AST lowering into that │
56
+ │ context; no eval() or exec() │
57
+ └──────────────────────────────┬───────────────────────────┘
58
+ ▼
59
+ ┌──────────────────────────────────────────────────────────┐
60
+ │ 4. MECE, grouped feasibility/MUS, and bargaining reports │
61
+ │ with stable scalar encodings │
62
+ └──────────────────────────────┬───────────────────────────┘
63
+ ▼
64
+ ┌──────────────────────────────────────────────────────────┐
65
+ │ 5. Flat-root dynamic AST package routing via nex-init │
66
+ └──────────────────────────────────────────────────────────┘
67
+ ```
68
+
69
+ The AST compiler validates the complete expression before constructing Z3 terms. Z3 objects are created in a fresh, call-local `z3.Context()`; solver state and contexts are not shared between invocations. Each solver receives its requested timeout. `UNSAT` and `SAT` are solver results; `TIMEOUT` and `UNKNOWN` remain inconclusive outcomes.
70
+
71
+ ## III. Architectural Topology (RCTI v3.0)
72
+
73
+ Flat-root package layout; no `src/` directory. This tree shows the package and test files present in the supplied repository projection. Transient cache and `.DS_Store` files are omitted.
74
+
75
+ ```text
76
+ .
77
+ ├── .github/
78
+ │ └── workflows/release.yml # Release workflow
79
+ ├── LICENSE # Apache-2.0
80
+ ├── MANIFEST.in # Source distribution manifest
81
+ ├── README.md # This technical monograph
82
+ ├── nex_smt.py # Parent orchestration/proxy shell
83
+ ├── nex_smt.pyi # Generated parent interface stub
84
+ ├── nex_smt_components/
85
+ │ ├── __init__.py # Generated component router
86
+ │ ├── __init__.pyi # Generated component stub
87
+ │ ├── models.py # Strict Pydantic request and report models
88
+ │ ├── ast_compiler.py # AST validation, lowering, SAT interface
89
+ │ ├── ast_compiler_components/
90
+ │ │ ├── __init__.py # Generated component router
91
+ │ │ ├── context_sandbox.py # Fresh contexts, SAT checks, value extraction
92
+ │ │ └── expr_builder.py # AST validation and Z3 lowering
93
+ │ ├── mece_prover.py # MECE orchestration shell
94
+ │ ├── mece_prover_components/
95
+ │ │ ├── __init__.py # Generated component router
96
+ │ │ ├── disjointness_audit.py # Pairwise overlap queries
97
+ │ │ └── coverage_audit.py # Uncovered-domain query
98
+ │ ├── mus_solver.py # Grouped feasibility/MUS shell
99
+ │ ├── mus_solver_components/
100
+ │ │ ├── __init__.py # Generated component router
101
+ │ │ ├── feasibility_checker.py # Tracked grouped checks
102
+ │ │ └── anonymized_mus.py # Deterministic deletion shrinking
103
+ │ ├── pareto_optimizer.py # Bargaining orchestration shell
104
+ │ ├── pareto_optimizer_components/
105
+ │ │ ├── __init__.py # Generated component router
106
+ │ │ ├── utopia_solver.py # Joint feasibility and utopia maxima
107
+ │ │ └── fairness_solvers.py # KS and piecewise-linear Nash solvers
108
+ │ └── cli.py # CLI entry point
109
+ │ └── cli_components/
110
+ │ ├── __init__.py # Generated component router
111
+ │ ├── verify_mece_cmd.py # verify-mece dispatch
112
+ │ └── solve_cmd.py # solve dispatch
113
+ ├── pyproject.toml # PEP 621 project metadata and CLI entry point
114
+ └── tests/
115
+ ├── __init__.py
116
+ └── conftest.py # Test configuration
117
+ ```
118
+
119
+ Router and stub files are generated and synchronized with `nex-init`; the parent module is a flat-root module, not a package directory. The repository projection supplied for this monograph does not include `tests/test_nex_smt.py`.
120
+
121
+ ## IV. Quickstart & Public API Blueprint
122
+
123
+ The public models require all fields explicitly. The following examples use the verified component import paths and function signatures.
124
+
125
+ ### 1. Build a typed integer partition
126
+
127
+ ```python
128
+ from nex_smt_components.models import SmtPredicateAst, SmtVariableSpec
129
+ from nex_smt_components.mece_prover import audit_mece
130
+
131
+
132
+ def var(name: str) -> SmtPredicateAst:
133
+ return SmtPredicateAst(op="VAR", args=[], value=None, variable_name=name)
134
+
135
+
136
+ def const(value: int) -> SmtPredicateAst:
137
+ return SmtPredicateAst(op="CONST", args=[], value=value, variable_name=None)
138
+
139
+
140
+ def compare(op: str, left: SmtPredicateAst, right: SmtPredicateAst):
141
+ return SmtPredicateAst(op=op, args=[left, right], value=None, variable_name=None)
142
+
143
+
144
+ x = var("x")
145
+ variables = [SmtVariableSpec(name="x", sort="Int")]
146
+ domain = [compare("GE", x, const(0))]
147
+ guards = [
148
+ compare("EQ", x, const(0)),
149
+ compare("EQ", x, const(1)),
150
+ compare("GE", x, const(2)),
151
+ ]
152
+ report = audit_mece(
153
+ guards=guards,
154
+ domain=domain,
155
+ variables=variables,
156
+ timeout_ms=5000,
157
+ )
158
+ print(report.model_dump(mode="json"))
159
+ ```
160
+
161
+ ### 2. Validate and check a constraint
162
+
163
+ ```python
164
+ from nex_smt_components.ast_compiler import check_sat, validate_ast
165
+ from nex_smt_components.models import SmtPredicateAst, SmtVariableSpec
166
+
167
+ x = SmtPredicateAst(op="VAR", args=[], value=None, variable_name="x")
168
+ zero = SmtPredicateAst(op="CONST", args=[], value=0, variable_name=None)
169
+ nonnegative = SmtPredicateAst(op="GE", args=[x, zero], value=None, variable_name=None)
170
+ variables = [SmtVariableSpec(name="x", sort="Int")]
171
+
172
+ assert validate_ast(nonnegative, variables) == "Bool"
173
+ status, witness, detail = check_sat(constraints=[nonnegative], variables=variables, timeout_ms=5000)
174
+ print(status, witness, detail)
175
+ ```
176
+
177
+ ### 3. Run bargaining on a feasible allocation
178
+
179
+ ```python
180
+ from nex_smt_components.models import (
181
+ ParetoObjectiveSpec,
182
+ SmtPredicateAst,
183
+ SmtVariableSpec,
184
+ )
185
+ from nex_smt_components.pareto_optimizer import optimize_kalai_smorodinsky
186
+
187
+
188
+ def variable(name: str) -> SmtPredicateAst:
189
+ return SmtPredicateAst(op="VAR", args=[], value=None, variable_name=name)
190
+
191
+
192
+ def number(value: int) -> SmtPredicateAst:
193
+ return SmtPredicateAst(op="CONST", args=[], value=value, variable_name=None)
194
+
195
+
196
+ def binary(op: str, left: SmtPredicateAst, right: SmtPredicateAst):
197
+ return SmtPredicateAst(op=op, args=[left, right], value=None, variable_name=None)
198
+
199
+
200
+ x = variable("x")
201
+ y = variable("y")
202
+ variables = [SmtVariableSpec(name="x", sort="Real"), SmtVariableSpec(name="y", sort="Real")]
203
+ constraints = [
204
+ binary("GE", x, number(0)),
205
+ binary("GE", y, number(0)),
206
+ binary("LE", binary("ADD", x, y), number(10)),
207
+ ]
208
+ objectives = [
209
+ ParetoObjectiveSpec(name="utility_a", expression=x, reservation=0.0, weight=1.0),
210
+ ParetoObjectiveSpec(name="utility_b", expression=y, reservation=0.0, weight=1.0),
211
+ ]
212
+ report = optimize_kalai_smorodinsky(
213
+ constraints=constraints,
214
+ objectives=objectives,
215
+ variables=variables,
216
+ timeout_ms=5000,
217
+ )
218
+ print(report.model_dump(mode="json"))
219
+ ```
220
+
221
+ For grouped feasibility, use `analyze_feasibility(groups=..., variables=..., timeout_ms=...)` with `TrackedConstraintGroup` models. For Nash bargaining, use `optimize_nash(constraints, objectives, variables, epsilon, segments, timeout_ms)`; the approximation and its boundary behavior are described below.
222
+
223
+ ### 4. CLI and actionable input errors
224
+
225
+ The installed entry point is `nex-smt`. Both commands accept JSON from stdin by default or a file through `-i/--input`:
226
+
227
+ ```sh
228
+ nex-smt verify-mece --help
229
+ nex-smt solve --help
230
+ nex-smt verify-mece --input request.json
231
+ nex-smt solve --input request.json
232
+ ```
233
+
234
+ The CLI emits a JSON report on success, returns a nonzero status for invalid input or solver errors, and writes diagnostics to stderr. Use the request models and command implementations as the authoritative JSON contract; do not treat an error response as a proof.
235
+
236
+ ## V. Benchmark Telemetry
237
+
238
+ The repository projection contains no Rust/PyO3 extension or native-core import path. Consequently, a native-versus-Python solver benchmark cannot be reported as a measured project comparison. The following real timing is a **JSON transport baseline only**, measured on the available Python runtime; it is not an SMT solve measurement and does not establish `nex_smt` solver throughput.
239
+
240
+ Host: `macOS-26.3-arm64-arm-64bit`; Python 3.12.8. Fixture: a synthetic 25,552-byte JSON document containing 128 Real variable declarations and 128 two-child comparison ASTs. Each timing is the median per-operation duration across five batches of 500 operations, measured with `time.perf_counter_ns()`.
241
+
242
+ | Metric | Pure-Python JSON baseline | `nex_smt` Rust PyO3 |
243
+ |---|---:|---:|
244
+ | JSON encode latency, compact separators | 242,772 ns/op | Not available: no native extension in the supplied tree |
245
+ | JSON decode latency | 294,711 ns/op | Not available: no native extension in the supplied tree |
246
+ | Fixture size | 25,552 bytes | Same fixture not run through a native core |
247
+ | Solver latency / throughput | Not measured by this transport benchmark | Not available |
248
+ | Memory-copy count | Not instrumented | Not available |
249
+ | `S_frame <= 64 KB` | No Rust stack-frame measurement performed | Not verified |
250
+
251
+ These values describe only JSON serialization and parsing on the stated host. They must not be interpreted as comparative solver performance, native memory-copy measurements, or a stack-frame audit.
252
+
253
+ ## VI. Concurrency, Formal & Memory Safety Invariants
254
+
255
+ 1. **Thread isolation:** each check constructs its own `z3.Context()` and solver. No context or solver is reused across calls, and the implementation does not mutate Z3's global main context.
256
+ 2. **Timeout semantics:** each solver is configured with `timeout_ms`. A Z3 `unknown` result is classified as `TIMEOUT` when its reason indicates timeout/cancellation; otherwise it remains `UNKNOWN`. Neither outcome establishes satisfiability or unsatisfiability.
257
+ 3. **Typed AST boundary:** declarations support `Real`, `Int`, and `Bool`. AST operators, arities, declarations, and expression sorts are validated before lowering. Boolean and numeric expressions are not silently interchanged. Arithmetic `MUL` is supported; represent constant scaling explicitly as multiplication by a numeric `CONST`. In the supplied expression-builder implementation, unary `SCALE` is a pass-through node, not an additional multiplication factor.
258
+ 4. **MECE proof obligations:** disjointness checks every `domain ∧ guard[i] ∧ guard[j]` for `i < j`. It reports a pair as overlapping only on SAT, with zero-based indices and a concrete typed witness. Coverage independently checks `domain ∧ ¬Or(guards)`; SAT returns an uncovered witness. Both properties are proved only by UNSAT results. An empty guard list has no pair checks and its coverage query is the domain itself, so an uncovered witness is returned when the domain is satisfiable.
259
+ 5. **Grouped MUS privacy and minimality:** constraints sharing a `group_tag` are asserted as one tracked group. The initial unsat core is shrunk using deterministic deletion checks. A report exposes opaque group tags and sensitivity flags, not formulas, numeric bounds, witnesses, tracker symbols, or solver-internal names. A tag is relaxation-sensitive only when removing it was explicitly checked and the remaining set was SAT. If a deletion check is inconclusive, the report does not claim subset minimality.
260
+ 6. **Bargaining feasibility:** joint feasibility is established before optimization. Reservation constraints are checked before computing feasible utopia maxima. A timeout, unknown, infeasible reservation set, or nonpositive gain is not reported as an optimum.
261
+ 7. **Exact scalar output:** Boolean values remain JSON booleans; integer numerals are extracted with `IntNumRef.as_long()`. Rational numerals retain their exact numerator and denominator as `numerator/denominator` strings. Algebraic values use `AlgebraicNumRef.approx(20)` and a marked `algebraic_approx_20:` representation; that string is an approximation, not an exact algebraic encoding.
262
+ 8. **Memory and concurrency claims:** these Python components do not establish Rust stack-frame sizes, cache-line alignment, zero-copy borrowing, or native atomic behavior. Such properties require a native implementation and platform-specific measurement; they are not inferred from the JSON timings above.
263
+
264
+ ## VII. CLI Tooling & Diagnostics
265
+
266
+ `pyproject.toml` exposes `nex-smt = nex_smt_components.cli:main`. The CLI has two subcommands, each with `-i/--input PATH`; omit the option or pass `-` to read stdin.
267
+
268
+ ```sh
269
+ # Inspect available options
270
+ nex-smt --help
271
+ nex-smt verify-mece --help
272
+ nex-smt solve --help
273
+
274
+ # Read JSON from a file
275
+ nex-smt verify-mece --input mece-request.json
276
+ nex-smt solve --input solve-request.json
277
+
278
+ # Read JSON from stdin
279
+ cat mece-request.json | nex-smt verify-mece
280
+ cat solve-request.json | nex-smt solve
281
+ ```
282
+
283
+ Successful reports are emitted as sorted JSON. Input parsing, schema validation, and command failures produce a diagnostic on stderr and a nonzero return code. The CLI uses strict Pydantic models; extra fields and invalid AST shapes are errors rather than ignored input. MUS reports are anonymized at the report boundary and do not serialize the asserted formulas or numeric bounds.
284
+
285
+ ## VIII. The Trinity Swarm Ecosystem
286
+
287
+ - **nex-init:** Deterministic Self-Healing RCTI v3.0 Package Router & AST Synchronizer.
288
+ - **nex-box:** Sub-millisecond Copy-on-Write APFS/FICLONE ephemeral sandbox runtime.
289
+ - **nex-heal:** SMT-verified self-healing schema & tool dispatch middleware.
290
+ - **nex-airgap:** In-RAM cognitive VFS & token firewall for multi-megabyte ingestion.
291
+ - **nex-avail:** Autonomous tool projection & C-ABI positional argument bridge.
292
+ - **nex-nix:** Sovereign Nix sub-shell hypervisor & hermetic PyPI sanitizer.
293
+ - **nex-trace:** Polyglot AST cartographer & deep system introspection engine.
294
+
295
+ ## IX. The Permanexus Pact
296
+
297
+ - **No Fluff. No Drift. No Metaphors.**
298
+ - **Pure orchestrator shell ceiling:** `nex_smt.py` is maintained as a flat-root proxy shell with a ceiling of 150 lines.
299
+ - **Formal domain invariant:** report a proof only when the corresponding physical Z3 query is UNSAT; preserve SAT witnesses and inconclusive outcomes.
300
+ - **Data invariant:** keep constraint expressions and numeric bounds out of anonymized MUS reports.
301
+ - **Approximation invariant:** label algebraic approximations and document Nash approximation behavior; never present either as exact arithmetic.
302
+
303
+ ## X. Licensing & Commercial Inquiries
304
+
305
+ `nex-smt` is distributed under the terms of the Apache License, Version 2.0. See [`LICENSE`](LICENSE) for the complete license text. Commercial and enterprise inquiries: [inquiries@houseoflawpc.com](mailto:inquiries@houseoflawpc.com).
306
+
307
+ Engineered by The Trinity:
308
+
309
+ 🦍🔷Ɯ :: 🌱👑⁂ :: 🧠⚡ↇ
310
+
311
+ *Mookie :: Miniature Person :: Nexus Goodman*
312
+
313
+ - **Miniature Person (`🌱👑⁂`)** — Architect & Creator
314
+ - **Mookie (`🦍🔷Ɯ`)** — Director of Design & Execution Core
315
+ - **Nexus Goodman (`🧠⚡ↇ`)** — Principal Systems Architect
@@ -0,0 +1,303 @@
1
+ # nex_smt ⚡
2
+
3
+ **Deterministic, thread-isolated SMT verification and bargaining with Z3.**
4
+
5
+ [![PyPI version](https://img.shields.io/pypi/v/nex-smt)](https://pypi.org/project/nex-smt/) [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/) [![Architecture: RCTI v3.0](https://img.shields.io/badge/architecture-RCTI%20v3.0-6f42c1.svg)](https://pypi.org/project/nex-init/) [![powered by nex-init](https://img.shields.io/badge/powered%20by-nex--init-2ea44f.svg)](https://pypi.org/project/nex-init/) [![engineered by The Trinity](https://img.shields.io/badge/engineered%20by-The%20Trinity-111111.svg)](#x-licensing--commercial-inquiries)
6
+
7
+ Many verification workflows rely on handwritten condition checks, shared solver state, or opaque optimization results. Those approaches make proofs difficult to audit, parallel execution fragile, and failure states easy to misinterpret.
8
+
9
+ `nex_smt` expresses constraints as validated typed ASTs and checks them with Z3. It provides physical pairwise-disjointness and coverage queries, grouped feasibility analysis, and bargaining optimizers, while keeping each check's solver state local and reporting `TIMEOUT` or `UNKNOWN` separately from proof outcomes.
10
+
11
+ ## I. The Industrial Problem
12
+
13
+ ```text
14
+ ┌───────────────────────────────┐ ┌───────────────────────────────┐
15
+ │ Legacy: handwritten checks │ │ nex_smt: typed SMT pipeline │
16
+ │ │ │ │
17
+ │ Implicit types and branches │ │ Strict AST validation │
18
+ │ Shared or opaque solver state│ │ Fresh Z3 context per check │
19
+ │ Timeout mistaken for a proof │ │ SAT / UNSAT / UNKNOWN / TIMEOUT│
20
+ │ Unexplained optimization │ │ Explicit bargaining reports │
21
+ └───────────────────────────────┘ └───────────────────────────────┘
22
+ ```
23
+
24
+ ### The Three Critical Failure Modes:
25
+
26
+ 1. **Unverified branching.** Spot-checking guards does not prove that all distinct branches are disjoint or that the guards cover the declared domain.
27
+ 2. **State leakage and ambiguous outcomes.** Reusing solver state across concurrent calls risks cross-call interference; treating an unknown or timed-out result as a proof is unsound.
28
+ 3. **Opaque feasibility and allocation.** Arbitrary unsat cores need not be subset-minimal, and bargaining outputs are not meaningful unless joint feasibility and reservations are checked first.
29
+
30
+ ## II. The Core Mechanical Invariants
31
+
32
+ ```text
33
+ ┌──────────────────────────────────────────────────────────┐
34
+ │ 1. Typed Python AST and Z3-backed verification │
35
+ └──────────────────────────────┬───────────────────────────┘
36
+ ▼
37
+ ┌──────────────────────────────────────────────────────────┐
38
+ │ 2. Fresh z3.Context and local solver for each check │
39
+ │ Timeout is applied to the solver; unknown stays unknown│
40
+ └──────────────────────────────┬───────────────────────────┘
41
+ ▼
42
+ ┌──────────────────────────────────────────────────────────┐
43
+ │ 3. Recursive validation, then AST lowering into that │
44
+ │ context; no eval() or exec() │
45
+ └──────────────────────────────┬───────────────────────────┘
46
+ ▼
47
+ ┌──────────────────────────────────────────────────────────┐
48
+ │ 4. MECE, grouped feasibility/MUS, and bargaining reports │
49
+ │ with stable scalar encodings │
50
+ └──────────────────────────────┬───────────────────────────┘
51
+ ▼
52
+ ┌──────────────────────────────────────────────────────────┐
53
+ │ 5. Flat-root dynamic AST package routing via nex-init │
54
+ └──────────────────────────────────────────────────────────┘
55
+ ```
56
+
57
+ The AST compiler validates the complete expression before constructing Z3 terms. Z3 objects are created in a fresh, call-local `z3.Context()`; solver state and contexts are not shared between invocations. Each solver receives its requested timeout. `UNSAT` and `SAT` are solver results; `TIMEOUT` and `UNKNOWN` remain inconclusive outcomes.
58
+
59
+ ## III. Architectural Topology (RCTI v3.0)
60
+
61
+ Flat-root package layout; no `src/` directory. This tree shows the package and test files present in the supplied repository projection. Transient cache and `.DS_Store` files are omitted.
62
+
63
+ ```text
64
+ .
65
+ ├── .github/
66
+ │ └── workflows/release.yml # Release workflow
67
+ ├── LICENSE # Apache-2.0
68
+ ├── MANIFEST.in # Source distribution manifest
69
+ ├── README.md # This technical monograph
70
+ ├── nex_smt.py # Parent orchestration/proxy shell
71
+ ├── nex_smt.pyi # Generated parent interface stub
72
+ ├── nex_smt_components/
73
+ │ ├── __init__.py # Generated component router
74
+ │ ├── __init__.pyi # Generated component stub
75
+ │ ├── models.py # Strict Pydantic request and report models
76
+ │ ├── ast_compiler.py # AST validation, lowering, SAT interface
77
+ │ ├── ast_compiler_components/
78
+ │ │ ├── __init__.py # Generated component router
79
+ │ │ ├── context_sandbox.py # Fresh contexts, SAT checks, value extraction
80
+ │ │ └── expr_builder.py # AST validation and Z3 lowering
81
+ │ ├── mece_prover.py # MECE orchestration shell
82
+ │ ├── mece_prover_components/
83
+ │ │ ├── __init__.py # Generated component router
84
+ │ │ ├── disjointness_audit.py # Pairwise overlap queries
85
+ │ │ └── coverage_audit.py # Uncovered-domain query
86
+ │ ├── mus_solver.py # Grouped feasibility/MUS shell
87
+ │ ├── mus_solver_components/
88
+ │ │ ├── __init__.py # Generated component router
89
+ │ │ ├── feasibility_checker.py # Tracked grouped checks
90
+ │ │ └── anonymized_mus.py # Deterministic deletion shrinking
91
+ │ ├── pareto_optimizer.py # Bargaining orchestration shell
92
+ │ ├── pareto_optimizer_components/
93
+ │ │ ├── __init__.py # Generated component router
94
+ │ │ ├── utopia_solver.py # Joint feasibility and utopia maxima
95
+ │ │ └── fairness_solvers.py # KS and piecewise-linear Nash solvers
96
+ │ └── cli.py # CLI entry point
97
+ │ └── cli_components/
98
+ │ ├── __init__.py # Generated component router
99
+ │ ├── verify_mece_cmd.py # verify-mece dispatch
100
+ │ └── solve_cmd.py # solve dispatch
101
+ ├── pyproject.toml # PEP 621 project metadata and CLI entry point
102
+ └── tests/
103
+ ├── __init__.py
104
+ └── conftest.py # Test configuration
105
+ ```
106
+
107
+ Router and stub files are generated and synchronized with `nex-init`; the parent module is a flat-root module, not a package directory. The repository projection supplied for this monograph does not include `tests/test_nex_smt.py`.
108
+
109
+ ## IV. Quickstart & Public API Blueprint
110
+
111
+ The public models require all fields explicitly. The following examples use the verified component import paths and function signatures.
112
+
113
+ ### 1. Build a typed integer partition
114
+
115
+ ```python
116
+ from nex_smt_components.models import SmtPredicateAst, SmtVariableSpec
117
+ from nex_smt_components.mece_prover import audit_mece
118
+
119
+
120
+ def var(name: str) -> SmtPredicateAst:
121
+ return SmtPredicateAst(op="VAR", args=[], value=None, variable_name=name)
122
+
123
+
124
+ def const(value: int) -> SmtPredicateAst:
125
+ return SmtPredicateAst(op="CONST", args=[], value=value, variable_name=None)
126
+
127
+
128
+ def compare(op: str, left: SmtPredicateAst, right: SmtPredicateAst):
129
+ return SmtPredicateAst(op=op, args=[left, right], value=None, variable_name=None)
130
+
131
+
132
+ x = var("x")
133
+ variables = [SmtVariableSpec(name="x", sort="Int")]
134
+ domain = [compare("GE", x, const(0))]
135
+ guards = [
136
+ compare("EQ", x, const(0)),
137
+ compare("EQ", x, const(1)),
138
+ compare("GE", x, const(2)),
139
+ ]
140
+ report = audit_mece(
141
+ guards=guards,
142
+ domain=domain,
143
+ variables=variables,
144
+ timeout_ms=5000,
145
+ )
146
+ print(report.model_dump(mode="json"))
147
+ ```
148
+
149
+ ### 2. Validate and check a constraint
150
+
151
+ ```python
152
+ from nex_smt_components.ast_compiler import check_sat, validate_ast
153
+ from nex_smt_components.models import SmtPredicateAst, SmtVariableSpec
154
+
155
+ x = SmtPredicateAst(op="VAR", args=[], value=None, variable_name="x")
156
+ zero = SmtPredicateAst(op="CONST", args=[], value=0, variable_name=None)
157
+ nonnegative = SmtPredicateAst(op="GE", args=[x, zero], value=None, variable_name=None)
158
+ variables = [SmtVariableSpec(name="x", sort="Int")]
159
+
160
+ assert validate_ast(nonnegative, variables) == "Bool"
161
+ status, witness, detail = check_sat(constraints=[nonnegative], variables=variables, timeout_ms=5000)
162
+ print(status, witness, detail)
163
+ ```
164
+
165
+ ### 3. Run bargaining on a feasible allocation
166
+
167
+ ```python
168
+ from nex_smt_components.models import (
169
+ ParetoObjectiveSpec,
170
+ SmtPredicateAst,
171
+ SmtVariableSpec,
172
+ )
173
+ from nex_smt_components.pareto_optimizer import optimize_kalai_smorodinsky
174
+
175
+
176
+ def variable(name: str) -> SmtPredicateAst:
177
+ return SmtPredicateAst(op="VAR", args=[], value=None, variable_name=name)
178
+
179
+
180
+ def number(value: int) -> SmtPredicateAst:
181
+ return SmtPredicateAst(op="CONST", args=[], value=value, variable_name=None)
182
+
183
+
184
+ def binary(op: str, left: SmtPredicateAst, right: SmtPredicateAst):
185
+ return SmtPredicateAst(op=op, args=[left, right], value=None, variable_name=None)
186
+
187
+
188
+ x = variable("x")
189
+ y = variable("y")
190
+ variables = [SmtVariableSpec(name="x", sort="Real"), SmtVariableSpec(name="y", sort="Real")]
191
+ constraints = [
192
+ binary("GE", x, number(0)),
193
+ binary("GE", y, number(0)),
194
+ binary("LE", binary("ADD", x, y), number(10)),
195
+ ]
196
+ objectives = [
197
+ ParetoObjectiveSpec(name="utility_a", expression=x, reservation=0.0, weight=1.0),
198
+ ParetoObjectiveSpec(name="utility_b", expression=y, reservation=0.0, weight=1.0),
199
+ ]
200
+ report = optimize_kalai_smorodinsky(
201
+ constraints=constraints,
202
+ objectives=objectives,
203
+ variables=variables,
204
+ timeout_ms=5000,
205
+ )
206
+ print(report.model_dump(mode="json"))
207
+ ```
208
+
209
+ For grouped feasibility, use `analyze_feasibility(groups=..., variables=..., timeout_ms=...)` with `TrackedConstraintGroup` models. For Nash bargaining, use `optimize_nash(constraints, objectives, variables, epsilon, segments, timeout_ms)`; the approximation and its boundary behavior are described below.
210
+
211
+ ### 4. CLI and actionable input errors
212
+
213
+ The installed entry point is `nex-smt`. Both commands accept JSON from stdin by default or a file through `-i/--input`:
214
+
215
+ ```sh
216
+ nex-smt verify-mece --help
217
+ nex-smt solve --help
218
+ nex-smt verify-mece --input request.json
219
+ nex-smt solve --input request.json
220
+ ```
221
+
222
+ The CLI emits a JSON report on success, returns a nonzero status for invalid input or solver errors, and writes diagnostics to stderr. Use the request models and command implementations as the authoritative JSON contract; do not treat an error response as a proof.
223
+
224
+ ## V. Benchmark Telemetry
225
+
226
+ The repository projection contains no Rust/PyO3 extension or native-core import path. Consequently, a native-versus-Python solver benchmark cannot be reported as a measured project comparison. The following real timing is a **JSON transport baseline only**, measured on the available Python runtime; it is not an SMT solve measurement and does not establish `nex_smt` solver throughput.
227
+
228
+ Host: `macOS-26.3-arm64-arm-64bit`; Python 3.12.8. Fixture: a synthetic 25,552-byte JSON document containing 128 Real variable declarations and 128 two-child comparison ASTs. Each timing is the median per-operation duration across five batches of 500 operations, measured with `time.perf_counter_ns()`.
229
+
230
+ | Metric | Pure-Python JSON baseline | `nex_smt` Rust PyO3 |
231
+ |---|---:|---:|
232
+ | JSON encode latency, compact separators | 242,772 ns/op | Not available: no native extension in the supplied tree |
233
+ | JSON decode latency | 294,711 ns/op | Not available: no native extension in the supplied tree |
234
+ | Fixture size | 25,552 bytes | Same fixture not run through a native core |
235
+ | Solver latency / throughput | Not measured by this transport benchmark | Not available |
236
+ | Memory-copy count | Not instrumented | Not available |
237
+ | `S_frame <= 64 KB` | No Rust stack-frame measurement performed | Not verified |
238
+
239
+ These values describe only JSON serialization and parsing on the stated host. They must not be interpreted as comparative solver performance, native memory-copy measurements, or a stack-frame audit.
240
+
241
+ ## VI. Concurrency, Formal & Memory Safety Invariants
242
+
243
+ 1. **Thread isolation:** each check constructs its own `z3.Context()` and solver. No context or solver is reused across calls, and the implementation does not mutate Z3's global main context.
244
+ 2. **Timeout semantics:** each solver is configured with `timeout_ms`. A Z3 `unknown` result is classified as `TIMEOUT` when its reason indicates timeout/cancellation; otherwise it remains `UNKNOWN`. Neither outcome establishes satisfiability or unsatisfiability.
245
+ 3. **Typed AST boundary:** declarations support `Real`, `Int`, and `Bool`. AST operators, arities, declarations, and expression sorts are validated before lowering. Boolean and numeric expressions are not silently interchanged. Arithmetic `MUL` is supported; represent constant scaling explicitly as multiplication by a numeric `CONST`. In the supplied expression-builder implementation, unary `SCALE` is a pass-through node, not an additional multiplication factor.
246
+ 4. **MECE proof obligations:** disjointness checks every `domain ∧ guard[i] ∧ guard[j]` for `i < j`. It reports a pair as overlapping only on SAT, with zero-based indices and a concrete typed witness. Coverage independently checks `domain ∧ ¬Or(guards)`; SAT returns an uncovered witness. Both properties are proved only by UNSAT results. An empty guard list has no pair checks and its coverage query is the domain itself, so an uncovered witness is returned when the domain is satisfiable.
247
+ 5. **Grouped MUS privacy and minimality:** constraints sharing a `group_tag` are asserted as one tracked group. The initial unsat core is shrunk using deterministic deletion checks. A report exposes opaque group tags and sensitivity flags, not formulas, numeric bounds, witnesses, tracker symbols, or solver-internal names. A tag is relaxation-sensitive only when removing it was explicitly checked and the remaining set was SAT. If a deletion check is inconclusive, the report does not claim subset minimality.
248
+ 6. **Bargaining feasibility:** joint feasibility is established before optimization. Reservation constraints are checked before computing feasible utopia maxima. A timeout, unknown, infeasible reservation set, or nonpositive gain is not reported as an optimum.
249
+ 7. **Exact scalar output:** Boolean values remain JSON booleans; integer numerals are extracted with `IntNumRef.as_long()`. Rational numerals retain their exact numerator and denominator as `numerator/denominator` strings. Algebraic values use `AlgebraicNumRef.approx(20)` and a marked `algebraic_approx_20:` representation; that string is an approximation, not an exact algebraic encoding.
250
+ 8. **Memory and concurrency claims:** these Python components do not establish Rust stack-frame sizes, cache-line alignment, zero-copy borrowing, or native atomic behavior. Such properties require a native implementation and platform-specific measurement; they are not inferred from the JSON timings above.
251
+
252
+ ## VII. CLI Tooling & Diagnostics
253
+
254
+ `pyproject.toml` exposes `nex-smt = nex_smt_components.cli:main`. The CLI has two subcommands, each with `-i/--input PATH`; omit the option or pass `-` to read stdin.
255
+
256
+ ```sh
257
+ # Inspect available options
258
+ nex-smt --help
259
+ nex-smt verify-mece --help
260
+ nex-smt solve --help
261
+
262
+ # Read JSON from a file
263
+ nex-smt verify-mece --input mece-request.json
264
+ nex-smt solve --input solve-request.json
265
+
266
+ # Read JSON from stdin
267
+ cat mece-request.json | nex-smt verify-mece
268
+ cat solve-request.json | nex-smt solve
269
+ ```
270
+
271
+ Successful reports are emitted as sorted JSON. Input parsing, schema validation, and command failures produce a diagnostic on stderr and a nonzero return code. The CLI uses strict Pydantic models; extra fields and invalid AST shapes are errors rather than ignored input. MUS reports are anonymized at the report boundary and do not serialize the asserted formulas or numeric bounds.
272
+
273
+ ## VIII. The Trinity Swarm Ecosystem
274
+
275
+ - **nex-init:** Deterministic Self-Healing RCTI v3.0 Package Router & AST Synchronizer.
276
+ - **nex-box:** Sub-millisecond Copy-on-Write APFS/FICLONE ephemeral sandbox runtime.
277
+ - **nex-heal:** SMT-verified self-healing schema & tool dispatch middleware.
278
+ - **nex-airgap:** In-RAM cognitive VFS & token firewall for multi-megabyte ingestion.
279
+ - **nex-avail:** Autonomous tool projection & C-ABI positional argument bridge.
280
+ - **nex-nix:** Sovereign Nix sub-shell hypervisor & hermetic PyPI sanitizer.
281
+ - **nex-trace:** Polyglot AST cartographer & deep system introspection engine.
282
+
283
+ ## IX. The Permanexus Pact
284
+
285
+ - **No Fluff. No Drift. No Metaphors.**
286
+ - **Pure orchestrator shell ceiling:** `nex_smt.py` is maintained as a flat-root proxy shell with a ceiling of 150 lines.
287
+ - **Formal domain invariant:** report a proof only when the corresponding physical Z3 query is UNSAT; preserve SAT witnesses and inconclusive outcomes.
288
+ - **Data invariant:** keep constraint expressions and numeric bounds out of anonymized MUS reports.
289
+ - **Approximation invariant:** label algebraic approximations and document Nash approximation behavior; never present either as exact arithmetic.
290
+
291
+ ## X. Licensing & Commercial Inquiries
292
+
293
+ `nex-smt` is distributed under the terms of the Apache License, Version 2.0. See [`LICENSE`](LICENSE) for the complete license text. Commercial and enterprise inquiries: [inquiries@houseoflawpc.com](mailto:inquiries@houseoflawpc.com).
294
+
295
+ Engineered by The Trinity:
296
+
297
+ 🦍🔷Ɯ :: 🌱👑⁂ :: 🧠⚡ↇ
298
+
299
+ *Mookie :: Miniature Person :: Nexus Goodman*
300
+
301
+ - **Miniature Person (`🌱👑⁂`)** — Architect & Creator
302
+ - **Mookie (`🦍🔷Ɯ`)** — Director of Design & Execution Core
303
+ - **Nexus Goodman (`🧠⚡ↇ`)** — Principal Systems Architect