trading_data_expr 0.5.1

Typed primitive algebra: one expression value read four ways — evaluate, differentiate, document, debug
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
//! One kernel, `(x0 + x1)² + |x0 − 1|`, read four ways: value, exact gradient (vs central FD),
//! symbolic derivative (vs the gradient), and the LaTeX/trace renderings.

use trading_data_expr::{Expr, Vars, abs, absent, constant, lt, max, present, square};

/// The shared kernel; returns the typed `impl Expr` so every test reads the same source of truth.
fn kernel() -> impl Expr {
	let v = Vars;
	let (x0, x1) = (v.get::<0>(), v.get::<1>());
	square(x0 + x1) + abs(x0 - constant(1.0))
}

fn central_fd(e: &impl Expr, env: &[f64], i: usize) -> f64 {
	let h = 1e-6;
	let (mut ep, mut em) = (env.to_vec(), env.to_vec());
	ep[i] += h;
	em[i] -= h;
	(e.eval(&ep) - e.eval(&em)) / (2.0 * h)
}

#[test]
fn eval_matches_hand_computation() {
	let e = kernel();
	// (3 + 5)² + |3 − 1| = 64 + 2
	assert_eq!(e.eval(&[3.0, 5.0]), 66.0);
	assert_eq!(e.eval(&[0.0, 0.0]), 1.0);
}

#[test]
fn grad_matches_central_difference() {
	let e = kernel();
	let env = [3.0, 5.0];
	let mut g = [0.0; 2];
	let val = e.grad(&env, 1.0, &mut g);
	assert_eq!(val, 66.0);
	// ∂/∂x0 = 2(x0+x1) + sign(x0−1) = 17, ∂/∂x1 = 2(x0+x1) = 16
	assert!((g[0] - 17.0).abs() < 1e-9, "{g:?}");
	assert!((g[1] - 16.0).abs() < 1e-9, "{g:?}");
	for i in 0..2 {
		assert!((g[i] - central_fd(&e, &env, i)).abs() < 1e-4, "grad {i} vs FD: {g:?}");
	}
}

#[test]
fn symbolic_derivative_matches_grad_on_random_envs() {
	let e = kernel();
	let ast = e.lower();
	// deterministic LCG; x0 kept clear of the |·| kink at 1.
	let mut s: u64 = 0x9e37_79b9_7f4a_7c15;
	let mut rng = || {
		s = s.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
		(s >> 33) as f64 / (1u64 << 31) as f64
	};
	for _ in 0..64 {
		let env = [2.0 + rng() * 5.0, rng() * 6.0 - 3.0];
		let mut g = [0.0; 2];
		e.grad(&env, 1.0, &mut g);
		for i in 0..2 {
			let d = ast.diff(i).simplify();
			assert!((d.eval(&env) - g[i]).abs() < 1e-9, "∂{i} {d} at {env:?}: {} vs {}", d.eval(&env), g[i]);
		}
	}
}

#[test]
fn latex_and_infix_render() {
	let ast = kernel().lower();
	assert_eq!(ast.to_string(), "((x0 + x1)^2 + |(x0 - 1)|)");
	assert_eq!(ast.latex(&["x", "y"]), "\\left(\\left(x + y\\right)^{2} + \\left|\\left(x - 1\\right)\\right|\\right)");
}

#[test]
fn trace_renders_intermediate_values() {
	let trace = kernel().lower().trace(&[3.0, 5.0]);
	let expected = "\
◉ +: 66
├──◉ sq: 64
│  └──◉ +: 8
│     ├──◉ var: 3
│     └──◉ var: 5
└──◉ abs: 2
   └──◉ -: 2
      ├──◉ var: 3
      └──◉ const: 1";
	assert_eq!(trace.to_string(), expected);
}

#[test]
fn simplify_clears_derivative_litter() {
	// d/dx1 of the kernel is 2(x0+x1)·1 with the |·| term vanishing — no 0-terms, no ×1 left.
	let d = kernel().lower().diff(1).simplify();
	assert_eq!(d.to_string(), "(2 * (x0 + x1))");
}

/// Every operator, differentiated two ways that share no code: `grad`'s chain rule, and a central
/// difference of `eval`. This is where the algebra is checked — a fire carries one array for the
/// one-step reading whichever way the kernel reached it (`r[kernels.jac.two-quantities]`), so the
/// engine has nothing to compare a `Pure` node's Jacobian against at runtime, deliberately, and the
/// comparison runs once here instead of every tick.
///
/// `Cmp`/`Select` carry a step, so they are sampled away from it: a difference across a jump is not
/// a slope, and neither reading claims one.
#[test]
fn every_operator_agrees_with_a_numeric_difference() {
	use trading_data_expr::{exp, gt, lt, max, min, or, powi_of, select, sqrt, sum};

	/// `(kernel, env)` pairs; the kernel is boxed through `lower` so one loop covers all of them.
	macro_rules! check {
		($($label:literal: |$v:ident| $body:expr, at $env:expr;)+) => {$({
			let $v = Vars;
			let e = $body;
			let env: [f64; 2] = $env;
			let mut g = [0.0; 2];
			let val = e.grad(&env, 1.0, &mut g);
			assert!((val - e.eval(&env)).abs() < 1e-12, "{}: grad's value disagrees with eval", $label);
			for i in 0..2 {
				let fd = central_fd(&e, &env, i);
				assert!((g[i] - fd).abs() < 1e-4 * fd.abs().max(1.0), "{} ∂{i}: grad {} vs central difference {fd}", $label, g[i]);
			}
			// and the symbolic derivative is a third reading of the same number
			let ast = e.lower();
			for i in 0..2 {
				let d = ast.diff(i).simplify();
				assert!((d.eval(&env) - g[i]).abs() < 1e-9, "{} ∂{i}: `diff` {} vs `grad` {}", $label, d.eval(&env), g[i]);
			}
		})+};
	}

	check! {
		"add":    |v| v.get::<0>() + v.get::<1>(),                        at [1.5, 2.5];
		"sub":    |v| v.get::<0>() - v.get::<1>(),                        at [1.5, 2.5];
		"mul":    |v| v.get::<0>() * v.get::<1>(),                        at [1.5, 2.5];
		"div":    |v| v.get::<0>() / v.get::<1>(),                        at [1.5, 2.5];
		"neg":    |v| -(v.get::<0>() * v.get::<1>()),                     at [1.5, 2.5];
		"square": |v| square(v.get::<0>() + v.get::<1>()),                at [1.5, 2.5];
		"abs":    |v| abs(v.get::<0>() - v.get::<1>()),                   at [1.5, 2.5];
		"sum":    |v| sum([v.get::<0>(), v.get::<0>()]) + v.get::<1>(),   at [1.5, 2.5];
		"sqrt":   |v| sqrt(v.get::<0>() * v.get::<1>()),                  at [1.5, 2.5];
		"exp":    |v| exp(v.get::<0>() - v.get::<1>()),                   at [1.5, 2.5];
		"powi":   |v| powi_of::<_, 3>(v.get::<0>() + v.get::<1>()),       at [1.5, 2.5];
		"powi-":  |v| powi_of::<_, -2>(v.get::<0>() + v.get::<1>()),      at [1.5, 2.5];
		"min":    |v| min(v.get::<0>(), v.get::<1>()) * constant(2.0),    at [1.5, 2.5];
		"max":    |v| max(v.get::<0>(), v.get::<1>()) * constant(2.0),    at [1.5, 2.5];
		"cmp":    |v| lt(v.get::<0>(), v.get::<1>()),                     at [1.5, 2.5];
		"cmp-gt": |v| gt(v.get::<0>(), v.get::<1>()),                     at [1.5, 2.5];
		"select": |v| select(lt(v.get::<0>(), v.get::<1>()), square(v.get::<0>()), v.get::<1>()), at [1.5, 2.5];
		"present":|v| present(v.get::<0>()) + v.get::<1>(),               at [1.5, 2.5];
		"or":     |v| or(v.get::<0>(), v.get::<1>()),                     at [1.5, 2.5];
	}
}

// r[verify outs.absence.typed]
/// A NaN that arithmetic produced — `0/0` inside a tree, which no type predicts — still reaches
/// `Cmp` and a `Select` condition, and both refuse it. `min`/`max` are not here: they are *defined*
/// over an absence, which the test below is about.
#[test]
fn nothing_compares_a_declination() {
	use trading_data_expr::{Ast, lt, select};

	// the refusals are `debug_assert` — a release build of a `Pure` node costs what the hand-written
	// arithmetic costs (`r[kernels.pure.zero-cost]`), so there is nothing to catch there.
	if !cfg!(debug_assertions) {
		return;
	}
	// `0.0 / 0.0` rather than `absent()`: a declination cannot reach a comparison at all any more
	// (`lt`/`gt`/`select`'s condition const-assert it away), so what is left to catch is the NaN the
	// reals themselves produce.
	let nan = || constant(0.0) / constant(0.0);
	let b = |a: Ast| Box::new(a);
	let quiet = std::panic::take_hook();
	std::panic::set_hook(Box::new(|_| {}));
	let refused = |label: &str, f: &(dyn Fn() -> f64 + std::panic::RefUnwindSafe)| {
		assert!(std::panic::catch_unwind(f).is_err(), "{label} compared a NaN operand instead of refusing it");
	};
	refused("cmp", &|| lt(nan(), constant(1.0)).0.eval(&[]));
	refused("select's condition", &|| select(nan(), constant(1.0), constant(2.0)).0.eval(&[]));
	refused("ast cmp", &|| Ast::Cmp(b(Ast::Const(f64::NAN)), b(Ast::Const(1.0))).eval(&[]));
	refused("ast select's condition", &|| {
		Ast::Select(b(Ast::Const(f64::NAN)), b(Ast::Const(1.0)), b(Ast::Const(2.0))).eval(&[])
	});
	std::panic::set_hook(quiet);

	// and the sanctioned decline goes through untouched, by both readings
	let declined = select(lt(constant(0.0), constant(1.0)), absent(), constant(2.0));
	assert!(declined.0.eval(&[]).is_nan(), "a `Select` branch is where a body declines");
	assert!(declined.0.lower().eval(&[]).is_nan());
}

// r[verify outs.absence.typed]
/// `min`/`max` skip an absent operand, and all three readings say the same thing about which side
/// came out — the value, the chain rule, and the symbolic derivative. This is what the type states:
/// `Min`/`Max` are absent only where *both* operands are, so a body may compare their result.
#[test]
fn min_and_max_skip_an_absence() {
	use trading_data_expr::min;

	macro_rules! skips {
		($label:literal : $e:expr,at $env:expr => $want:expr,seed_on $i:expr) => {{
			let e = $e;
			let env: [f64; 2] = $env;
			assert_eq!(e.eval(&env), $want, "{}: eval", $label);
			assert_eq!(e.lower().eval(&env), $want, "{}: the lowered reading", $label);
			let mut g = [0.0; 2];
			assert_eq!(e.grad(&env, 1.0, &mut g), $want, "{}: grad's value", $label);
			assert_eq!(g[$i], 1.0, "{}: the seed lands on the operand that came out, {g:?}", $label);
			let ast = e.lower();
			for i in 0..2 {
				assert_eq!(ast.diff(i).simplify().eval(&env), g[i], "{} ∂{i}", $label);
			}
		}};
	}

	let v = Vars;
	skips!("max, absent left":  max(v.get::<0>(), v.get::<1>()), at [f64::NAN, 2.0] => 2.0, seed_on 1);
	skips!("max, absent right": max(v.get::<0>(), v.get::<1>()), at [2.0, f64::NAN] => 2.0, seed_on 0);
	skips!("min, absent left":  min(v.get::<0>(), v.get::<1>()), at [f64::NAN, 2.0] => 2.0, seed_on 1);
	skips!("min, absent right": min(v.get::<0>(), v.get::<1>()), at [2.0, f64::NAN] => 2.0, seed_on 0);

	// and the type agrees with the values: absent only where both operands are
	assert!(!<trading_data_expr::Max<trading_data_expr::Absent, trading_data_expr::Const> as Expr>::MAYBE);
	assert!(<trading_data_expr::Max<trading_data_expr::Absent, trading_data_expr::Absent> as Expr>::MAYBE);
	assert!(max(absent(), constant(2.0)).0.eval(&[]) == 2.0);
}

// r[verify outs.absence.typed]
/// The two doors a body reasons about absence through, and the asymmetry that makes `or` a node of
/// its own: what comes back is a number exactly as often as the fallback is one, where a `Select`
/// written by hand would be absent as often as *either* branch.
#[test]
fn present_and_or_read_an_absence() {
	use trading_data_expr::or;

	assert_eq!(present(absent()).0.eval(&[]), 0.0);
	assert_eq!(present(constant(3.0)).0.eval(&[]), 1.0);
	assert_eq!(or(absent(), constant(7.0)).0.eval(&[]), 7.0);
	assert_eq!(or(constant(3.0), constant(7.0)).0.eval(&[]), 3.0);
	// the lowered reading is the same expression, so it answers the same
	assert_eq!(or(absent(), constant(7.0)).0.lower().eval(&[]), 7.0);
	assert_eq!(present(absent()).0.lower().eval(&[]), 0.0);
	// and what it hands back is comparable, which is the whole of what it is for
	assert_eq!(lt(or(absent(), constant(7.0)), constant(9.0)).0.eval(&[]), 1.0);
}

/// `min`/`max` are branches, and both readings must take the *same* branch — otherwise the exact
/// Jacobian and the documented derivative would disagree exactly where a screener sits.
#[test]
fn min_and_max_break_ties_the_same_way_in_both_readings() {
	use trading_data_expr::{max, min};

	for build in [0, 1] {
		let v = Vars;
		let (mut g, env) = ([0.0; 2], [2.0, 2.0]);
		let ast = match build {
			0 => {
				let e = min(v.get::<0>(), v.get::<1>());
				e.grad(&env, 1.0, &mut g);
				e.lower()
			}
			_ => {
				let e = max(v.get::<0>(), v.get::<1>());
				e.grad(&env, 1.0, &mut g);
				e.lower()
			}
		};
		// the tie goes right, so the whole seed lands on x1 and none on x0
		assert_eq!(g, [0.0, 1.0], "build {build}");
		for i in 0..2 {
			assert_eq!(ast.diff(i).simplify().eval(&env), g[i], "build {build} ∂{i}");
		}
	}
}

/// **Phase 5 — the algebra against a finite difference, over random trees.** `kernels.jac` makes
/// exactness normative, and the two readings that must agree are computed by completely different
/// code: [`Expr::grad`] accumulates partials by the chain rule down the typed tree, [`Ast::diff`]
/// rewrites the lowered tree symbolically. `eval` differenced numerically is the third opinion, and
/// the one neither of them can have talked itself into.
///
/// The typed tree is nested marker structs, so its *shape* is fixed at compile time and no runtime
/// generator can vary it. `Ast` is a plain enum, so this fuzzes shapes there and keeps the typed
/// path pinned by the fixed kernel above — which is the split the type-level algebra forces.
mod fuzz {
	use trading_data_expr::Ast;

	/// Deterministic, ten lines, no dependency. The crate is `#![no_std]` and zero-dep on purpose;
	/// a fuzz loop is not a reason to put `rand` in its dev-tree.
	struct Lcg(u64);
	impl Lcg {
		fn next(&mut self) -> u64 {
			self.0 = self.0.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
			self.0 >> 33
		}

		fn below(&mut self, n: u64) -> u64 {
			self.next() % n
		}

		fn span(&mut self, lo: f64, hi: f64) -> f64 {
			lo + (hi - lo) * (self.next() % 4096) as f64 / 4095.0
		}
	}

	const VARS: usize = 3;

	/// A random tree, bounded in depth. Every node kind is in the draw, kinks included: a kink is not
	/// avoided, it is *detected* below, because avoiding it would be avoiding `Min`/`Max`/`Select`
	/// altogether and those are exactly where a tie-break has to resolve the same way in the value and
	/// in the derivative.
	///
	/// What *is* avoided is leaving the algebra's domain: `Sqrt` takes an `Abs`, `Div` a denominator
	/// that cannot be zero, `Powi` a non-negative exponent, and `Exp` an argument bounded above. NaN
	/// is a declination and `Min`/`Max` refuse one in debug, so a generator that produced NaN would be
	/// testing the assert rather than the algebra. This is deterministic at a fixed seed, so passing
	/// once is passing.
	fn tree(r: &mut Lcg, depth: u32) -> Ast {
		let leaf = |r: &mut Lcg| match r.below(3) {
			0 => Ast::Const(r.span(-3.0, 3.0)),
			_ => Ast::Var(r.below(VARS as u64) as usize),
		};
		if depth == 0 {
			return leaf(r);
		}
		fn sub(r: &mut Lcg, depth: u32) -> Box<Ast> {
			Box::new(tree(r, depth - 1))
		}
		match r.below(17) {
			0 => Ast::Add(sub(r, depth), sub(r, depth)),
			1 => Ast::Sub(sub(r, depth), sub(r, depth)),
			2 => Ast::Mul(sub(r, depth), sub(r, depth)),
			3 => Ast::Div(sub(r, depth), Box::new(Ast::Add(Box::new(Ast::Abs(sub(r, depth))), Box::new(Ast::Const(1.0))))),
			4 => Ast::Neg(sub(r, depth)),
			5 => Ast::Square(sub(r, depth)),
			6 => Ast::Abs(sub(r, depth)),
			7 => Ast::Sqrt(Box::new(Ast::Abs(sub(r, depth)))),
			// `exp` of an unbounded subtree overflows to infinity, and two infinities meeting is a NaN
			8 => Ast::Exp(Box::new(Ast::Min(sub(r, depth), Box::new(Ast::Const(4.0))))),
			9 => Ast::Powi(sub(r, depth), r.below(4) as i32),
			10 => Ast::Min(sub(r, depth), sub(r, depth)),
			11 => Ast::Max(sub(r, depth), sub(r, depth)),
			12 => Ast::Cmp(sub(r, depth), sub(r, depth)),
			13 => Ast::Select(sub(r, depth), sub(r, depth), sub(r, depth)),
			14 => Ast::Sum((0..2 + r.below(2)).map(|_| tree(r, depth - 1)).collect()),
			15 => Ast::IsNan(sub(r, depth)),
			_ => leaf(r),
		}
	}

	/// Whether every *subexpression* is finite here, not merely the root — an infinity swallowed by a
	/// `Min` still poisons the difference taken around it, and the root would never say so.
	fn finite_everywhere(e: &Ast, env: &[f64]) -> bool {
		if !e.eval(env).is_finite() {
			return false;
		}
		let kids: Vec<&Ast> = match e {
			Ast::Const(_) | Ast::Var(_) => vec![],
			Ast::Neg(a) | Ast::Square(a) | Ast::Abs(a) | Ast::Sqrt(a) | Ast::Exp(a) | Ast::Powi(a, _) | Ast::IsNan(a) => vec![&**a],
			Ast::Add(a, b) | Ast::Sub(a, b) | Ast::Mul(a, b) | Ast::Div(a, b) | Ast::Min(a, b) | Ast::Max(a, b) | Ast::Cmp(a, b) => vec![&**a, &**b],
			Ast::Select(a, b, c) => vec![&**a, &**b, &**c],
			Ast::Sum(xs) => xs.iter().collect(),
		};
		kids.into_iter().all(|k| finite_everywhere(k, env))
	}

	/// The central difference at `h` and at `2h`, Richardson-extrapolated — and `None` where the two
	/// disagree, which is the whole conditioning test.
	///
	/// This is what keeps the tolerance from being a tuning exercise. A point near a kink, a division
	/// by something near zero, or an `Exp` on its way to infinity all show up as the two step sizes
	/// disagreeing, and a point the *difference* cannot resolve is no evidence about the derivative.
	/// A well-conditioned point, meanwhile, is resolved to far better than the tolerance below.
	fn difference(e: &Ast, env: &[f64], i: usize) -> Option<f64> {
		let at = |h: f64| {
			let (mut p, mut m) = (env.to_vec(), env.to_vec());
			p[i] += h;
			m[i] -= h;
			let (a, b) = (e.eval(&p), e.eval(&m));
			(a.is_finite() && b.is_finite() && a.abs() < 1e9 && b.abs() < 1e9).then(|| (a - b) / (2.0 * h))
		};
		let h = 1e-5;
		let (fine, coarse) = (at(h)?, at(2.0 * h)?);
		((fine - coarse).abs() <= 1e-4 * (1.0 + fine.abs())).then(|| (4.0 * fine - coarse) / 3.0)
	}

	// r[verify kernels.jac.two-quantities]
	/// Every reading of one expression agrees: the symbolic derivative, the simplified symbolic
	/// derivative, and the numeric difference.
	#[test]
	fn the_symbolic_derivative_is_the_numeric_one() {
		let mut r = Lcg(0x9e37_79b9_7f4a_7c15);
		let (mut checked, mut skipped, mut recovered) = (0u32, 0u32, 0u32);
		for _ in 0..2_000 {
			let depth = 1 + r.below(4) as u32;
			let e = tree(&mut r, depth);
			// positive and away from 0, so `Sqrt` and `Div` have a fighting chance; the conditioning
			// test above is what handles the points where they do not.
			let env: Vec<f64> = (0..VARS).map(|_| r.span(0.4, 2.6)).collect();
			if !finite_everywhere(&e, &env) {
				continue;
			}
			for i in 0..VARS {
				let d = e.diff(i);
				let (raw, exact) = (d.eval(&env), d.simplify().eval(&env));
				// Simplification is a rewrite of the same expression, so where both readings are
				// numbers they are the same number. Where the raw one is *not* a number and the
				// simplified one is, simplify has removed an indeterminacy the chain rule wrote down
				// and cannot cancel by evaluating — `∂sqrt(u) = u'/(2·sqrt(u))` is `0/0` where `u` is a
				// flat `Cmp` reading zero, and the composite's derivative is the `0` the fold finds.
				// That is why the crate's own tests evaluate `diff(i).simplify()` and not `diff(i)`,
				// and it is the contract this checks against rather than one it argues with.
				if raw.is_finite() {
					assert!((raw - exact).abs() <= 1e-9 * (1.0 + raw.abs()), "simplify moved ∂{i} of {e} from {raw} to {exact} at {env:?}");
				} else {
					recovered += 1;
				}
				let Some(fd) = difference(&e, &env, i) else {
					skipped += 1;
					continue;
				};
				if !exact.is_finite() {
					skipped += 1;
					continue;
				}
				checked += 1;
				assert!(
					(exact - fd).abs() <= 1e-4 * (1.0 + exact.abs().max(fd.abs())),
					"∂{i} of {e} at {env:?}: algebra says {exact}, the difference says {fd}"
				);
			}
		}
		// Loud, because a conditioning test that rejected everything would report green.
		eprintln!("expr fuzz: {checked} derivatives checked, {skipped} points too ill-conditioned to be evidence, {recovered} indeterminacies simplify removed");
		assert!(checked > 2_000, "only {checked} of {} points were well-conditioned enough to check", checked + skipped);
	}
}