Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Question about recursive function

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Question about recursive function


Chronological Thread 
  • From: Adam Chlipala <adamc AT csail.mit.edu>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Question about recursive function
  • Date: Sun, 9 Jul 2017 12:14:24 -0400
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=adamc AT csail.mit.edu; spf=Pass smtp.mailfrom=adamc AT csail.mit.edu; spf=None smtp.helo=postmaster AT outgoing-stata.csail.mit.edu
  • Ironport-phdr: 9a23:ilJcYBDGzK9T85B7tfqvUyQJP3N1i/DPJgcQr6AfoPdwSPv4psbcNUDSrc9gkEXOFd2CrakV1KyO6+jJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fdbghMhjexe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfOpWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnMVhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Xymp4aV2Rx/ykCoJKiA38G/XhMJzgqxUrh2uqB5jzIDbe4yVKPhzc7nBcd8GS2dMXMBcXDFBDIOmaIsPCvIMMPpFoIbnolsFsAWzBQmoBOPu0j9HnHv20rcn2OkmCw7JwRYvH9cSv3nPsNr1L70dUeGxzKXSyDXDbu9W1S3j54fVbxAsuPeBVq9zf8rJ0UQjCh3Jg1aKpYHrIz+ZzPoBv3KF4+Z9Se6jk2wqpxxrrjSxyMohhJPFip8Vx13G7yl13ps5KNO+RUVme9CrCoFQuDufN4ZuQsMtXWVouCEix70BpJ67YCcKyJMmxx7ZZPyLapOI4g75W+aNOzh0nm5qeKmliBaz9Uis0Oj8Vsio0FpQsCVKj8TMumgM1xzV9MeHVuNw8lq/1TuMzQze5P1ILVoqmabBNZIt36I8moIWsUvZHy/2nEv2jLWRdkUh4uWn8fnoba/jppCALIJ7lhr+Pb4vmsy7G+g4NwkOX3SB9euiybLj4FX1QK9Wgf0ujqnZrJfaKNwHqa6+Gg9Zy5os6xKiDzi9y9kYhnkGLFddeB2dlYTpOlfOIOr5DfilmVisni1rlLj6OejqBYyIJXzemp/ge6x84ghS0lkd19dasrtYA7RJC/L3W1f4sNWQWhY1Ogm/6+38AdR5kIYfRSSCDrLPY/CaikOB+u96e7rEX4QSojuoc/U=

Quick warning: it's great that you're interested in learning about Coq, but Software Foundations asks students not to share publicly any details of their solutions to its exercises, and I think your question already breaks that rule, since it includes details of a first attempt. A public reply answering your question would go even further against the spirit of the rule.

On 07/09/2017 12:04 PM, Andreas Ames wrote:
Hi all,

I am ridiculously new to Coq, proof assistants in genral etc. My
primary interest is formal verification of real-world programs,
currently with frama-c. Therefore I am working through Software
Foundations, which seems to be exactly what I need to learn something
about Coq.

Unfortunately I am currently stuck at the end of the second chapter
about induction, where I would like to normalise the inductive type
"bin":

Inductive bin : Type :=
| B0 : bin (* binary zero *)
| BEV : bin -> bin (* even binary: 2*x *)
| BOD : bin -> bin. (* odd binary: 2*x+1 *)

The task is to make the notation of binary numbers unambiguous by
providing a normalisation for such numbers, because "BEV B0 = B0".

My idea to achieve this is to have a helper "normalize'" replacing a
single "BEV B0" with "B0" and call that from "normalize" as often as
needed. If normalize' returns its argument, ecursion has to stop.
Otherwise normalize has to recurse.

Fixpoint normalize' (b : bin) : bin :=
match b with
| B0 => B0
| BEV B0 => B0
| BEV b' => BEV (normalize' b')
| BOD b' => BOD (normalize' b')
end.

Unfortunately I am lacking the syntactic abilities to do so and the Coq
reference of "match" is still beyond my reach. I have tried things like
the following to no avail:

Fixpoint normalize (b : bin) : bin :=
match (normalize' b) with
| b => b
| _ => normalize _
end.

Could you please provide me some hint how to write normalize in a way
aceptable to Coq?


TIA,

Andreas





Archive powered by MHonArc 2.6.18.

Top of Page