coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: "Kevin Sullivan" <sullivan.kevinj AT gmail.com>
- To: coq-club AT inria.fr
- Subject: [Coq-Club] An interated composition puzzle
- Date: Sat, 10 Nov 2012 14:54:57 +0100 (CET)
My students presented two solutions to the simple problem of applying a
function f n times to an argument x (iterated composition). The first says
apply f to the result of applying f n-1 times to x; the second, apply f n-1
times to the result of applying f to x. I challenged one student to prove that
the programs are equivalent. This ought to be pretty easy based on the
associativity of composition. Your best solution?
Fixpoint ant {X: Type} (f: X->X) (x: X) (n: nat) : X :=
match n with
| O => x
| S n' => f (ant f x n')
end.
Fixpoint ant' {X: Type} (f: X->X) (x: X) (n: nat) : X :=
match n with
| O => x
| S n' => ant' f (f x) n'
end.
Theorem equiv: forall (X: Type) (f: X->X) (x: X) (n: nat),
(ant f x n) = (ant' f x n).
Proof. admit.
- [Coq-Club] An interated composition puzzle, Kevin Sullivan, 11/10/2012
- Re: [Coq-Club] An interated composition puzzle, Adam Chlipala, 11/10/2012
- Re: [Coq-Club] An interated composition puzzle, Laurent Théry, 11/10/2012
- Re: [Coq-Club] An interated composition puzzle, AUGER Cédric, 11/10/2012
- Re: [Coq-Club] An interated composition puzzle, Jean-Francois Monin, 11/11/2012
- Re: [Coq-Club] An interated composition puzzle, Jonas Oberhauser, 11/11/2012
- Re: [Coq-Club] An interated composition puzzle, AUGER Cédric, 11/11/2012
- Re: [Coq-Club] An interated composition puzzle, Jonas Oberhauser, 11/11/2012
- Re: [Coq-Club] An interated composition puzzle, AUGER Cédric, 11/11/2012
- Re: [Coq-Club] An interated composition puzzle, Jonas Oberhauser, 11/11/2012
Archive powered by MHonArc 2.6.18.