Description
Recent work by
- Choudhury and Fiore, on the free commutative monoid in HoTT, and
- Kupke, Forsberg, and Watters on fresh lists
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 relatesas ++ bs
andbs ++ as
- algorithmically the least relation such that
[]
is related to itself, and that ifcs
is related toas ++ bs
, thenc ∷ cs
is related toas ++ 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 tobs
, thena ∷ as
is related toa ∷ bs
(so that we have left-prefix-closure for_++_
, if not full congruence, straightaway) - if
as
is related tob ∷ cs
, andbs
is related toa ∷ cs
, thena ∷ as
is related tob ∷ 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