Proofs: Green's filter
These are the human proofs of Green's filter, at full length.
Green's network sorts each input of 16 items full
This proof shows: correctness.
Call the network . It is a fixed list of standard comparators, so its output is a permutation of its input. By the zero-one principle it is enough to show that sorts each . For wires write when each bit of is also a bit of .
Lemma 1 (the filter). After lines L1 to L4, for each input over a totally ordered set, the item on wire is at most the item on wire whenever .
Proof. Let be a set of bits, and say that is monotone in when for each and each with bit equal to 0. The layer for bit makes monotone in . We show that it keeps monotone in each other bit . Take with bits and equal to 0, and let and . The layer for replaces the pairs and by their minimum and maximum. If and before, then
so the order in bit holds after the layer. So after the four layers is monotone in all four bits. If , add the bits of that are not in one at a time; each step does not decrease the item.
So for , the set of wires that hold a 0 after line L4 is a down-set: if and , then . Let . The network sorts if and only if, at the end, the zeros are on the wires .
Lemma 2 (symmetry). Let . Then , and maps sorted sequences to sorted sequences.
Proof. For a comparator let be . On , the comparator writes to wire and to wire , which is of the result of on . Each layer is mapped to itself by : in lines L1 to L4, maps to , which is in the same layer; in lines L5 to L10 the pairs map as , , , , , , , , , , , , and , , , map to themselves. The comparators of one layer have disjoint wires, so their order does not matter.
The input has zeros if has zeros. So by Lemma 2 it is enough to show that sorts each 0-1 input with at most 8 zeros. From now on .
The groups. Let , and , and let , and . If then . A wire of in brings the three wires of and the three wires of below it, and wire 0, so forces . Hence , only if , , and wire . Also a wire of in brings its two wires of , so .
Lemma 3 (the four sorts). Wires 0 and 15 are not touched after line L4. In lines L5 to L7, the comparators on the wires of are exactly , and they sort in the order ; wire 8 holds the largest item of after line L6, and wires 1 and 2 are not touched after line L7. In the same way is sorted in the order , wire 7 holds its smallest item after line L6, and wires 13 and 14 are not touched after line L7. After line L5, the comparators (L6), (L7), (L8), (L9) sort the wires in this order, and (L6), (L7), (L8), (L9) sort the wires . After line L8, wire 3 holds the smallest and wire 8 the largest item of , and wire 7 the smallest and wire 12 the largest item of .
Proof. Read the layers. Each of the named groups of five comparators is the standard sorter on four wires , which sorts each input, and after its third and fourth comparators holds the minimum and the maximum. No other comparator touches these wires between the comparators of the group, except that the comparator of comes after wire 8 has its final value from (line L6), and of comes after wire 7 has its final value from . In line L9 the comparators , and run at the same time as and , on other wires.
Now we follow a 0-1 input with zeros. Write for the bit on wire after line L4.
Line L5 compares the complementary pairs , , of . Both wires of such a pair in would bring all four wires of into . Let be the number of these pairs with two zeros and the number with one zero, so , and only if . After line L5, wires 3, 5, 6 hold zeros and wires 9, 10, 12 hold zeros. With Lemma 3, the group holds zeros, because wire 8 holds a zero only if all of is zero, and holds zeros. After the sort of , wires hold , and after the sort of , wire 7 holds a 0 if and only if , and wires 11, 13, 14 hold 1.
In each case below , so wire 12, which holds the largest item of the four wires of , holds 1, and the comparator of line L9 changes nothing. It remains to follow , (line L9) and , (line L10), with and sorted. We use for .
Case , so and . The zeros are on wire 0 and on the first wires of , that is, on wires and , and no other wire holds a 0. Every later comparator sees two ones or a 0 on its lower wire. So the output has the zeros on wires .
Case , , so , , , , . Wire 3 holds the only zero of , wires 4 and 8 hold 1, and holds no zero. The comparators , , , change nothing. The zeros are on wires 0 to 3.
Case . Then , , , , wire 4 holds 0 and wire 8 holds 1. So holds zeros on its first wires in the order , and wire 8 holds 1.
- : wire 3 holds 1 and wire 4 holds 0, so exchanges them. The zeros are on wires 0 to 3, and .
- : zeros on wires 0, 1, 2, 3, 4, and .
- : zeros on wires 0 to 5, and .
- , : zeros on wires 0 to 6, and wire 7 holds 1. So .
- , : zeros on wires 0 to 6, and wire 7 holds the smallest item of , a 0. So the zeros are on wires 0 to 7, and .
In each subcase, , and see a 0 on the lower wire or two equal bits, so they change nothing.
Case . Then , so , and because needs . So is one of , with and . Wires 1, 2, 4 hold 0, so changes nothing.
- : , a zero on wire 3. Zeros on wires 0 to 4, and .
- : , zeros on wires 3 and 5. Zeros on wires 0 to 5, and .
- : , zeros on wires 3, 5, 6. Zeros on wires 0 to 6, and .
- : , zeros on wires 3, 5, 6, 8, and , so wire 7 holds 1. The comparator exchanges them. Then the zeros are on wires 0 to 7, wire 8 holds 1, and and change nothing. So .
- : , zeros on wires 3 and 5; , a zero on wire 7. Wire 8 holds 1, so changes nothing. Before line L10 the zeros are on wires 0 to 5 and 7, and wire 6 holds 1. The comparator exchanges them, and sees two ones. The zeros are on wires 0 to 6, and .
- : , zeros on wires 3, 5, 6; , a zero on wire 7. Zeros on wires 0 to 7, and .
In each case the zeros end on the wires , so sorts each 0-1 input with at most 8 zeros. By Lemma 2 it sorts each 0-1 input, and by the zero-one principle it sorts each input.