Skip to content

Refactor to support multiple definitions of Data.List.Relation.Binary.Permutation #2311

Open
@jamesmckinna

Description

@jamesmckinna

Recent work by

has looked at lists-modulo-permutation, with a view to establishing that (Setoid) structure as (a representation of) (the carrier of) the free commutative monoid, with the former alluding to difficulties in establishing such results for the stdlib definition of permutation, and the latter, IIUC, by observing that fresh/sorted lists, by providing a constructive representative of the equivalence-classes-modulo makes such difficulties more tractable, at the cost of a(nother) new representation (but one already in the library, and interesting in its own right).

Each of the above, IMHO, fails to tackle the elephant in the room (incl. stdlib ;-), alas, by taking a prefix-closed, transitive relation which can swap only the top two elements of a list; it's very fiddly, and requires transitivity to be built in), namely that there are two 'natural' definitions of the relation, for which it is interesting (and useful/computationally relevant!) to prove the equivalence between them (something already done, but lost in the archaeology of my PhD thesis back in 1992), namely as:

  • declaratively the least congruence for [], _∷_ (and hence for _++_) which 'makes _++_ commutative', ie relates as ++ bs and bs ++ as
  • algorithmically the least relation such that [] is related to itself, and that if cs is related to as ++ bs, then c ∷ cs is related to as ++ c ∷ bs (whence the correctness of insertion sort)

I've recently come across the following definition, due, which I learnt from Ralf Hinze (UPDATED: apparently the inspiration for him came from Choudhury and Fiore's paper above), which may easily be shown equivalent to each of these definitions (NB in the Propositional case, I'm still looking at the Setoid generalisation), as the least relation such that:

  • [] is related to itself
  • if as is related to bs, then a ∷ as is related to a ∷ bs
    (so that we have left-prefix-closure for _++_, if not full congruence, straightaway)
  • if as is related to b ∷ cs, and bs is related to a ∷ cs, then a ∷ as is related to b ∷ bs (whence the correctness of mergesort, as well, again IIUC)

This may easily be shown to be reflexive, symmetric, makes _++_ commutative, and by a slightly fiddly length induction, may be shown to be transitive. Cancellation properties, as well as full congruence, follow easily from this.

PROPOSAL: subject to the Setoid generalisation working out, that we replace the library definition with the one above, together with the Properties showing it equivalent to the declarative and algorithmic ones above.

ISSUES:

  • the library computes a notion steps counting the number of rule applications of the existing constructors, but AFAICT, it is used nowhere else in the library, but would need to be retained for backwards-compatibility (I don't see the point myself, but hey)
  • we might argue about whether the new definition is more tractable, but it certainly is more beautiful (again, IMHO), esp. as regards the free commutative monoid characterisation

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions