Skip to content
Novus Examples
csv727 B

Catastrophic Cancellation — Naive versus Stable Formulas (.csv)

Five computations done twice, once with the obvious formula and once with the numerically stable one, with the relative error of the naive version alongside. The one-pass variance row is the memorable one: five values a millisecond apart near 1e8 can produce a negative variance.

Preview — first 7 linescsv
case,a,b,naive_result,stable_result,relative_error_of_naive,technique
1e+16 - 9999999999999998.0,1e+16,9999999999999998.0,2.0,2.0,0,direct subtraction of near-equal values
1.0 - 0.999999999999,1.0,0.999999999999,9.999778782798785e-13,9.999778782798785e-13,0,direct subtraction of near-equal values
100000000.0 - 99999999.9999,100000000.0,99999999.9999,0.00010000169277191162,0.00010000169277191162,0,direct subtraction of near-equal values
"quadratic small root, b=1e8",100000000.0,1.0,-7.450580596923828e-09,-1e-08,2.549e-01,use 2c / (-b - sqrt(disc)) instead of (-b + sqrt(disc)) / 2a
variance of 5 values near 1e8,100000000.001,100000000.005,2.0,1.9999902249434596e-06,1.000e+06,two-pass variance instead of E[x^2] - E[x]^2

Specifications

Rows
5
Columns
7
Cases
near-equal subtraction, quadratic small root, one-pass variance
Worst Relative Error
the one-pass variance row
Naive Variance Result
2.0
Stable Variance Result
1.9999902249434596e-06

Testing contract

Reference control
Scenario
Implement both the naive and the stable formula for each row and compare your two results with the columns here.
Expected result
Your stable results match stable_result to full double precision while the naive quadratic root and one-pass variance rows show relative errors of order 1e-1 or worse.

What is a .csv file?

CSV (Comma-Separated Values) is a plain-text tabular format where rows are lines and fields are separated by commas, with quoting rules for values that contain delimiters, quotes, or newlines. It has no formal type system and depends on encoding and dialect conventions. It is the most portable format for tabular data exchange.

How to use this file

Use an example CSV to test parsers against quoting and embedded-delimiter edge cases, header handling, encoding detection, and import pipelines into databases or spreadsheets.

How to use this file for testing

“Catastrophic Cancellation — Naive versus Stable Formulas (.csv)” is a deterministic Novus Examples fixture for Scientific data, CSV parsing, Editor testing. Citation catalogs (BibTeX, RIS), chemistry structures (MDL Molfile, PDB), and gridded binary data (NetCDF, FITS) — for testing reference managers, molecule viewers, and scientific-data loaders.

Documented properties for this file: 5 rows · 7 columns. Compare results against paired or grouped companions on this page when present (clean↔damaged, searchable↔scanned, or format twins) so scores stay reproducible across runs.

Download the file once, keep the path stable in CI or local scripts, and treat the spec table as the contract: dimensions, seeds, field lists, and roles are intentional. Corrupt or invalid samples are labelled as such — expect parsers to fail loudly rather than silently accept them.

Scientific fixtures are small, valid, and fully synthetic — no real organism, patient, sample, or observation. Point your parser or loader at the file and check it reads the documented records, variables, or headers; binary formats ship a readable twin or metadata listing for comparison.

Code examples

import pandas as pd

df = pd.read_csv("catastrophic-cancellation.csv")
print(df.head())
print(df.dtypes)

Generated by generation/scientific.py. Free for any use, no attribution required — license.