Skip to Content.
Sympa Menu

coq-club - [Coq-Club] A question of encoding...

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

[Coq-Club] A question of encoding...


Chronological Thread 
  • From: Fred Smith <fsmith1024 AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: [Coq-Club] A question of encoding...
  • Date: Sun, 2 Dec 2018 15:25:25 -0500
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=fsmith1024 AT gmail.com; spf=Pass smtp.mailfrom=fsmith1024 AT gmail.com; spf=None smtp.helo=postmaster AT mail-oi1-f177.google.com
  • Ironport-phdr: 9a23:PpvAExCdECtrAMUAQgH0UyQJP3N1i/DPJgcQr6AfoPdwSPrzrsbcNUDSrc9gkEXOFd2Cra4c26yO6+jJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglUhzexe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfOpWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnMVhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Xymp4aV2Rx/ykCoIOD43/m/UhMJtkqxUvAmsqAZjz4POeoyZKOZyc6HbcNgHRWRBRMFRVylZD428dYsAEfcONvtFoYn4plsOsRu+DhSrCePh0T9Ig3723bE60+g8DQ3KwgMtEskBsHTRttr1NaMSXfqpw6nPyDXOdvVb0ir+5ojQah0tv+2AULZqfcfSyUQjDR7Jg1SSpID/Ij+Y1OYAvm6G5OR6T+2vkXQoqwRprziv2Mgsjo7Ji5oQyl/e9CV5xJ85Jdq5SEJmeNKkHoZcuiOYOodsTcMiRGZouCk+yrIYo5K0YC8KyJE/yx7ebfyIbZSI7wr9WOqNJTp0nnFodbKlixqv8EWtyPfwWtS23VtItiZFl8PDtnEJ1xzd8MiHTf5981+v2TaU0gDT6/1EIUApmabHNZIszaU9lpUWsUvZHy/2nF/6g7ORdkUh4uSo8fjoYq36pp+AMI95kh3xMqM3msCmHes4NhUOUHOA9OSn1Lzj+FX5T69Qgv03lKnZqpHaKt4Bqq63GQ8Gmrokvh24FnKt1MkStXgBNlNMPhyd3KbzPFSbDur1Ab+EhlWwkH8/yevDP6HhW82XclDMlb7gefB27EsKm1l79sxW+58BUuJJG/n0QEKk7IWJXC98CBS9xqPcMPs404ofXWyVBarAafHdtFaJ4qQkJOzePdZJ6ga4EOAs4rvVtVF8gUUUJPD70p4eaXT+FfNjcR3APCjcx+wZGGJPhTIQCeznjFrYD2xWbne2GqU9v3Q1Ud35S4jEQY+pjfqK2yLpRpA=

Hi,

I am looking for engineering advice to help me understand the tradeoffs between different ways of encoding the same information in Coq.

As my exercise, I am trying to encode paths in a graph.  For simplicity these are just lists of edges where each edge ends where the next edge begins.

Below is a Coq file that uses 3 different encodings.  Two inductive ones, and the third as a predicate.  What are the pros and cons of these choices?

Thanks,

Fred

----- path.v below -----

(* Experiments in encoding paths in Coq.

A path is simply a list of edges where the destination of the
preceding edge is the source of the next edge.

*)

Require Import List.

Definition vertex := nat.
Definition edge := (vertex * vertex)%type.

(* Simple encoding as lists with a predicate *)
Fixpoint path (l : list edge) :=
  match l with
  | nil => False
  | hd :: tl => (match tl with
                 | nil => True
                 | hd2 :: tl2 => (snd hd) = (fst hd2)
                 end) /\ (path tl)
  end.

(* Define as a subset. *)
Definition Path := { l : list edge | path l }.

(* Encode as an inductive definition that makes the path correct by
construction.  Note, need to include the vertex endpoints in the type
to enforce the invariants. *)
Inductive pathI : vertex -> vertex -> Set :=
| path_tl : forall e:edge, pathI (fst e) (snd e)
| path_hd : forall e:edge, forall v1 v2:vertex, forall p:pathI v1 v2, (snd e) = v1 -> pathI (fst e) v2.

(* We could write a symmetrical encoding as well. *)
Inductive pathS : vertex -> vertex -> Set :=
| pathS_edge : forall e:edge, pathS (fst e) (snd e)
| pathS_compose : forall v1 v2 v3 : vertex, forall p1 : pathS v1 v2, forall p2 : pathS v2 v3, pathS v1 v3.

                                    
(* Which of these encoding is preferred?
  1. Predicate encoding allows reuse of list facts and definitions, but requires lemmas connecting them together.
  2. Inductive encoding requires reimplmenting all list elements.
  3. Symmetric encoding makes simple equality not work, requires a special equality operator.
 *)





Archive powered by MHonArc 2.6.18.

Top of Page