Skip to Content.
Sympa Menu

coq-club - [Coq-Club] How can you build a coinductive memoization table for recursive functions over binary trees?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

[Coq-Club] How can you build a coinductive memoization table for recursive functions over binary trees?


Chronological Thread 
  • From: roconnor AT theorem.ca
  • To: Coq Club <coq-club AT inria.fr>
  • Subject: [Coq-Club] How can you build a coinductive memoization table for recursive functions over binary trees?
  • Date: Wed, 25 Apr 2018 12:11:17 -0700 (PDT)
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=roconnor AT theorem.ca; spf=PermError smtp.mailfrom=roconnor AT theorem.ca; spf=PermError smtp.helo=postmaster AT theorem.ca
  • Ironport-phdr: 9a23:LsvPrRFHLVQCOtgX00RKiJ1GYnF86YWxBRYc798ds5kLTJ78oMmwAkXT6L1XgUPTWs2DsrQY07GQ6/iocFdDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZrKeTpAI7SiNm82/yv95HJbAhEmDSwbaluIBmqsA7cqtQYjYx+J6gr1xDHuGFIe+NYxWNpIVKcgRPx7dqu8ZBg7ipdpesv+9ZPXqvmcas4S6dYDCk9PGAu+MLrrxjDQhCR6XYaT24bjwBHAwnB7BH9Q5fxri73vfdz1SWGIcH7S60/VC+85Kl3VhDnlCYHNyY48G7JjMxwkLlbqw+lqxBm3oLYfJ2ZOP94c6jAf90VWHBBU95fWSJBHI2ycogBAOQOMulEtIT9u0cCoAGiCQWwHu7j1DlFjWL2060g1OQhFBnL3BYnH90St3TUqtP1NKAIUe2u0KnIzSvMb/RM2Tjj7YjEaAwuruuKULltf8TRzkwvGBnEjlWWsYHlJC+V2f4RvGiY8eVhWv6gi249pAF3rTig2N0ghZXOhoIQ0lzE+iR5wJo1Jd2lU0F3e8KrEJxVty2CLYt7Q9kuTH1ytyoizb0HtoS3czIWx5g92h7faPqKeJWL7BL7TOudPyt0iXZ/dL+7hRu+61asxvPiWsWuzVpHoTZJn9/RvX4XzRPT8NKISv5l80ehxzmP0wfT5/lYIUA0i6XbLIQhzaA1lpYJrUvMBDf6mETwjKCIakUp4vak5/jjb7n8opKRNZV4hh/gPqgwgMCzHOs1PhQWU2ie4+u81bnj/UPjQLVNi/07irPZsJfGKsQcoK65BQhV0pw45hajDzepztMYnWMZI1JAYh6Ik5LmN0nUIP/kFfe/n0iskDBzyv/aOb3hG4zBIWTHkLf8Zrlw8FVcyQo2zdBH/Z1YELABIPTpWk/wrtPUFBE5Mxbni9rgXf56z8s1XX+FSvuSN7qXuluV7MouJfONbckbomCuBeIi4qv0inQ+n1kaZ4G13ZYQcn29WP9vcBbRWmblntpUSTRChQE5VuG/zQTaCWcCNUb3ZLo143QAMKzjCI7CQo63h7nYhnWnHpBRfG1DTFuFQymxK9e0HswUYSfXGfdP1yQeXOH7GZMh2Ba0uQq8wLM1drOJqB1djorq0Z1O38OWlRw28mUuXdid3maXQmQylWpaGTI=

I've posted this question on the cstheory stack exchange at https://cstheory.stackexchange.com/questions/40631/how-can-you-build-a-coinductive-memoization-table-for-recursive-functions-over-b
but I'm hoping to reach a wider audience by also asking here on the Coq Club mailing list. I copy my question below.

----

The StreamMemo library for Coq illustrates how to memoize a function f : nat -> A over the natural numbers. In particular when f (S n) = g (f n), the imemo_make shares the computation of recursive calls.

Suppose instead of natural numbers, we want to memoize recursive functions over binary trees:

Inductive binTree : Set :=
| Leaf : binTree
| Branch : binTree -> binTree -> binTree.

Suppose we have a function f : binTree -> A that is structurally recursive, meaning that there is a function g : A -> A -> A such that f (Branch x y) = g (f x) (f y). How do we build a similar memo table for f in Coq such that the recursive computations are shared?

In Haskell, it is not too hard to build such a memo table (see MemoTrie for example) and tie-the-knot. Clearly such memo tables are productive. How can we arrange things to convince a dependently typed language to accept such knot tying is productive?

----

Even building a memotrie data type for binary trees is difficult in Coq. The natural solution calls for using a Bushy Datatype (see https://www.cs.ox.ac.uk/richard.bird/online/BirdMeertens98Nested.pdf) which doesn't pass Coq's positivity check (but does seem to pass Agda's positivity check; maybe Christine Paulin could even further relax Coq's positivity check. :) ). At the risk of prejudicing the reader, I have a gist of how I've worked around this to define a memotrie data type for binary trees in Coq at https://gist.github.com/roconnor/52375c3a81c927c5a8234be858f9830b

My above solution to building a memotrie is moderately contrived and adhoc, so I encourage those intrested in this problem to try a solution themselves first before reading my gist. You may come up with a better solution than what I have.

The memotrie I build in my gist doesn't memoize recursive calls of a structurally recursive function over binary trees. At the end I write out the type of solution one would write in Haskell to build an example memotrie that memoizes recurive calls. However, this definition fails that corecursive guard check (and rightly so I think).

I don't know how to build a memotrie to memoize recursive calls in a structurally recursive function. I'm hoping someone one the mailing list might know a solution.

--
Russell O'Connor <http://r6.ca/>



Archive powered by MHonArc 2.6.18.

Top of Page