@ohtaman/washi 0.7.0 → 0.8.1

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 (162) hide show
  1. package/README.ja.md +60 -23
  2. package/README.md +59 -22
  3. package/README.zh-CN.md +62 -25
  4. package/THIRD_PARTY_LICENSES.md +34 -1
  5. package/dist/browser/solvers/glpk.js +289 -238
  6. package/dist/browser/solvers/glpk.min.js +1 -1
  7. package/dist/browser/solvers/highs-__vite-browser-external-Dn-83hnF.js +7 -0
  8. package/dist/browser/solvers/highs-browser-runtime-0Bgq5ksG.js +2021 -0
  9. package/dist/browser/{loader-DewlSho8.js → solvers/highs-loader-BLY3wzDH.js} +190 -149
  10. package/dist/browser/solvers/highs-worker.js +54 -0
  11. package/dist/browser/solvers/highs.js +1414 -0
  12. package/dist/browser/solvers/highs.wasm +0 -0
  13. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
  14. package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
  15. package/dist/browser/solvers/pumpkin-worker.js +45 -0
  16. package/dist/browser/solvers/pumpkin.js +1777 -0
  17. package/dist/browser/solvers/pumpkin.wasm +0 -0
  18. package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
  19. package/dist/browser/solvers/z3.js +1600 -1335
  20. package/dist/browser/solvers/z3.min.js +2 -2
  21. package/dist/browser/washi.js +3313 -1699
  22. package/dist/browser/washi.min.js +5 -3
  23. package/dist/lib/solvers/__vite-browser-external-oLchLuMx.js +7 -0
  24. package/dist/lib/solvers/glpk.js +174 -132
  25. package/dist/lib/solvers/highs-browser-runtime.js +2413 -0
  26. package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
  27. package/dist/lib/solvers/highs-runtime.js +16 -0
  28. package/dist/lib/solvers/highs-worker.js +54 -0
  29. package/dist/lib/solvers/highs.js +410 -0
  30. package/dist/lib/solvers/highs.wasm +0 -0
  31. package/dist/lib/{loader-BZUQNvh4.js → solvers/loader-CDpPXN_F.js} +138 -116
  32. package/dist/lib/solvers/loader-Ow74Fa1B.js +311 -0
  33. package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
  34. package/dist/lib/solvers/pumpkin-assets.js +1 -0
  35. package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
  36. package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
  37. package/dist/lib/solvers/pumpkin-worker.js +45 -0
  38. package/dist/lib/solvers/pumpkin.js +868 -0
  39. package/dist/lib/solvers/pumpkin.wasm +0 -0
  40. package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
  41. package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
  42. package/dist/lib/solvers/rolldown-runtime-DtPi1Y-2.js +13 -0
  43. package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
  44. package/dist/lib/solvers/z3.js +489 -307
  45. package/dist/lib/washi.js +3905 -1410
  46. package/dist/types/decomposition/benders.d.ts.map +1 -1
  47. package/dist/types/index.d.ts +4 -5
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/modeler/boolean-expr.d.ts +137 -29
  50. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  51. package/dist/types/modeler/constraint.d.ts +40 -4
  52. package/dist/types/modeler/constraint.d.ts.map +1 -1
  53. package/dist/types/modeler/expression.d.ts +129 -2
  54. package/dist/types/modeler/expression.d.ts.map +1 -1
  55. package/dist/types/modeler/index.d.ts +4 -6
  56. package/dist/types/modeler/index.d.ts.map +1 -1
  57. package/dist/types/modeler/linearizer.d.ts +11 -2
  58. package/dist/types/modeler/linearizer.d.ts.map +1 -1
  59. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  60. package/dist/types/modeler/model.d.ts +86 -126
  61. package/dist/types/modeler/model.d.ts.map +1 -1
  62. package/dist/types/modeler/parser.d.ts.map +1 -1
  63. package/dist/types/modeler/quad-expr.d.ts +8 -2
  64. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  65. package/dist/types/modeler/solution-validator.d.ts +12 -12
  66. package/dist/types/modeler/solution-validator.d.ts.map +1 -1
  67. package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
  68. package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
  69. package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
  70. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  71. package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
  72. package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
  73. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  74. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  75. package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
  76. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  77. package/dist/types/modeler/solvers/index.d.ts +2 -1
  78. package/dist/types/modeler/solvers/index.d.ts.map +1 -1
  79. package/dist/types/modeler/solvers/mock.d.ts +2 -3
  80. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  81. package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
  82. package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
  83. package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
  84. package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
  85. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
  86. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
  87. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
  88. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
  89. package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
  90. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
  91. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
  92. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
  93. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
  94. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
  95. package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
  96. package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
  97. package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
  98. package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
  99. package/dist/types/modeler/solvers/types.d.ts +7 -9
  100. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  101. package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
  102. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  103. package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
  104. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  105. package/dist/types/modeler/types.d.ts +12 -15
  106. package/dist/types/modeler/types.d.ts.map +1 -1
  107. package/dist/types/modeler/validation.d.ts +26 -2
  108. package/dist/types/modeler/validation.d.ts.map +1 -1
  109. package/dist/types/modeler/variable.d.ts +9 -5
  110. package/dist/types/modeler/variable.d.ts.map +1 -1
  111. package/docs/examples/diet-sensitivity.md +33 -14
  112. package/docs/examples/ecommerce-coupons.md +17 -9
  113. package/docs/examples/index.md +36 -27
  114. package/docs/examples/knapsack.md +11 -5
  115. package/docs/examples/portfolio-qp.md +21 -8
  116. package/docs/examples/production.md +10 -5
  117. package/docs/examples/project-scheduling.md +119 -0
  118. package/docs/examples/shift-scheduling.md +29 -18
  119. package/docs/examples/smt-security.md +27 -11
  120. package/docs/examples/transportation.md +23 -13
  121. package/docs/examples/traveling-salesperson.md +34 -22
  122. package/docs/examples/unsat-core.md +27 -14
  123. package/docs/examples/vehicle-routing.md +74 -28
  124. package/docs/getting-started/ai-agents.md +190 -82
  125. package/docs/getting-started/coding-agents.md +177 -0
  126. package/docs/getting-started/cross-origin.md +27 -14
  127. package/docs/getting-started/index.md +49 -43
  128. package/docs/getting-started/runtimes.md +94 -40
  129. package/docs/guide/constraint-programming.md +171 -0
  130. package/docs/guide/constraints.md +115 -33
  131. package/docs/guide/decomposition.md +118 -88
  132. package/docs/guide/expressions.md +106 -43
  133. package/docs/guide/formulation-tips.md +47 -28
  134. package/docs/guide/objectives.md +102 -75
  135. package/docs/guide/unsat-core.md +62 -50
  136. package/docs/guide/variables.md +81 -35
  137. package/docs/solvers/custom-solver.md +163 -122
  138. package/docs/solvers/glpk.md +58 -17
  139. package/docs/solvers/highs.md +124 -57
  140. package/docs/solvers/index.md +33 -20
  141. package/docs/solvers/pumpkin.md +171 -0
  142. package/docs/solvers/z3.md +63 -25
  143. package/llms-full.txt +2232 -932
  144. package/llms.txt +144 -91
  145. package/package.json +55 -19
  146. package/skills/washi/SKILL.md +107 -34
  147. package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
  148. package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
  149. package/dist/browser/highs-worker.js +0 -39
  150. package/dist/browser/highs.wasm +0 -0
  151. package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
  152. package/dist/lib/highs-browser-runtime.js +0 -2185
  153. package/dist/lib/highs-runtime.js +0 -2
  154. package/dist/lib/highs-worker.js +0 -39
  155. package/dist/lib/highs.wasm +0 -0
  156. package/dist/lib/registry-D7TZ3Wh_.js +0 -1034
  157. package/docs/ja/getting-started/ai-agents.md +0 -280
  158. package/docs/zh/getting-started/ai-agents.md +0 -280
  159. /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
  160. /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
  161. /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
  162. /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
@@ -1,12 +1,12 @@
1
1
  # Z3 SMT Solver Engine
2
2
 
3
- **Z3** is a theorem prover and Satisfiability Modulo Theories (SMT) solver developed by Microsoft Research. In WaSHI, Z3 provides advanced propositional logic reasoning and conflict diagnosis.
3
+ **Z3** is an open-source theorem prover and Satisfiability Modulo Theories (SMT) solver from Microsoft Research. In WaSHI, Z3 handles logical rules involving `Continuous` variables or decimal coefficients/constants, exact arithmetic, and `unsatCore` conflict diagnosis.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Installation
8
8
 
9
- Z3 is provided as an optional peer dependency:
9
+ `z3-solver` is an optional peer dependency:
10
10
 
11
11
  ```bash
12
12
  npm install z3-solver
@@ -14,45 +14,57 @@ npm install z3-solver
14
14
 
15
15
  ---
16
16
 
17
- ## When to Use Z3?
17
+ ## When to Choose Z3
18
18
 
19
- 1. **Unsat Core Conflict Diagnosis**:
20
- When your MIP model is infeasible and you need to isolate which constraints are contradictory.
21
- 2. **Boolean / Logical Formulations**:
22
- When solving problems containing complex logical relations (implications, XOR, nested Boolean expressions).
23
- 3. **Exact Mathematical Guarantees**:
24
- Z3 can perform exact rational arithmetic without floating-point inaccuracies.
19
+ | Goal | Recommended Solver | Why |
20
+ | :--- | :--- | :--- |
21
+ | **Logical rules with `Continuous` or decimal values** | **Z3** (`m.check({ solver: "z3" })`) | Evaluates real-valued inequalities natively inside `implies`, `not`, `and`, `or`, and `xor`. |
22
+ | **Conflict diagnosis (`unsatCore`) with `Continuous` vars** | **Z3** (`m.check({ solver: "z3" })`) | Extracts scale-invariant `unsatCore` subsets across mixed continuous and integer models. |
23
+ | **Bounded integer/boolean Constraint Programming** | **[Pumpkin](./pumpkin.md)** | Bundled with zero dependencies and needs no Cross-Origin Isolation headers. |
24
+ | **Numerical linear, mixed-integer, or convex quadratic optimization** | **[HiGHS](./highs.md)** (default) | Built-in simplex, interior-point, and branch-and-cut solver; much faster for objective optimization. |
25
25
 
26
26
  > [!TIP]
27
- > **Z3 (`m.check()`) vs. HiGHS (`m.solve()`)**: Z3 excels at satisfiability checking (`m.check()`), formal policy verification, general inequality implications (`` implies(expr`${x} <= 50`, y) ``), and scale-invariant `unsatCore` extraction. For numerical LP, MIP, or Convex QP optimization with objective functions over tens or hundreds of variables, use the built-in **HiGHS** solver (`m.solve()`), whose simplex relaxations and branch-and-bound cutting planes are orders of magnitude faster than `Z3.Optimize`. Or combine both in a hybrid pipeline: verify/diagnose rules with Z3 `m.check()`, then optimize costs with HiGHS `m.solve()`.
27
+ > A common workflow is to verify rules and diagnose conflicts via **Z3** `model.check()`, then optimize numerical costs via **HiGHS** `model.solve()`.
28
28
 
29
29
  ---
30
30
 
31
- ## Basic Usage
31
+ ## Basic Usage (`model.solve()` vs. `model.check()`)
32
+
33
+ Import `@ohtaman/washi/solvers/z3` once to register the `"z3"` solver. Z3 supports two execution modes on the same `Model`:
34
+
35
+ - **`model.check()`**: Checks satisfiability without an objective and returns `"Sat"`, `"Unsat"` (with `conflicts` / `unsatCore`), or `"Unknown"`.
36
+ - **`model.solve()`**: Optimizes a linear objective via Z3 Optimize. When no objective is set, `solve()` finds any feasible assignment and reports `"Optimal"` (or `"Feasible"` if `signal` was aborted while the call was completing).
37
+
38
+ The example below finds a feasible assignment for a continuous threshold rule controlled by a boolean flag:
32
39
 
33
40
  ```typescript
34
- import { Model, expr } from "@ohtaman/washi";
41
+ import { Model, expr, implies } from "@ohtaman/washi";
35
42
  import "@ohtaman/washi/solvers/z3";
36
43
 
37
44
  const model = new Model({ solver: "z3" });
38
45
 
39
- const x = model.integer("x", { lb: 0, ub: 10 });
40
- const y = model.integer("y", { lb: 0, ub: 10 });
46
+ const temp = model.continuous("temp", { lb: 0, ub: 100 });
47
+ const coolingOn = model.bool("cooling_on");
41
48
 
42
- model.constraint(expr`${x} + ${y} == 15`, "sum_15");
43
- model.constraint(expr`${x} >= 8`, "x_at_least_8");
49
+ model.constraint(coolingOn, "enable_cooling");
50
+ model.constraint(implies(coolingOn, expr`${temp} <= 22.5`), "cooling_target");
44
51
 
52
+ // Without an objective, solve() finds any feasible assignment.
53
+ // Call model.check() instead for "Sat" / "Unsat" and unsatCore diagnostics.
45
54
  await model.solve();
46
- console.log(`x = ${x.value}, y = ${y.value}`);
55
+ console.log(`Status: ${model.status}, temp = ${temp.value}`);
47
56
  ```
48
57
 
49
58
  ---
50
59
 
51
- ## Unsat Core Extraction (`model.check()`)
60
+ ## Conflict Diagnosis (`model.check()`)
52
61
 
53
- Use `await model.check()` with Z3 to verify satisfiability and extract the conflicting subset of named constraints (`conflicts` / `unsatCore`) when a model is unsatisfiable:
62
+ Call `await model.check()` to verify satisfiability across continuous, integer, or mixed rules. When the model is `"Unsat"`, Z3 returns a conflicting subset of named constraints via `result.conflicts` (also available as `result.unsatCore` and `model.unsatCore`):
54
63
 
55
64
  ```typescript
65
+ import { Model, expr } from "@ohtaman/washi";
66
+ import "@ohtaman/washi/solvers/z3";
67
+
56
68
  const model = new Model({ solver: "z3" });
57
69
  const a = model.continuous("a");
58
70
 
@@ -62,20 +74,46 @@ model.constraint(expr`${a} <= 5`, "req_B");
62
74
  const result = await model.check();
63
75
 
64
76
  if (result.status === "Unsat") {
65
- console.log("Conflicting constraints:", result.conflicts); // or model.conflicts / model.unsatCore
77
+ console.log("Conflicting constraints:", result.conflicts);
66
78
  // ["req_A", "req_B"]
67
79
  }
68
80
  ```
69
81
 
70
82
  ---
71
83
 
72
- ## Browser Security Note
84
+ ## Supported & Unsupported Options
85
+
86
+ Z3 validates options strictly and throws a runtime `Error` when unsupported options or model features are supplied.
73
87
 
74
- In browser environments, the Z3 WASM engine relies on pthreads and `SharedArrayBuffer`, which require cross-origin isolation headers (`COOP` / `COEP`). See the [Cross-Origin Isolation Guide](../getting-started/cross-origin.md) for detailed setup.
88
+ ### Supported Options
75
89
 
76
- ## Runtime Failures and Thread Cleanup
90
+ - `z3JsUrl` / `z3WasmUrl`: Override browser asset URLs for `z3-built.js` and `z3-built.wasm` (or configure globally with `setZ3Assets()`).
91
+ - `signal`: `AbortSignal` checked **before** Z3 starts solving (pre-solve cancellation only; it cannot interrupt an active Z3 call).
92
+ - `onProgress`: Applies to `solve()` only (ignored by `check()`). Invoked once after `solve()` completes with elapsed time and, when a solution exists, the final objective value.
77
93
 
78
- If a Z3 worker encounters a fatal runtime error, pending operations on that instance reject with an error and the broken runtime is invalidated; subsequent `solve()` or `check()` calls automatically initialize a fresh Z3 runtime rather than misclassifying failures as `Sat` or `Unsat`.
94
+ ### Unsupported Options & Features (Throw at Runtime)
79
95
 
80
- To explicitly terminate Z3 pthread workers when tearing down a browser view or worker pool, call `killZ3Threads()` from `@ohtaman/washi/solvers/z3`.
96
+ - **Unsupported tuning options**: `timeLimit`, `relativeGap`, `absoluteGap`, `presolve`, `threads`, `verbose`, `outputFlag`, and unknown option keys throw an `Error`.
97
+ - **Unsupported modes & features**: `relax: true`, `useWorker: true`, `initialValue` warm starts, and `QuadExpr` quadratic objectives throw an `Error`.
81
98
 
99
+ > [!NOTE]
100
+ > Z3 Optimize is an SMT engine without LP sensitivity or branch-and-bound dual bounds: `c.dual`, `c.slack`, and `v.reducedCost` remain `null`, and `objectiveBound`, `relativeGap`, and `absoluteGap` remain `undefined`.
101
+
102
+ ---
103
+
104
+ ## Browser Requirements & Thread Cleanup
105
+
106
+ In browsers, Z3 uses `SharedArrayBuffer` and Emscripten pthreads. Your page must satisfy two browser preconditions:
107
+
108
+ 1. **Secure Context**: Served over `HTTPS` or `localhost`.
109
+ 2. **Cross-Origin Isolation (`COOP`/`COEP`)**: Document responses must send `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`.
110
+
111
+ See the [Cross-Origin Isolation Guide](../getting-started/cross-origin.md) for server setup. If you cannot configure these headers and only need bounded integers and booleans, use [Pumpkin](./pumpkin.md) instead.
112
+
113
+ If a Z3 worker hits a fatal error, the pending promise rejects and the broken runtime is discarded so the next call starts cleanly. To shut down Z3 pthread workers explicitly—both in Node.js (so CLI scripts and processes exit cleanly) and in browsers (for example, when unmounting a view)—call:
114
+
115
+ ```typescript
116
+ import { killZ3Threads } from "@ohtaman/washi/solvers/z3";
117
+
118
+ await killZ3Threads();
119
+ ```