coq-club AT inria.fr
Subject: The Coq mailing list
List archive
Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?
Chronological Thread
- From: Adam Chlipala <adamc AT csail.mit.edu>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?
- Date: Mon, 15 Jul 2013 08:00:59 -0400
Here's how to do it with a bit less duplication. The key is to use a [Section] or explicit [fun] to bind each argument that is not supposed to vary during recursion, so that expanding out the definitions leads to exactly the code you gave at first.
Section frec_grec.
Variables f g : nat -> nat -> nat.
Variable a : nat.
Fixpoint frec b :=
match a with
| O => 0
| S a' => f a' b + g a' b
end +
match b with
| O => 0
| S b' => frec b' + grec b'
end
with grec b :=
match a with
| O => 0
| S a' => f a' b + g a' b
end +
match b with
| O => 0
| S b' => grec b'
end.
End frec_grec.
Fixpoint f (a : nat) :=
frec f g a
with g (a : nat) :=
grec f g a.
On 07/15/2013 04:18 AM, Jacques-Henri Jourdan wrote:
Does the following fits your needs ?
Fixpoint f (a:nat) :=
(fix frec b :=
match a with
| O => 0
| S a' => f a' b + g a' b
end +
match b with
| O => 0
| S b' => frec b' + grec b'
end
with grec b :=
match a with
| O => 0
| S a' => f a' b + g a' b
end +
match b with
| O => 0
| S b' => grec b'
end
for frec)
with g (a:nat) :=
(fix frec b :=
match a with
| O => 0
| S a' => f a' b + g a' b
end +
match b with
| O => 0
| S b' => frec b' + grec b'
end
with grec b :=
match a with
| O => 0
| S a' => f a' b + g a' b
end +
match b with
| O => 0
| S b' => grec b'
end
for grec).
I was searching how to do that without code replication, but I have no Idea for now.
- [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, Michiel Helvensteijn, 07/15/2013
- Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, t x, 07/15/2013
- Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, Michiel Helvensteijn, 07/15/2013
- Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, Adam Chlipala, 07/15/2013
- Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, Michiel Helvensteijn, 07/15/2013
- Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, AUGER Cédric, 07/15/2013
- Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, Jacques-Henri Jourdan, 07/15/2013
- Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, Adam Chlipala, 07/15/2013
- Re: [Coq-Club] Mutually recursive function with structurally decreasing argument pair?, t x, 07/15/2013
Archive powered by MHonArc 2.6.18.