Hmm...
https://en.wikipedia.org/wiki/Lehmer_code#Encoding_and_decoding
lehmercode=: ({., $:^:(1<#@])@(}. - }. > {.))"1
lehmerdecode=: ([,]+<:)/"1
lehmercode 1 5 0 6 3 4 2
1 4 0 3 1 1 0
lehmerdecode 1 4 0 3 1 1 0
1 5 0 6 3 4 2
lehmercode (A.&i.~ !)3
0 0 0
0 1 0
1 0 0
1 1 0
2 0 0
2 1 0
And,
(1+i.-3) #. lehmercode (A.&i.~ !)3
0 1 2 3 4 5
Or, it looks like A. organizes its results in "ascending lehmercode order".
So, I guess you are saying that to compute the A. left argument for a
given permutation, we could use:
perm2A=: (1 + i.@-@#) #. lehmercode
Testing that, it seems to work:
1299721 A. i.10
3 6 1 9 2 0 4 5 8 7
perm2A 3 6 1 9 2 0 4 5 8 7
1299721
I was lost on this issue until you started dropping hints here.
But... that's what the A. monad already does:
A. 3 6 1 9 2 0 4 5 8 7
1299721
So I guess I am still feeling a bit lost.
Any more hints you can throw out might jog my brain into gear...
Thanks,
--
Raul
On Mon, Mar 21, 2022 at 12:31 AM Ian Clark <[email protected]> wrote:
>
> Today I discovered from my archives that I'd revisited my old 1970 work in
> 2018 and got much further with it than I recall. The code I wrote back then
> has verbs which convert between (A.) and my 1970 treatment, as well as
> dissecting my algorithm in an explainable way, which doesn't invoke too
> much fancy group theory.
>
> It'll take me a few days to decipher what I did back then and compare it
> with the Wikipedia articles and Norman Thomson's Perming and Combing
> article in "Fifty Shades". I want to convince myself that I've simply
> re-invented the Lehmer wheel, in which case I'll cheerfully abandon my
> approach in favor of published descriptions based on Lehmer codes. I'll
> also consider if your (A.&i.&.|.~ !) sheds light on the problem of an
> efficient J implementation. The pattern it generates doesn't ring a bell
> with me, I fear.
>
> On Sun, 20 Mar 2022 at 23:19, Raul Miller <[email protected]> wrote:
>
> > After thinking about this, I am wondering whether this would match
> > your concept of Lehmer codes?
> >
> > (A.&i.&.|.~ !) 4
> > 3 2 1 0
> > 3 2 0 1
> > 3 1 2 0
> > 3 1 0 2
> > 3 0 2 1
> > 3 0 1 2
> > 2 3 1 0
> > 2 3 0 1
> > 2 1 3 0
> > 2 1 0 3
> > 2 0 3 1
> > 2 0 1 3
> > 1 3 2 0
> > 1 3 0 2
> > 1 2 3 0
> > 1 2 0 3
> > 1 0 3 2
> > 1 0 2 3
> > 0 3 2 1
> > 0 3 1 2
> > 0 2 3 1
> > 0 2 1 3
> > 0 1 3 2
> > 0 1 2 3
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Sun, Mar 20, 2022 at 7:34 AM Ian Clark <[email protected]> wrote:
> > >
> > > Raul wrote:
> > >
> > > > someone with a stronger background in permutations might be able to
> > describe
> > > some useful techniques.
> > >
> > >
> > > Ascending Radix numerals (aka the Factorial Number System) offer a
> > natural
> > > way of putting permutations in 1-1 correspondence with the positive
> > > integers. These articles explain how:
> > >
> > > [1] https://en.wikipedia.org/wiki/Permutation#Numbering_permutations
> > >
> > > [2] https://en.wikipedia.org/wiki/Lehmer_code
> > >
> > > [3] https://en.wikipedia.org/wiki/Factorial_number_system
> > >
> > >
> > > Let's define a permutation on 4 points to be equivalent to a
> > corresponding
> > > permutation on 5 points which fixes the 5th point.
> > >
> > > This is roughly analogous to saying the decimal numerals 3276 and 03276
> > > (say) are "equivalent".
> > >
> > > EXAMPLE: these permutations are equivalent:
> > >
> > > 3 2 1 0
> > >
> > > 3 2 1 0 4
> > >
> > > 3 2 1 0 4 5
> > >
> > > 3 2 1 0 4 5 6
> > >
> > > etc.
> > >
> > >
> > > Essentially (A.) follows the Lehmer approach, but does it back to front.
> > > Lehmer gives the same integer for two "equivalent" permutations, whereas
> > > (A.) doesn't…
> > >
> > >
> > > A. 3 2 1 0
> > >
> > > 23
> > >
> > > A. 3 2 1 0 4
> > >
> > > 86
> > >
> > >
> > > For this reason I feel the methods of [1], [2] and [3] offer a
> > > better-behaved way of enumerating permutations than (A.).
> > >
> > >
> > > Back in 1970 I worked on fast computer algorithms to do this on a
> > Burroughs
> > > B6700 and eventually stumbled on the Lehmer code myself, or something
> > very
> > > much like it, which I implemented in Algol. Alas the code is no longer
> > > extant, but I still have the manual algorithm. I'm going to dust off this
> > > old work, get my algorithm working as an explicit verb and derive a tacit
> > > implementation. But someone with a fresher brain could doubtless take [2]
> > > and implement Lehmer codes efficiently in J far quicker than I shall.
> > >
> > > On Mon, 14 Mar 2022 at 18:37, Raul Miller <[email protected]> wrote:
> > >
> > > > Watching this, I got to thinking about your anagram index of the "by
> > suit"
> > > > deck.
> > > >
> > > > We know that an anagram index is in some sense based on the factorial
> > > > of the length of the sequence.
> > > >
> > > > But, also, we can use the indices of the sequence as a base for the
> > > > anagram index, if we toss the 0 and 1. For example:
> > > >
> > > > ((i.!4)A.i.4),._,.(_2}.i.-4)#:i.!4
> > > > 0 1 2 3 _ 0 0
> > > > 0 1 3 2 _ 0 1
> > > > 0 2 1 3 _ 1 0
> > > > 0 2 3 1 _ 1 1
> > > > 0 3 1 2 _ 2 0
> > > > 0 3 2 1 _ 2 1
> > > > 1 0 2 3 _ 0 0
> > > > 1 0 3 2 _ 0 1
> > > > 1 2 0 3 _ 1 0
> > > > 1 2 3 0 _ 1 1
> > > > 1 3 0 2 _ 2 0
> > > > 1 3 2 0 _ 2 1
> > > > 2 0 1 3 _ 0 0
> > > > 2 0 3 1 _ 0 1
> > > > 2 1 0 3 _ 1 0
> > > > 2 1 3 0 _ 1 1
> > > > 2 3 0 1 _ 2 0
> > > > 2 3 1 0 _ 2 1
> > > > 3 0 1 2 _ 0 0
> > > > 3 0 2 1 _ 0 1
> > > > 3 1 0 2 _ 1 0
> > > > 3 1 2 0 _ 1 1
> > > > 3 2 0 1 _ 2 0
> > > > 3 2 1 0 _ 2 1
> > > >
> > > > We can see here that the swaps in the permutations (the numbers on the
> > > > left) correspond in some way to the "anagram index in base 0 1-.~i.-#"
> > > > (the numbers on the right). Here, I guess we ignore the leftmost and
> > > > rightmost values in the permutation, since they are fully determined,
> > > > in the sense of swaps, by the other values.
> > > >
> > > > So, now we have a way of looking at the anagram index of the
> > > > transposed deck of cards:
> > > >
> > > > (_2}.i.-52)#:A.,|:i.4 13
> > > > 12 24 36 0 11 22 33 0 10 20 30 0 9 18 27 0 8 16 24 0 7 14 21 0 6 12 18
> > > > 0 5 10 15 0 4 8 12 0 3 6 9 0 2 4 6 0 1 2 3 0 0 0
> > > >
> > > > At first, the pattern there doesn't really leap out at us. But, after
> > > > a short look, it's obvious that these numbers occur in sequences of
> > > > four. So:
> > > >
> > > > _4]\(_2}.i.-52)#:A.,|:i.4 13
> > > > 12 24 36 0
> > > > 11 22 33 0
> > > > 10 20 30 0
> > > > 9 18 27 0
> > > > 8 16 24 0
> > > > 7 14 21 0
> > > > 6 12 18 0
> > > > 5 10 15 0
> > > > 4 8 12 0
> > > > 3 6 9 0
> > > > 2 4 6 0
> > > > 1 2 3 0
> > > >
> > > > In other words, it's:
> > > >
> > > > _2}.,(i._13) */ 1|.i.4
> > > > 12 24 36 0 11 22 33 0 10 20 30 0 9 18 27 0 8 16 24 0 7 14 21 0 6 12 18
> > > > 0 5 10 15 0 4 8 12 0 3 6 9 0 2 4 6 0 1 2 3 0 0 0
> > > >
> > > > Now... I should probably do some more experiments here, to see if I
> > > > could form a more general insight into how we might compute an
> > > > arbitrary anagram index. But there's definitely a pattern here, and
> > > > someone with a stronger background in permutations might be able to
> > > > describe some useful techniques.
> > > >
> > > > Thanks,
> > > >
> > > > --
> > > > Raul
> > > >
> > > > On Sun, Mar 13, 2022 at 5:22 PM Michal Wallace <
> > [email protected]>
> > > > wrote:
> > > > >
> > > > > I made a short beginner video about dealing cards, using ? and A. :
> > > > >
> > > > > https://www.youtube.com/watch?v=eXGKK8BkCkg
> > > > >
> > ----------------------------------------------------------------------
> > > > > For information about J forums see
> > http://www.jsoftware.com/forums.htm
> > > > ----------------------------------------------------------------------
> > > > For information about J forums see http://www.jsoftware.com/forums.htm
> > > >
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm