Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] functions for even

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] functions for even


chronological Thread 
  • From: Pierre Courtieu <Pierre.Courtieu AT univ-orleans.fr>
  • To: chris jhons <chrisformal AT yahoo.co.uk>
  • Cc: coq-club AT pauillac.inria.fr
  • Subject: Re: [Coq-Club] functions for even
  • Date: Tue, 21 Sep 2004 17:55:11 +0200
  • List-archive: <http://pauillac.inria.fr/pipermail/coq-club/>

On 21 sep 2004, chris jhons wrote:

> Dear all,
>  
> I want to define the following functions in Coq. Can you tell me how?
>  

This is rather straightforward:

Fixpoint even (n:nat) : bool :=
match n with
  | O => true
  | 1 => false
  | S (S n') => even n'
end.


Eval compute in even (S (S O)).
Eval compute in even (S (S (S O))).

(* even' and odd are mutually recursive: *)

Fixpoint even' (n:nat) : bool :=
match n with
  | O => true
  | S n' => odd n'
end
with odd (n:nat) : bool :=
match n with
  | O => false
  | S n' => even' n'
end
.


Eval compute in even' (S (S O)).
Eval compute in even' (S (S (S O))).


Cheers,

Pierre Courtieu




Archive powered by MhonArc 2.6.16.

Top of Page