List with concatenation operation is monoid.
We will try to prove in Coq that list with concatenation ( ++ ) is monoid. Monoid is set S with binary operation with following properties.
1). Closure.
2). Associativity.
3) Identity.
Proof in Coq.
Require Import List. Theorem Closure : forall ( X : Type ) ( l1 l2 : list X ) , exists ( l3 : list X ), l1 ++ l2 = l3. Proof. intros X l1 l2. exists ( l1 ++ l2) . reflexivity. Qed. Theorem Association : forall ( X : Type ) ( l1 l2 l3 : list X ) , l1 ++ ( l2 ++ l3 ) = ( l1 ++ l2 ) ++ l3. Proof. intros X l1 l2 l3. simpl. rewrite -> app_assoc_reverse. reflexivity. Qed. Theorem Existence_identity_left : forall ( X : Type ) ( l : list X ), exists e, e ++ l = l. Proof. intros X l. exists nil. simpl. reflexivity. Qed. Theorem Existence_identify_right : forall ( X : Type ) ( l : list X ) , exists e, l ++ e = l. Proof. intros X l. exists nil. apply app_nil_r. Qed.
We don’t need to prove the closure property because all the functions in Coq is total. See thec discussion . Source code on github[1] and other proofs from software foundation[2].
[1] https://github.com/mukeshtiwari/Coq/blob/master/Monoid.v
[2] https://github.com/mukeshtiwari/Coq/blob/master/Poly.v
September 10, 2014 - Posted by tiwari_mukesh | Programming | Concatenation, Coq, List, Monoid, Thorem Proving
2 Comments »
Leave a comment Cancel reply
About
Hello All, My name is Mukesh Tiwari and I graduated from IIITM Gwalior in 2009. I am passionate about programming and mathematics. I love solving problems on SPOJ , UVA , Topcoder and Project Euler. I am curious about functional languages specially Haskell and it’s one the excellent language I encountered after python. I am also looking for some challenging functional programming job specially related to Haskell. You can reach me mukeshtiwariDOTiiitmATgmailDOTcom. Replace DOT with . and AT with @
September 2014 M T W T F S S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Recent Comments
carl johnson on SPOJ 9126. Time to live gratitude on SPOJ problem INTEGMAX stan on SPOJ 9126. Time to live Roni on SPOJ DIE HARD avinish on SPOJ 8756. Shake Shake Sh…
Twitter Updates
Tweets by mukesh_tiwariBlog Stats
- 139,226 hits
-
Join 364 other subscribers
Search Articles
Archives
Is n’t association theorem should be l1 ++ ( l2 ++ l3 ) = (l1 ++ l2) ++ l3
Comment by divyanshu ranjan (@rdivyanshu) | September 10, 2014 |
@Divyanshu Yes. Thank you for pointing out. Now it’s fixed.
Comment by tiwari_mukesh | September 10, 2014 |