|
| 1 | +/- |
| 2 | +Copyright (c) 2026 Lean FRO, LLC. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Kim Morrison |
| 5 | +-/ |
| 6 | + |
| 7 | +module |
| 8 | + |
| 9 | +public import HexIntervalMathlib.Experiment.DyadicInterval |
| 10 | + |
| 11 | +@[expose] public section |
| 12 | + |
| 13 | +/-! |
| 14 | +# Proof objects for conservative raster graphs |
| 15 | +
|
| 16 | +This module states what a verified rasterizer must prove. It does not know |
| 17 | +which functions the interval engine supports, how search chooses subdivisions, |
| 18 | +or how a bitmap is encoded. A function package supplies interval theorems; a |
| 19 | +raster assembly proves that every graph point over the horizontal viewport is |
| 20 | +inside a marked pixel and that every blank pixel is disjoint from the graph. |
| 21 | +
|
| 22 | +Marked pixels are deliberately allowed to be conservative: `Correct` does not |
| 23 | +claim that every marked pixel is hit. A PNG or other image is an untrusted |
| 24 | +rendering of the finite `Raster.cells` mask, not part of the proof boundary. |
| 25 | +-/ |
| 26 | + |
| 27 | +namespace Hex.Interval.Experiment.VerifiedRaster |
| 28 | + |
| 29 | +open DyadicInterval |
| 30 | + |
| 31 | +/-- One rectangular pixel, with exact open or closed boundaries inherited |
| 32 | +from its dyadic interval facts. -/ |
| 33 | +structure Pixel where |
| 34 | + x : Fact |
| 35 | + y : Fact |
| 36 | + marked : Bool |
| 37 | + deriving DecidableEq |
| 38 | + |
| 39 | +/-- Exact membership in one pixel rectangle. -/ |
| 40 | +def Pixel.Contains (pixel : Pixel) (x y : ℝ) : Prop := |
| 41 | + pixel.x.Contains x ∧ pixel.y.Contains y |
| 42 | + |
| 43 | +/-- A finite row-major mask and its exact mathematical viewport. `shape` |
| 44 | +binds the flat mask to its declared dimensions; rendering may choose any |
| 45 | +external image format which preserves this order and the `marked` bits. -/ |
| 46 | +structure Raster where |
| 47 | + width : Nat |
| 48 | + height : Nat |
| 49 | + xViewport : Fact |
| 50 | + yViewport : Fact |
| 51 | + cells : List Pixel |
| 52 | + shape : cells.length = width * height |
| 53 | + |
| 54 | +/-- Every graph point over the horizontal viewport is enclosed by at least one |
| 55 | +marked pixel. This stronger form also proves that the graph stays inside the |
| 56 | +vertical viewport whenever all listed pixels do. -/ |
| 57 | +def Covers (raster : Raster) (f : ℝ → ℝ) : Prop := |
| 58 | + ∀ x, raster.xViewport.Contains x → |
| 59 | + ∃ pixel, pixel ∈ raster.cells ∧ pixel.marked = true ∧ |
| 60 | + pixel.Contains x (f x) |
| 61 | + |
| 62 | +/-- Every pixel rendered blank is disjoint from the graph. The horizontal |
| 63 | +premise is local to the pixel, so this property remains useful even when a |
| 64 | +raster covers only part of a larger function domain. -/ |
| 65 | +def Excludes (raster : Raster) (f : ℝ → ℝ) : Prop := |
| 66 | + ∀ pixel, pixel ∈ raster.cells → pixel.marked = false → |
| 67 | + ∀ x, pixel.x.Contains x → ¬pixel.y.Contains (f x) |
| 68 | + |
| 69 | +/-- Every rendered cell lies within the declared viewport. This prevents the |
| 70 | +finite mask from proving a graph enclosure over one rectangle while labelling |
| 71 | +it as an unrelated viewport. -/ |
| 72 | +def Contained (raster : Raster) : Prop := |
| 73 | + ∀ pixel, pixel ∈ raster.cells → ∀ x y, pixel.Contains x y → |
| 74 | + raster.xViewport.Contains x ∧ raster.yViewport.Contains y |
| 75 | + |
| 76 | +/-- Sound conservative graph rendering. It intentionally omits the stronger |
| 77 | +and usually false assertion that every marked pixel contains a graph point. -/ |
| 78 | +structure Correct (raster : Raster) (f : ℝ → ℝ) : Prop where |
| 79 | + contained : Contained raster |
| 80 | + covers : Covers raster f |
| 81 | + excludes : Excludes raster f |
| 82 | + |
| 83 | +end Hex.Interval.Experiment.VerifiedRaster |
0 commit comments