I did not see the ordering of the permutations specified in the
benchmark. And, the order should not matter (since both >. and + are
both commutative and associative, and those are what we are using to
combine the values obtained from the different permutations).

However, changing the while. in my bgame1 to whilst. might be
necessary. (This will change the number of iterations when 1 is the
first value in the permutation.)

That said, if the checksum is positive for length two permutations,
that implementation has not fully implemented the benchmark as
documented at 
https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/fannkuchredux.html

For length 2 permutations, there are two permutations to consider: 1 2
and 2 1. These either both require 1 flip or one of them requires 1
flip and the other requires 0 flips. And the benchmark states that odd
flip counts are negative.

FYI,

--
Raul



On Mon, Sep 6, 2021 at 12:55 PM Jan-Pieter Jacobs
<[email protected]> wrote:
>
> Hi Raul,
>
> The output produced by the python version is:
> Pfannkuchen(2) = 1
> 2
> Pfannkuchen(3) = 2
> 4
> Pfannkuchen(4) = 4
> 11
> Pfannkuchen(5) = 7
> 49
> Pfannkuchen(6) = 10
> 228
> Pfannkuchen(7) = 16
>
> with the bare numbers being the checksums, so it seems there's something
> off with the checksums.
>
> Note that the permutations are not in the order A. produces them for (i.e.
> (i.!n)A. i. n). You can get the order used by using a negative number as
> input to either the J or python script I provided.
>
> Jan-Pieter
>
> On Mon, Sep 6, 2021, 17:00 Raul Miller <[email protected]> wrote:
>
> > I am not quite sure that I have implemented this properly (I didn't
> > see any example results to check against), but I think that this
> > should be close to what that benchmark asks for:
> >
> > bgame1=:{{
> >   P=. y
> >   N=. 0
> >   while. 1~:{.P do.
> >     N=. N+1
> >     F=. {.P
> >     P=. (|.F{.P) (i.F)} P
> >   end.
> >   N
> > }}
> >
> > bgame=:{{
> >   P=. i.y
> >   CHK=.MAX=. 0
> >   for_J. i.!y do.
> >     MAX=.MAX>.N=. bgame1 1+J A. P
> >     CHK=. CHK+N*_1^2|N
> >   end.
> >   MAX,CHK
> > }}
> >
> >   bgame 7
> > 16 _108
> >    timespacex 'bgame 7'
> > 0.016073 69408
> >
> > If my result here seems to be correct, implementing a "parallel"
> > version which spins up multiple J instances should be relatively
> > straightforward.
> >
> > I hope this helps,
> >
> > --
> > Raul
> >
> > On Mon, Sep 6, 2021 at 9:49 AM Jan-Pieter Jacobs
> > <[email protected]> wrote:
> > >
> > > Hi,
> > >
> > > I converted one of the BenchmarkGame problem's python solution (
> > >
> > https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/fannkuchredux.html
> > )
> > > to J.
> > > I just transliterated the Python solution (including all the stinking
> > > loops, ugly workarounds for generators etc), sticking to the original as
> > > much as possible, so I am sure a faster solution must exist in J, and I
> > > also did not implement the parallel part of the python solution once
> > > arguments get large: this solution works till permutations of length 8.
> > > This is mainly because I wrote this on my phone and neither J's nor
> > > Python's parallelism is supported on my OS.
> > >
> > > The scripts used are in attachment (strip the .txt from the names)
> > >
> > > Results (abbreviated output; ran in powershell on Windows 10 on an Intel
> > > core i7-8665U):
> > >
> > > PS C:\Users\myuser\j903-user\temp> Measure-Command { For($i=0; $i -lt
> > 100;
> > > $i++) {..\..\j903\bin\jconsole.exe fannkuch-redux_noai.ijs 8}}
> > >
> > > TotalMilliseconds : 53978,1287
> > >
> > > PS C:\Users\myuser\j903-user\temp> Measure-Command { For($i=0; $i -lt
> > 100;
> > > $i++) {python fannkuch-redux.py 8}}
> > >
> > > TotalMilliseconds : 50086,8826
> > >
> > > PS C:\Users\myuser\j903-user\temp> python --version
> > > Python 3.8.3
> > >
> > > PS C:\Users\myuser\j903-user\temp> ..\..\j903\bin\jconsole.exe -js 'exit
> > 0:
> > > echo JVERSION'
> > > Engine: j903/j64avx2/windows
> > > Beta-o: commercial/2021-08-24T18:57:03
> > > Library: 9.03.06
> > > Platform: Win 64
> > > Installer: J903 install
> > > InstallPath: c:/users/myuser/j903
> > > Contact: www.jsoftware.com
> > >
> > >    100 * 53978.1287 % 50086.8826
> > > 107.769
> > >
> > > Jconsole takes 7.8% longer than Python averaged over 100 runs.
> > >
> > > Which is quite good, I think, when compared with j903-beta a (most recent
> > > available for my phone, Android 32 (armeabi-v7a)) and python 3.9.6; there
> > > 50 runs of J took 2m19.879s vs. python 0m49.456s.
> > >
> > > That is, J takes 182.8% longer than Python, averaged over 50 runs!
> > >
> > > I'm also curious to see how the best J solution ranks compared to the
> > > above, as well as the paralnel version.
> > >
> > >
> > > Best regards,
> > >
> > > Jan-Pieter
> > >
> > > On Sun, Aug 29, 2021, 04:59 Henry Rich <[email protected]> wrote:
> > >
> > > > In beta-o I have rewritten the parser one more time.  I don't see how
> > it
> > > > can get much faster.  In a weakly-typed language like J there is only
> > so
> > > > much analysis that can be done before executing a sentence.  I wonder
> > > > how J performs compared to other popular languages, especially Python
> > > > which is what the cool kids are using.  If anyone is willing to do the
> > > > comparison, I'd be obliged.
> > > >
> > > > I am thinking of measuring the execution time of a simple program, one
> > > > that does scalar-only operations so we are focusing on the parser.  A
> > > > sample J program would be:
> > > >
> > > > v =: {{ totl =. 0 for_i. y do. totl =. totl + i * i_index end. totl }}
> > > > 10 (6!:2) 'v a' [ a =. i. 1e6
> > > >
> > > > Large improvement would require heroic intervention: parsing & caching
> > > > sentences on the fly &  watching assignments to make sure the cached
> > > > parse is valid.  I would rather avoid that.
> > > >
> > > > Henry Rich
> > > >
> > > > --
> > > > This email has been checked for viruses by AVG.
> > > > https://www.avg.com
> > > >
> > > > ----------------------------------------------------------------------
> > > > 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

Reply via email to