We are concerned with demonstrating productivity of specifications of infinite streams of data, based on orthogonal rewrite rules. In general, this property is undecidable, but for restricted formats computable sufficient conditions can be obtained. The usual analysis, also adopted here, disregards the identity of data, thus leading to approaches that we call data-oblivious. We present a method that is provably optimal among all such data-oblivious approaches. This means that in order to improve on the algorithm in this paper one has to proceed in a data-aware fashion.
Q = diff(M) M = h(0:tail(M)) |
stream layer |
tail(x:s) = s h(0:s) = 0:1:h(s) h(1:s) = 1:0:h(s) diff(x:y:s) = abc(x,y):diff(y:s) |
function layer |
abc(0,0) = a abc(0,1) = b abc(1,0) = c abc(1,1) = a |
data layer |
f(s) = g(s,s) (1) g(0:y:s, x:t) = 0:0:g(s,t) (2) g(1:s, x1:x2:x3:x4:t) = 1:1:1:1:1:g(s,t) (3)The following picture shows a selection of function call traces for f. In particular it shows the traces that contribute to the lower bound of the quantitative consumption/production behaviour of f.
f(0:1:1:1:0:0:0:0) = g(0:1:1:1:0:0:0:0, 0:1:1:1:0:0:0:0) = 0:0:g(1:1:0:0:0:0, 1:1:1:0:0:0:0) = 0:0:1:1:1:1:1:g(1:0:0:0:0, 0:0:0)producing only 7 elements and g(1:0:0:0:0, 0:0:0) being a normal form.
dup(x:s) = x:x:dup(s) even(x:y:s) = x:even(s)The quantitative behaviour of dup is f(n) = 2n, but the best bound that [4] can assign is f(n) = n.
div3(x:y:z:s) = x:div3(s) mul2(x:s) = x:x:mul2(s)The result of the composition div3(mul2(...)), that is --+-+, falls out of their class, which implies the need of approximations and a loss of power.
We have implemented the decision algorithm for data-oblivious productivity as a Haskell program. The program reads a given stream specification, automatically recognizes to class of the specification (pure/flat/other), and then attempts to prove or disprove productivity. As output a .pdf file is generated containing the (dis)proof of productivity or a message in case the attempt failed.