type Iter = Int where 0 <= it and it <= 10000
Paths
The entry module declares no path.
module mandelbrot
type Coord = Int where 0 <= it
record Viewport {
x_min: Float
x_max: Float where it > x_min
y_min: Float
y_max: Float where it > y_min
}pub fn escape_count(cx: Float, cy: Float, limit: Iter) -> Iter
requires limit > 0ensures result <= limitinvariant i <= limitdecreases limit - iexample escape_count: passed
{ ... } expand body (counted)
pub fn escape_count(cx: Float, cy: Float, limit: Iter) -> Iter
requires limit > 0
ensures result <= limit
{
var zx: Float = 0.0
var zy: Float = 0.0
var i: Iter = 0
loop while i < limit and zx * zx + zy * zy <= 4.0
invariant i <= limit
decreases limit - i
{
let nx: Float = zx * zx - zy * zy + cx
zy = 2.0 * zx * zy + cy
zx = nx
i = i + 1
}
return i
}property escape_bounded(cx: Float, cy: Float, limit: Iter where it > 0) {
escape_count(cx: cx, cy: cy, limit: limit) <= limit
}property escape_bounded: checked
pub fn render( view: Viewport, width: Coord where it > 0, height: Coord where it > 0, limit: Iter where it > 0 ) -> Grid[Iter, width, height] may alloc
{ ... } expand body (counted)
pub fn render(
view: Viewport,
width: Coord where it > 0,
height: Coord where it > 0,
limit: Iter where it > 0
) -> Grid[Iter, width, height] may alloc {
var grid: Grid[Iter, width, height] = Grid.filled(value: 0, width: width, height: height)
for py: Int in 0 ..< height {
for px: Int in 0 ..< width {
let cx: Float = view.x_min + (view.x_max - view.x_min) * Float.of(x: px) / Float.of(x: width)
let cy: Float = view.y_min + (view.y_max - view.y_min) * Float.of(x: py) / Float.of(x: height)
Grid.set(grid: inout grid, x: px, y: py, value: escape_count(cx: cx, cy: cy, limit: limit))
}
}
return grid
}pub fn main(args: List[Text], files: io.Files) -> Result[Unit, io.Error] may io.file, alloc
{ ... } expand body (counted)
pub fn main(args: List[Text], files: io.Files) -> Result[Unit, io.Error] may io.file, alloc {
-- files is a root capability supplied by the runtime (§8.3)
let view: Viewport = Viewport { x_min: -2.5, x_max: 1.0, y_min: -1.0, y_max: 1.0 }
let grid: Grid[Iter, 800, 600] = render(view: view, width: 800, height: 600, limit: 255)
let out: io.File = try io.create(files: files, path: "mandelbrot.pgm")
try io.write(file: out, text: "P2\n800 600\n255\n")
for py: Int in 0 ..< 600 {
for px: Int in 0 ..< 800 {
try io.write(file: out, text: Int.to_text(x: Grid.get(grid: grid, x: px, y: py)) ++ " ")
}
try io.write(file: out, text: "\n")
}
return Ok(value: Unit)
}Ledger
| status | kind | obligation | in | at | by |
|---|---|---|---|---|---|
| proved | refinement | 0 <= it and it <= 10000 | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:21:17 | z3 |
| proved | invariant-entry | i <= limit | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:22:3 | z3 |
| proved | invariant-step | i <= limit | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:22:3 | z3 |
| proved | decreases | limit - i | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:22:3 | z3 |
| proved | overflow | limit - i within Int | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:24:15 | z3 |
| proved | refinement | 0 <= it and it <= 10000 | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:29:9 | z3 |
| proved | overflow | i + 1 within Int | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:29:9 | z3 |
| proved | ensures | result <= limit | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:31:3 | z3 |
| proved | requires | limit > 0 | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:35:3 | z3 |
| proved | refinement | 0 <= it and it <= 10000 | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:35:41 | z3 |
| proved | requires | limit > 0 | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:36:3 | z3 |
| proved | refinement | 0 <= it and it <= 10000 | mandelbrot.escape_count | examples/mandelbrot/mandelbrot.onus:36:41 | z3 |
| checked | property | escape_bounded | mandelbrot.escape_bounded | examples/mandelbrot/mandelbrot.onus:39:1 | milestone 5: run under generated inputs |
| proved | requires | limit > 0 | mandelbrot.escape_bounded | examples/mandelbrot/mandelbrot.onus:40:3 | z3 |
| proved | refinement | 0 <= it and it <= 10000 | mandelbrot.escape_bounded | examples/mandelbrot/mandelbrot.onus:40:39 | z3 |
| proved | refinement | 0 <= it and it <= 10000 | mandelbrot.render | examples/mandelbrot/mandelbrot.onus:49:60 | z3 |
| proved | refinement | it > 0 | mandelbrot.render | examples/mandelbrot/mandelbrot.onus:49:70 | z3 |
| proved | refinement | it > 0 | mandelbrot.render | examples/mandelbrot/mandelbrot.onus:49:85 | z3 |
| proved | refinement | 0 <= it and it < w | mandelbrot.render | examples/mandelbrot/mandelbrot.onus:54:37 | z3 |
| proved | refinement | 0 <= it and it < h | mandelbrot.render | examples/mandelbrot/mandelbrot.onus:54:44 | z3 |
| proved | requires | limit > 0 | mandelbrot.render | examples/mandelbrot/mandelbrot.onus:54:55 | z3 |
| proved | refinement | 0 <= it and it <= 10000 | mandelbrot.render | examples/mandelbrot/mandelbrot.onus:54:91 | z3 |
| proved | refinement | it > x_min | mandelbrot.main | examples/mandelbrot/mandelbrot.onus:62:55 | constant evaluation |
| proved | refinement | it > y_min | mandelbrot.main | examples/mandelbrot/mandelbrot.onus:62:80 | constant evaluation |
| proved | refinement | it > 0 and 0 <= it | mandelbrot.main | examples/mandelbrot/mandelbrot.onus:63:62 | z3 |
| proved | refinement | it > 0 and 0 <= it | mandelbrot.main | examples/mandelbrot/mandelbrot.onus:63:75 | z3 |
| proved | refinement | it > 0 and 0 <= it and it <= 10000 | mandelbrot.main | examples/mandelbrot/mandelbrot.onus:63:87 | z3 |
| proved | refinement | 0 <= it and it < w | mandelbrot.main | examples/mandelbrot/mandelbrot.onus:68:76 | z3 |
| proved | refinement | 0 <= it and it < h | mandelbrot.main | examples/mandelbrot/mandelbrot.onus:68:83 | z3 |
Assumptions (0)
None.
Recover sites (0)
None.
Capability construction sites (0)
None on any path.
Diff
No previous interface was given (onus review --against <interface.json>).
Diagnostics
None.