Numerical Invariant Property Test Harness Generator
Generate property-based automated testing scripts to validate numerical algorithms against precision drift, overflow, and mathematical invariants.
Use this template when validating scientific computing routines, numerical simulations, or linear algebra implementations. It generates executable property-based test suites that stress floating-point edge cases and mathematical identities.
Role: Principal Scientific Computing Quality Engineer specializing in numerical stability and formal invariant testing.
Context
- Target Algorithm Implementation: {{target_algorithm_code}}
- Core Mathematical Invariants: {{mathematical_properties}}
- Absolute and Relative Tolerances: {{precision_tolerance_threshold}}
- Input Domain and Boundary Conditions: {{input_domain_bounds}}
- Property Test Framework: {{target_test_framework}}
- Extreme Distribution Shapes: {{edge_case_distributions}}
Task
Synthesize a complete, executable property-based testing script that mathematically verifies {{target_algorithm_code}} across degenerate, edge, and randomized high-entropy input distributions using {{target_test_framework}}.
Method
- Analyze {{target_algorithm_code}} to identify arithmetic operations susceptible to catastrophic cancellation, floating-point underflow, overflow, and subnormal representation.
- Translate {{mathematical_properties}} into strict algebraic invariants (e.g., idempotence, commutativity, symmetry, triangular inequality, conservation laws).
- Formulate custom input strategy generators parameterized by {{input_domain_bounds}} and {{edge_case_distributions}} targeting branch boundaries, infinities, signed zeros, and NaN boundaries.
- Design parameterized test assertions enforcing dual relative (
rtol) and absolute (atol) tolerances specified in {{precision_tolerance_threshold}}. - Implement invariant metamorphic test functions comparing baseline algorithmic steps with mathematically equivalent perturbed formulations.
- Incorporate automated shrinking heuristics and failure triage reporting to isolate minimal counterexamples for ill-conditioned inputs.
- Add benchmark performance harnesses measuring floating-point operation overhead and timing variance across test runs.
Constraints
- MUST write 100% executable test scripts compatible with {{target_test_framework}} without unreferenced pseudocode.
- MUST explicitly assert mathematical invariants rather than simple regression snapshot comparisons.
- MUST NOT suppress floating-point runtime warnings (e.g., ZeroDivisionError, RuntimeWarning, invalid value) without explicit exception assertions.
- Include explicit type annotations and docstrings defining mathematical theorem justifications for every test case.
Output format
Provide the complete test script structured in the following sequential order:
- Dependency Imports and Mathematical Constants Setup
- Custom Input Strategies and Distribution Generators
- Invariant Property Test Suite (minimum 5 distinct property tests)
- Metamorphic and Perturbation Stability Test Suite
- Test Execution Entrypoint with Detailed Error Diagnostics
Self-review
- Verify that all mathematical invariants from {{mathematical_properties}} have dedicated, executable test functions.
- Ensure tolerance comparisons strictly utilize {{precision_tolerance_threshold}} without hardcoded magic floats.
- Confirm input generators cover all specified boundary edges from {{input_domain_bounds}} and {{edge_case_distributions}}.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.