From 5427cd7b2d8d4af85a8a85d1845bac3434fc1b7e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 6 Nov 2026 22:17:39 -0800 Subject: [PATCH] linesweeper: the ratio lemma assumes a finite, nonzero denominator The accuracy lemma for (y - y0) / (y1 - y0) said that y0 <= y <= y1 rules out overflow. It does not: with y0 = -1e308, y = 0 and y1 = 1e308, y1 - y0 rounds to infinity and the computed ratio is 0 instead of 1/2. The lemma now assumes y0 < y1 and a finite fl(y1 - y0), and its proof bounds fl(y1 - y0) where it wrote fl(y + y0). The x-coordinate accuracy lemma that uses it takes M as a floating-point number and shows both assumptions hold for a segment that is not horizontal. README.craft.md and SOURCE.json record the change. --- vendor/linesweeper/README.craft.md | 22 +++++++++++++++------- vendor/linesweeper/SOURCE.json | 6 ++++-- vendor/linesweeper/docs/sweep.typ | 17 ++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index f683ca53de..c84d359499 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -1,15 +1,23 @@ # Local linesweeper 0.5.0 copy -This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and no -file changed. `.cargo_vcs_info.json` names the commit it was packaged from, +This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and the +changes listed under Local changes. `.cargo_vcs_info.json` names the commit it was packaged from, `824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest names, which is archived; its README says development moved off GitHub. -Every file here except this one and `SOURCE.json` is byte for byte the file in the `.crate` archive. -`SOURCE.json` records the hash of the `.crate` download (`source_archive_sha256`) and, for every file -kept, the hash in the package (`source_sha256`) and the hash here (`sha256`). `upstream_repository` is -null because no public repository this copy can name holds `upstream_revision`. `local_patches` is -empty. +Every file here except this one, `SOURCE.json` and the files under Local changes is byte for byte the +file in the `.crate` archive. `SOURCE.json` records the hash of the `.crate` download +(`source_archive_sha256`) and, for every file kept, the hash in the package (`source_sha256`) and the +hash here (`sha256`). `upstream_repository` is null because no public repository this copy can name +holds `upstream_revision`. `local_patches` describes each local change. + +## Local changes + +| Change | Code comment label | Touches | Tests | +|---|---|---|---| +| The floating-point ratio lemma assumes `fl(y_1 - y_0)` is finite and `y_0 < y_1`, and its proof bounds `fl(y_1 - y_0)` instead of `fl(y + y_0)`; the x-coordinate accuracy lemma takes `M` as a floating-point number and shows both assumptions hold | `Craft patch (ratio lemma)` | `docs/sweep.typ` | None (documentation only) | + +Every change here updates this table and `SOURCE.json` in the same commit. `omitted_files` lists the 43 files of the package left out here, with their hashes: diff --git a/vendor/linesweeper/SOURCE.json b/vendor/linesweeper/SOURCE.json index 9c71e51add..a2b68d4ac7 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -7,7 +7,9 @@ "upstream_repository": null, "upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e", "upstream_directory": "", - "local_patches": [], + "local_patches": [ + "In `docs/sweep.typ`, the floating-point ratio lemma assumes `y_0 < y_1` and a finite `fl(y_1 - y_0)`, and its proof bounds `fl(y_1 - y_0)` where it wrote `fl(y + y_0)`. The ordering alone does not rule out overflow: with `y_0 = -1e308`, `y = 0` and `y_1 = 1e308` the computed ratio is 0. The x-coordinate accuracy lemma that uses it takes `M` as a floating-point number, and its proof shows both assumptions hold for a segment that is not horizontal." + ], "files": [ { "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" }, { "path": ".gitignore", "source_sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0", "source_git_blob": null, "sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0" }, @@ -21,7 +23,7 @@ { "path": "benches/linebender_logo.rs", "source_sha256": "d10867f43439d37f0e1da5d30eaed9ab3bfbe655ed47212f65dc20ab4db65cb3", "source_git_blob": null, "sha256": "d10867f43439d37f0e1da5d30eaed9ab3bfbe655ed47212f65dc20ab4db65cb3" }, { "path": "benches/painted_dreams.rs", "source_sha256": "073008db93840d380710e13ed3ae38e08cb823f10c12e5f838dac1ccf37eaecf", "source_git_blob": null, "sha256": "073008db93840d380710e13ed3ae38e08cb823f10c12e5f838dac1ccf37eaecf" }, { "path": "benches/synthetic.rs", "source_sha256": "7ce59bef2e1c4f28b00cb89feb15bc71ca4b098a8d27e7b02ea699aca9bcc810", "source_git_blob": null, "sha256": "7ce59bef2e1c4f28b00cb89feb15bc71ca4b098a8d27e7b02ea699aca9bcc810" }, - { "path": "docs/sweep.typ", "source_sha256": "4766082c8672a7bb4356b5581043489c13b4e3fb8931ba3a5f0a473fab0172f3", "source_git_blob": null, "sha256": "4766082c8672a7bb4356b5581043489c13b4e3fb8931ba3a5f0a473fab0172f3" }, + { "path": "docs/sweep.typ", "source_sha256": "4766082c8672a7bb4356b5581043489c13b4e3fb8931ba3a5f0a473fab0172f3", "source_git_blob": null, "sha256": "dac8d5c5d0d97d796824578a29ebbf5b23f79fba76a91f3dd8e6110db4e55821" }, { "path": "examples/boolean_op.rs", "source_sha256": "3b38a1ccda7e736cce4b191a3a45ab4824c4c365190e3eb637b2fb39b5996c9f", "source_git_blob": null, "sha256": "3b38a1ccda7e736cce4b191a3a45ab4824c4c365190e3eb637b2fb39b5996c9f" }, { "path": "examples/bus.rs", "source_sha256": "e206a08be73899f564188052c8ecc15526b54606e52ee2935a64ce6b5723da33", "source_git_blob": null, "sha256": "e206a08be73899f564188052c8ecc15526b54606e52ee2935a64ce6b5723da33" }, { "path": "examples/curve_metrics.rs", "source_sha256": "0db6a5327fd2119a03a9a66624fea3e04b6bbb519655667ad30487aee6c787d2", "source_git_blob": null, "sha256": "0db6a5327fd2119a03a9a66624fea3e04b6bbb519655667ad30487aee6c787d2" }, diff --git a/vendor/linesweeper/docs/sweep.typ b/vendor/linesweeper/docs/sweep.typ index 0f83ac1c6e..08897277b1 100644 --- a/vendor/linesweeper/docs/sweep.typ +++ b/vendor/linesweeper/docs/sweep.typ @@ -640,18 +640,23 @@ Now, if the result of floating point addition or subtraction is subnormal then i for any floating-point $x$ and $y$, if $x - y$ and $x + y$ don't overflow then after rounding they have relative error at most $epsilon_0$. +// Craft patch (ratio lemma): the finite, nonzero denominator assumption and fl(y_1 - y_0) in the proof. #lemma[ - If $y_0 <= y <= y_1$ are floating-point numbers and $epsilon_0 <= 1/2$ then computing $(y - y_0) / (y_1 - y_0)$ + If $y_0 <= y <= y_1$ are floating-point numbers with $y_0 < y_1$, $fl(y_1 - y_0)$ is finite + and $epsilon_0 <= 1/2$ then computing $(y - y_0) / (y_1 - y_0)$ the naive way gives an absolute error of at most $3 epsilon_0 + 4 epsilon_0^2$. ] #proof[ -The assumption $y_0 <= y <= y_1$ ensures that $y - y_0$ and $y_1 - y_0$ do not overflow. Therefore +The assumption that $fl(y_1 - y_0)$ is finite ensures that $y_1 - y_0$ does not overflow, and since +$0 <= y - y_0 <= y_1 - y_0$, neither does $y - y_0$. (The ordering $y_0 <= y <= y_1$ alone is not +enough: with $y_0 = -10^308$, $y = 0$ and $y_1 = 10^308$, $fl(y_1 - y_0)$ is infinite and the computed +ratio is $0$ instead of $1/2$.) Therefore $ fl(y - y_0) &= (y - y_0) (1 plus.minus epsilon_0) \ -fl(y + y_0) &= (y + y_0) (1 plus.minus epsilon_0) +fl(y_1 - y_0) &= (y_1 - y_0) (1 plus.minus epsilon_0) $ and so $ @@ -794,8 +799,9 @@ the maximum of these inverse-slopes. ] Putting all this together (and handling the "chamfers" yet): +// Craft patch (ratio lemma): M is a floating-point number, and the proof shows the ratio lemma's assumptions hold. #lemma[ -Assume all line segments are inside the square $[-M/2, M/2]^2$, +Assume $M$ is a floating-point number, all line segments are inside the square $[-M/2, M/2]^2$, and take $delta = 64 epsilon_0 M$. If $epsilon_0 <= 1/4$ then - We can compute $x$ coordinates of line segments to additive accuracy $delta/8$. @@ -808,7 +814,8 @@ and take $delta = 64 epsilon_0 M$. If $epsilon_0 <= 1/4$ then #proof[ We compute $x$ coordinates by first computing $t = (y - y_0) / (y_1 - y_0)$ (with error at most $3 epsilon_0 + 4 epsilon_0^2$ by -@lem-ratio-error). Then we apply @lem-convex-combination-error with $epsilon = 3 epsilon_0 + 4 epsilon_0^2$ to see that we +@lem-ratio-error, which applies because a segment that is not horizontal has $y_0 < y_1$, and $fl(y_1 - y_0)$ +is finite because $0 < y_1 - y_0 <= M$ and $M$ is a floating-point number). Then we apply @lem-convex-combination-error with $epsilon = 3 epsilon_0 + 4 epsilon_0^2$ to see that we can compute the horizontal coordinate with error at most $(6 epsilon_0 + 4 epsilon_0^2)M$. If $epsilon_0 <= 1/4$ as we assumed, this is at most $7 epsilon_0 M <= delta/8$. This proves the first claim.