# Verification against hand-drawn graphs

rille v0 was accepted against two decision graphs of floating that were
drawn by hand before rille existed: the interval product and the binary
integer power. The hand graphs share no code with rille, so they are an
independent oracle for the order and the lines of the tests rille finds.
This page records the comparison and classifies every difference.

## Method

- Source: floating at commit `f403bd66`, the commit both hand graphs read,
  taken read-only with `git archive` (floating's `main` has since moved
  lines). Module root: the archive's `library` directory.
- rille: `main` at `a910661`, native release build.
- Hand graphs: `interval-mul.md` section 1.2 and `binary-pown.md` section
  1.2, in floating's plan directory (`.tmp/plan-0.12/route-review/graph/`).
- Commands, with `R` the rille executable and `M` the module root:

```bash
$R graph --module $M --package interval --entry multiplication_bounds --depth 0 --format tests
$R graph --module $M --package interval --entry mul_interval_impl --depth 2 --format tests
$R graph --module $M --package binary --entry Binary::pown_ctx --depth 0 --format tests
$R graph --module $M --package binary --entry Binary::pown_ctx --depth 2 --format tests
$R graph --module $M --package binary --entry Binary::pow_nat_ctx --depth 2 --format tests
```

Each difference is classified as one of:

| Class | Meaning |
| --- | --- |
| rille wrong | rille misses a test, adds one that is not there, or gets the order or line wrong |
| hand graph wrong | the hand graph names a line or a test that the source does not have |
| granularity | both are right and describe the same flow at different grain: the hand graph merges, splits or leaves out a step on purpose |

## Interval product

### `multiplication_bounds`, depth 0

| Hand (section 1.2) | Hand line | rille | rille line | Class |
| --- | --- | --- | --- | --- |
| T1 all four bounds finite | 757 | T1 `if a.is_common_interval() && b.is_common_interval()` | 757 | same |
| T2 `nn(a) and nn(b)` | 762 | T2 `if a_nonnegative && b_nonnegative` | 762 | same |
| T3 `np(a) and np(b)` | 778 | T3 | 778 | same |
| T4 `nn(a) and np(b)` | 794 | T4 | 794 | same |
| T5 `np(a) and nn(b)` | 810 | T5 | 810 | same |
| T6 `st(a) and nn(b) and not z(b)` | 832 | T6 | 832 | same |
| T7 `st(a) and np(b) and not z(b)` | 848 | T7 | 848 | same |
| T8 `st(b) and nn(a) and not z(a)` | 864 | T8 | 864 | same |
| T9 `st(b) and np(a) and not z(a)` | 880 | T9 | 880 | same |
| T10 (fallback), four corners | 896-920 | no test: the calls of the fallback follow T9 | 896-920 | granularity: T10 is a terminal, not a test |
| route B (1.2.2) | 922-941 | T10 `for corner in corners`, T11 `match lower`, T12 `match upper` | 929, 932, 936 | granularity: the hand graph treats route B as one route; rille lists the loop and the two `Option` matches that accumulate its bounds |

The derived predicates at 758-761 and 828-831 are `let` bindings, not
tests; rille shows them as the calls they make (`is_zero`, `signum`)
without a test number, as the hand graph does ("computed here and not
before").

### `mul_interval_impl`, depth 2

rille gives 69 tests. In order, by the function they are in:

| rille | Function | Hand | Class |
| --- | --- | --- | --- |
| T1 `if a.is_empty() \|\| b.is_empty()`, 947 | `mul_interval_impl` | T0 `a = empty or b = empty`, 946-948 | same (the hand graph gives the range of the `if`) |
| T2 `match precision_error(precision)`, 87 | `checked_precision` (in `empty_interval`, the empty result) | not listed | granularity: the hand graph stops at the result's constructor |
| T3, T4, T9, T14, T19, T24, T29, T34, T39 at 757, 762, 778, 794, 810, 832, 848, 864, 880 | `multiplication_bounds` | T1 to T9 | same tests, same order |
| T5 to T8 and the other 655/658 pairs: 40 tests, two for each of the 20 calls | `extended_mul` | `mulc(u,v,dir)`: "0 if u = 0 or v = 0, +-inf if one is infinite, else one directed `mul_ctx`" | granularity: the hand graph states the two tests of `extended_mul` once in its notation; rille expands each call |
| T52, T53 at 619, 628 | `bin_min`, `bin_max` of the fallback | "min(...)", "max(...)" | granularity |
| T54 `for corner in corners`, 929; T58, T60 at 932, 936 | `multiplication_bounds`, route B | route B | granularity (as above) |
| T55 to T57 at 675, 689, 691 | `extended_mul_both` | 1.2.2: "zero or infinity -> `extended_mul` ...; else one coefficient product, the exponent sum saturated at +-2^31" | same tests (the zero-or-infinity test, then the two saturation tests), in the hand graph's words |
| T59, T61 | `bin_min`, `bin_max` of route B | "min of the four down values", "max of the four up values" | granularity |
| T62 to T69 at 113, 87, 314-348 | `store_interval`'s helpers (`validate_interval`, `lower_round_bound`, `upper_round_bound`) | the terminal `store_interval` | granularity: the hand graph ends at `store_interval` |

## Binary integer power

### `Binary::pown_ctx`, depth 0

| Hand (section 1.2) | Hand line | rille | rille line | Class |
| --- | --- | --- | --- | --- |
| P1 `n = 0 and x is not sNaN` | 1663 | T1 `if exponent == 0 && !self.signaling()` | 1663 | same |
| P2 `x` is NaN | 1666 | T2 `if self.class() == FpClass::NaN` | 1666 | same |
| (inside P2's result: "invalid if sNaN") | | T3 `if self.signaling()` | 1669 | granularity: the hand graph folds the choice of flags into P2's result |
| P3 `x` infinite | 1681 | T4 `match self.class()` at 1680, arm `FpClass::Infinity` at 1681 | 1680, 1681 | granularity: the hand graph lists the arms as tests; rille lists the `match` as the test and its arms as nodes under it |
| (inside P3's result: `0` if `n<0` else `inf`, sign) | | T5 `if exponent < 0`, T6 `if negative` | 1682, 1690 | granularity: folded into P3's result |
| P4 `x = 0` | 1700 | arm `FpClass::Finite if self.is_zero()` of T4 | 1700 | granularity (as P3) |
| (inside P4's result) | | T7 `if exponent < 0`, T8 `if negative` | 1701, 1704 | granularity: folded into P4's result |
| P5 `n = 1` | 1720 | T9 `if exponent == 1` | 1720 | same |
| P6 `n = 2` | 1723 | T10 `if exponent == 2` | 1723 | same |
| P7 `ES(x,m,rec)` | 1726 | T11 `if binary_pow_should_use_exact_fast(...)` | 1726 | same |
| P8 `cb = 1` | 1729 | T12 `if binary_pow_is_power_of_two(self)` | 1729 | same |
| (call) `binary_pow_magnitude_with_stats` | 1734 | call at 1734, not followed at depth 0 | 1734 | same |

### `Binary::pown_ctx`, depth 2: the back end

rille gives 97 tests; the tests of the functions the hand graph tables are,
in order:

| Hand | Hand line | rille | rille line | Class |
| --- | --- | --- | --- | --- |
| M1 `cb = 1` | 1626 | T89 `if binary_pow_is_power_of_two(base)` | 1626 | same |
| F1 `!rec and m = 1` | 1548 | T91 | 1548 | same |
| F2 `!rec and m = 2` | 1551 | T92 | 1551 | same |
| F3 `ES(x,m,rec)` | 1555 | T93 | 1555 | same |
| F4 out of range | 1561 | T94 `match binary_pow_out_of_range(...)` | 1561 | same |
| F5 `!rec` and exact and small | 1566 | T95 `if !reciprocal` at 1565, T96 `match binary_pow_exact_positive_if_small(...)` at 1566 | 1565, 1566 | granularity: the hand graph merges the guard `!rec` and the match into one test |
| F6 Ziv loop | 1571 | the call `binary_pow_ziv` at 1571, a call and not a test | 1571 | same (the hand graph marks it as the route, not a test) |
| F7 Ziv gave `None` | 1572 | T97 `match candidate` | 1574 | **hand graph wrong**: `binary-pown.md` section 1.2, row F7, gives line 1572; the test `match candidate` is at line 1574 of `library/src/binary/context_arithmetic.mbt` at `f403bd66` (1571-1573 is the call of `binary_pow_ziv`) |

The other 77 tests at depth 2 are in helpers the hand graph does not table
(`Binary::class`, `Binary::negative`, `normalize_finite`,
`binary_round_dyadic`, `Binary::mul_ctx`, ...): granularity.

### `Binary::pow_nat_ctx`, depth 2

| Hand | rille | Class |
| --- | --- | --- |
| P1, P2 | T1 `if exponent == 0U && !self.signaling()` at 1752, T3 `if self.class() == FpClass::NaN` at 1755 | same |
| (P2's result) | T9 `if self.signaling()` at 1758 | granularity (as in `pown_ctx`) |
| P3, P4 "without the `n<0` arm" | T12 `match self.class()` at 1766, T14 `if negative` at 1770 | same (no `n < 0` test; the sign test folded as before) |
| M1, F1 to F5, F7 | T22 at 1626, T24 to T30 at 1548, 1551, 1555, 1561, 1565, 1566, 1574 | same as `pown_ctx` |

## Result

Rows of the tables above, by class:

| | Same | Granularity | rille wrong | Hand graph wrong |
| --- | --- | --- | --- | --- |
| interval product (`multiplication_bounds`, `mul_interval_impl`) | 12 | 8 | 0 | 0 |
| binary power (`pown_ctx`, `pow_nat_ctx`) | 16 | 7 | 0 | 1 |

Every test of both hand tables is found by rille, in the same order, at the
same line, except where the hand graph merges, splits or folds steps on
purpose, and one line of the hand graph that is off by two. rille found no
test the hand graphs miss that changes the route of a class: the tests it
adds are inside results (the choice of flags or sign), in bookkeeping
(`for`, `Option` matches of route B), or in helpers the hand graphs end at.

## Re-run with arm guards as tests (`rille.graph/1`)

From `rille.graph/1` on, the guard of an arm is a test of kind `arm_guard`.
The five commands above were run again on the same archive of floating
`f403bd66`, with rille at `main` before the change and with the change, and
the two test lists compared after dropping the test numbers.

| Command | Tests before | Tests after | Added |
| --- | --- | --- | --- |
| `multiplication_bounds`, depth 0 | 12 | 12 | none |
| `mul_interval_impl`, depth 2 | 69 | 69 | none |
| `Binary::pown_ctx`, depth 0 | 12 | 13 | `arm_guard self.is_zero()` at 1700 |
| `Binary::pown_ctx`, depth 2 | 97 | 99 | the same at 1700; `arm_guard self.is_zero() \|\| other.is_zero()` at 965 in `Binary::mul_ctx` |
| `Binary::pow_nat_ctx`, depth 2 | 30 | 31 | `arm_guard self.is_zero()` at 1779 |

Apart from the added rows, every list is the same as before, line for line
and in the same order: no test moved, disappeared or changed its text.

New classification of the rows the change touches:

| Row | Before | After |
| --- | --- | --- |
| `pown_ctx` depth 0, P4 `x = 0` at 1700 | granularity: the arm `FpClass::Finite if self.is_zero()` was a node under T4, not a test | same: T7 `arm_guard self.is_zero()` at 1700 |
| `pow_nat_ctx`, P3, P4 | same | same; P4 is now also a test of its own, T15 at 1779 |
| the guard at 965 in `Binary::mul_ctx` | not listed | granularity: a helper the hand graph does not table (now 78 such tests instead of 77) |

The interval product has no arm guards, so its rows do not change. Result
after the re-run:

| | Same | Granularity | rille wrong | Hand graph wrong |
| --- | --- | --- | --- | --- |
| interval product | 12 | 8 | 0 | 0 |
| binary power | 17 | 6 | 0 | 1 |
