@milkenjoyer/toolchain 0.14.0 → 0.14.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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/formal/z3.ts +18 -1
package/README.md
CHANGED
|
@@ -241,7 +241,7 @@ export default z3({
|
|
|
241
241
|
|
|
242
242
|
A `z3` proof passes only when all of these hold:
|
|
243
243
|
|
|
244
|
-
- `code` returns a whole number equal to the model's output on `samples` seeded inputs
|
|
244
|
+
- `code` returns a whole number equal to the model's output on `samples` seeded inputs. Edge values come first, then one draw uniform over each range for every three small-magnitude draws, which put each input within a random power of two of its range's value nearest 0.
|
|
245
245
|
- The claim uses only Int and BitVec arithmetic. Real and Float arithmetic fail.
|
|
246
246
|
- `holds` is false for some output, so the claim constrains the model.
|
|
247
247
|
- z3 answers `unsat` for the negated claim. `unknown`, a timeout or a crash fails.
|
package/package.json
CHANGED
package/src/formal/z3.ts
CHANGED
|
@@ -163,6 +163,22 @@ export const prove = async (
|
|
|
163
163
|
return scalar ? values.value : values;
|
|
164
164
|
};
|
|
165
165
|
const draw = random(relative(request.root, request.proof));
|
|
166
|
+
const uniform = (d: Domain) => draw(d.min, d.max);
|
|
167
|
+
const small = (d: Domain) => {
|
|
168
|
+
const min = BigInt(d.min);
|
|
169
|
+
const max = BigInt(d.max);
|
|
170
|
+
const anchor = min >= 0n ? min : max <= 0n ? max : 0n;
|
|
171
|
+
const span = max - min;
|
|
172
|
+
const k = draw(0, span === 0n ? 0 : span.toString(2).length);
|
|
173
|
+
const reach = (1n << BigInt(k)) - 1n;
|
|
174
|
+
const lower = anchor - reach;
|
|
175
|
+
const upper = anchor + reach;
|
|
176
|
+
return draw(
|
|
177
|
+
Number(lower < min ? min : lower),
|
|
178
|
+
Number(upper > max ? max : upper)
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
const samplers = [uniform, small, small, small];
|
|
166
182
|
const corner = corners(domains);
|
|
167
183
|
const accepted: Tuple[] = [];
|
|
168
184
|
let drawn = 0;
|
|
@@ -173,9 +189,10 @@ export const prove = async (
|
|
|
173
189
|
100 * request.samples - drawn
|
|
174
190
|
);
|
|
175
191
|
for (let i = 0; i < count; i++) {
|
|
192
|
+
const sample = samplers[drawn % samplers.length] ?? uniform;
|
|
176
193
|
batch.push(
|
|
177
194
|
corner[drawn] ??
|
|
178
|
-
Object.fromEntries(domains.map((d) => [d.name,
|
|
195
|
+
Object.fromEntries(domains.map((d) => [d.name, sample(d)]))
|
|
179
196
|
);
|
|
180
197
|
drawn++;
|
|
181
198
|
}
|