More efficient list encoding for Countable
This changes the encoding used for finite lists of values of countable types to be linear instead of exponential. The encoding works by duplicating bits of each element so that 0 -> 00 and 1 -> 11, and then separating each element with 10. The top 1-bits are not kept since we know a 10 is starting a new element which ends with a 1.
Please don't hold back on feedback. I'm sure this could do with some improvements :)
Merge request reports
Activity
mentioned in merge request !61 (closed)
- Resolved by Robbert Krebbers
- Resolved by Robbert Krebbers
- Resolved by Robbert Krebbers
- Resolved by Robbert Krebbers
- Resolved by Jakob Botsch Nielsen
- Resolved by Jakob Botsch Nielsen
- Resolved by Jakob Botsch Nielsen
- Resolved by Jakob Botsch Nielsen
- Resolved by Jakob Botsch Nielsen
- Resolved by Jakob Botsch Nielsen
I started thinking a bit more about this, and also how it relates to the issue with namespaces in !61 (closed).
Could we do the following:
- Have functions
positives_flatten : list positive → positive
andpositives_unflatten : positive → list positive
innumbers.v
that are basically this MRsencode
anddecode
. - We could then use these in
namespaces
, without having to duplicate an encoding function there. The proposedpositives_flatten
function enjoys the suffix property that we need. - For the
Countable
instance, we could then useencode xs := positives_flatten (encode <$> xs)
anddecode p := fmap decode <$> positives_unflatten p
.
Does this sound reasonable @jakobbotsch @jung?
Edited by Robbert Krebbers- Have functions
Right, but
positives_flatten
would need to be my version (or similarly efficient) to solve the exponential problem. You decouple namespaces from countable, but we still need to prove the suffix properties for my encoding. I had some problems proving the_eq
one when I tried, but maybe I just didn't stare at it for long enough.Yes, you are entirely right,
positives_flatten
should be your version.Edited by Robbert KrebbersYes, please, but only the
flatten
/unflatten
things, theCountable (list A)
instance should remain incountable.v
.Edited by Robbert Krebbers