coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: mukesh tiwari <mukeshtiwari.iiitm AT gmail.com>
- To: coq-club AT inria.fr
- Subject: [Coq-Club] Non linear recursion
- Date: Tue, 26 Jul 2016 16:16:23 +1000
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=mukeshtiwari.iiitm AT gmail.com; spf=Pass smtp.mailfrom=mukeshtiwari.iiitm AT gmail.com; spf=None smtp.helo=postmaster AT mail-io0-f178.google.com
- Ironport-phdr: 9a23:1casSRapEXEcPxlz+w3Bl5P/LSx+4OfEezUN459isYplN5qZpc+zbnLW6fgltlLVR4KTs6sC0LuO9f66Ej1Qqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZvIaytQ8iJ3pzxibr5qs2bSj4LrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYeVcyDAgD1uSmxHh+pX4p8Y7oGwD884mosVHSODxe7kyZb1eFjUvdW4vt+PxshyWSBaM62AcGnkXjRNSAkCR6Qz5U4zxrirlv/B8niibPNHzZb8xUDWmqaxsTUm72288Kzcl/TSP2YRLh6VBrUf5qg==
Hello everyone,
I am trying to learn how to represent computations as Inductive data type. I can convert a linear recursion/computation into inductive data type (kindly see if my definitions for remainder and greatest common divisor are correct or not), but I am not able to see how to do this for non linear recursion/computation (breath first search or depth first search ). Any code or literature would be great. Best regards,
Mukesh Tiwari
Computation of greatest common divisor function gcd(a, b) while a ≠ b if a > b a := a − b; else b := b − a; return a;
and function gcd in terms of inductive definition
Inductive gcd : nat -> nat -> nat -> Prop :=
|cons_a a b : a = b -> gcd a b b
|cons_b a b c : b > a -> gcd a (b - a) c -> gcd a b c
|cons_c a b c : a > b -> gcd (a - b) b c -> gcd a b c.
Lemma gcd_0 : gcd 10 3 1.
Proof.
constructor 3. omega. constructor 3. omega. simpl.
constructor 3. omega. simpl. constructor 2. omega.
simpl. constructor 2. omega. simpl. constructor 1.
auto.
Qed.
Print gcd_0.
Lemma gcd_1 : forall n : nat, gcd n n n.
Proof.
intros. constructor 1. auto.
Qed.
Or remainder of two numbers
function rem(a, b) while a >= b a := a − b; return a;
and corresponding inductive definition
Inductive rem : nat -> nat -> nat -> Prop :=
| cons_0 n1 n2 : n1 < n2 -> rem n1 n2 n1
| cons_1 n1 n2 n3 : n1 >= n2 -> rem (n1 - n2) n2 n3 -> rem n1 n2 n3.
Lemma rem_3 : forall n : nat, n <> 0 -> rem n n 0.
Proof.
intros. constructor 2. omega.
assert (H1 : n - n = 0) by omega.
rewrite H1. constructor 1. omega.
Qed.
Lemma rem_4 : forall n m p : nat, p <> 0 -> rem n m p -> rem (n + m) m p.
Proof.
constructor 2. omega.
assert (H1 : n + m - m = n) by omega.
rewrite H1. trivial.
Qed.
- [Coq-Club] Non linear recursion, mukesh tiwari, 07/26/2016
- Re: [Coq-Club] Non linear recursion, Dirk Pattinson, 07/27/2016
Archive powered by MHonArc 2.6.18.