[r-t] delta based transposition for blue line generation

Alan Burlison alan.burlison at gmail.com
Sat Jun 11 20:56:01 UTC 2016


On 11 June 2016 at 21:05, Mark Davies <mark at snowtiger.net> wrote:

> I like the delta representation, Alan. It's a useful way of dealing with
> general permutations as well as standard and jump changes. I guess it would
> be nice to see it manifested as a Scala class rather than simply a Seq[Int]
> though. In my code I use a Perm class for this. The return signature of your
> expandPart method would then be more pleasant:
>
>         def expandPart(pn: String): Seq[Perm] = ...

Yeah that would be better - it was thrown together as an experiment
more than anything else and could definitely do with a bit of buffing
:-)

> Also I wonder whether the bowels of your parsing code could be made simpler
> by adding -1 and "stage" to the sequence of place notation digits before
> generating the deltas. You might not need the special cases for head and
> last then. Something like:
>
>         var p = -1 +: c.toSeq.map(CCBRToPlace) :+ stage
>         p.sliding(2).flatMap(...)

Yes, I did think about that as an alternative originally but the first
version of the guts were simpler and missed code for one of the edge
cases, when I fixed that I just fixed it and didn't revisit the 'fake'
head/tail option.

> Actually you might be able to get rid of the special case for "-" this way,
> too. You'd need to CCBRToPlace to return a sequence of results; normally one
> item, but nothing for "-", and use a flatMap to coelesce.

Yes you could, but I think that probably just moves the special case
into CCBRToPlace, which I use elsewhere as well.

> Of course to create the Perm instance, instead of Seq[Int], you'd need a
> suitable constructor / companion object apply():
>
>         Perm( p.sliding(2).flatMap(...) )

Yes. I have an equivalent of the Perm class already, which I called
Change as it seemed to fit common ringing. I haven't got round to
fitting it into the parsing code yet.

> Finally, I think I would also pull out helper methods for the string splits
> in the outer for loop, and also maybe the partial function (cases) creating
> the deltas. You'd end up with something simpler and maybe easier to read:
>
>      def expandPart(pn: String): Seq[Perm] = {
>        for (c <- splitPN(pn)) yield {
>           var p = -1 +: c.toSeq.flatMap(CCBRToPlace) :+ stage
>           Perm( p.sliding(2).flatMap(makeDelta) )
>        }
>      }

Simpler? Where's the fun in that? ;-)

Yes, I'm absolutely sure it could be improved. The other issue is that
it only really copes with the PN that's used on methods.ringing.org
and could do with extending to cope with other variants as well.

> Other than that minor refactor (err... which probably needs debugging!) I
> like the code and the concept.

Thanks :-) If there's any interest I'm happy to sand off some of the
rough edges and put it on a repo somewhere. I took some inspiration
from the C++ Ringing Library and there's a couple of extra methods to
find 'jump' changes, cycles etc, but I didn't get very far with that
aspect - the cycles code is distressingly imperative, for example.

--
Alan Burlison
--




More information about the ringing-theory mailing list