220 likes | 226 Views
Equality of Streams is a Problem. Grigore Rosu University of Illinois at Urbana-Champaign. Streams. Infinite sequences (of 0,1 bits) 0, 1, 1, 0, 0, 1, … Many applications Protocols (inputs/outputs) Lazy functional programming (elegant) Canonical infinite structures
E N D
Equality of Streams is a Problem Grigore Rosu University of Illinois at Urbana-Champaign
Streams • Infinite sequences (of 0,1 bits) 0, 1, 1, 0, 0, 1, … • Many applications • Protocols (inputs/outputs) • Lazy functional programming (elegant) • Canonical infinite structures • Basic case study for theoretical or algorithmic approaches to infinite state systems Many streams of interest can be defined equationally, with a finite number of equations
Outline • Equational definitions of streams • Stream equality problem • Computation as equational deduction • Stream equality is 20-hard • Reduction from TOTALITY • Stream equality is in20 • Completeness of FOL=
Equational Definitions of Streams • Many practical streams and operations on streams can be defined equationally; e.g. • Many languages support such definitions: functional (Haskell), algebraic (Maude), coalgebraic (BOBJ), etc. 0 E 1 (01)
E Stream Equality Problem Given an equational definition of streams E and stream terms str and str’, is it true that Estr = str’ E.g: ? E ?
On Proving Stream Equality • Equational deduction sound, but weak • Cannot show zip(zeros,ones) = blink • Ordinary structural induction • Not always sound (constructors for streams?) • Weak, initial model not appropriate • zip(zeros,ones) ≠ blink in the initial model • Behavioral/observational techniques • Indistinguishability under experiments • Coinduction (Rutten), context induction (Hennicker), circular coinduction (Rosu)
h t t h Circular Coinductionzip(zeros, ones) = blink Cobasis {h,t} (i.e., experiments with h and t) zip(zeros, ones) = blink 0 = 0 zip(ones,zeros) = t(blink) 1 = 1 zip(zeros,ones) = blink
The Temptation … • We show that neither of these is possible ! • Moreover, we give a precise characterization of the difficulty of this problem Search for “complete” proof systems or algorithms for equality or for inequality of streams …
What is … r P is iff P(k) = (i)(j) r(i,j,k)
A Complete Problem TOTALITY Input: the kth • Turing machine, or • Partial recursive function Output • Does it halt, or is it total, on any input? TOTALITY ( input i)( computation j) r(i,j,k)
TOTALITY: Simpler Version Fix a universal machine U, such that U(1i01k) runs machine number k on input number i Input • integerk Output • Does U(1i01k) halt for any integer i ? TOTALITY - simpler -
Encoding Computation as Equational Deduction - 1 • Well known, but involved • Bergstra & Tucker, Nipkow, etc. • We give simpler encoding (thanks to streams) • Turing machine M with tape infinite at both ends • Configuations q(L,R) • Add equation q(b’:L, b:R) = q’(L, b’:b:R) whenMmoves head to left, changing state fromqtoq’ • qstart initial state, qhalt halt state; add qhalt(L,R) = 1 zeros zeros b’ b L R b:R, b’:L streams
Encoding Computation as Equational Deduction - 2 • Let EM be the equational specification associated to Turing machine M as above Theorem M halts on b1b2…bn iff EMsatisfies qstart(zeros, b1 : b2 : … : bn : zeros) = 1 • We apply it whenMisU(the universal TM)
Stream Equality is Hard - 1 • Reduction from TOTALITY • Let EU be the equational specification associated to universal Turing machine U Input • integerk Output • Does EUsatisfy qstart(0, 1i01k0) = 1 for any i ? TOTALITY - deductive -
Stream Equality is Hard - 1 • Reduction from TOTALITY • Let EU be the equational specification associated to universal Turing machine U Input • integerk Output • Does EUsatisfy qstart(0, 1i01k0) = 1 for any i ? TOTALITY - deductive -
Stream Equality is Hard - 2 • Define an additional stream operation total?(R) = qstart(0, R) : total?(1:R) Input • integerk Output • Does EUsatisfy total?(01k0) = 1 ? TOTALITY - equational -
Membership in - 1 Stream equality Input • specification E and • streams str, str’ Output • Does E satisfy str =str’ ? P is iff P(k) = (i)(j) r(i,j,k)
Membership in - 2 • Step 1: build FOL= spec EBit as follows • For each stream = stream’ in E, add r.e. set { hd(tli(stream)) = hd(tli(stream’)) | i N } • Add (0 = 1) • Add ( b:Bit) b = 0 b = 1 • Step 2: prove theorem • Estream-satisfies str = str’ iff • for all i, EBitsatisfies hd(tli(str)) = hd(tli(str’))in FOL= • Step 3: conclude • is , by the complete deduction of FOL=
Conclusion • hardness • Reduction from TOTALITY • Membership in • Completeness of FOL= Stream Equality is - complete
What this result tells us No way to automatically • Prove equalities of streams • Prove inequalities of streams …
Then, what should we do? • Should we then stop trying? • NO • Instead, develop • Algorithms that work in “practice” • Criteria that filter out “bad” stream definitions • For example, what makes the following coinductive proof work?
h t t h Circular Coinductionzip(odd(S), even(S)) = S Cobasis {h,t} zip(odd(S), even(S)) = S h(S) = h(S) zip(even(S),even(t(S))) = t(S) h(t(S)) = h(t(S)) zip(even(t(S)), even(t(t(S)))) = t(t(S))