Re: [Jprogramming] Partitions

2017-11-30 Thread 'Mike Day' via Programming
I've continued tinkering with ways to derive subsets of Restricted 
Generation
Functions equivalent to,  ie capable of mapping to,  set partitions as 
discussed

at length a few weeks ago.

The best I've found recently in dealing with x choices out of n elements 
generates
RGFs as columns in a character matrix with n rows and as many columns as 
required

to exhaust all possibilities.

A row i then corresponds to the i-th element of each of the RGFs.

It's faster than my previous offering,  uses somewhat more space,  but 
still benefits

from using a character set.

Rather than using x comb n as in my previous posts,  it starts with a 
2x2 table:

   0 0
   0 1
and adds n-2 rows,  in an explicit loop.  I haven't explored the 
possibility yet,

but someone might enjoy turning the loop into a verb to the power n-2 (!)

Here's a snapshot of each stage for the (4,6) problem:

   t2bnoc/4 6    NB. Top to Bottom NOt using Comb
+--+
|00|
|01|
+--+
+-+
|0|
|00111|
|01012|
+-+
+--+
|00|
|11|
|0111000111|
|10120120120123|
+--+
+---+
|000|
|000|
|0110011|
|1010101|
|22201232201232201230123012301230123|
+---+
+-+
|0|
|00111|
|01012|
|1012220122201222000111222|
|2220122201222012012012012|
|33012330123301201201201230123012301230123|
+-+

The linear output could be modified to a tree-form.
eg the second stage listed above,  the one with 3 rows and 5 columns
could be regarded as:

 0
    / \
   /   \
  0 1
 / \   /|\
0   1 0 1 2

which might save some space,  but would be less useful for deriving
the set-partitions that this thread has been discussing.

Here's the code - below my sign-off.
It's more verbose than it could be, partly to allow the same special
case treatment of edge cases as before.

Beware line-wrapping - the longest line is nearly 100 characters wide.
Enjoy!

Mike




NB. Longest line:
NB. 
=


NB. "Top to Bottom,  NOt using Comb"

t2bnoc  =: 3 : 0
:
k    =. <: x
n    =. y
a    =. x{. a. |.~ a. i. '0'   NB. symbol list - arbitrary,  but 
'012...' here

if. x > n do. NB. special-case impossible partitions
   |:' '$~ 0, n  return.
elseif. x = 1 do. NB. special-case 1-partition
   ,. n#{.a    return.
elseif. x = 2 do. NB. special-case 2-partition
   |:a{~ (n#2) #: }. i. 2 ^ n-1   return.
elseif. x = n-1 do.   NB. special-case (n-1)-partition
   r =. 1 + i.x
   |: r ((#-)@[ |."0 1 ;@:((a{~i.)each@[),. # ) r |."0 1 x # ,: a
   return.
elseif. x = n do. NB. special-case n-partition
   ,. n{.a return.
end.
min  =. (-n) {. i.x  NB. lowest possible entry in each row, if not 
present earlier in column
out  =. a{~ 0 0,: 0 1    NB. output array - optionally a character array 
here

max  =. 0 1  NB. highest element, so far, in each column
ins  =. 0    NB. preset for max definition below
nins =. 1    NB. number of items to replace each single 
entry in a row
for_row. 2}.i.n do.   NB. append rows - turn this into a 
verb to power n-2 ???
   max  =. ins >. nins# max   NB. update max vector for next row - 
reason for preset of max and ins above
   minr =. row{min    NB. number which must appear in this 
row if not before
   doins=. minr < maxp1 =. >: max NB. whether to insert a number of 
alternative vals,  or just a singleton
   hi   =. (doins * k <. maxp1) + lo =. minr * -. doins NB. bounds for 
new values
   nins =. hi >:@:- lo    NB. number of vals to insert for each 
column
   ins  =. ((] # lo + [: -@(+/\) 0 , }:) + [: i. +/) nins    NB. new 
row,  as integers

NB. equivalent to,  but faster than,  ins =. ;lo (+ i.) each nins
   NB. eg if lo = 0 1 2 1,  nins = 2 1 2 3,  we get ; 0 1; 1; 2 3; 
1 2 3 [not necessarily realistic!]
   out  =. (ins{a) ,~ nins#"1 out NB. append new row string to expanded 
output table

end.
)



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-23 Thread Raul Miller
Hmm.. and playing with this idea shows that I'm not on quite on the
right track for the n-2 case.

   +/@, (i.3)=  -~/~^:2 i.3
18
   #3 parMD 5
25

I can get away with bits for the n-1 case, but I need to track two
independent free positions for the n-2 case.

-- 
Raul

On Thu, Nov 23, 2017 at 5:36 AM, 'Mike Day' via Programming
 wrote:
> It's pretty efficient though.
>
> Here's the result of a crude 13 : tacitisation,  resulting from replacing
> all (i.x) by y, and assuming the single argument is n :
> RDM1 =: (([: |. >:/~) #&(,/) ] + (1 j. ] =/ -~/~) #"1"_1 -~/~ ) @: i. @
> <:
>
> |: RDM1 4
> 0 0 0 0 0 0
> 0 1 1 1 1 1
> 1 0 2 1 2 2
> 2 2 0 2 1 2
>
>ts'RDM1 10'
> 0.000420082 216064
>ts'rgfMD/9 10'
> 0.00145139 27264
>
> The main overhead in mine for k=n-1 appears to be in the
> makeinsert routine,  even with a somewhat more efficient
> use of it than in the listing I posted yesterday.I might
> special-case it...
>
> Thanks for using 1j1 in the left arg of # - if I'd ever seen
> that, I'd certainly forgotten it!  V useful.
>
> Perhaps best to leave k=3, n-2, etc, to the existing codes.
>
> I phorgot phumbs... phrom my laptop,
>
> Mike
>
>
>
> On 23/11/2017 09:59, Raul Miller wrote:
>>
>> Well.. hmm...
>>
>> Here's the heart of that k=n-1 expression:
>>
>> (i.x)=/-~/~i.x)
>>
>> For example:
>> (i.4)=/-~/~i.4
>> 1 0 0 0
>> 0 1 0 0
>> 0 0 1 0
>> 0 0 0 1
>>
>> 0 1 0 0
>> 0 0 1 0
>> 0 0 0 1
>> 0 0 0 0
>>
>> 0 0 1 0
>> 0 0 0 1
>> 0 0 0 0
>> 0 0 0 0
>>
>> 0 0 0 1
>> 0 0 0 0
>> 0 0 0 0
>> 0 0 0 0
>>
>> (As you can see, it's not incredibly efficient. It might make sense to
>> transform one of those dimensions into index values to gain an order
>> of magnitude in compactness. You do not have to worry much about index
>> values all 0 rows because those get compressed out later. But the
>> problem you would have to solve is: what do you replace the rightmost
>> # operation with, when working with indices? It will probably be
>> something like an index and ravel and then another transformation to
>> get the partition control list. On the positive side, this should
>> eliminate the need to subtrace/add the rows - which is how I am
>> inserting non-zero values into the final rows with that # operation.)
>>
>> Anyways...
>>
>> In principle you could use a similar expression with a rank-4 bit
>> array which a triangular plane slicing it in a similar fashion (or,
>> ok, maybe map that to a rank 3 array of indices). But of course, you
>> lose an additional order of magnitude in efficiency from the
>> additional array rank - though sparse arrays might help here,
>> depending on how the expressions work. But I've not thought up any
>> good expressions for constructing that array.
>>
>> Thanks,
>>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-23 Thread 'Mike Day' via Programming

It's pretty efficient though.

Here's the result of a crude 13 : tacitisation,  resulting from replacing
all (i.x) by y, and assuming the single argument is n :
    RDM1 =: (([: |. >:/~) #&(,/) ] + (1 j. ] =/ -~/~) #"1"_1 -~/~ ) @: 
i. @ <:


    |: RDM1 4
0 0 0 0 0 0
0 1 1 1 1 1
1 0 2 1 2 2
2 2 0 2 1 2

   ts'RDM1 10'
0.000420082 216064
   ts'rgfMD/9 10'
0.00145139 27264

The main overhead in mine for k=n-1 appears to be in the
makeinsert routine,  even with a somewhat more efficient
use of it than in the listing I posted yesterday.I might
special-case it...

Thanks for using 1j1 in the left arg of # - if I'd ever seen
that, I'd certainly forgotten it!  V useful.

Perhaps best to leave k=3, n-2, etc, to the existing codes.

I phorgot phumbs... phrom my laptop,

Mike


On 23/11/2017 09:59, Raul Miller wrote:

Well.. hmm...

Here's the heart of that k=n-1 expression:

(i.x)=/-~/~i.x)

For example:
(i.4)=/-~/~i.4
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 0

0 0 1 0
0 0 0 1
0 0 0 0
0 0 0 0

0 0 0 1
0 0 0 0
0 0 0 0
0 0 0 0

(As you can see, it's not incredibly efficient. It might make sense to
transform one of those dimensions into index values to gain an order
of magnitude in compactness. You do not have to worry much about index
values all 0 rows because those get compressed out later. But the
problem you would have to solve is: what do you replace the rightmost
# operation with, when working with indices? It will probably be
something like an index and ravel and then another transformation to
get the partition control list. On the positive side, this should
eliminate the need to subtrace/add the rows - which is how I am
inserting non-zero values into the final rows with that # operation.)

Anyways...

In principle you could use a similar expression with a rank-4 bit
array which a triangular plane slicing it in a similar fashion (or,
ok, maybe map that to a rank 3 array of indices). But of course, you
lose an additional order of magnitude in efficiency from the
additional array rank - though sparse arrays might help here,
depending on how the expressions work. But I've not thought up any
good expressions for constructing that array.

Thanks,




---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-23 Thread Raul Miller
Well.. hmm...

Here's the heart of that k=n-1 expression:

   (i.x)=/-~/~i.x)

For example:
   (i.4)=/-~/~i.4
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 0

0 0 1 0
0 0 0 1
0 0 0 0
0 0 0 0

0 0 0 1
0 0 0 0
0 0 0 0
0 0 0 0

(As you can see, it's not incredibly efficient. It might make sense to
transform one of those dimensions into index values to gain an order
of magnitude in compactness. You do not have to worry much about index
values all 0 rows because those get compressed out later. But the
problem you would have to solve is: what do you replace the rightmost
# operation with, when working with indices? It will probably be
something like an index and ravel and then another transformation to
get the partition control list. On the positive side, this should
eliminate the need to subtrace/add the rows - which is how I am
inserting non-zero values into the final rows with that # operation.)

Anyways...

In principle you could use a similar expression with a rank-4 bit
array which a triangular plane slicing it in a similar fashion (or,
ok, maybe map that to a rank 3 array of indices). But of course, you
lose an additional order of magnitude in efficiency from the
additional array rank - though sparse arrays might help here,
depending on how the expressions work. But I've not thought up any
good expressions for constructing that array.

Thanks,

-- 
Raul


On Thu, Nov 23, 2017 at 3:45 AM, 'Mike Day' via Programming
 wrote:
> Wow - more than I could manage with my phone and phingers!
>
> Or desktop!
>
> So have we got closed forms for k=3,  k=n-2?
>
> M
>
>
> On 23/11/2017 02:49, Raul Miller wrote:
>>
>> Hmm... right - it corresponds to an upper (or lower) triangular matrix,
>> not
>> the identity matrix. So...
>>
>> (|.>:/~i.x)#&(,/)(i.x)+(1 j.(i.x)=/-~/~i.x)#"1"_1-~/~i.x
>>
>> In other words, once again, oops. (But at least, this time, I tested the
>> expression. Though I know it could be refactored to be more concise-- but
>> the phone UI is too clumsy for that...)
>>
>> Thanks,
>>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-23 Thread 'Mike Day' via Programming

Wow - more than I could manage with my phone and phingers!

Or desktop!

So have we got closed forms for k=3,  k=n-2?

M


On 23/11/2017 02:49, Raul Miller wrote:

Hmm... right - it corresponds to an upper (or lower) triangular matrix, not
the identity matrix. So...

(|.>:/~i.x)#&(,/)(i.x)+(1 j.(i.x)=/-~/~i.x)#"1"_1-~/~i.x

In other words, once again, oops. (But at least, this time, I tested the
expression. Though I know it could be refactored to be more concise-- but
the phone UI is too clumsy for that...)

Thanks,




---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-22 Thread Raul Miller
Hmm... right - it corresponds to an upper (or lower) triangular matrix, not
the identity matrix. So...

(|.>:/~i.x)#&(,/)(i.x)+(1 j.(i.x)=/-~/~i.x)#"1"_1-~/~i.x

In other words, once again, oops. (But at least, this time, I tested the
expression. Though I know it could be refactored to be more concise-- but
the phone UI is too clumsy for that...)

Thanks,

-- 
Raul

On Wednesday, November 22, 2017, 'Mike Day' via Programming <
programm...@jsoftware.com> wrote:

> I was going to say that that’s a nice special case and I hadn’t quite got
> there!
>
> But it misses several cases,  eg
> 01203,  01023 and so on.  There are 10 partitions in all.
>
> What a pity,
>
> Mike
>
> Please reply to mike_liz@tiscali.co.uk .
> Sent from my iPad
>
> > On 22 Nov 2017, at 22:51, Raul Miller  > wrote:
> >
> > Oops, sorry, yes.
> >
> > I was expecting exponential growth to make the results unrepresentable.
> But
> > that only happens at the low end (of the x values).
> >
> > I guess maybe just set a=:u:i.48+n
> >
> > That said, note that when x=y-1 you can use a result of the form
> > (1+=i.x)#"1 i.x
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Wednesday, November 22, 2017, 'Mike Day' via Programming <
> > programm...@jsoftware.com > wrote:
> >
> >> How’s that, Raul?
> >>
> >> Wouldn’t ParXXX / 300 400 (Heaven forbid!) need 300 things,  whether
> >> integers,  symbols or what you will?
> >>
> >> What have I misunderstood?
> >>
> >> Cheers,
> >>
> >> Mike
> >>
> >>
> >> Please reply to mike_liz@tiscali.co.uk 
> .
> >> Sent from my iPad
> >>
> >>> On 22 Nov 2017, at 21:56, Raul Miller  
> >> > wrote:
> >>>
> >>> The only case where you need more than 256 symbols is when the left
> >>> arg matches the right arg.
> >>>
> >>> For that case, it's reasonable to produce the result u:i.1,y
> >>>
> >>> Thanks,
> >>>
> >>> --
> >>> Raul
> >>>
> >>> On Wed, Nov 22, 2017 at 2:05 PM, 'Mike Day' via Programming
> >>>  > wrote:
>  Here's another shot at a non-recursive constructive approach to
> >> generating
>  RGFs.
>  It continues to use characters to store and represent the RGFs.  It
> >> would
>  need
>  reworking if there were more than 256 digits/symbols, though I think
> >> we'd
>  hit other
>  problems before needing to worry about representation in such cases.
> 
>  Performance is reasonable if not outstanding,  similar to or a bit
> >> better
>  than parMD.
> 
>  I think it's a bit easier to understand than my earlier effort.  I
> hope
> >> the
>  comments in
>  the following script help.
> 
>  NB. Please take care with line-wrapping...
> 
>  makeinsert =: 3 : 0   M.   NB. to memoise or not to memoise?
>  a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
> >> here
>  'd g' =. 1 0 + y
>  a{~ d #.inv i. d^g
>  )
> 
>  join =: 3 : 0
>  :
>  nx =. #x [ ny =. #y
>  (ny#x),. (,y)$~ (nx,1) * $y
>  )
> 
>  NB. join =: ,/@(,"1/)
> 
>  NB. Generate all RGFs, each using at least one of each symbol/digit
> >> 0123...k
>  representing
>  NB.  (k+1)partitions
>  NB.  Method:  let a "basic" RGF for 4 symbols be, eg, 0001002000300,
>  NB.   ie having exactly one of each non-zero
>  NB.  This example has gaps of size 2 3 and 2 again between digits 1&2,
> >> 2&3,
>  and 3&[end] respectively
>  NB.   it is the template for many derived RGFs.
>  NB.   A derived RGF is based on a basic RGF with arbitrary
> >> digits
>  replacing zeros in the gaps,
>  NB.   subject to added digits not exceeding the left hand
> >> boundary
>  of the gap.
>  NB.   eg,  the sequence 20003 may have some or all of the 3
> >> zeros
>  replaced by 1 or 2 but not 3
> 
>  NB. 3 helper functions: x join y : x ,/@(,"1/) y,  but seems better in
>  explicit code!?
>  NB. - concatenates all rows of x with all rows of
> y
> 
>  NB. makeinsert d,g : form a table with g columns
>  NB.  of all possible perms of 0 1
> 2
> >> ...
>  d
>  NB.  to yield all suitable
> >> replacements
>  for g zeros
> 
>  NB. comb - as in stats.ijs,  or otherwise,
> >> according to
>  taste!
> 
>  require'stats'
> 
>  rgfMD =: 3 : 0
>  :
>  k=. <: x
>  n=. y
>  a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
> >> here
>  if. x > n do. NB. special-case impossible partitions
>   ' '$~ 0, n  return.
>  elseif. x = 1 do. NB. special-case 1-partition
>   ,: n#{.areturn.
>  elseif. x = 2 do. NB. special-case 2-partition
>   a{~ (n#2) #: }. i. 2 ^ n-1   return.
>  elseif. x = n do. NB. special-case n-partition
>   ,: n{.a return.
>  end.
>  c=. >: k com

Re: [Jprogramming] Partitions

2017-11-22 Thread 'Mike Day' via Programming
I was going to say that that’s a nice special case and I hadn’t quite got 
there!  

But it misses several cases,  eg 
01203,  01023 and so on.  There are 10 partitions in all.

What a pity,

Mike

Please reply to mike_liz@tiscali.co.uk.  
Sent from my iPad

> On 22 Nov 2017, at 22:51, Raul Miller  wrote:
> 
> Oops, sorry, yes.
> 
> I was expecting exponential growth to make the results unrepresentable. But
> that only happens at the low end (of the x values).
> 
> I guess maybe just set a=:u:i.48+n
> 
> That said, note that when x=y-1 you can use a result of the form
> (1+=i.x)#"1 i.x
> 
> Thanks,
> 
> -- 
> Raul
> 
> On Wednesday, November 22, 2017, 'Mike Day' via Programming <
> programm...@jsoftware.com> wrote:
> 
>> How’s that, Raul?
>> 
>> Wouldn’t ParXXX / 300 400 (Heaven forbid!) need 300 things,  whether
>> integers,  symbols or what you will?
>> 
>> What have I misunderstood?
>> 
>> Cheers,
>> 
>> Mike
>> 
>> 
>> Please reply to mike_liz@tiscali.co.uk .
>> Sent from my iPad
>> 
>>> On 22 Nov 2017, at 21:56, Raul Miller > > wrote:
>>> 
>>> The only case where you need more than 256 symbols is when the left
>>> arg matches the right arg.
>>> 
>>> For that case, it's reasonable to produce the result u:i.1,y
>>> 
>>> Thanks,
>>> 
>>> --
>>> Raul
>>> 
>>> On Wed, Nov 22, 2017 at 2:05 PM, 'Mike Day' via Programming
>>> > wrote:
 Here's another shot at a non-recursive constructive approach to
>> generating
 RGFs.
 It continues to use characters to store and represent the RGFs.  It
>> would
 need
 reworking if there were more than 256 digits/symbols, though I think
>> we'd
 hit other
 problems before needing to worry about representation in such cases.
 
 Performance is reasonable if not outstanding,  similar to or a bit
>> better
 than parMD.
 
 I think it's a bit easier to understand than my earlier effort.  I hope
>> the
 comments in
 the following script help.
 
 NB. Please take care with line-wrapping...
 
 makeinsert =: 3 : 0   M.   NB. to memoise or not to memoise?
 a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
>> here
 'd g' =. 1 0 + y
 a{~ d #.inv i. d^g
 )
 
 join =: 3 : 0
 :
 nx =. #x [ ny =. #y
 (ny#x),. (,y)$~ (nx,1) * $y
 )
 
 NB. join =: ,/@(,"1/)
 
 NB. Generate all RGFs, each using at least one of each symbol/digit
>> 0123...k
 representing
 NB.  (k+1)partitions
 NB.  Method:  let a "basic" RGF for 4 symbols be, eg, 0001002000300,
 NB.   ie having exactly one of each non-zero
 NB.  This example has gaps of size 2 3 and 2 again between digits 1&2,
>> 2&3,
 and 3&[end] respectively
 NB.   it is the template for many derived RGFs.
 NB.   A derived RGF is based on a basic RGF with arbitrary
>> digits
 replacing zeros in the gaps,
 NB.   subject to added digits not exceeding the left hand
>> boundary
 of the gap.
 NB.   eg,  the sequence 20003 may have some or all of the 3
>> zeros
 replaced by 1 or 2 but not 3
 
 NB. 3 helper functions: x join y : x ,/@(,"1/) y,  but seems better in
 explicit code!?
 NB. - concatenates all rows of x with all rows of y
 
 NB. makeinsert d,g : form a table with g columns
 NB.  of all possible perms of 0 1 2
>> ...
 d
 NB.  to yield all suitable
>> replacements
 for g zeros
 
 NB. comb - as in stats.ijs,  or otherwise,
>> according to
 taste!
 
 require'stats'
 
 rgfMD =: 3 : 0
 :
 k=. <: x
 n=. y
 a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
>> here
 if. x > n do. NB. special-case impossible partitions
  ' '$~ 0, n  return.
 elseif. x = 1 do. NB. special-case 1-partition
  ,: n#{.areturn.
 elseif. x = 2 do. NB. special-case 2-partition
  a{~ (n#2) #: }. i. 2 ^ n-1   return.
 elseif. x = n do. NB. special-case n-partition
  ,: n{.a return.
 end.
 c=. >: k comb <:n NB. possible start cols for 1 2 ... k
 g=. <: +/\inv"1] c =. c,. n   NB. sizes of gaps between starts of 1
>> 2 3
 ... for each RGF pattern
 a=. a. }.~ a. i. '0'  NB. symbol list - arbitrary,  but '012...'
>> here
 out  =. ' '$~ 0, n
 for_i. i.#c do.   NB. loop for each patterns of start cols
  gi=. i{g
  new   =. 1 0$a NB. defer setting initial zeros
  for_j. }.i.#gi do. NB. loop over non-zero digits
 new=. new,. j{a NB. append next non-zero digit
 gj =. j{ gi NB. size of following gap
 if. gj do.  NB. if size of gap is non-zero, append all
 gap-sized sets of 0 1 ... j
new   =. new join makeinsert j, gj

Re: [Jprogramming] Partitions

2017-11-22 Thread Raul Miller
Oops again, I meant a=:u:48+i.n

I really need to build better posting habits when writing on a phone.

Thanks,

-- 
Raul

On Wednesday, November 22, 2017, Raul Miller  wrote:

> Oops, sorry, yes.
>
> I was expecting exponential growth to make the results unrepresentable.
> But that only happens at the low end (of the x values).
>
> I guess maybe just set a=:u:i.48+n
>
> That said, note that when x=y-1 you can use a result of the form
> (1+=i.x)#"1 i.x
>
> Thanks,
>
> --
> Raul
>
> On Wednesday, November 22, 2017, 'Mike Day' via Programming <
> programm...@jsoftware.com
> > wrote:
>
>> How’s that, Raul?
>>
>> Wouldn’t ParXXX / 300 400 (Heaven forbid!) need 300 things,  whether
>> integers,  symbols or what you will?
>>
>> What have I misunderstood?
>>
>> Cheers,
>>
>> Mike
>>
>>
>> Please reply to mike_liz@tiscali.co.uk.
>> Sent from my iPad
>>
>> > On 22 Nov 2017, at 21:56, Raul Miller  wrote:
>> >
>> > The only case where you need more than 256 symbols is when the left
>> > arg matches the right arg.
>> >
>> > For that case, it's reasonable to produce the result u:i.1,y
>> >
>> > Thanks,
>> >
>> > --
>> > Raul
>> >
>> > On Wed, Nov 22, 2017 at 2:05 PM, 'Mike Day' via Programming
>> >  wrote:
>> >> Here's another shot at a non-recursive constructive approach to
>> generating
>> >> RGFs.
>> >> It continues to use characters to store and represent the RGFs.  It
>> would
>> >> need
>> >> reworking if there were more than 256 digits/symbols, though I think
>> we'd
>> >> hit other
>> >> problems before needing to worry about representation in such cases.
>> >>
>> >> Performance is reasonable if not outstanding,  similar to or a bit
>> better
>> >> than parMD.
>> >>
>> >> I think it's a bit easier to understand than my earlier effort.  I
>> hope the
>> >> comments in
>> >> the following script help.
>> >>
>> >> NB. Please take care with line-wrapping...
>> >>
>> >> makeinsert =: 3 : 0   M.   NB. to memoise or not to memoise?
>> >> a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
>> here
>> >> 'd g' =. 1 0 + y
>> >> a{~ d #.inv i. d^g
>> >> )
>> >>
>> >> join =: 3 : 0
>> >> :
>> >> nx =. #x [ ny =. #y
>> >> (ny#x),. (,y)$~ (nx,1) * $y
>> >> )
>> >>
>> >> NB. join =: ,/@(,"1/)
>> >>
>> >> NB. Generate all RGFs, each using at least one of each symbol/digit
>> 0123...k
>> >> representing
>> >> NB.  (k+1)partitions
>> >> NB.  Method:  let a "basic" RGF for 4 symbols be, eg, 0001002000300,
>> >> NB.   ie having exactly one of each non-zero
>> >> NB.  This example has gaps of size 2 3 and 2 again between digits
>> 1&2,  2&3,
>> >> and 3&[end] respectively
>> >> NB.   it is the template for many derived RGFs.
>> >> NB.   A derived RGF is based on a basic RGF with arbitrary
>> digits
>> >> replacing zeros in the gaps,
>> >> NB.   subject to added digits not exceeding the left hand
>> boundary
>> >> of the gap.
>> >> NB.   eg,  the sequence 20003 may have some or all of the 3
>> zeros
>> >> replaced by 1 or 2 but not 3
>> >>
>> >> NB. 3 helper functions: x join y : x ,/@(,"1/) y,  but seems better in
>> >> explicit code!?
>> >> NB. - concatenates all rows of x with all rows of y
>> >>
>> >> NB. makeinsert d,g : form a table with g columns
>> >> NB.  of all possible perms of 0 1
>> 2 ...
>> >> d
>> >> NB.  to yield all suitable
>> replacements
>> >> for g zeros
>> >>
>> >> NB. comb - as in stats.ijs,  or otherwise,
>> according to
>> >> taste!
>> >>
>> >> require'stats'
>> >>
>> >> rgfMD =: 3 : 0
>> >> :
>> >> k=. <: x
>> >> n=. y
>> >> a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
>> here
>> >> if. x > n do. NB. special-case impossible partitions
>> >>   ' '$~ 0, n  return.
>> >> elseif. x = 1 do. NB. special-case 1-partition
>> >>   ,: n#{.areturn.
>> >> elseif. x = 2 do. NB. special-case 2-partition
>> >>   a{~ (n#2) #: }. i. 2 ^ n-1   return.
>> >> elseif. x = n do. NB. special-case n-partition
>> >>   ,: n{.a return.
>> >> end.
>> >> c=. >: k comb <:n NB. possible start cols for 1 2 ... k
>> >> g=. <: +/\inv"1] c =. c,. n   NB. sizes of gaps between starts of
>> 1 2 3
>> >> ... for each RGF pattern
>> >> a=. a. }.~ a. i. '0'  NB. symbol list - arbitrary,  but '012...'
>> here
>> >> out  =. ' '$~ 0, n
>> >> for_i. i.#c do.   NB. loop for each patterns of start cols
>> >>   gi=. i{g
>> >>   new   =. 1 0$a NB. defer setting initial zeros
>> >>   for_j. }.i.#gi do. NB. loop over non-zero digits
>> >>  new=. new,. j{a NB. append next non-zero digit
>> >>  gj =. j{ gi NB. size of following gap
>> >>  if. gj do.  NB. if size of gap is non-zero, append all
>> >> gap-sized sets of 0 1 ... j
>> >> new   =. new join makeinsert j, gj
>> >>  end.
>> >>   end.
>> >>   out   =. out, new join

Re: [Jprogramming] Partitions

2017-11-22 Thread Raul Miller
Oops, sorry, yes.

I was expecting exponential growth to make the results unrepresentable. But
that only happens at the low end (of the x values).

I guess maybe just set a=:u:i.48+n

That said, note that when x=y-1 you can use a result of the form
(1+=i.x)#"1 i.x

Thanks,

-- 
Raul

On Wednesday, November 22, 2017, 'Mike Day' via Programming <
programm...@jsoftware.com> wrote:

> How’s that, Raul?
>
> Wouldn’t ParXXX / 300 400 (Heaven forbid!) need 300 things,  whether
> integers,  symbols or what you will?
>
> What have I misunderstood?
>
> Cheers,
>
> Mike
>
>
> Please reply to mike_liz@tiscali.co.uk .
> Sent from my iPad
>
> > On 22 Nov 2017, at 21:56, Raul Miller  > wrote:
> >
> > The only case where you need more than 256 symbols is when the left
> > arg matches the right arg.
> >
> > For that case, it's reasonable to produce the result u:i.1,y
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Wed, Nov 22, 2017 at 2:05 PM, 'Mike Day' via Programming
> > > wrote:
> >> Here's another shot at a non-recursive constructive approach to
> generating
> >> RGFs.
> >> It continues to use characters to store and represent the RGFs.  It
> would
> >> need
> >> reworking if there were more than 256 digits/symbols, though I think
> we'd
> >> hit other
> >> problems before needing to worry about representation in such cases.
> >>
> >> Performance is reasonable if not outstanding,  similar to or a bit
> better
> >> than parMD.
> >>
> >> I think it's a bit easier to understand than my earlier effort.  I hope
> the
> >> comments in
> >> the following script help.
> >>
> >> NB. Please take care with line-wrapping...
> >>
> >> makeinsert =: 3 : 0   M.   NB. to memoise or not to memoise?
> >> a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
> here
> >> 'd g' =. 1 0 + y
> >> a{~ d #.inv i. d^g
> >> )
> >>
> >> join =: 3 : 0
> >> :
> >> nx =. #x [ ny =. #y
> >> (ny#x),. (,y)$~ (nx,1) * $y
> >> )
> >>
> >> NB. join =: ,/@(,"1/)
> >>
> >> NB. Generate all RGFs, each using at least one of each symbol/digit
> 0123...k
> >> representing
> >> NB.  (k+1)partitions
> >> NB.  Method:  let a "basic" RGF for 4 symbols be, eg, 0001002000300,
> >> NB.   ie having exactly one of each non-zero
> >> NB.  This example has gaps of size 2 3 and 2 again between digits 1&2,
> 2&3,
> >> and 3&[end] respectively
> >> NB.   it is the template for many derived RGFs.
> >> NB.   A derived RGF is based on a basic RGF with arbitrary
> digits
> >> replacing zeros in the gaps,
> >> NB.   subject to added digits not exceeding the left hand
> boundary
> >> of the gap.
> >> NB.   eg,  the sequence 20003 may have some or all of the 3
> zeros
> >> replaced by 1 or 2 but not 3
> >>
> >> NB. 3 helper functions: x join y : x ,/@(,"1/) y,  but seems better in
> >> explicit code!?
> >> NB. - concatenates all rows of x with all rows of y
> >>
> >> NB. makeinsert d,g : form a table with g columns
> >> NB.  of all possible perms of 0 1 2
> ...
> >> d
> >> NB.  to yield all suitable
> replacements
> >> for g zeros
> >>
> >> NB. comb - as in stats.ijs,  or otherwise,
> according to
> >> taste!
> >>
> >> require'stats'
> >>
> >> rgfMD =: 3 : 0
> >> :
> >> k=. <: x
> >> n=. y
> >> a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
> here
> >> if. x > n do. NB. special-case impossible partitions
> >>   ' '$~ 0, n  return.
> >> elseif. x = 1 do. NB. special-case 1-partition
> >>   ,: n#{.areturn.
> >> elseif. x = 2 do. NB. special-case 2-partition
> >>   a{~ (n#2) #: }. i. 2 ^ n-1   return.
> >> elseif. x = n do. NB. special-case n-partition
> >>   ,: n{.a return.
> >> end.
> >> c=. >: k comb <:n NB. possible start cols for 1 2 ... k
> >> g=. <: +/\inv"1] c =. c,. n   NB. sizes of gaps between starts of 1
> 2 3
> >> ... for each RGF pattern
> >> a=. a. }.~ a. i. '0'  NB. symbol list - arbitrary,  but '012...'
> here
> >> out  =. ' '$~ 0, n
> >> for_i. i.#c do.   NB. loop for each patterns of start cols
> >>   gi=. i{g
> >>   new   =. 1 0$a NB. defer setting initial zeros
> >>   for_j. }.i.#gi do. NB. loop over non-zero digits
> >>  new=. new,. j{a NB. append next non-zero digit
> >>  gj =. j{ gi NB. size of following gap
> >>  if. gj do.  NB. if size of gap is non-zero, append all
> >> gap-sized sets of 0 1 ... j
> >> new   =. new join makeinsert j, gj
> >>  end.
> >>   end.
> >>   out   =. out, new join~ a{~ ,: 0{. ~ -{.i{cNB. prepend initial
> zeros
> >> end.
> >> )
> >>
> >> makeinsert =: 3 : 0   M.
> >> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...'
> here
> >> 'd g' =. 1 0 + y
> >> a{~ d #.inv i. d^g
> >> )
> >>
> >> join =: 3 : 0
> >> :
> >> nx =. #x [ ny =. #y
> >> (ny#x),. (,y)$~ (nx,1) * $y
> >> )
> >>
> >

Re: [Jprogramming] Partitions

2017-11-22 Thread 'Mike Day' via Programming
How’s that, Raul?   

Wouldn’t ParXXX / 300 400 (Heaven forbid!) need 300 things,  whether integers,  
symbols or what you will?

What have I misunderstood?

Cheers,

Mike


Please reply to mike_liz@tiscali.co.uk.  
Sent from my iPad

> On 22 Nov 2017, at 21:56, Raul Miller  wrote:
> 
> The only case where you need more than 256 symbols is when the left
> arg matches the right arg.
> 
> For that case, it's reasonable to produce the result u:i.1,y
> 
> Thanks,
> 
> -- 
> Raul
> 
> On Wed, Nov 22, 2017 at 2:05 PM, 'Mike Day' via Programming
>  wrote:
>> Here's another shot at a non-recursive constructive approach to generating
>> RGFs.
>> It continues to use characters to store and represent the RGFs.  It would
>> need
>> reworking if there were more than 256 digits/symbols, though I think we'd
>> hit other
>> problems before needing to worry about representation in such cases.
>> 
>> Performance is reasonable if not outstanding,  similar to or a bit better
>> than parMD.
>> 
>> I think it's a bit easier to understand than my earlier effort.  I hope the
>> comments in
>> the following script help.
>> 
>> NB. Please take care with line-wrapping...
>> 
>> makeinsert =: 3 : 0   M.   NB. to memoise or not to memoise?
>> a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
>> 'd g' =. 1 0 + y
>> a{~ d #.inv i. d^g
>> )
>> 
>> join =: 3 : 0
>> :
>> nx =. #x [ ny =. #y
>> (ny#x),. (,y)$~ (nx,1) * $y
>> )
>> 
>> NB. join =: ,/@(,"1/)
>> 
>> NB. Generate all RGFs, each using at least one of each symbol/digit 0123...k
>> representing
>> NB.  (k+1)partitions
>> NB.  Method:  let a "basic" RGF for 4 symbols be, eg, 0001002000300,
>> NB.   ie having exactly one of each non-zero
>> NB.  This example has gaps of size 2 3 and 2 again between digits 1&2,  2&3,
>> and 3&[end] respectively
>> NB.   it is the template for many derived RGFs.
>> NB.   A derived RGF is based on a basic RGF with arbitrary digits
>> replacing zeros in the gaps,
>> NB.   subject to added digits not exceeding the left hand boundary
>> of the gap.
>> NB.   eg,  the sequence 20003 may have some or all of the 3 zeros
>> replaced by 1 or 2 but not 3
>> 
>> NB. 3 helper functions: x join y : x ,/@(,"1/) y,  but seems better in
>> explicit code!?
>> NB. - concatenates all rows of x with all rows of y
>> 
>> NB. makeinsert d,g : form a table with g columns
>> NB.  of all possible perms of 0 1 2 ...
>> d
>> NB.  to yield all suitable replacements
>> for g zeros
>> 
>> NB. comb - as in stats.ijs,  or otherwise,  according to
>> taste!
>> 
>> require'stats'
>> 
>> rgfMD =: 3 : 0
>> :
>> k=. <: x
>> n=. y
>> a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
>> if. x > n do. NB. special-case impossible partitions
>>   ' '$~ 0, n  return.
>> elseif. x = 1 do. NB. special-case 1-partition
>>   ,: n#{.areturn.
>> elseif. x = 2 do. NB. special-case 2-partition
>>   a{~ (n#2) #: }. i. 2 ^ n-1   return.
>> elseif. x = n do. NB. special-case n-partition
>>   ,: n{.a return.
>> end.
>> c=. >: k comb <:n NB. possible start cols for 1 2 ... k
>> g=. <: +/\inv"1] c =. c,. n   NB. sizes of gaps between starts of 1 2 3
>> ... for each RGF pattern
>> a=. a. }.~ a. i. '0'  NB. symbol list - arbitrary,  but '012...' here
>> out  =. ' '$~ 0, n
>> for_i. i.#c do.   NB. loop for each patterns of start cols
>>   gi=. i{g
>>   new   =. 1 0$a NB. defer setting initial zeros
>>   for_j. }.i.#gi do. NB. loop over non-zero digits
>>  new=. new,. j{a NB. append next non-zero digit
>>  gj =. j{ gi NB. size of following gap
>>  if. gj do.  NB. if size of gap is non-zero, append all
>> gap-sized sets of 0 1 ... j
>> new   =. new join makeinsert j, gj
>>  end.
>>   end.
>>   out   =. out, new join~ a{~ ,: 0{. ~ -{.i{cNB. prepend initial zeros
>> end.
>> )
>> 
>> makeinsert =: 3 : 0   M.
>> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
>> 'd g' =. 1 0 + y
>> a{~ d #.inv i. d^g
>> )
>> 
>> join =: 3 : 0
>> :
>> nx =. #x [ ny =. #y
>> (ny#x),. (,y)$~ (nx,1) * $y
>> )
>> 
>> NB. join =: ,/@(,"1/)NB. explicit verb seems better!?
>> 
>> Cheers,
>> 
>> Mike
>> 
>> 
>> 
>> 
>>> On 17/11/2017 18:14, 'mike_liz@tiscali.co.uk' via Programming wrote:
>>> 
>>> Erling Helenas,  Raul Miller,  and others have come up with various
>>> methods to generate subsets of “restricted generating functions” (RGFs)
>>> suitable for the production of partitions of sets.  Several of these
>>> have used Ruskey’s algorithm.
>>> 
>>> I’ve found a fairly simple approach which has the benefits of (a) not
>>> being recursive,  (b) being fairly easy to understand, and (c) not
>>> generating redundant data needing later filtering.  It does,  ho

Re: [Jprogramming] Partitions

2017-11-22 Thread Raul Miller
The only case where you need more than 256 symbols is when the left
arg matches the right arg.

For that case, it's reasonable to produce the result u:i.1,y

Thanks,

-- 
Raul

On Wed, Nov 22, 2017 at 2:05 PM, 'Mike Day' via Programming
 wrote:
> Here's another shot at a non-recursive constructive approach to generating
> RGFs.
> It continues to use characters to store and represent the RGFs.  It would
> need
> reworking if there were more than 256 digits/symbols, though I think we'd
> hit other
> problems before needing to worry about representation in such cases.
>
> Performance is reasonable if not outstanding,  similar to or a bit better
> than parMD.
>
> I think it's a bit easier to understand than my earlier effort.  I hope the
> comments in
> the following script help.
>
> NB. Please take care with line-wrapping...
>
> makeinsert =: 3 : 0   M.   NB. to memoise or not to memoise?
> a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
> 'd g' =. 1 0 + y
> a{~ d #.inv i. d^g
> )
>
> join =: 3 : 0
> :
> nx =. #x [ ny =. #y
> (ny#x),. (,y)$~ (nx,1) * $y
> )
>
> NB. join =: ,/@(,"1/)
>
> NB. Generate all RGFs, each using at least one of each symbol/digit 0123...k
> representing
> NB.  (k+1)partitions
> NB.  Method:  let a "basic" RGF for 4 symbols be, eg, 0001002000300,
> NB.   ie having exactly one of each non-zero
> NB.  This example has gaps of size 2 3 and 2 again between digits 1&2,  2&3,
> and 3&[end] respectively
> NB.   it is the template for many derived RGFs.
> NB.   A derived RGF is based on a basic RGF with arbitrary digits
> replacing zeros in the gaps,
> NB.   subject to added digits not exceeding the left hand boundary
> of the gap.
> NB.   eg,  the sequence 20003 may have some or all of the 3 zeros
> replaced by 1 or 2 but not 3
>
> NB. 3 helper functions: x join y : x ,/@(,"1/) y,  but seems better in
> explicit code!?
> NB. - concatenates all rows of x with all rows of y
>
> NB. makeinsert d,g : form a table with g columns
> NB.  of all possible perms of 0 1 2 ...
> d
> NB.  to yield all suitable replacements
> for g zeros
>
> NB. comb - as in stats.ijs,  or otherwise,  according to
> taste!
>
> require'stats'
>
> rgfMD =: 3 : 0
> :
> k=. <: x
> n=. y
> a=. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
> if. x > n do. NB. special-case impossible partitions
>' '$~ 0, n  return.
> elseif. x = 1 do. NB. special-case 1-partition
>,: n#{.areturn.
> elseif. x = 2 do. NB. special-case 2-partition
>a{~ (n#2) #: }. i. 2 ^ n-1   return.
> elseif. x = n do. NB. special-case n-partition
>,: n{.a return.
> end.
> c=. >: k comb <:n NB. possible start cols for 1 2 ... k
> g=. <: +/\inv"1] c =. c,. n   NB. sizes of gaps between starts of 1 2 3
> ... for each RGF pattern
> a=. a. }.~ a. i. '0'  NB. symbol list - arbitrary,  but '012...' here
> out  =. ' '$~ 0, n
> for_i. i.#c do.   NB. loop for each patterns of start cols
>gi=. i{g
>new   =. 1 0$a NB. defer setting initial zeros
>for_j. }.i.#gi do. NB. loop over non-zero digits
>   new=. new,. j{a NB. append next non-zero digit
>   gj =. j{ gi NB. size of following gap
>   if. gj do.  NB. if size of gap is non-zero, append all
> gap-sized sets of 0 1 ... j
>  new   =. new join makeinsert j, gj
>   end.
>end.
>out   =. out, new join~ a{~ ,: 0{. ~ -{.i{cNB. prepend initial zeros
> end.
> )
>
> makeinsert =: 3 : 0   M.
> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
> 'd g' =. 1 0 + y
> a{~ d #.inv i. d^g
> )
>
> join =: 3 : 0
> :
> nx =. #x [ ny =. #y
> (ny#x),. (,y)$~ (nx,1) * $y
> )
>
> NB. join =: ,/@(,"1/)NB. explicit verb seems better!?
>
> Cheers,
>
> Mike
>
>
>
>
> On 17/11/2017 18:14, 'mike_liz@tiscali.co.uk' via Programming wrote:
>>
>> Erling Helenas,  Raul Miller,  and others have come up with various
>> methods to generate subsets of “restricted generating functions” (RGFs)
>> suitable for the production of partitions of sets.  Several of these
>> have used Ruskey’s algorithm.
>>
>> I’ve found a fairly simple approach which has the benefits of (a) not
>> being recursive,  (b) being fairly easy to understand, and (c) not
>> generating redundant data needing later filtering.  It does,  however,
>> use a loop,  albeit needing fewer loops than the final number of rows,
>> ie RGFs .
>>
>> It saves a fair amount of space by using a character array of symbols
>> rather than integers to represent the RGFs.  A character string serves
>> equally as well as an integer vector as left argument to > generation of boxed partitions.
>>
>> Key features,  which might be improved upon, include the local verb
>> “ki” which yields the index of that ele

Re: [Jprogramming] Partitions

2017-11-22 Thread 'Mike Day' via Programming
Here's another shot at a non-recursive constructive approach to 
generating RGFs.
It continues to use characters to store and represent the RGFs.  It 
would need
reworking if there were more than 256 digits/symbols, though I think 
we'd hit other

problems before needing to worry about representation in such cases.

Performance is reasonable if not outstanding,  similar to or a bit 
better than parMD.


I think it's a bit easier to understand than my earlier effort.  I hope 
the comments in

the following script help.

NB. Please take care with line-wrapping...

makeinsert =: 3 : 0   M.   NB. to memoise or not to memoise?
a    =. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
'd g' =. 1 0 + y
a{~ d #.inv i. d^g
)

join =: 3 : 0
:
nx =. #x [ ny =. #y
(ny#x),. (,y)$~ (nx,1) * $y
)

NB. join =: ,/@(,"1/)

NB. Generate all RGFs, each using at least one of each symbol/digit 
0123...k representing

NB.  (k+1)partitions
NB.  Method:  let a "basic" RGF for 4 symbols be, eg, 0001002000300,
NB.   ie having exactly one of each non-zero
NB.  This example has gaps of size 2 3 and 2 again between digits 1&2,  
2&3, and 3&[end] respectively

NB.   it is the template for many derived RGFs.
NB.   A derived RGF is based on a basic RGF with arbitrary 
digits replacing zeros in the gaps,
NB.   subject to added digits not exceeding the left hand 
boundary of the gap.
NB.   eg,  the sequence 20003 may have some or all of the 3 
zeros replaced by 1 or 2 but not 3


NB. 3 helper functions: x join y : x ,/@(,"1/) y,  but seems better in 
explicit code!?

NB. - concatenates all rows of x with all rows of y

NB. makeinsert d,g : form a table with g columns
NB.  of all possible perms of 0 1 2 
... d
NB.  to yield all suitable 
replacements for g zeros


NB. comb - as in stats.ijs,  or otherwise,  
according to taste!


require'stats'

rgfMD =: 3 : 0
:
k    =. <: x
n    =. y
a    =. a. |.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
if. x > n do. NB. special-case impossible partitions
   ' '$~ 0, n  return.
elseif. x = 1 do. NB. special-case 1-partition
   ,: n#{.a    return.
elseif. x = 2 do. NB. special-case 2-partition
   a{~ (n#2) #: }. i. 2 ^ n-1   return.
elseif. x = n do. NB. special-case n-partition
   ,: n{.a return.
end.
c    =. >: k comb <:n NB. possible start cols for 1 2 ... k
g    =. <: +/\inv"1] c =. c,. n   NB. sizes of gaps between starts of 1 
2 3 ... for each RGF pattern

a    =. a. }.~ a. i. '0'  NB. symbol list - arbitrary,  but '012...' here
out  =. ' '$~ 0, n
for_i. i.#c do.   NB. loop for each patterns of start cols
   gi    =. i{g
   new   =. 1 0$a NB. defer setting initial zeros
   for_j. }.i.#gi do. NB. loop over non-zero digits
  new=. new,. j{a NB. append next non-zero digit
  gj =. j{ gi NB. size of following gap
  if. gj do.  NB. if size of gap is non-zero, append all 
gap-sized sets of 0 1 ... j

 new   =. new join makeinsert j, gj
  end.
   end.
   out   =. out, new join~ a{~ ,: 0{. ~ -{.i{c    NB. prepend initial zeros
end.
)

makeinsert =: 3 : 0   M.
a    =. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
'd g' =. 1 0 + y
a{~ d #.inv i. d^g
)

join =: 3 : 0
:
nx =. #x [ ny =. #y
(ny#x),. (,y)$~ (nx,1) * $y
)

NB. join =: ,/@(,"1/)    NB. explicit verb seems better!?

Cheers,

Mike



On 17/11/2017 18:14, 'mike_liz@tiscali.co.uk' via Programming wrote:

Erling Helenas,  Raul Miller,  and others have come up with various
methods to generate subsets of “restricted generating functions” (RGFs)
suitable for the production of partitions of sets.  Several of these
have used Ruskey’s algorithm.

I’ve found a fairly simple approach which has the benefits of (a) not
being recursive,  (b) being fairly easy to understand, and (c) not
generating redundant data needing later filtering.  It does,  however,
use a loop,  albeit needing fewer loops than the final number of rows,
ie RGFs .

It saves a fair amount of space by using a character array of symbols
rather than integers to represent the RGFs.  A character string serves
equally as well as an integer vector as left argument to  n do. NB. special-case impossible partitions
' '$~ 0, n
elseif. x = 1 do. NB. special-case 1-partition
,: n#{.a
elseif. x = 2 do. NB. special-case 2-partition
a{~ (n#2) #: }. i. 2 ^ n-1
elseif. x = n do. NB. special-case n-partition
,: n{.a
elseif. 1 do.
NB.  I use the term k-partition, below, loosely - it should be x-
partition or (k+1)-partn.
list =. a {~ list NB.  output as char array,  offset so that 0 1 2
... <==> '012...'
NB. end  =. k <. i. n NB.  preset last row if required for stopping
condition
incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
blnk 

Re: [Jprogramming] Partitions

2017-11-20 Thread 'Mike Day' via Programming
Sorry.  Shooting from the hip as usual!  
Mike

Please reply to mike_liz@tiscali.co.uk.  
Sent from my iPad

> On 20 Nov 2017, at 11:44, Erling Hellenäs  wrote:
> 
> There is no key operation in this published version. /Erling
> 
> 
>> Den 2017-11-20 kl. 12:20, skrev 'Mike Day' via Programming:
>> Yes,  the char array uses less space.  Also,  as has been observed before,  
>> the main work is deriving the “RGFs”   and there’s a considerable overhead 
>> in turning them into their partition equivalents.  Try removing the key 
>> operation.
>> 
>> Mike
>> 
>> Please reply to mike_liz@tiscali.co.uk.
>> Sent from my iPad
>> 
>>> On 20 Nov 2017, at 10:33, Erling Hellenäs  wrote:
>>> 
>>> Hi all!
>>> 
>>> I made a comparison.
>>> 
>>> They are very similar in theirtime requirements, but Mike Days version uses 
>>> considerably less space.
>>> 
>>> This might be mainly due to the choice of ascii representation of theresult.
>>> 
>>> Some consequences of this choice:
>>> 
>>>x=:15
>>>y=:15
>>>x parMD y
>>> 0123456789:;<=>
>>>x SetPartitionsGenerateF y
>>> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
>>> 
>>>x=:255
>>>y=:256
>>>ts'x parMD y'
>>> |index error: parMD
>>> |   list=.a{~list
>>>ts'x SetPartitionsGenerateF y'
>>> 2.53384 1.73658e8
>>> 
>>> See below.
>>> 
>>> Cheers,
>>> 
>>> Erling Hellenäs
>>> 
>>> Output---
>>> 
>>>x=:1
>>>y=:1
>>> 
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>> 
>>>x=:1
>>>y=:2
>>> 
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>> 
>>>x=:1
>>>y=:3
>>> 
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>> 
>>>x=:2
>>>y=:4
>>> 
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>> 
>>>x=:2
>>>y=:5
>>> 
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>> 
>>>x=:3
>>>y=:5
>>> 
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>> 
>>> 
>>>x=:5
>>>y=:10
>>> 
>>>ts'x SetPartitionsGenerateF y'
>>> 0.0217097 8.39974e6
>>>ts'x parMD y'
>>> 0.0381484 796032
>>> 
>>>x=:6
>>>y=:12
>>> 
>>>ts'x SetPartitionsGenerateF y'
>>> 1.03637 2.68448e8
>>>ts'x parMD y'
>>> 1.06117 2.51788e7
>>> 
>>>  Project 
>>> 
>>> ts=: 6!:2 , 7!:2@]   NB. Time and space
>>> 
>>> normalize=: 3 :0
>>> NB. The idea here is to normalize the representation so that
>>> NB. the copies are adjacent.
>>> NB. Sort buckets within each combination after first item in each bucket
>>> v31=.(] /: {.&.>)"1 y
>>> NB. Sort buckets within each combination after number of items in each 
>>> bucket
>>> v4=.(] /: #&.>)"1 v31
>>> NB. Sort
>>> v5=. /:~  v4
>>> (/: #&.> v5){ v5
>>> )
>>> 
>>> compare=: -:&:normalize
>>> 
>>> NB. Mike Day
>>> 
>>> NB. produce a table of "restricted growth functions" (rgf) (strings of 
>>> symbols) subject to
>>> NB. requirement that each "function" (or string) includes at least one 
>>> instance of each symbol
>>> NB. eg 001100 is an rgf,  but if all the symbols '012' are required,  it's 
>>> not suitable here
>>> NB. eg an rgf such as 001213 is a suitable equivalent to
>>> NB. |01|24|3|5|,  a 4-partition for 6 elements
>>> 
>>> NB. Any symbols may be used,  but they are subject to an implicit or 
>>> explicit ordering.
>>> 
>>> parMD =: 3 : 0
>>> y parMD~ <:#y
>>> :
>>> k=. <: x
>>> NB. starting/current row
>>> if. 1 = #y do.
>>>list =. ,: cur =. (-y){.i.x
>>> else.NB. Admit a starting row (of integers, not symbols) other than 0 0 
>>> 0 1 2 ...
>>>  NB. NB. not tested here for validity!!!
>>>list =. ,: cur =. y
>>> end.
>>> n=. #cur
>>> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
>>> if. x > n do. NB. special-case impossible partitions
>>>' '$~ 0, n
>>> elseif. x = 1 do. NB. special-case 1-partition
>>>,: n#{.a
>>> elseif. x = 2 do. NB. special-case 2-partition
>>>a{~ (n#2) #: }. i. 2 ^ n-1
>>> elseif. x = n do. NB. special-case n-partition
>>>,: n{.a
>>> elseif. 1 do.
>>> NB.  I use the term k-partition, below, loosely - it should be x-partition 
>>> or (k+1)-partn.
>>> list =. a {~ list NB.  output as char array,  offset so that 0 1 2 ... 
>>> <==> '012...'
>>> NB. end  =. k <. i. n NB.  preset last row if required for stopping 
>>> condition
>>> incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
>>> blnk =. +/\ incr  NB.  look-up array for blanking all elements after 
>>> i{cur
>>> block=. x makeblock n NB.  look-up array for forcing "new" rows to be 
>>> k-partition equivalents.
>>> ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth 
>>> function index finder,
>>>   NB. modified for limitation 
>>> to 1+k symbols
>>> while. n | i =. ki cur do.  NB. test new index - 

Re: [Jprogramming] Partitions

2017-11-20 Thread Erling Hellenäs

There is no key operation in this published version. /Erling


Den 2017-11-20 kl. 12:20, skrev 'Mike Day' via Programming:

Yes,  the char array uses less space.  Also,  as has been observed before,  the 
main work is deriving the “RGFs”   and there’s a considerable overhead in 
turning them into their partition equivalents.  Try removing the key operation.

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad


On 20 Nov 2017, at 10:33, Erling Hellenäs  wrote:

Hi all!

I made a comparison.

They are very similar in theirtime requirements, but Mike Days version uses 
considerably less space.

This might be mainly due to the choice of ascii representation of theresult.

Some consequences of this choice:

x=:15
y=:15
x parMD y
0123456789:;<=>
x SetPartitionsGenerateF y
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

x=:255
y=:256
ts'x parMD y'
|index error: parMD
|   list=.a{~list
ts'x SetPartitionsGenerateF y'
2.53384 1.73658e8

See below.

Cheers,

Erling Hellenäs

Output---

x=:1
y=:1

EH=:(x SetPartitionsGenerateF y))"1 y
NB. Sort buckets within each combination after number of items in each bucket
v4=.(] /: #&.>)"1 v31
NB. Sort
v5=. /:~  v4
(/: #&.> v5){ v5
)

compare=: -:&:normalize

NB. Mike Day

NB. produce a table of "restricted growth functions" (rgf) (strings of symbols) 
subject to
NB. requirement that each "function" (or string) includes at least one instance 
of each symbol
NB. eg 001100 is an rgf,  but if all the symbols '012' are required,  it's not 
suitable here
NB. eg an rgf such as 001213 is a suitable equivalent to
NB. |01|24|3|5|,  a 4-partition for 6 elements

NB. Any symbols may be used,  but they are subject to an implicit or explicit 
ordering.

parMD =: 3 : 0
y parMD~ <:#y
:
k=. <: x
NB. starting/current row
if. 1 = #y do.
list =. ,: cur =. (-y){.i.x
else.NB. Admit a starting row (of integers, not symbols) other than 0 0 0 1 
2 ...
  NB. NB. not tested here for validity!!!
list =. ,: cur =. y
end.
n=. #cur
a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
if. x > n do. NB. special-case impossible partitions
' '$~ 0, n
elseif. x = 1 do. NB. special-case 1-partition
,: n#{.a
elseif. x = 2 do. NB. special-case 2-partition
a{~ (n#2) #: }. i. 2 ^ n-1
elseif. x = n do. NB. special-case n-partition
,: n{.a
elseif. 1 do.
NB.  I use the term k-partition, below, loosely - it should be x-partition or 
(k+1)-partn.
list =. a {~ list NB.  output as char array,  offset so that 0 1 2 ... <==> 
'012...'
NB. end  =. k <. i. n NB.  preset last row if required for stopping condition
incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
blnk =. +/\ incr  NB.  look-up array for blanking all elements after i{cur
block=. x makeblock n NB.  look-up array for forcing "new" rows to be 
k-partition equivalents.
ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth function 
index finder,
   NB. modified for limitation to 
1+k symbols
while. n | i =. ki cur do.  NB. test new index - stop if = n
   NB. one of several possible stopping conditions - could 
test cur -: end
new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth 
function"
mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a k-partition
NB. Adjust "new" if not already a k-partition equivalent,  and expand to 
several rows
new   =. new +"1 >mx { block
NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if (and 
only if) x = 4
list  =. list, new { a
cur   =. {: new
end.
list
end.
)

NB. assemble look-up array of blocks
NB. eg
NB.4 makeblock 5
NB. +-+-+-+-+
NB. |0 0 1 2 3|0 0 0 2 3|0 0 0 0 3|0 0 0 0 0|
NB. | |0 0 1 2 3|0 0 0 1 3|0 0 0 0 1|
NB. | | |0 0 0 2 3|0 0 0 0 2|
NB. | | | |0 0 0 0 3|
NB. +-+-+-+-+
makeblock =: 3 : 0
makeblock/ y
:
NB. a work-a-day method,  not a smart implementation!
m  =. 0
b  =. ''
i  =. i. x
while. x >: m =. >: m do.
b =. b, < (i.m),. m#,: i =. }. i
end.
(-y){."1 each b
)


NB. Erling Hellenäs

SetPartitionsGenerateF =: 4 : 0
NB. Generate all set partitions with k subsets from
NB. an original set with n unique items.
NB. x - number of subsets
NB. y - number of items in the set to partition
NB. Result - table of integers
NB. -each row is a generated set partition
NB. -columns contain the subset number of the items
NB.  with the corresponding position in the set to
NB.  partition.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
(,: i.y) SPGF (x-1);y-1
)

SPGF =: 4 : 0
'k n' =. y
r=. (0,_1{.$x)$0
if. k=n do.
   r=.x
else.
   s=.n {."1 x
   e=.(n+1)}."1 x
   a=.,/s ( [,"1 1 (i.k+1),"0 1 ])"1 e
   r=.r, a SPGF k;n-1
   if. k > 0 do.
 a=.s,.k,.e
 r=.r, a SPG

Re: [Jprogramming] Partitions

2017-11-20 Thread Raul Miller
(it's kind of silly, though, since in real life you'd just use i.)

Thanks,

-- 
Raul


On Mon, Nov 20, 2017 at 6:27 AM, Raul Miller  wrote:
> Note also that the 256 parMD 256 case could have been addressed by
> using |. instead of }. when defining a
>
> Thanks,
>
> --
> Raul
>
>
> On Mon, Nov 20, 2017 at 6:20 AM, 'Mike Day' via Programming
>  wrote:
>> Yes,  the char array uses less space.  Also,  as has been observed before,  
>> the main work is deriving the “RGFs”   and there’s a considerable overhead 
>> in turning them into their partition equivalents.  Try removing the key 
>> operation.
>>
>> Mike
>>
>> Please reply to mike_liz@tiscali.co.uk.
>> Sent from my iPad
>>
>>> On 20 Nov 2017, at 10:33, Erling Hellenäs  wrote:
>>>
>>> Hi all!
>>>
>>> I made a comparison.
>>>
>>> They are very similar in theirtime requirements, but Mike Days version uses 
>>> considerably less space.
>>>
>>> This might be mainly due to the choice of ascii representation of theresult.
>>>
>>> Some consequences of this choice:
>>>
>>>x=:15
>>>y=:15
>>>x parMD y
>>> 0123456789:;<=>
>>>x SetPartitionsGenerateF y
>>> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
>>>
>>>x=:255
>>>y=:256
>>>ts'x parMD y'
>>> |index error: parMD
>>> |   list=.a{~list
>>>ts'x SetPartitionsGenerateF y'
>>> 2.53384 1.73658e8
>>>
>>> See below.
>>>
>>> Cheers,
>>>
>>> Erling Hellenäs
>>>
>>> Output---
>>>
>>>x=:1
>>>y=:1
>>>
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>>
>>>x=:1
>>>y=:2
>>>
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>>
>>>x=:1
>>>y=:3
>>>
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>>
>>>x=:2
>>>y=:4
>>>
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>>
>>>x=:2
>>>y=:5
>>>
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>>
>>>x=:3
>>>y=:5
>>>
>>>EH=:(x SetPartitionsGenerateF y)>>MD=:(x parMD y) >>EH compare MD
>>> 1
>>>
>>>
>>>x=:5
>>>y=:10
>>>
>>>ts'x SetPartitionsGenerateF y'
>>> 0.0217097 8.39974e6
>>>ts'x parMD y'
>>> 0.0381484 796032
>>>
>>>x=:6
>>>y=:12
>>>
>>>ts'x SetPartitionsGenerateF y'
>>> 1.03637 2.68448e8
>>>ts'x parMD y'
>>> 1.06117 2.51788e7
>>>
>>>  Project 
>>>
>>> ts=: 6!:2 , 7!:2@]   NB. Time and space
>>>
>>> normalize=: 3 :0
>>> NB. The idea here is to normalize the representation so that
>>> NB. the copies are adjacent.
>>> NB. Sort buckets within each combination after first item in each bucket
>>> v31=.(] /: {.&.>)"1 y
>>> NB. Sort buckets within each combination after number of items in each 
>>> bucket
>>> v4=.(] /: #&.>)"1 v31
>>> NB. Sort
>>> v5=. /:~  v4
>>> (/: #&.> v5){ v5
>>> )
>>>
>>> compare=: -:&:normalize
>>>
>>> NB. Mike Day
>>>
>>> NB. produce a table of "restricted growth functions" (rgf) (strings of 
>>> symbols) subject to
>>> NB. requirement that each "function" (or string) includes at least one 
>>> instance of each symbol
>>> NB. eg 001100 is an rgf,  but if all the symbols '012' are required,  it's 
>>> not suitable here
>>> NB. eg an rgf such as 001213 is a suitable equivalent to
>>> NB. |01|24|3|5|,  a 4-partition for 6 elements
>>>
>>> NB. Any symbols may be used,  but they are subject to an implicit or 
>>> explicit ordering.
>>>
>>> parMD =: 3 : 0
>>> y parMD~ <:#y
>>> :
>>> k=. <: x
>>> NB. starting/current row
>>> if. 1 = #y do.
>>>list =. ,: cur =. (-y){.i.x
>>> else.NB. Admit a starting row (of integers, not symbols) other than 0 0 
>>> 0 1 2 ...
>>>  NB. NB. not tested here for validity!!!
>>>list =. ,: cur =. y
>>> end.
>>> n=. #cur
>>> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
>>> if. x > n do. NB. special-case impossible partitions
>>>' '$~ 0, n
>>> elseif. x = 1 do. NB. special-case 1-partition
>>>,: n#{.a
>>> elseif. x = 2 do. NB. special-case 2-partition
>>>a{~ (n#2) #: }. i. 2 ^ n-1
>>> elseif. x = n do. NB. special-case n-partition
>>>,: n{.a
>>> elseif. 1 do.
>>> NB.  I use the term k-partition, below, loosely - it should be x-partition 
>>> or (k+1)-partn.
>>> list =. a {~ list NB.  output as char array,  offset so that 0 1 2 ... 
>>> <==> '012...'
>>> NB. end  =. k <. i. n NB.  preset last row if required for stopping 
>>> condition
>>> incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
>>> blnk =. +/\ incr  NB.  look-up array for blanking all elements after 
>>> i{cur
>>> block=. x makeblock n NB.  look-up array for forcing "new" rows to be 
>>> k-partition equivalents.
>>> ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth 
>>> function index finder,
>>>   NB. modified for limitation 
>>> to 1+k symbols
>>> while. n | i =. ki cur do.  NB. test ne

Re: [Jprogramming] Partitions

2017-11-20 Thread Raul Miller
Note also that the 256 parMD 256 case could have been addressed by
using |. instead of }. when defining a

Thanks,

-- 
Raul


On Mon, Nov 20, 2017 at 6:20 AM, 'Mike Day' via Programming
 wrote:
> Yes,  the char array uses less space.  Also,  as has been observed before,  
> the main work is deriving the “RGFs”   and there’s a considerable overhead in 
> turning them into their partition equivalents.  Try removing the key 
> operation.
>
> Mike
>
> Please reply to mike_liz@tiscali.co.uk.
> Sent from my iPad
>
>> On 20 Nov 2017, at 10:33, Erling Hellenäs  wrote:
>>
>> Hi all!
>>
>> I made a comparison.
>>
>> They are very similar in theirtime requirements, but Mike Days version uses 
>> considerably less space.
>>
>> This might be mainly due to the choice of ascii representation of theresult.
>>
>> Some consequences of this choice:
>>
>>x=:15
>>y=:15
>>x parMD y
>> 0123456789:;<=>
>>x SetPartitionsGenerateF y
>> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
>>
>>x=:255
>>y=:256
>>ts'x parMD y'
>> |index error: parMD
>> |   list=.a{~list
>>ts'x SetPartitionsGenerateF y'
>> 2.53384 1.73658e8
>>
>> See below.
>>
>> Cheers,
>>
>> Erling Hellenäs
>>
>> Output---
>>
>>x=:1
>>y=:1
>>
>>EH=:(x SetPartitionsGenerateF y)>MD=:(x parMD y) >EH compare MD
>> 1
>>
>>x=:1
>>y=:2
>>
>>EH=:(x SetPartitionsGenerateF y)>MD=:(x parMD y) >EH compare MD
>> 1
>>
>>x=:1
>>y=:3
>>
>>EH=:(x SetPartitionsGenerateF y)>MD=:(x parMD y) >EH compare MD
>> 1
>>
>>x=:2
>>y=:4
>>
>>EH=:(x SetPartitionsGenerateF y)>MD=:(x parMD y) >EH compare MD
>> 1
>>
>>x=:2
>>y=:5
>>
>>EH=:(x SetPartitionsGenerateF y)>MD=:(x parMD y) >EH compare MD
>> 1
>>
>>x=:3
>>y=:5
>>
>>EH=:(x SetPartitionsGenerateF y)>MD=:(x parMD y) >EH compare MD
>> 1
>>
>>
>>x=:5
>>y=:10
>>
>>ts'x SetPartitionsGenerateF y'
>> 0.0217097 8.39974e6
>>ts'x parMD y'
>> 0.0381484 796032
>>
>>x=:6
>>y=:12
>>
>>ts'x SetPartitionsGenerateF y'
>> 1.03637 2.68448e8
>>ts'x parMD y'
>> 1.06117 2.51788e7
>>
>>  Project 
>>
>> ts=: 6!:2 , 7!:2@]   NB. Time and space
>>
>> normalize=: 3 :0
>> NB. The idea here is to normalize the representation so that
>> NB. the copies are adjacent.
>> NB. Sort buckets within each combination after first item in each bucket
>> v31=.(] /: {.&.>)"1 y
>> NB. Sort buckets within each combination after number of items in each bucket
>> v4=.(] /: #&.>)"1 v31
>> NB. Sort
>> v5=. /:~  v4
>> (/: #&.> v5){ v5
>> )
>>
>> compare=: -:&:normalize
>>
>> NB. Mike Day
>>
>> NB. produce a table of "restricted growth functions" (rgf) (strings of 
>> symbols) subject to
>> NB. requirement that each "function" (or string) includes at least one 
>> instance of each symbol
>> NB. eg 001100 is an rgf,  but if all the symbols '012' are required,  it's 
>> not suitable here
>> NB. eg an rgf such as 001213 is a suitable equivalent to
>> NB. |01|24|3|5|,  a 4-partition for 6 elements
>>
>> NB. Any symbols may be used,  but they are subject to an implicit or 
>> explicit ordering.
>>
>> parMD =: 3 : 0
>> y parMD~ <:#y
>> :
>> k=. <: x
>> NB. starting/current row
>> if. 1 = #y do.
>>list =. ,: cur =. (-y){.i.x
>> else.NB. Admit a starting row (of integers, not symbols) other than 0 0 
>> 0 1 2 ...
>>  NB. NB. not tested here for validity!!!
>>list =. ,: cur =. y
>> end.
>> n=. #cur
>> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
>> if. x > n do. NB. special-case impossible partitions
>>' '$~ 0, n
>> elseif. x = 1 do. NB. special-case 1-partition
>>,: n#{.a
>> elseif. x = 2 do. NB. special-case 2-partition
>>a{~ (n#2) #: }. i. 2 ^ n-1
>> elseif. x = n do. NB. special-case n-partition
>>,: n{.a
>> elseif. 1 do.
>> NB.  I use the term k-partition, below, loosely - it should be x-partition 
>> or (k+1)-partn.
>> list =. a {~ list NB.  output as char array,  offset so that 0 1 2 ... 
>> <==> '012...'
>> NB. end  =. k <. i. n NB.  preset last row if required for stopping condition
>> incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
>> blnk =. +/\ incr  NB.  look-up array for blanking all elements after 
>> i{cur
>> block=. x makeblock n NB.  look-up array for forcing "new" rows to be 
>> k-partition equivalents.
>> ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth function 
>> index finder,
>>   NB. modified for limitation to 
>> 1+k symbols
>> while. n | i =. ki cur do.  NB. test new index - stop if = n
>>   NB. one of several possible stopping conditions - 
>> could test cur -: end
>>new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth 
>> function"
>>mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a 
>> k-partition
>> NB. Adjust "new" if not already a k-partition eq

Re: [Jprogramming] Partitions

2017-11-20 Thread 'Mike Day' via Programming
Yes,  the char array uses less space.  Also,  as has been observed before,  the 
main work is deriving the “RGFs”   and there’s a considerable overhead in 
turning them into their partition equivalents.  Try removing the key operation.

Mike

Please reply to mike_liz@tiscali.co.uk.  
Sent from my iPad

> On 20 Nov 2017, at 10:33, Erling Hellenäs  wrote:
> 
> Hi all!
> 
> I made a comparison.
> 
> They are very similar in theirtime requirements, but Mike Days version uses 
> considerably less space.
> 
> This might be mainly due to the choice of ascii representation of theresult.
> 
> Some consequences of this choice:
> 
>x=:15
>y=:15
>x parMD y
> 0123456789:;<=>
>x SetPartitionsGenerateF y
> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
> 
>x=:255
>y=:256
>ts'x parMD y'
> |index error: parMD
> |   list=.a{~list
>ts'x SetPartitionsGenerateF y'
> 2.53384 1.73658e8
> 
> See below.
> 
> Cheers,
> 
> Erling Hellenäs
> 
> Output---
> 
>x=:1
>y=:1
> 
>EH=:(x SetPartitionsGenerateF y)MD=:(x parMD y) EH compare MD
> 1
> 
>x=:1
>y=:2
> 
>EH=:(x SetPartitionsGenerateF y)MD=:(x parMD y) EH compare MD
> 1
> 
>x=:1
>y=:3
> 
>EH=:(x SetPartitionsGenerateF y)MD=:(x parMD y) EH compare MD
> 1
> 
>x=:2
>y=:4
> 
>EH=:(x SetPartitionsGenerateF y)MD=:(x parMD y) EH compare MD
> 1
> 
>x=:2
>y=:5
> 
>EH=:(x SetPartitionsGenerateF y)MD=:(x parMD y) EH compare MD
> 1
> 
>x=:3
>y=:5
> 
>EH=:(x SetPartitionsGenerateF y)MD=:(x parMD y) EH compare MD
> 1
> 
> 
>x=:5
>y=:10
> 
>ts'x SetPartitionsGenerateF y'
> 0.0217097 8.39974e6
>ts'x parMD y'
> 0.0381484 796032
> 
>x=:6
>y=:12
> 
>ts'x SetPartitionsGenerateF y'
> 1.03637 2.68448e8
>ts'x parMD y'
> 1.06117 2.51788e7
> 
>  Project 
> 
> ts=: 6!:2 , 7!:2@]   NB. Time and space
> 
> normalize=: 3 :0
> NB. The idea here is to normalize the representation so that
> NB. the copies are adjacent.
> NB. Sort buckets within each combination after first item in each bucket
> v31=.(] /: {.&.>)"1 y
> NB. Sort buckets within each combination after number of items in each bucket
> v4=.(] /: #&.>)"1 v31
> NB. Sort
> v5=. /:~  v4
> (/: #&.> v5){ v5
> )
> 
> compare=: -:&:normalize
> 
> NB. Mike Day
> 
> NB. produce a table of "restricted growth functions" (rgf) (strings of 
> symbols) subject to
> NB. requirement that each "function" (or string) includes at least one 
> instance of each symbol
> NB. eg 001100 is an rgf,  but if all the symbols '012' are required,  it's 
> not suitable here
> NB. eg an rgf such as 001213 is a suitable equivalent to
> NB. |01|24|3|5|,  a 4-partition for 6 elements
> 
> NB. Any symbols may be used,  but they are subject to an implicit or explicit 
> ordering.
> 
> parMD =: 3 : 0
> y parMD~ <:#y
> :
> k=. <: x
> NB. starting/current row
> if. 1 = #y do.
>list =. ,: cur =. (-y){.i.x
> else.NB. Admit a starting row (of integers, not symbols) other than 0 0 0 
> 1 2 ...
>  NB. NB. not tested here for validity!!!
>list =. ,: cur =. y
> end.
> n=. #cur
> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
> if. x > n do. NB. special-case impossible partitions
>' '$~ 0, n
> elseif. x = 1 do. NB. special-case 1-partition
>,: n#{.a
> elseif. x = 2 do. NB. special-case 2-partition
>a{~ (n#2) #: }. i. 2 ^ n-1
> elseif. x = n do. NB. special-case n-partition
>,: n{.a
> elseif. 1 do.
> NB.  I use the term k-partition, below, loosely - it should be x-partition or 
> (k+1)-partn.
> list =. a {~ list NB.  output as char array,  offset so that 0 1 2 ... 
> <==> '012...'
> NB. end  =. k <. i. n NB.  preset last row if required for stopping condition
> incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
> blnk =. +/\ incr  NB.  look-up array for blanking all elements after i{cur
> block=. x makeblock n NB.  look-up array for forcing "new" rows to be 
> k-partition equivalents.
> ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth function 
> index finder,
>   NB. modified for limitation to 
> 1+k symbols
> while. n | i =. ki cur do.  NB. test new index - stop if = n
>   NB. one of several possible stopping conditions - could 
> test cur -: end
>new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth 
> function"
>mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a k-partition
> NB. Adjust "new" if not already a k-partition equivalent,  and expand to 
> several rows
>new   =. new +"1 >mx { block
> NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if (and 
> only if) x = 4
>list  =. list, new { a
>cur   =. {: new
> end.
> list
> end.
> )
> 
> NB. assemble look-up array of blocks
> NB. eg
> NB.4 makeblock 5
> NB. +-+-+-

Re: [Jprogramming] Partitions

2017-11-20 Thread Erling Hellenäs

Hi all!

I made a comparison.

They are very similar in theirtime requirements, but Mike Days version 
uses considerably less space.


This might be mainly due to the choice of ascii representation of theresult.

Some consequences of this choice:

   x=:15
   y=:15
   x parMD y
0123456789:;<=>
   x SetPartitionsGenerateF y
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

   x=:255
   y=:256
   ts'x parMD y'
|index error: parMD
|   list=.a    {~list
   ts'x SetPartitionsGenerateF y'
2.53384 1.73658e8

See below.

Cheers,

Erling Hellenäs

Output---

   x=:1
   y=:1

   EH=:(x SetPartitionsGenerateF y))"1 y
NB. Sort buckets within each combination after number of items in each 
bucket

v4=.(] /: #&.>)"1 v31
NB. Sort
v5=. /:~  v4
(/: #&.> v5){ v5
)

compare=: -:&:normalize

NB. Mike Day

NB. produce a table of "restricted growth functions" (rgf) (strings of 
symbols) subject to
NB. requirement that each "function" (or string) includes at least one 
instance of each symbol
NB. eg 001100 is an rgf,  but if all the symbols '012' are required,  
it's not suitable here

NB. eg an rgf such as 001213 is a suitable equivalent to
NB. |01|24|3|5|,  a 4-partition for 6 elements

NB. Any symbols may be used,  but they are subject to an implicit or 
explicit ordering.


parMD =: 3 : 0
y parMD~ <:#y
:
k    =. <: x
NB. starting/current row
if. 1 = #y do.
   list =. ,: cur =. (-y){.i.x
else.    NB. Admit a starting row (of integers, not symbols) other than 
0 0 0 1 2 ...

 NB. NB. not tested here for validity!!!
   list =. ,: cur =. y
end.
n    =. #cur
a    =. a. }.~ a. i. '0'   NB. symbol list - arbitrary, but '012...' here
if. x > n do. NB. special-case impossible partitions
   ' '$~ 0, n
elseif. x = 1 do. NB. special-case 1-partition
   ,: n#{.a
elseif. x = 2 do. NB. special-case 2-partition
   a{~ (n#2) #: }. i. 2 ^ n-1
elseif. x = n do. NB. special-case n-partition
   ,: n{.a
elseif. 1 do.
NB.  I use the term k-partition, below, loosely - it should be 
x-partition or (k+1)-partn.
list =. a {~ list NB.  output as char array,  offset so that 0 1 2 
... <==> '012...'
NB. end  =. k <. i. n NB.  preset last row if required for stopping 
condition

incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
blnk =. +/\ incr  NB.  look-up array for blanking all elements after 
i{cur
block=. x makeblock n NB.  look-up array for forcing "new" rows to be 
k-partition equivalents.
ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth 
function index finder,
  NB. modified for 
limitation to 1+k symbols

while. n | i =. ki cur do.  NB. test new index - stop if = n
  NB. one of several possible stopping conditions - 
could test cur -: end
   new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth 
function"
   mx    =. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a 
k-partition
NB. Adjust "new" if not already a k-partition equivalent,  and expand to 
several rows

   new   =. new +"1 >mx { block
NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if 
(and only if) x = 4

   list  =. list, new { a
   cur   =. {: new
end.
list
end.
)

NB. assemble look-up array of blocks
NB. eg
NB.    4 makeblock 5
NB. +-+-+-+-+
NB. |0 0 1 2 3|0 0 0 2 3|0 0 0 0 3|0 0 0 0 0|
NB. | |0 0 1 2 3|0 0 0 1 3|0 0 0 0 1|
NB. | | |0 0 0 2 3|0 0 0 0 2|
NB. | | | |0 0 0 0 3|
NB. +-+-+-+-+
makeblock =: 3 : 0
makeblock/ y
:
NB. a work-a-day method,  not a smart implementation!
m  =. 0
b  =. ''
i  =. i. x
while. x >: m =. >: m do.
   b =. b, < (i.m),. m#,: i =. }. i
end.
(-y){."1 each b
)


NB. Erling Hellenäs

SetPartitionsGenerateF =: 4 : 0
NB. Generate all set partitions with k subsets from
NB. an original set with n unique items.
NB. x - number of subsets
NB. y - number of items in the set to partition
NB. Result - table of integers
NB. -each row is a generated set partition
NB. -columns contain the subset number of the items
NB.  with the corresponding position in the set to
NB.  partition.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
(,: i.y) SPGF (x-1);y-1
)

SPGF =: 4 : 0
'k n' =. y
r=. (0,_1{.$x)$0
if. k=n do.
  r=.x
else.
  s=.n {."1 x
  e=.(n+1)}."1 x
  a=.,/s ( [,"1 1 (i.k+1),"0 1 ])"1 e
  r=.r, a SPGF k;n-1
  if. k > 0 do.
    a=.s,.k,.e
    r=.r, a SPGF (k-1);n-1
  end.
end.
r
)

x=:1
y=:1

EH=:(x SetPartitionsGenerateF y)Den 2017-11-17 kl. 19:14, skrev 'mike_liz@tiscali.co.uk' via 
Programming:

NB. produce a table of "restricted growth functions" (rgf) (strings of
symbols) subject to
NB. requirement that each "function" (or string) includes at least one
instance of each symbol
NB. eg 001100 is an rgf,  but if all the symbols '012' are required,
it's not suitable here
NB. eg an rgf such as 001213 is a suitable equivalent to
NB. |01|24|3|5|,

Re: [Jprogramming] Partitions

2017-11-19 Thread Roger Shepherd
I have probably lost track of the various goals and contexts in play here, but 
“enumerating k-sets” may fit somewhere and be useful.
Pick a positive integer k. For that k, there is an enumeration of all k-sets, 
so KSet[N] = CharacteristicInteger ( of Nth k-set in lexicographical order).
So, say, for N=25.
For k=1, KSet[25 (25!1)] = 33554432 (2^25)
For k=2, KSet[25 (2!7 + 1!4)] = 144 (2^7+2^4)
For k=3, KSet[25 ((3!6)+(2!3)+(1!2))] = 76 ((2^6)+(2^3)+(2^2))

The algorithm is well known and lends itself to creating a “random” k-set.
https://en.wikipedia.org/wiki/Combinatorial_number_system
 
Sent from Mail for Windows 10

From: Linda Alvord
Sent: Friday, November 3, 2017 2:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Oops, this should be better:


   comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.2^y'
   comb4
[: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
   #3 comb4  5
10
   
Linda


-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Thursday, November 2, 2017 2:54 AM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

No, you did not test your work.

   #3 comb 5
10
   #3 comb4 5
56

Probably the simplest way to approach what I think you are trying to do 
involves expanding the part in parenthesis independent of the rest of it.

And, personally, when I am working on a line of J code, I like to have a little 
test rig so that I can quickly see when I have gone astray.
Doing that here (and clipping out my mistakes), then adding comments gets me 
this:

First, I set up a test rig with the original expression:

   #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
10

Then, I rephrase the outer part as an explicit expression for 13 :

  #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
10

Since that worked, I take a look at what 13 : gave me

   13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
[ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]

Next, I try that out in my test rig:

   #3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
10

So, now that I have that, I do a rephrase of the inner part for another 13 :

   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
10

And, since that works, I take a look at what it gave me:

   [ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ] [ ([: |. [: I. ] #~ [ = [: 
+/"1 ]) [: #: [: i. 2 ^ ]

And, voila, I've got another variation that I can use in a word definition:

   comb4a=: [ ([: |. [: I. ] #~ [ = [: +/"1 ]) [: #: [: i. 2 ^ ]

That's a bit ugly, but ascii is ugly (but, also, standardized and - thus - 
widely available).

So, we can try that out and see it in operation:

   3 comb4a 5
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4

Also... note that when working with "real life" mechanisms (not just J), having 
some sort of test rig to make sure that what you are doing behaves like you 
think it does can be an invaluable time saver. (The alternative - putting a lot 
of work into something, only to find out that it doesn't work and that you have 
to start over again - is sometimes necessary but not always attractive.)

(Well, that, and remember that this approach is slower than the stock comb 
implementation when y > 10 - so mostly I would just do require'stats' and then 
use that comb implementation.)

Then again, now that we have this variation, we could also try to reconstruct 
an explicit expression which does the same thing. For that we want to merge 
these two examples:

   #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5

Perhaps something like:
   #3 (13 :'|.I.(x = +/"1 t) # t=. #:i. 2^y') 5
10

(But I would not blindly enshrine results just because they were generated by 
an automated mechanism - such things can be useful tools, of course, but if you 
abandon your own understanding that's not good.)

I hope this helps,

--
Raul

On Wed, Nov 1, 2017 at 11:55 PM, Linda Alvord  wrote:
> This is another way to get to Raul's ideas in a tacit soluion:
>
> comb4=: 13 :'|.I.(x=+/"1#:i.x^y)##:i.x^y'
>2 comb4 4
> 0 1
> 0 2
> 0 3
> 1 2
> 1 3
> 2 3
>comb4
> [: |. [: I. ([ = [: +/"1 [: #: [: i. ^) # [: #: [: i. ^
>
> Linda
>
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On 
> Behalf Of Lippu Esa
> Sent: Wednesday, November 1, 2017 5:53 PM
> To: 'programm...@jsoftware.com' 
> Subject: Re: [Jprogramming] Partitions
>
> Thank you, Raul! I knew that there would be a tacit solution. But comb is 
> better with big y as you said.
>
> Esa
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsof

Re: [Jprogramming] Partitions

2017-11-18 Thread 'Mike Day' via Programming
Had to be a better way,  though its performance isn’t crucial, of course.
Thanks, 
Mike

Please reply to mike_liz@tiscali.co.uk.  
Sent from my iPad

> On 18 Nov 2017, at 01:07, Raul Miller  wrote:
> 
>   blockmake=: (-@[ {."1&.> ] <@({.,"0 1 }.)"0 1~ 1+])i.
>   (5 blockmake 4) -: 4 makeblock 5
> 1
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
> On Fri, Nov 17, 2017 at 1:14 PM, 'mike_liz@tiscali.co.uk' via
> Programming  wrote:
>> Erling Helenas,  Raul Miller,  and others have come up with various
>> methods to generate subsets of “restricted generating functions” (RGFs)
>> suitable for the production of partitions of sets.  Several of these
>> have used Ruskey’s algorithm.
>> 
>> I’ve found a fairly simple approach which has the benefits of (a) not
>> being recursive,  (b) being fairly easy to understand, and (c) not
>> generating redundant data needing later filtering.  It does,  however,
>> use a loop,  albeit needing fewer loops than the final number of rows,
>> ie RGFs .
>> 
>> It saves a fair amount of space by using a character array of symbols
>> rather than integers to represent the RGFs.  A character string serves
>> equally as well as an integer vector as left argument to > generation of boxed partitions.
>> 
>> Key features,  which might be improved upon, include the local verb
>> “ki” which yields the index of that element in an RGF which needs to be
>> incremented in generating the next RGF,  and a number of small look-up
>> mini-arrays useful in finding the next appropriate few RGFs.
>> 
>> Its performance compares favourably with other recent offerings.
>> 
>> There is one main verb,  “parMD”,  and a helper verb,  “makeblock”,
>> which constructs one of the look-up arrays.
>> 
>> Here it is;  look out for line-wraps,  though it looks ok this end! :-
>> 
>> ==
>> NB. produce a table of "restricted growth functions" (rgf) (strings of
>> symbols) subject to
>> NB. requirement that each "function" (or string) includes at least one
>> instance of each symbol
>> NB. eg 001100 is an rgf,  but if all the symbols '012' are required,
>> it's not suitable here
>> NB. eg an rgf such as 001213 is a suitable equivalent to
>> NB. |01|24|3|5|,  a 4-partition for 6 elements
>> 
>> NB. Any symbols may be used,  but they are subject to an implicit or
>> explicit ordering.
>> 
>> parMD =: 3 : 0
>> y parMD~ <:#y
>> :
>> k=. <: x
>> NB. starting/current row
>> if. 1 = #y do.
>>   list =. ,: cur =. (-y){.i.x
>> else.NB. Admit a starting row (of integers, not symbols) other than
>> 0 0 0 1 2 ...
>> NB. NB. not tested here for validity!!!
>>   list =. ,: cur =. y
>> end.
>> n=. #cur
>> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary,  but '012...'
>> here
>> if. x > n do. NB. special-case impossible partitions
>>   ' '$~ 0, n
>> elseif. x = 1 do. NB. special-case 1-partition
>>   ,: n#{.a
>> elseif. x = 2 do. NB. special-case 2-partition
>>   a{~ (n#2) #: }. i. 2 ^ n-1
>> elseif. x = n do. NB. special-case n-partition
>>   ,: n{.a
>> elseif. 1 do.
>> NB.  I use the term k-partition, below, loosely - it should be x-
>> partition or (k+1)-partn.
>> list =. a {~ list NB.  output as char array,  offset so that 0 1 2
>> ... <==> '012...'
>> NB. end  =. k <. i. n NB.  preset last row if required for stopping
>> condition
>> incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
>> blnk =. +/\ incr  NB.  look-up array for blanking all elements
>> after i{cur
>> block=. x makeblock n NB.  look-up array for forcing "new" rows to be k-
>> partition equivalents.
>> ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth
>> function index finder,
>>  NB. modified for
>> limitation to 1+k symbols
>> while. n | i =. ki cur do.  NB. test new index - stop if = n
>>  NB. one of several possible stopping conditions -
>> could test cur -: end
>>   new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth
>> function"
>>   mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a k-
>> partition
>> NB. Adjust "new" if not already a k-partition equivalent,  and expand
>> to several rows
>>   new   =. new +"1 >mx { block
>> NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if
>> (and only if) x = 4
>>   list  =. list, new { a
>>   cur   =. {: new
>> end.
>> list
>> end.
>> )
>> 
>> NB. assemble look-up array of blocks
>> NB. eg
>> NB.4 makeblock 5
>> NB. +-+-+-+-+
>> NB. |0 0 1 2 3|0 0 0 2 3|0 0 0 0 3|0 0 0 0 0|
>> NB. | |0 0 1 2 3|0 0 0 1 3|0 0 0 0 1|
>> NB. | | |0 0 0 2 3|0 0 0 0 2|
>> NB. | | | |0 0 0 0 3|
>> NB. +-+-+-+-+
>> makeblock =: 3 : 0
>> makeblock/ y
>> :
>> NB. a work-a-day method,  not a smart implementation!
>> m  =. 0
>> b  =. ''
>> i  =. i. x

Re: [Jprogramming] Partitions

2017-11-18 Thread 'Mike Day' via Programming
Yes,  choice of symbols is a matter of taste or something...
Mike

Please reply to mike_liz@tiscali.co.uk.  
Sent from my iPad

> On 18 Nov 2017, at 12:36, Raul Miller  wrote:
> 
> Yeah, that's ascii for you - though it doesn't really matter.
> 
> Of course, if that bothers you you could replace
> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary,  but '012...'
> with
> a=. ~.;{:@;: ::a:"1 '0',.~a.
> 
> But that's probably not worth the extra millisecond it costs.
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
> On Sat, Nov 18, 2017 at 7:01 AM, Erling Hellenäs
>  wrote:
>> Hi all!
>> 
>> I wondered what would happen when we ran out of digits.
>> 
>>   a=:14 parMD 15
>>   1{a
>> 01023456789:;<=
>> 
>> Cheers,
>> Erling Hellenäs
>> 
>> 
>>> On 2017-11-17 19:14, 'mike_liz@tiscali.co.uk' via Programming wrote:
>>> 
>>> Erling Helenas,  Raul Miller,  and others have come up with various
>>> methods to generate subsets of “restricted generating functions” (RGFs)
>>> suitable for the production of partitions of sets.  Several of these
>>> have used Ruskey’s algorithm.
>>> 
>>> I’ve found a fairly simple approach which has the benefits of (a) not
>>> being recursive,  (b) being fairly easy to understand, and (c) not
>>> generating redundant data needing later filtering.  It does,  however,
>>> use a loop,  albeit needing fewer loops than the final number of rows,
>>> ie RGFs .
>>> 
>>> It saves a fair amount of space by using a character array of symbols
>>> rather than integers to represent the RGFs.  A character string serves
>>> equally as well as an integer vector as left argument to >> generation of boxed partitions.
>>> 
>>> Key features,  which might be improved upon, include the local verb
>>> “ki” which yields the index of that element in an RGF which needs to be
>>> incremented in generating the next RGF,  and a number of small look-up
>>> mini-arrays useful in finding the next appropriate few RGFs.
>>> 
>>> Its performance compares favourably with other recent offerings.
>>> 
>>> There is one main verb,  “parMD”,  and a helper verb,  “makeblock”,
>>> which constructs one of the look-up arrays.
>>> 
>>> Here it is;  look out for line-wraps,  though it looks ok this end! :-
>>> 
>>> 
>>> ==
>>> NB. produce a table of "restricted growth functions" (rgf) (strings of
>>> symbols) subject to
>>> NB. requirement that each "function" (or string) includes at least one
>>> instance of each symbol
>>> NB. eg 001100 is an rgf,  but if all the symbols '012' are required,
>>> it's not suitable here
>>> NB. eg an rgf such as 001213 is a suitable equivalent to
>>> NB. |01|24|3|5|,  a 4-partition for 6 elements
>>> 
>>> NB. Any symbols may be used,  but they are subject to an implicit or
>>> explicit ordering.
>>> 
>>> parMD =: 3 : 0
>>> y parMD~ <:#y
>>> :
>>> k=. <: x
>>> NB. starting/current row
>>> if. 1 = #y do.
>>>list =. ,: cur =. (-y){.i.x
>>> else.NB. Admit a starting row (of integers, not symbols) other than
>>> 0 0 0 1 2 ...
>>>  NB. NB. not tested here for validity!!!
>>>list =. ,: cur =. y
>>> end.
>>> n=. #cur
>>> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary,  but '012...'
>>> here
>>> if. x > n do. NB. special-case impossible partitions
>>>' '$~ 0, n
>>> elseif. x = 1 do. NB. special-case 1-partition
>>>,: n#{.a
>>> elseif. x = 2 do. NB. special-case 2-partition
>>>a{~ (n#2) #: }. i. 2 ^ n-1
>>> elseif. x = n do. NB. special-case n-partition
>>>,: n{.a
>>> elseif. 1 do.
>>> NB.  I use the term k-partition, below, loosely - it should be x-
>>> partition or (k+1)-partn.
>>> list =. a {~ list NB.  output as char array,  offset so that 0 1 2
>>> ... <==> '012...'
>>> NB. end  =. k <. i. n NB.  preset last row if required for stopping
>>> condition
>>> incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
>>> blnk =. +/\ incr  NB.  look-up array for blanking all elements
>>> after i{cur
>>> block=. x makeblock n NB.  look-up array for forcing "new" rows to be k-
>>> partition equivalents.
>>> ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth
>>> function index finder,
>>>   NB. modified for
>>> limitation to 1+k symbols
>>> while. n | i =. ki cur do.  NB. test new index - stop if = n
>>>   NB. one of several possible stopping conditions -
>>> could test cur -: end
>>>new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth
>>> function"
>>>mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a k-
>>> partition
>>> NB. Adjust "new" if not already a k-partition equivalent,  and expand
>>> to several rows
>>>new   =. new +"1 >mx { block
>>> NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if
>>> (and only if) x = 4
>>>list  =. list, new { a
>>>cur   =. {: new
>>> end.
>>> list
>>> end.
>>

Re: [Jprogramming] Partitions

2017-11-18 Thread Raul Miller
Yeah, that's ascii for you - though it doesn't really matter.

Of course, if that bothers you you could replace
a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary,  but '012...'
with
a=. ~.;{:@;: ::a:"1 '0',.~a.

But that's probably not worth the extra millisecond it costs.

Thanks,

-- 
Raul


On Sat, Nov 18, 2017 at 7:01 AM, Erling Hellenäs
 wrote:
> Hi all!
>
> I wondered what would happen when we ran out of digits.
>
>a=:14 parMD 15
>1{a
> 01023456789:;<=
>
> Cheers,
> Erling Hellenäs
>
>
> On 2017-11-17 19:14, 'mike_liz@tiscali.co.uk' via Programming wrote:
>>
>> Erling Helenas,  Raul Miller,  and others have come up with various
>> methods to generate subsets of “restricted generating functions” (RGFs)
>> suitable for the production of partitions of sets.  Several of these
>> have used Ruskey’s algorithm.
>>
>> I’ve found a fairly simple approach which has the benefits of (a) not
>> being recursive,  (b) being fairly easy to understand, and (c) not
>> generating redundant data needing later filtering.  It does,  however,
>> use a loop,  albeit needing fewer loops than the final number of rows,
>> ie RGFs .
>>
>> It saves a fair amount of space by using a character array of symbols
>> rather than integers to represent the RGFs.  A character string serves
>> equally as well as an integer vector as left argument to > generation of boxed partitions.
>>
>> Key features,  which might be improved upon, include the local verb
>> “ki” which yields the index of that element in an RGF which needs to be
>> incremented in generating the next RGF,  and a number of small look-up
>> mini-arrays useful in finding the next appropriate few RGFs.
>>
>> Its performance compares favourably with other recent offerings.
>>
>> There is one main verb,  “parMD”,  and a helper verb,  “makeblock”,
>> which constructs one of the look-up arrays.
>>
>> Here it is;  look out for line-wraps,  though it looks ok this end! :-
>>
>>
>> ==
>> NB. produce a table of "restricted growth functions" (rgf) (strings of
>> symbols) subject to
>> NB. requirement that each "function" (or string) includes at least one
>> instance of each symbol
>> NB. eg 001100 is an rgf,  but if all the symbols '012' are required,
>> it's not suitable here
>> NB. eg an rgf such as 001213 is a suitable equivalent to
>> NB. |01|24|3|5|,  a 4-partition for 6 elements
>>
>> NB. Any symbols may be used,  but they are subject to an implicit or
>> explicit ordering.
>>
>> parMD =: 3 : 0
>> y parMD~ <:#y
>> :
>> k=. <: x
>> NB. starting/current row
>> if. 1 = #y do.
>> list =. ,: cur =. (-y){.i.x
>> else.NB. Admit a starting row (of integers, not symbols) other than
>> 0 0 0 1 2 ...
>>   NB. NB. not tested here for validity!!!
>> list =. ,: cur =. y
>> end.
>> n=. #cur
>> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary,  but '012...'
>> here
>> if. x > n do. NB. special-case impossible partitions
>> ' '$~ 0, n
>> elseif. x = 1 do. NB. special-case 1-partition
>> ,: n#{.a
>> elseif. x = 2 do. NB. special-case 2-partition
>> a{~ (n#2) #: }. i. 2 ^ n-1
>> elseif. x = n do. NB. special-case n-partition
>> ,: n{.a
>> elseif. 1 do.
>> NB.  I use the term k-partition, below, loosely - it should be x-
>> partition or (k+1)-partn.
>> list =. a {~ list NB.  output as char array,  offset so that 0 1 2
>> ... <==> '012...'
>> NB. end  =. k <. i. n NB.  preset last row if required for stopping
>> condition
>> incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
>> blnk =. +/\ incr  NB.  look-up array for blanking all elements
>> after i{cur
>> block=. x makeblock n NB.  look-up array for forcing "new" rows to be k-
>> partition equivalents.
>> ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth
>> function index finder,
>>NB. modified for
>> limitation to 1+k symbols
>> while. n | i =. ki cur do.  NB. test new index - stop if = n
>>NB. one of several possible stopping conditions -
>> could test cur -: end
>> new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth
>> function"
>> mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a k-
>> partition
>> NB. Adjust "new" if not already a k-partition equivalent,  and expand
>> to several rows
>> new   =. new +"1 >mx { block
>> NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if
>> (and only if) x = 4
>> list  =. list, new { a
>> cur   =. {: new
>> end.
>> list
>> end.
>> )
>>
>> NB. assemble look-up array of blocks
>> NB. eg
>> NB.4 makeblock 5
>> NB. +-+-+-+-+
>> NB. |0 0 1 2 3|0 0 0 2 3|0 0 0 0 3|0 0 0 0 0|
>> NB. | |0 0 1 2 3|0 0 0 1 3|0 0 0 0 1|
>> NB. | | |0 0 0 2 3|0 0 0 0 2|
>> NB. | | | |0 0 0 0 3|
>> NB. +-

Re: [Jprogramming] Partitions

2017-11-18 Thread Erling Hellenäs

Hi all!

I wondered what would happen when we ran out of digits.

   a=:14 parMD 15
   1{a
01023456789:;<=

Cheers,
Erling Hellenäs

On 2017-11-17 19:14, 'mike_liz@tiscali.co.uk' via Programming wrote:

Erling Helenas,  Raul Miller,  and others have come up with various
methods to generate subsets of “restricted generating functions” (RGFs)
suitable for the production of partitions of sets.  Several of these
have used Ruskey’s algorithm.

I’ve found a fairly simple approach which has the benefits of (a) not
being recursive,  (b) being fairly easy to understand, and (c) not
generating redundant data needing later filtering.  It does,  however,
use a loop,  albeit needing fewer loops than the final number of rows,
ie RGFs .

It saves a fair amount of space by using a character array of symbols
rather than integers to represent the RGFs.  A character string serves
equally as well as an integer vector as left argument to  n do. NB. special-case impossible partitions
' '$~ 0, n
elseif. x = 1 do. NB. special-case 1-partition
,: n#{.a
elseif. x = 2 do. NB. special-case 2-partition
a{~ (n#2) #: }. i. 2 ^ n-1
elseif. x = n do. NB. special-case n-partition
,: n{.a
elseif. 1 do.
NB.  I use the term k-partition, below, loosely - it should be x-
partition or (k+1)-partn.
list =. a {~ list NB.  output as char array,  offset so that 0 1 2
... <==> '012...'
NB. end  =. k <. i. n NB.  preset last row if required for stopping
condition
incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
blnk =. +/\ incr  NB.  look-up array for blanking all elements
after i{cur
block=. x makeblock n NB.  look-up array for forcing "new" rows to be k-
partition equivalents.
ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth
function index finder,
   NB. modified for
limitation to 1+k symbols
while. n | i =. ki cur do.  NB. test new index - stop if = n
   NB. one of several possible stopping conditions -
could test cur -: end
new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth
function"
mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a k-
partition
NB. Adjust "new" if not already a k-partition equivalent,  and expand
to several rows
new   =. new +"1 >mx { block
NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if
(and only if) x = 4
list  =. list, new { a
cur   =. {: new
end.
list
end.
)

NB. assemble look-up array of blocks
NB. eg
NB.4 makeblock 5
NB. +-+-+-+-+
NB. |0 0 1 2 3|0 0 0 2 3|0 0 0 0 3|0 0 0 0 0|
NB. | |0 0 1 2 3|0 0 0 1 3|0 0 0 0 1|
NB. | | |0 0 0 2 3|0 0 0 0 2|
NB. | | | |0 0 0 0 3|
NB. +-+-+-+-+
makeblock =: 3 : 0
makeblock/ y
:
NB. a work-a-day method,  not a smart implementation!
m  =. 0
b  =. ''
i  =. i. x
while. x >: m =. >: m do.
b =. b, < (i.m),. m#,: i =. }. i
end.
(-y){."1 each b
)


==

eg - generate RGFs suitable for 4-partitions of 5 elements:
parMD/ 4 5
00123
01023
01123
01203
01213
01223
01230
01231
01232
01233

(parMD/ 4 5)http://www.jsoftware.com/forums.htm



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-17 Thread Raul Miller
   blockmake=: (-@[ {."1&.> ] <@({.,"0 1 }.)"0 1~ 1+])i.
   (5 blockmake 4) -: 4 makeblock 5
1

Thanks,

-- 
Raul


On Fri, Nov 17, 2017 at 1:14 PM, 'mike_liz@tiscali.co.uk' via
Programming  wrote:
> Erling Helenas,  Raul Miller,  and others have come up with various
> methods to generate subsets of “restricted generating functions” (RGFs)
> suitable for the production of partitions of sets.  Several of these
> have used Ruskey’s algorithm.
>
> I’ve found a fairly simple approach which has the benefits of (a) not
> being recursive,  (b) being fairly easy to understand, and (c) not
> generating redundant data needing later filtering.  It does,  however,
> use a loop,  albeit needing fewer loops than the final number of rows,
> ie RGFs .
>
> It saves a fair amount of space by using a character array of symbols
> rather than integers to represent the RGFs.  A character string serves
> equally as well as an integer vector as left argument to  generation of boxed partitions.
>
> Key features,  which might be improved upon, include the local verb
> “ki” which yields the index of that element in an RGF which needs to be
> incremented in generating the next RGF,  and a number of small look-up
> mini-arrays useful in finding the next appropriate few RGFs.
>
> Its performance compares favourably with other recent offerings.
>
> There is one main verb,  “parMD”,  and a helper verb,  “makeblock”,
> which constructs one of the look-up arrays.
>
> Here it is;  look out for line-wraps,  though it looks ok this end! :-
>
> ==
> NB. produce a table of "restricted growth functions" (rgf) (strings of
> symbols) subject to
> NB. requirement that each "function" (or string) includes at least one
> instance of each symbol
> NB. eg 001100 is an rgf,  but if all the symbols '012' are required,
> it's not suitable here
> NB. eg an rgf such as 001213 is a suitable equivalent to
> NB. |01|24|3|5|,  a 4-partition for 6 elements
>
> NB. Any symbols may be used,  but they are subject to an implicit or
> explicit ordering.
>
> parMD =: 3 : 0
> y parMD~ <:#y
> :
> k=. <: x
> NB. starting/current row
> if. 1 = #y do.
>list =. ,: cur =. (-y){.i.x
> else.NB. Admit a starting row (of integers, not symbols) other than
> 0 0 0 1 2 ...
>  NB. NB. not tested here for validity!!!
>list =. ,: cur =. y
> end.
> n=. #cur
> a=. a. }.~ a. i. '0'   NB. symbol list - arbitrary,  but '012...'
> here
> if. x > n do. NB. special-case impossible partitions
>' '$~ 0, n
> elseif. x = 1 do. NB. special-case 1-partition
>,: n#{.a
> elseif. x = 2 do. NB. special-case 2-partition
>a{~ (n#2) #: }. i. 2 ^ n-1
> elseif. x = n do. NB. special-case n-partition
>,: n{.a
> elseif. 1 do.
> NB.  I use the term k-partition, below, loosely - it should be x-
> partition or (k+1)-partn.
> list =. a {~ list NB.  output as char array,  offset so that 0 1 2
> ... <==> '012...'
> NB. end  =. k <. i. n NB.  preset last row if required for stopping
> condition
> incr =. =/~ i.n   NB.  look-up array for incrementing i{cur
> blnk =. +/\ incr  NB.  look-up array for blanking all elements
> after i{cur
> block=. x makeblock n NB.  look-up array for forcing "new" rows to be k-
> partition equivalents.
> ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth
> function index finder,
>   NB. modified for
> limitation to 1+k symbols
> while. n | i =. ki cur do.  NB. test new index - stop if = n
>   NB. one of several possible stopping conditions -
> could test cur -: end
>new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth
> function"
>mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a k-
> partition
> NB. Adjust "new" if not already a k-partition equivalent,  and expand
> to several rows
>new   =. new +"1 >mx { block
> NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if
> (and only if) x = 4
>list  =. list, new { a
>cur   =. {: new
> end.
> list
> end.
> )
>
> NB. assemble look-up array of blocks
> NB. eg
> NB.4 makeblock 5
> NB. +-+-+-+-+
> NB. |0 0 1 2 3|0 0 0 2 3|0 0 0 0 3|0 0 0 0 0|
> NB. | |0 0 1 2 3|0 0 0 1 3|0 0 0 0 1|
> NB. | | |0 0 0 2 3|0 0 0 0 2|
> NB. | | | |0 0 0 0 3|
> NB. +-+-+-+-+
> makeblock =: 3 : 0
> makeblock/ y
> :
> NB. a work-a-day method,  not a smart implementation!
> m  =. 0
> b  =. ''
> i  =. i. x
> while. x >: m =. >: m do.
>b =. b, < (i.m),. m#,: i =. }. i
> end.
> (-y){."1 each b
> )
>
>
> ==
>
> eg - generate RGFs suitable for 4-partitions of 5 elements:
>parMD/ 4 5
> 00123
> 01023
> 01123
> 01203
> 01213
> 01223
> 01230
> 01231
> 012

Re: [Jprogramming] Partitions

2017-11-17 Thread 'mike_liz....@tiscali.co.uk' via Programming
Erling Helenas,  Raul Miller,  and others have come up with various 
methods to generate subsets of “restricted generating functions” (RGFs) 
suitable for the production of partitions of sets.  Several of these 
have used Ruskey’s algorithm.

I’ve found a fairly simple approach which has the benefits of (a) not 
being recursive,  (b) being fairly easy to understand, and (c) not 
generating redundant data needing later filtering.  It does,  however,  
use a loop,  albeit needing fewer loops than the final number of rows, 
ie RGFs .

It saves a fair amount of space by using a character array of symbols 
rather than integers to represent the RGFs.  A character string serves 
equally as well as an integer vector as left argument to  n do. NB. special-case impossible partitions
   ' '$~ 0, n 
elseif. x = 1 do. NB. special-case 1-partition
   ,: n#{.a
elseif. x = 2 do. NB. special-case 2-partition
   a{~ (n#2) #: }. i. 2 ^ n-1 
elseif. x = n do. NB. special-case n-partition
   ,: n{.a
elseif. 1 do. 
NB.  I use the term k-partition, below, loosely - it should be x-
partition or (k+1)-partn. 
list =. a {~ list NB.  output as char array,  offset so that 0 1 2 
... <==> '012...'
NB. end  =. k <. i. n NB.  preset last row if required for stopping 
condition 
incr =. =/~ i.n   NB.  look-up array for incrementing i{cur 
blnk =. +/\ incr  NB.  look-up array for blanking all elements 
after i{cur
block=. x makeblock n NB.  look-up array for forcing "new" rows to be k-
partition equivalents.
ki   =. >:@i:&1@:(}. < k <. >:@:(>./\)@:}:)   NB. restricted growth 
function index finder, 
  NB. modified for 
limitation to 1+k symbols
while. n | i =. ki cur do.  NB. test new index - stop if = n
  NB. one of several possible stopping conditions - 
could test cur -: end 
   new   =. (i{incr) + cur*i{blnk  NB. next suitable "restricted growth 
function" 
   mx=. >./ new   NB. ALL values 0 1 2 ... k MUST appear for a k-
partition
NB. Adjust "new" if not already a k-partition equivalent,  and expand 
to several rows 
   new   =. new +"1 >mx { block 
NB.  eg 00101000 (invalid k-part if x>2) becomes 00101023, 00101123 if 
(and only if) x = 4
   list  =. list, new { a
   cur   =. {: new
end.
list
end.
)

NB. assemble look-up array of blocks 
NB. eg
NB.4 makeblock 5
NB. +-+-+-+-+
NB. |0 0 1 2 3|0 0 0 2 3|0 0 0 0 3|0 0 0 0 0|
NB. | |0 0 1 2 3|0 0 0 1 3|0 0 0 0 1|
NB. | | |0 0 0 2 3|0 0 0 0 2|
NB. | | | |0 0 0 0 3|
NB. +-+-+-+-+
makeblock =: 3 : 0
makeblock/ y
:
NB. a work-a-day method,  not a smart implementation! 
m  =. 0
b  =. ''
i  =. i. x
while. x >: m =. >: m do. 
   b =. b, < (i.m),. m#,: i =. }. i 
end.
(-y){."1 each b
)


==

eg - generate RGFs suitable for 4-partitions of 5 elements:
   parMD/ 4 5
00123
01023
01123
01203
01213
01223
01230
01231
01232
01233

   (parMD/ 4 5)http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-15 Thread Erling Hellenäs

Hi all !

The performance of my MultisetPermutationsEnumerate is far from glimmering:

   N=: 1 2 1 2 1 1 1
   y=: 0 1 1 2 3 3 4 5 6
   ts'MultisetPermutationsEnumerate N'
1.9134 1.67805e7
   ts'permUnique y'
0.254264 1.05908e8
   (/:~ permUnique y) -: /:~MultisetPermutationsEnumerate N
1

permUnique=: [: ~. (A.~i.@!@#)

MultisetPermutationsEnumerate =: 3 : 0
NB. Enumerate multiset or bag permutations.
NB. y - vector with number of repetitions.
NB. Result - table of permutations - indexes in the nub
NB. of the multiset.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
p=.(+/y)#0
'r p N'=. (p;y) MPERec <:#p
|."1 r
)

MPERec =: 4 : 0
'p N'=.x
if. (0{N) = >:y do.
  r=.,:p
else.
  r=. (0,#p)$0
  for_j. (N>0)#i.#N do.
    p=. j y } p
    N=. (<:j{N) j } N
    't p N'=. (p;N) MPERec <:y
    r=.r,t
    N=. (>:j{N) j } N
    p=.0 y }p
  end.
end.
r;p;N
)

Cheers,

Erling Hellenäs


Den 2017-11-07 kl. 11:50, skrev Erling Hellenäs:

Hi all!

I created a program for enumeration of multiset permutations. It could 
possibly be used to answer the Quora question.


Comments are welcome.

   Display=: 4 : ' x { ~. y'

   N=: ,2 1
   y=: ,6 6 7
   MultisetPermutationsEnumerate N
0 0 1
0 1 0
1 0 0
   (MultisetPermutationsEnumerate N )Display y
6 6 7
6 7 6
7 6 6

--Project

MultisetPermutationsEnumerate =: 3 : 0
NB. Enumerate multiset or bag permutations.
NB. y - vector with number of repetitions.
NB. Result - table of permutations - indexes in the nub
NB. of the multiset.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
p=.(+/y)#0
'r p N'=. (p;y) MPERec <:#p
|."1 r
)

MPERec =: 4 : 0
'p N'=.x
if. (0{N) = >:y do.
  r=.,:p
else.
  r=. (0,#p)$0
  for_j. (N>0)#i.#N do.
    p=. j y } p
    N=. (<:j{N) j } N
    't p N'=. (p;N) MPERec <:y
    r=.r,t
    N=. (>:j{N) j } N
    p=.0 y }p
  end.
end.
r;p;N
)

Display=: 4 : ' x { ~. y'

log=: ,.
Hi all!

Do we have a program or built-in  function to enumerate the 
permutations of multisets, sets with item repetitions?


Cheers,

Erling Hellenäs


Den 2017-11-06 kl. 10:37, skrev Linda Alvord:

  This is handier when there are more sets of repetions.

  (!6)%(!2)*!2
180
    /
    (!6)%*/!2 2
180

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] 
On Behalf Of Erling Hellenäs

Sent: Sunday, November 5, 2017 11:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

Even though this solution is only relevant as an answer to the Quora 
question, I want to post a correction.
Since there can be duplicates in the root sets, there is not always 
!n permutations.

The formula is here:
https://brilliant.org/wiki/permutations-with-repetition/
The corrected list:

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
perm=.3 : '(!#y)%*/!+/y=/~.y'
r5=.perm"1 r4
+/r5
)

Test output:

     v=: ((x-1)#1),q:u=:2*2*3*3
     r1=:3 parRuskeyE #v
     r2=: >r1 (*/)@:{&.>"1 0 < v
     r3=:/:~"1 r2
     [r4=: ~.r3
1 2 18
2 2  9
1 4  9
2 3  6
3 3  4
1 6  6
1 3 12
1 1 36
     *./u =*/"1 r4
1
     perm=: 3 : '(!#y)%*/!+/y=/~.y'
     [r5=:perm"1 r4
6 3 6 6 3 3 6 3
     [+/r5
36

     3 list 2*2*3*3
36

     perm 1 2 3 3
12
     (!4)%!2
12
     perm 1 2 3 3 5 5
180
     (!6)%(!2)*!2
180

Cheers,

Erling Hellenäs



On 2017-11-03 18:24, Erling Hellenäs wrote:

Hi all!

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
(!x)*#r4
)

    3 list 24
36

Cheers,
Erling Hellenäs

On 2017-11-03 17:36, Erling Hellenäs wrote:

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

    [v=: 1 1 ,q:24
1 1 2 2 2 3
    [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5    │2 3    │
├───┼───┼───┤
│0 3    │1 4 5  │2  │
├───┼───┼───┤
│0  │1 3 4 5│2  │
├───┼───┼───┤
│0  │1 4 5  │2 3    │
├───┼───┼───┤
│0 3    │1 5    │2 4    │
├───┼───┼───┤
│0  │1 3 5  │2 4    │
├───

Re: [Jprogramming] Partitions

2017-11-15 Thread Erling Hellenäs

Was this problem solved? /Erling


Den 2017-11-14 kl. 14:04, skrev Raul Miller:

Are you looking for this?

https://www.mediawiki.org/wiki/Help:Links#External_links

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-14 Thread Raul Miller
Are you looking for this?

https://www.mediawiki.org/wiki/Help:Links#External_links

Thanks,

-- 
Raul


On Tue, Nov 14, 2017 at 6:20 AM, Erling Hellenäs
 wrote:
> Hi all!
>
> I modified this page:
>
> http://code.jsoftware.com/wiki/Essays/Set_Partitions
>
> The reference links look strange. Maybe someone can fix if you want it
> differently. Or tell me how to do.
>
> Cheers,
>
> Erling Hellenäs
>
>
>
> Den 2017-11-07 kl. 16:12, skrev Raul Miller:
>>
>> This book:
>> https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf
>>
>> Thanks,
>>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-14 Thread Erling Hellenäs

Hi all!

I modified this page:

http://code.jsoftware.com/wiki/Essays/Set_Partitions

The reference links look strange. Maybe someone can fix if you want it 
differently. Or tell me how to do.


Cheers,

Erling Hellenäs



Den 2017-11-07 kl. 16:12, skrev Raul Miller:

This book: 
https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-10 Thread Erling Hellenäs

Hi all!

Sorry, I referenced the wrong link.
Should I put it on this page? 
http://code.jsoftware.com/wiki/Essays/Set_Partitions


Cheers,
Erling Hellenäs

Den 2017-11-07 kl. 13:43, skrev Erling Hellenäs:

Hi all!

If we want to include parRuskeyE in a text about set partitions, we 
could use this definition:


SetPartitionsGenerateF =: 4 : 0
NB. Generate all set partitions with k subsets from
NB. an original set with n unique items.
NB. x - number of subsets
NB. y - number of items in the set to partition
NB. Result - table of integers
NB. -each row is a generated set partition
NB. -columns contain the subset number of the items
NB.  with the corresponding position in the set to
NB.  partition.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
(,: i.y) SPGF (x-1);y-1
)

SPGF =: 4 : 0
'k n' =. y
r=. (0,_1{.$x)$0
if. k=n do.
  r=.x
else.
  s=.n {."1 x
  e=.(n+1)}."1 x
  a=.,/s ( [,"1 1 (i.k+1),"0 1 ])"1 e
  r=.r, a SPGF k;n-1
  if. k > 0 do.
    a=.s,.k,.e
    r=.r, a SPGF (k-1);n-1
  end.
end.
r
)

It could possibly be included in this page: 
https://en.wikipedia.org/wiki/Partition_of_a_set


I could include it with some minimal text.

Opinions?

Cheers,

Erling Hellenäs


Den 2017-11-07 kl. 11:50, skrev Erling Hellenäs:

Hi all!

I created a program for enumeration of multiset permutations. It 
could possibly be used to answer the Quora question.


Comments are welcome.

   Display=: 4 : ' x { ~. y'

   N=: ,2 1
   y=: ,6 6 7
   MultisetPermutationsEnumerate N
0 0 1
0 1 0
1 0 0
   (MultisetPermutationsEnumerate N )Display y
6 6 7
6 7 6
7 6 6

--Project

MultisetPermutationsEnumerate =: 3 : 0
NB. Enumerate multiset or bag permutations.
NB. y - vector with number of repetitions.
NB. Result - table of permutations - indexes in the nub
NB. of the multiset.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
p=.(+/y)#0
'r p N'=. (p;y) MPERec <:#p
|."1 r
)

MPERec =: 4 : 0
'p N'=.x
if. (0{N) = >:y do.
  r=.,:p
else.
  r=. (0,#p)$0
  for_j. (N>0)#i.#N do.
    p=. j y } p
    N=. (<:j{N) j } N
    't p N'=. (p;N) MPERec <:y
    r=.r,t
    N=. (>:j{N) j } N
    p=.0 y }p
  end.
end.
r;p;N
)

Display=: 4 : ' x { ~. y'

log=: ,.
Hi all!

Do we have a program or built-in  function to enumerate the 
permutations of multisets, sets with item repetitions?


Cheers,

Erling Hellenäs


Den 2017-11-06 kl. 10:37, skrev Linda Alvord:

  This is handier when there are more sets of repetions.

  (!6)%(!2)*!2
180
    /
    (!6)%*/!2 2
180

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] 
On Behalf Of Erling Hellenäs

Sent: Sunday, November 5, 2017 11:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

Even though this solution is only relevant as an answer to the 
Quora question, I want to post a correction.
Since there can be duplicates in the root sets, there is not always 
!n permutations.

The formula is here:
https://brilliant.org/wiki/permutations-with-repetition/
The corrected list:

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
perm=.3 : '(!#y)%*/!+/y=/~.y'
r5=.perm"1 r4
+/r5
)

Test output:

     v=: ((x-1)#1),q:u=:2*2*3*3
     r1=:3 parRuskeyE #v
     r2=: >r1 (*/)@:{&.>"1 0 < v
     r3=:/:~"1 r2
     [r4=: ~.r3
1 2 18
2 2  9
1 4  9
2 3  6
3 3  4
1 6  6
1 3 12
1 1 36
     *./u =*/"1 r4
1
     perm=: 3 : '(!#y)%*/!+/y=/~.y'
     [r5=:perm"1 r4
6 3 6 6 3 3 6 3
     [+/r5
36

     3 list 2*2*3*3
36

     perm 1 2 3 3
12
     (!4)%!2
12
     perm 1 2 3 3 5 5
180
     (!6)%(!2)*!2
180

Cheers,

Erling Hellenäs



On 2017-11-03 18:24, Erling Hellenäs wrote:

Hi all!

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
(!x)*#r4
)

    3 list 24
36

Cheers,
Erling Hellenäs

On 2017-11-03 17:36, Erling Hellenäs wrote:

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

    [v=: 1 1 ,q:24
1 1 2 2 2 3
    [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5 

Re: [Jprogramming] Partitions

2017-11-07 Thread Erling Hellenäs
My opinion is that Frank Ruskey is advertently sharing this draft and 
that we can reference it.

https://scholar.google.ca/citations?user=z81N4kUJ
/Erling

On 2017-11-07 19:32, Roger Shepherd wrote:

Here is at least one reference, with linked references to others:
http://www3.cs.stonybrook.edu/~algorith/implement/ruskey/implement.shtml


Sent from Mail for Windows 10

From: Raul Miller
Sent: Tuesday, November 7, 2017 10:13 AM
To: Programming forum
Subject: Re: [Jprogramming] Partitions

This book: 
https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-07 Thread Roger Shepherd
Here is at least one reference, with linked references to others:
http://www3.cs.stonybrook.edu/~algorith/implement/ruskey/implement.shtml


Sent from Mail for Windows 10

From: Raul Miller
Sent: Tuesday, November 7, 2017 10:13 AM
To: Programming forum
Subject: Re: [Jprogramming] Partitions

This book: 
https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf

Thanks,

-- 
Raul


On Tue, Nov 7, 2017 at 8:38 AM, Erling Hellenäs
 wrote:
> Like this?
>
> "Generate Set Partitions - K Subsets
>
> Generate all set partitions with k subsets from an original set with n
> unique items.
> J definition created by Erling Hellenäs from a Frank Ruskey algorithm."
>
> Followed by the two programs.
>
> The book in the reference list and the reference number after "algorithm".
> I did not find a published book with this name.
>
> /Erling
>
> Den 2017-11-07 kl. 14:23, skrev Raul Miller:
>>
>> Depends on the text?
>>
>> But I don't think we have a full collection of partition routines to
>> adequately address the various partitioning concepts ennumerated in
>> the book linked from
>> http://jsoftware.com/pipermail/programming/2017-October/049377.html
>>
>> Thanks,
>>
>
> --
> 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

Re: [Jprogramming] Partitions

2017-11-07 Thread Raul Miller
This book: 
https://math.dartmouth.edu/news-resources/electronic/kpbogart/ComboNoteswHints11-06-04.pdf

Thanks,

-- 
Raul


On Tue, Nov 7, 2017 at 8:38 AM, Erling Hellenäs
 wrote:
> Like this?
>
> "Generate Set Partitions - K Subsets
>
> Generate all set partitions with k subsets from an original set with n
> unique items.
> J definition created by Erling Hellenäs from a Frank Ruskey algorithm."
>
> Followed by the two programs.
>
> The book in the reference list and the reference number after "algorithm".
> I did not find a published book with this name.
>
> /Erling
>
> Den 2017-11-07 kl. 14:23, skrev Raul Miller:
>>
>> Depends on the text?
>>
>> But I don't think we have a full collection of partition routines to
>> adequately address the various partitioning concepts ennumerated in
>> the book linked from
>> http://jsoftware.com/pipermail/programming/2017-October/049377.html
>>
>> Thanks,
>>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-07 Thread Erling Hellenäs

Like this?

"Generate Set Partitions - K Subsets

Generate all set partitions with k subsets from an original set with n unique 
items.
J definition created by Erling Hellenäs from a Frank Ruskey algorithm."

Followed by the two programs.

The book in the reference list and the reference number after "algorithm".
I did not find a published book with this name.

/Erling

Den 2017-11-07 kl. 14:23, skrev Raul Miller:

Depends on the text?

But I don't think we have a full collection of partition routines to
adequately address the various partitioning concepts ennumerated in
the book linked from
http://jsoftware.com/pipermail/programming/2017-October/049377.html

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-07 Thread Raul Miller
t;> 6 8 6 7
>> 6 8 7 6
>> 7 6 6 8
>> 7 6 8 6
>> 7 8 6 6
>> 8 6 6 7
>> 8 6 7 6
>> 8 7 6 6
>>N=: ,1 2 1
>>y=: ,7 6 6 8
>>MultisetPermutationsEnumerate N
>> 0 1 1 2
>> 0 1 2 1
>> 0 2 1 1
>> 1 0 1 2
>> 1 0 2 1
>> 1 1 0 2
>> 1 1 2 0
>> 1 2 0 1
>> 1 2 1 0
>> 2 0 1 1
>> 2 1 0 1
>> 2 1 1 0
>>(MultisetPermutationsEnumerate N )Display y
>> 7 6 6 8
>> 7 6 8 6
>> 7 8 6 6
>> 6 7 6 8
>> 6 7 8 6
>> 6 6 7 8
>> 6 6 8 7
>> 6 8 7 6
>> 6 8 6 7
>> 8 7 6 6
>> 8 6 7 6
>> 8 6 6 7
>>
>> Cheers,
>>
>> Erling Hellenäs
>>
>>
>>
>> Den 2017-11-06 kl. 14:21, skrev Erling Hellenäs:
>>>
>>> Hi all!
>>>
>>> Do we have a program or built-in  function to enumerate the permutations
>>> of multisets, sets with item repetitions?
>>>
>>> Cheers,
>>>
>>> Erling Hellenäs
>>>
>>>
>>> Den 2017-11-06 kl. 10:37, skrev Linda Alvord:
>>>>
>>>>   This is handier when there are more sets of repetions.
>>>>
>>>>   (!6)%(!2)*!2
>>>> 180
>>>> /
>>>> (!6)%*/!2 2
>>>> 180
>>>>
>>>> Linda
>>>>
>>>> -Original Message-
>>>> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
>>>> Behalf Of Erling Hellenäs
>>>> Sent: Sunday, November 5, 2017 11:28 AM
>>>> To: programm...@jsoftware.com
>>>> Subject: Re: [Jprogramming] Partitions
>>>>
>>>> Hi all!
>>>>
>>>> Even though this solution is only relevant as an answer to the Quora
>>>> question, I want to post a correction.
>>>> Since there can be duplicates in the root sets, there is not always !n
>>>> permutations.
>>>> The formula is here:
>>>> https://brilliant.org/wiki/permutations-with-repetition/
>>>> The corrected list:
>>>>
>>>> list=:4 : 0
>>>> v=.((x-1)#1),q: y
>>>> r1=.x parRuskeyE #v
>>>> r2=. >r1 (*/)@:{&.>"1 0 < v
>>>> r3=./:~"1 r2
>>>> r4=. ~.r3
>>>> perm=.3 : '(!#y)%*/!+/y=/~.y'
>>>> r5=.perm"1 r4
>>>> +/r5
>>>> )
>>>>
>>>> Test output:
>>>>
>>>>  v=: ((x-1)#1),q:u=:2*2*3*3
>>>>  r1=:3 parRuskeyE #v
>>>>  r2=: >r1 (*/)@:{&.>"1 0 < v
>>>>  r3=:/:~"1 r2
>>>>  [r4=: ~.r3
>>>> 1 2 18
>>>> 2 2  9
>>>> 1 4  9
>>>> 2 3  6
>>>> 3 3  4
>>>> 1 6  6
>>>> 1 3 12
>>>> 1 1 36
>>>>  *./u =*/"1 r4
>>>> 1
>>>>  perm=: 3 : '(!#y)%*/!+/y=/~.y'
>>>>  [r5=:perm"1 r4
>>>> 6 3 6 6 3 3 6 3
>>>>  [+/r5
>>>> 36
>>>>
>>>>  3 list 2*2*3*3
>>>> 36
>>>>
>>>>  perm 1 2 3 3
>>>> 12
>>>>  (!4)%!2
>>>> 12
>>>>  perm 1 2 3 3 5 5
>>>> 180
>>>>  (!6)%(!2)*!2
>>>> 180
>>>>
>>>> Cheers,
>>>>
>>>> Erling Hellenäs
>>>>
>>>>
>>>>
>>>> On 2017-11-03 18:24, Erling Hellenäs wrote:
>>>>>
>>>>> Hi all!
>>>>>
>>>>> list=:4 : 0
>>>>> v=.((x-1)#1),q: y
>>>>> r1=.x parRuskeyE #v
>>>>> r2=. >r1 (*/)@:{&.>"1 0 < v
>>>>> r3=./:~"1 r2
>>>>> r4=. ~.r3
>>>>> (!x)*#r4
>>>>> )
>>>>>
>>>>> 3 list 24
>>>>> 36
>>>>>
>>>>> Cheers,
>>>>> Erling Hellenäs
>>>>>
>>>>> On 2017-11-03 17:36, Erling Hellenäs wrote:
>>>>>>
>>>>>> Hi all  !
>>>>>>
>>>>>> Below is the output of the run on the Quora question.
>>>>>>
>>>>>> Maybe someone can see if there is a problem.
>>>>>>
>>>>>> Cheers,
>>>>>>
>>>>>> Erling Hellenäs
>>>>>>
>>>>>> 

Re: [Jprogramming] Partitions

2017-11-07 Thread Erling Hellenäs

Hi all!

If we want to include parRuskeyE in a text about set partitions, we 
could use this definition:


SetPartitionsGenerateF =: 4 : 0
NB. Generate all set partitions with k subsets from
NB. an original set with n unique items.
NB. x - number of subsets
NB. y - number of items in the set to partition
NB. Result - table of integers
NB. -each row is a generated set partition
NB. -columns contain the subset number of the items
NB.  with the corresponding position in the set to
NB.  partition.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
(,: i.y) SPGF (x-1);y-1
)

SPGF =: 4 : 0
'k n' =. y
r=. (0,_1{.$x)$0
if. k=n do.
  r=.x
else.
  s=.n {."1 x
  e=.(n+1)}."1 x
  a=.,/s ( [,"1 1 (i.k+1),"0 1 ])"1 e
  r=.r, a SPGF k;n-1
  if. k > 0 do.
    a=.s,.k,.e
    r=.r, a SPGF (k-1);n-1
  end.
end.
r
)

It could possibly be included in this page: 
https://en.wikipedia.org/wiki/Partition_of_a_set


I could include it with some minimal text.

Opinions?

Cheers,

Erling Hellenäs


Den 2017-11-07 kl. 11:50, skrev Erling Hellenäs:

Hi all!

I created a program for enumeration of multiset permutations. It could 
possibly be used to answer the Quora question.


Comments are welcome.

   Display=: 4 : ' x { ~. y'

   N=: ,2 1
   y=: ,6 6 7
   MultisetPermutationsEnumerate N
0 0 1
0 1 0
1 0 0
   (MultisetPermutationsEnumerate N )Display y
6 6 7
6 7 6
7 6 6

--Project

MultisetPermutationsEnumerate =: 3 : 0
NB. Enumerate multiset or bag permutations.
NB. y - vector with number of repetitions.
NB. Result - table of permutations - indexes in the nub
NB. of the multiset.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
p=.(+/y)#0
'r p N'=. (p;y) MPERec <:#p
|."1 r
)

MPERec =: 4 : 0
'p N'=.x
if. (0{N) = >:y do.
  r=.,:p
else.
  r=. (0,#p)$0
  for_j. (N>0)#i.#N do.
    p=. j y } p
    N=. (<:j{N) j } N
    't p N'=. (p;N) MPERec <:y
    r=.r,t
    N=. (>:j{N) j } N
    p=.0 y }p
  end.
end.
r;p;N
)

Display=: 4 : ' x { ~. y'

log=: ,.
Hi all!

Do we have a program or built-in  function to enumerate the 
permutations of multisets, sets with item repetitions?


Cheers,

Erling Hellenäs


Den 2017-11-06 kl. 10:37, skrev Linda Alvord:

  This is handier when there are more sets of repetions.

  (!6)%(!2)*!2
180
    /
    (!6)%*/!2 2
180

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] 
On Behalf Of Erling Hellenäs

Sent: Sunday, November 5, 2017 11:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

Even though this solution is only relevant as an answer to the Quora 
question, I want to post a correction.
Since there can be duplicates in the root sets, there is not always 
!n permutations.

The formula is here:
https://brilliant.org/wiki/permutations-with-repetition/
The corrected list:

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
perm=.3 : '(!#y)%*/!+/y=/~.y'
r5=.perm"1 r4
+/r5
)

Test output:

     v=: ((x-1)#1),q:u=:2*2*3*3
     r1=:3 parRuskeyE #v
     r2=: >r1 (*/)@:{&.>"1 0 < v
     r3=:/:~"1 r2
     [r4=: ~.r3
1 2 18
2 2  9
1 4  9
2 3  6
3 3  4
1 6  6
1 3 12
1 1 36
     *./u =*/"1 r4
1
     perm=: 3 : '(!#y)%*/!+/y=/~.y'
     [r5=:perm"1 r4
6 3 6 6 3 3 6 3
     [+/r5
36

     3 list 2*2*3*3
36

     perm 1 2 3 3
12
     (!4)%!2
12
     perm 1 2 3 3 5 5
180
     (!6)%(!2)*!2
180

Cheers,

Erling Hellenäs



On 2017-11-03 18:24, Erling Hellenäs wrote:

Hi all!

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
(!x)*#r4
)

    3 list 24
36

Cheers,
Erling Hellenäs

On 2017-11-03 17:36, Erling Hellenäs wrote:

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

    [v=: 1 1 ,q:24
1 1 2 2 2 3
    [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5    │2 3    │
├───┼───┼───┤
│0 3    │1 4 5  │2  │
├───┼───┼───┤
│0  │1 3 4 5│2  │
├───┼───┼───┤
│0  │1 4 5  │2 3    │
├───┼───┼───┤
│0 3    │1 5 

Re: [Jprogramming] Partitions

2017-11-07 Thread Erling Hellenäs

Hi all!

I created a program for enumeration of multiset permutations. It could 
possibly be used to answer the Quora question.


Comments are welcome.

   Display=: 4 : ' x { ~. y'

   N=: ,2 1
   y=: ,6 6 7
   MultisetPermutationsEnumerate N
0 0 1
0 1 0
1 0 0
   (MultisetPermutationsEnumerate N )Display y
6 6 7
6 7 6
7 6 6

--Project

MultisetPermutationsEnumerate =: 3 : 0
NB. Enumerate multiset or bag permutations.
NB. y - vector with number of repetitions.
NB. Result - table of permutations - indexes in the nub
NB. of the multiset.
NB. Algorithm from Frank Ruskey: Combinatorial Generation
NB. Working Version (1j-CSC 425/520).
p=.(+/y)#0
'r p N'=. (p;y) MPERec <:#p
|."1 r
)

MPERec =: 4 : 0
'p N'=.x
if. (0{N) = >:y do.
  r=.,:p
else.
  r=. (0,#p)$0
  for_j. (N>0)#i.#N do.
    p=. j y } p
    N=. (<:j{N) j } N
    't p N'=. (p;N) MPERec <:y
    r=.r,t
    N=. (>:j{N) j } N
    p=.0 y }p
  end.
end.
r;p;N
)

Display=: 4 : ' x { ~. y'

log=: ,.
Hi all!

Do we have a program or built-in  function to enumerate the 
permutations of multisets, sets with item repetitions?


Cheers,

Erling Hellenäs


Den 2017-11-06 kl. 10:37, skrev Linda Alvord:

  This is handier when there are more sets of repetions.

  (!6)%(!2)*!2
180
    /
    (!6)%*/!2 2
180

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] 
On Behalf Of Erling Hellenäs

Sent: Sunday, November 5, 2017 11:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

Even though this solution is only relevant as an answer to the Quora 
question, I want to post a correction.
Since there can be duplicates in the root sets, there is not always 
!n permutations.

The formula is here:
https://brilliant.org/wiki/permutations-with-repetition/
The corrected list:

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
perm=.3 : '(!#y)%*/!+/y=/~.y'
r5=.perm"1 r4
+/r5
)

Test output:

     v=: ((x-1)#1),q:u=:2*2*3*3
     r1=:3 parRuskeyE #v
     r2=: >r1 (*/)@:{&.>"1 0 < v
     r3=:/:~"1 r2
     [r4=: ~.r3
1 2 18
2 2  9
1 4  9
2 3  6
3 3  4
1 6  6
1 3 12
1 1 36
     *./u =*/"1 r4
1
     perm=: 3 : '(!#y)%*/!+/y=/~.y'
     [r5=:perm"1 r4
6 3 6 6 3 3 6 3
     [+/r5
36

     3 list 2*2*3*3
36

     perm 1 2 3 3
12
     (!4)%!2
12
     perm 1 2 3 3 5 5
180
     (!6)%(!2)*!2
180

Cheers,

Erling Hellenäs



On 2017-11-03 18:24, Erling Hellenäs wrote:

Hi all!

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
(!x)*#r4
)

    3 list 24
36

Cheers,
Erling Hellenäs

On 2017-11-03 17:36, Erling Hellenäs wrote:

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

    [v=: 1 1 ,q:24
1 1 2 2 2 3
    [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5    │2 3    │
├───┼───┼───┤
│0 3    │1 4 5  │2  │
├───┼───┼───┤
│0  │1 3 4 5│2  │
├───┼───┼───┤
│0  │1 4 5  │2 3    │
├───┼───┼───┤
│0 3    │1 5    │2 4    │
├───┼───┼───┤
│0  │1 3 5  │2 4    │
├───┼───┼───┤
│0  │1 5    │2 3 4  │
├───┼───┼───┤
│0 3 4  │1  │2 5    │
├───┼───┼───┤
│0 4    │1 3    │2 5    │
├───┼───┼───┤
│0 4    │1  │2 3 5  │
├───┼───┼───┤
│0 3    │1 4    │2 5    │
├───┼───┼───┤
│0  │1 3 4  │2 5    │
├───┼───┼───┤
│0  │1 4    │2 3 5  │
├───┼───┼───┤
│0 3    │1  │2 4 5  │
├───┼───┼───┤
│0  │1 3    │2 4 5  │
├───┼───┼───┤
│0  │1  │2 3 4 5│
├───┼───┼───┤
│0 2 4 5│1  │3  │
├───┼───┼───┤
│0 4 5  │1 2    │3  │
├───┼───┼───┤
│0 2 5  │1 4    │3  │
├───┼───┼───┤
│0 5    │1 2 4  │3  │
├───┼───┼───┤
│0 2 5  │1  │3 4    │
├───┼───┼───┤
│0 5    │1 2    │3 4    │
├───┼───┼───┤
│0 2 4  │1 5    │3  │
├───┼───┼───┤
│0 4    │1 2 5  │3  │
├───┼───┼───┤
│0 2    │1 4 5  │3  │
├───┼───┼───┤
│0  │1 2 4 5│3  │
├───┼───┼───┤

Re: [Jprogramming] Partitions

2017-11-07 Thread Erling Hellenäs

Hi all!

Anyone who want's a wiki discussion can start one? I don't know why 
first Raul and now Skip seemingly asks me.


Cheers,

Erling Hellenäs


Den 2017-11-06 kl. 19:54, skrev 'Skip Cave' via Programming:

Interesting. Erling's bitmap CombE help solves another category of Quora
problems:

How many four digit numbers can be formed from the number 1,3,4,6,8 and 9 if
repetition of digits is not allowed?
<https://www.quora.com/How-many-four-digit-numbers-can-be-formed-from-the-number-1-3-4-6-8-and-9-if-repetition-of-digits-is-not-allowed>


b =. 4 CombE 6

a =. 1 3 4 6 8 9

#c = b#a

15  NB. so the answer is 15.


NB. What are the numbers?

  c

1 3 4 6

1 3 4 8

1 3 4 9

1 3 6 8

1 3 6 9

1 3 8 9

1 4 6 8

1 4 6 9

1 4 8 9

1 6 8 9

3 4 6 8

3 4 6 9

3 4 8 9

3 6 8 9

4 6 8 9

 NB. Convert to decimal

 10 10 10 10#. c

1346 1348 1349 1368 1369 1389 1468 1469 1489 1689 3468 3469 3489 3689 4689


I agree with Raul, This deserves a Wiki page. For that matter, the various
combination verbs and partition verbs recently discussed in the programming
forum also deserves a Wiki discussion page.

​Skip
​

Skip Cave
Cave Consulting LLC

On Mon, Nov 6, 2017 at 9:31 AM, Erling Hellenäs 
wrote:


Hi all!

I made a version of comb, which uses bitmaps.

2 CombE 3
1 1 0
1 0 1
0 1 1
(2 CombE 3) #"1 i.3
0 1
0 2
1 2

ts'12 comb 24'
0.606316 9.02647e8
ts'12 CombE 24'
0.202434 2.82336e8
ts'35 comb 40'
1.39813 1.22167e9
ts'35 CombE 40'
0.268998 1.53241e8

CombE=: 4 : 0
k=. <"1 (-i.1+d=.y-x)|."0 1 y{.1
z=. (d$<(0,y)$0),<,:y#0
for. i.x do. z=. k (+."1)&.> ,&.>/\. (_1&|."1)&.> z end.
; z
)

Cheers,

Erling Hellenäs








Den 2017-11-03 kl. 08:18, skrev Linda Alvord:


You can compare the tree versions of comb3a and comb4 to see their
differences:

comb3a
┌─ [
│  ┌─ =
│   ┌──┤  ┌─ / ─── +
│   │  └─ " ──┴─ 1
│   │
├───┤ ┌─ |.
──┤   │  ┌─ @: ─┴─ I.
│   ├─ @ ──┴─ #
│   └─ ]
│
│   ┌─ 2
│   │ ┌─ #:
└───┤  ┌─ @ ──┴─ i.
├─ @: ─┴─ ^
└─ ]
 comb4
┌─ [:
├─ |.
│┌─ [:
│├─ I.
──┤│┌─ [
││├─ =
│││┌─ [:
││┌───┤│ ┌─ / ─── +
└┤│   │├─ " ─┴─ 1
 ││   └┤
 │││ ┌─ [:
 │││ ├─ #:
 ││└─┤ ┌─ [:
 ││  │ ├─ i.
 └┤  └─┤┌─ 2
  │└┼─ ^
  │ └─ ]
  ├─ #
  │   ┌─ [:
  │   ├─ #:
  └───┤┌─ [:
  │├─ i.
  └┤ ┌─ 2
   └─┼─ ^
 └─ ]

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
Behalf Of Linda Alvord
Sent: Friday, November 3, 2017 2:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Oops, this should be better:


 comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.   2^y'
 comb4
[: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
 #3 comb4  5
10
 Linda


-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
Behalf Of Raul Miller
Sent: Thursday, November 2, 2017 2:54 AM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

No, you did not test your work.

 #3 comb 5
10
 #3 comb4 5
56

Probably the simplest way to approach what I think you are trying to do
involves expanding the part in parenthesis independent of the rest of it.

And, personally, when I am working on a line of J code, I like to have a
little test rig so that I can quickly see when I have gone astray.
Doing that here (and clipping out my mistakes), then adding comments gets
me this:

First, I set up a test rig with the original expression:

 #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
10

Then, I rephrase the outer part as an explicit expression for 13 :

#3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
10

Since that worked, I take a look at what 13 : gave me

 13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
[ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]

Next, I try that out in my test rig:

 #3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
10

So, now that I have that, I do a rephrase of the inner part for another
13 :

 # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
10

And, since that works, I take a look at what it gave me:

 [ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ] [ ([: |. [: I. ] #~
[ = [: +/"1 ]) [: #: [: i. 2 ^ ]

And, voila, I've g

Re: [Jprogramming] Partitions

2017-11-06 Thread 'Skip Cave' via Programming
Interesting. Erling's bitmap CombE help solves another category of Quora
problems:

How many four digit numbers can be formed from the number 1,3,4,6,8 and 9 if
repetition of digits is not allowed?
<https://www.quora.com/How-many-four-digit-numbers-can-be-formed-from-the-number-1-3-4-6-8-and-9-if-repetition-of-digits-is-not-allowed>


   b =. 4 CombE 6

   a =. 1 3 4 6 8 9

   #c = b#a

15  NB. so the answer is 15.


NB. What are the numbers?

 c

1 3 4 6

1 3 4 8

1 3 4 9

1 3 6 8

1 3 6 9

1 3 8 9

1 4 6 8

1 4 6 9

1 4 8 9

1 6 8 9

3 4 6 8

3 4 6 9

3 4 8 9

3 6 8 9

4 6 8 9

NB. Convert to decimal

10 10 10 10#. c

1346 1348 1349 1368 1369 1389 1468 1469 1489 1689 3468 3469 3489 3689 4689


I agree with Raul, This deserves a Wiki page. For that matter, the various
combination verbs and partition verbs recently discussed in the programming
forum also deserves a Wiki discussion page.

​Skip
​

Skip Cave
Cave Consulting LLC

On Mon, Nov 6, 2017 at 9:31 AM, Erling Hellenäs 
wrote:

> Hi all!
>
> I made a version of comb, which uses bitmaps.
>
>2 CombE 3
> 1 1 0
> 1 0 1
> 0 1 1
>(2 CombE 3) #"1 i.3
> 0 1
> 0 2
> 1 2
>
>ts'12 comb 24'
> 0.606316 9.02647e8
>ts'12 CombE 24'
> 0.202434 2.82336e8
>ts'35 comb 40'
> 1.39813 1.22167e9
>ts'35 CombE 40'
> 0.268998 1.53241e8
>
> CombE=: 4 : 0
> k=. <"1 (-i.1+d=.y-x)|."0 1 y{.1
> z=. (d$<(0,y)$0),<,:y#0
> for. i.x do. z=. k (+."1)&.> ,&.>/\. (_1&|."1)&.> z end.
> ; z
> )
>
> Cheers,
>
> Erling Hellenäs
>
>
>
>
>
>
>
>
> Den 2017-11-03 kl. 08:18, skrev Linda Alvord:
>
>> You can compare the tree versions of comb3a and comb4 to see their
>> differences:
>>
>> comb3a
>>┌─ [
>>│  ┌─ =
>>│   ┌──┤  ┌─ / ─── +
>>│   │  └─ " ──┴─ 1
>>│   │
>>├───┤ ┌─ |.
>> ──┤   │  ┌─ @: ─┴─ I.
>>│   ├─ @ ──┴─ #
>>│   └─ ]
>>│
>>│   ┌─ 2
>>│   │ ┌─ #:
>>└───┤  ┌─ @ ──┴─ i.
>>├─ @: ─┴─ ^
>>└─ ]
>> comb4
>>┌─ [:
>>├─ |.
>>│┌─ [:
>>│├─ I.
>> ──┤│┌─ [
>>││├─ =
>>│││┌─ [:
>>││┌───┤│ ┌─ / ─── +
>>└┤│   │├─ " ─┴─ 1
>> ││   └┤
>> │││ ┌─ [:
>> │││ ├─ #:
>> ││└─┤ ┌─ [:
>> ││  │ ├─ i.
>> └┤  └─┤┌─ 2
>>  │└┼─ ^
>>  │ └─ ]
>>  ├─ #
>>  │   ┌─ [:
>>  │   ├─ #:
>>  └───┤┌─ [:
>>  │├─ i.
>>  └┤ ┌─ 2
>>   └─┼─ ^
>> └─ ]
>>
>> Linda
>>
>> -Original Message-
>> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
>> Behalf Of Linda Alvord
>> Sent: Friday, November 3, 2017 2:28 AM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Partitions
>>
>> Oops, this should be better:
>>
>>
>> comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.   2^y'
>> comb4
>> [: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
>> #3 comb4  5
>> 10
>> Linda
>>
>>
>> -Original Message-
>> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
>> Behalf Of Raul Miller
>> Sent: Thursday, November 2, 2017 2:54 AM
>> To: Programming forum 
>> Subject: Re: [Jprogramming] Partitions
>>
>> No, you did not test your work.
>>
>> #3 comb 5
>> 10
>> #3 comb4 5
>> 56
>>
>> Probably the simplest way to approach what I think you are trying to do
>> involves expanding the part in parenthesis independent of the rest of it.
>>
>> And, personally, when I am working on a line of J code, I like to have a
>> little test rig so that I can quickly see when I have gone astray.
>> Doing that here (and clipping out my mistakes), then adding comments gets
>> me this:
>>
>> First, I set up a test rig with the original expression:
>>
>> #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
>> 10
>>
>> Then, I rephrase the outer

Re: [Jprogramming] Partitions

2017-11-06 Thread Raul Miller
Very nice.

This deserves its own thread though. And possibly a wiki entry.

Thanks,

-- 
Raul


On Mon, Nov 6, 2017 at 10:31 AM, Erling Hellenäs
 wrote:
> Hi all!
>
> I made a version of comb, which uses bitmaps.
>
>2 CombE 3
> 1 1 0
> 1 0 1
> 0 1 1
>(2 CombE 3) #"1 i.3
> 0 1
> 0 2
> 1 2
>
>ts'12 comb 24'
> 0.606316 9.02647e8
>ts'12 CombE 24'
> 0.202434 2.82336e8
>ts'35 comb 40'
> 1.39813 1.22167e9
>ts'35 CombE 40'
> 0.268998 1.53241e8
>
> CombE=: 4 : 0
> k=. <"1 (-i.1+d=.y-x)|."0 1 y{.1
> z=. (d$<(0,y)$0),<,:y#0
> for. i.x do. z=. k (+."1)&.> ,&.>/\. (_1&|."1)&.> z end.
> ; z
> )
>
> Cheers,
>
> Erling Hellenäs
>
>
>
>
>
>
>
>
> Den 2017-11-03 kl. 08:18, skrev Linda Alvord:
>>
>> You can compare the tree versions of comb3a and comb4 to see their
>> differences:
>>
>> comb3a
>>┌─ [
>>│  ┌─ =
>>│   ┌──┤  ┌─ / ─── +
>>│   │  └─ " ──┴─ 1
>>│   │
>>├───┤ ┌─ |.
>> ──┤   │  ┌─ @: ─┴─ I.
>>│   ├─ @ ──┴─ #
>>│   └─ ]
>>│
>>│   ┌─ 2
>>│   │ ┌─ #:
>>└───┤  ┌─ @ ──┴─ i.
>>├─ @: ─┴─ ^
>>└─ ]
>> comb4
>>┌─ [:
>>├─ |.
>>│┌─ [:
>>│├─ I.
>> ──┤│┌─ [
>>││├─ =
>>│││┌─ [:
>>││┌───┤│ ┌─ / ─── +
>>└┤│   │├─ " ─┴─ 1
>> ││   └┤
>> │││ ┌─ [:
>> │││ ├─ #:
>> ││└─┤ ┌─ [:
>> ││  │ ├─ i.
>> └┤  └─┤┌─ 2
>>  │└┼─ ^
>>  │ └─ ]
>>  ├─ #
>>  │   ┌─ [:
>>  │   ├─ #:
>>  └───┤┌─ [:
>>  │├─ i.
>>  └┤ ┌─ 2
>>   └─┼─ ^
>> └─ ]
>>
>> Linda
>>
>> -Original Message-
>> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
>> Behalf Of Linda Alvord
>> Sent: Friday, November 3, 2017 2:28 AM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Partitions
>>
>> Oops, this should be better:
>>
>>
>> comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.   2^y'
>> comb4
>> [: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
>> #3 comb4  5
>> 10
>> Linda
>>
>>
>> -Original Message-
>> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
>> Behalf Of Raul Miller
>> Sent: Thursday, November 2, 2017 2:54 AM
>> To: Programming forum 
>> Subject: Re: [Jprogramming] Partitions
>>
>> No, you did not test your work.
>>
>> #3 comb 5
>> 10
>> #3 comb4 5
>> 56
>>
>> Probably the simplest way to approach what I think you are trying to do
>> involves expanding the part in parenthesis independent of the rest of it.
>>
>> And, personally, when I am working on a line of J code, I like to have a
>> little test rig so that I can quickly see when I have gone astray.
>> Doing that here (and clipping out my mistakes), then adding comments gets
>> me this:
>>
>> First, I set up a test rig with the original expression:
>>
>> #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
>> 10
>>
>> Then, I rephrase the outer part as an explicit expression for 13 :
>>
>>#3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
>> 10
>>
>> Since that worked, I take a look at what 13 : gave me
>>
>> 13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
>> [ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]
>>
>> Next, I try that out in my test rig:
>>
>> #3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
>> 10
>>
>> So, now that I have that, I do a rephrase of the inner part for another 13
>> :
>>
>> # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
>> 10
>>
>> And, since that works, I take a look at what it gave me:
>>
>> [ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ] [ ([: |. [: I.

Re: [Jprogramming] Partitions

2017-11-06 Thread Erling Hellenäs

Hi all!

I made a version of comb, which uses bitmaps.

   2 CombE 3
1 1 0
1 0 1
0 1 1
   (2 CombE 3) #"1 i.3
0 1
0 2
1 2

   ts'12 comb 24'
0.606316 9.02647e8
   ts'12 CombE 24'
0.202434 2.82336e8
   ts'35 comb 40'
1.39813 1.22167e9
   ts'35 CombE 40'
0.268998 1.53241e8

CombE=: 4 : 0
k=. <"1 (-i.1+d=.y-x)|."0 1 y{.1
z=. (d$<(0,y)$0),<,:y#0
for. i.x do. z=. k (+."1)&.> ,&.>/\. (_1&|."1)&.> z end.
; z
)

Cheers,

Erling Hellenäs







Den 2017-11-03 kl. 08:18, skrev Linda Alvord:

You can compare the tree versions of comb3a and comb4 to see their differences:

comb3a
   ┌─ [
   │  ┌─ =
   │   ┌──┤  ┌─ / ─── +
   │   │  └─ " ──┴─ 1
   │   │
   ├───┤ ┌─ |.
──┤   │  ┌─ @: ─┴─ I.
   │   ├─ @ ──┴─ #
   │   └─ ]
   │
   │   ┌─ 2
   │   │ ┌─ #:
   └───┤  ┌─ @ ──┴─ i.
   ├─ @: ─┴─ ^
   └─ ]

comb4

   ┌─ [:
   ├─ |.
   │┌─ [:
   │├─ I.
──┤│┌─ [
   ││├─ =
   │││┌─ [:
   ││┌───┤│ ┌─ / ─── +
   └┤│   │├─ " ─┴─ 1
││   └┤
│││ ┌─ [:
│││ ├─ #:
││└─┤ ┌─ [:
││  │ ├─ i.
└┤  └─┤┌─ 2
 │└┼─ ^
 │ └─ ]
 ├─ #
 │   ┌─ [:
 │   ├─ #:
 └───┤┌─ [:
 │├─ i.
 └┤ ┌─ 2
  └─┼─ ^
└─ ]

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Linda Alvord
Sent: Friday, November 3, 2017 2:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Oops, this should be better:


comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.  2^y'
comb4
[: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
#3 comb4  5
10

Linda



-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Thursday, November 2, 2017 2:54 AM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

No, you did not test your work.

#3 comb 5
10
#3 comb4 5
56

Probably the simplest way to approach what I think you are trying to do 
involves expanding the part in parenthesis independent of the rest of it.

And, personally, when I am working on a line of J code, I like to have a little 
test rig so that I can quickly see when I have gone astray.
Doing that here (and clipping out my mistakes), then adding comments gets me 
this:

First, I set up a test rig with the original expression:

#3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
10

Then, I rephrase the outer part as an explicit expression for 13 :

   #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
10

Since that worked, I take a look at what 13 : gave me

13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
[ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]

Next, I try that out in my test rig:

#3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
10

So, now that I have that, I do a rephrase of the inner part for another 13 :

# 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
10

And, since that works, I take a look at what it gave me:

[ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ] [ ([: |. [: I. ] #~ [ = [: 
+/"1 ]) [: #: [: i. 2 ^ ]

And, voila, I've got another variation that I can use in a word definition:

comb4a=: [ ([: |. [: I. ] #~ [ = [: +/"1 ]) [: #: [: i. 2 ^ ]

That's a bit ugly, but ascii is ugly (but, also, standardized and - thus - 
widely available).

So, we can try that out and see it in operation:

3 comb4a 5
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4

Also... note that when working with "real life" mechanisms (not just J), having 
some sort of test rig to make sure that what you are doing behaves like you think it does 
can be an invaluable time saver. (The alternative - putting a lot of work into something, 
only to find out that it doesn't work and that you have to start over again - is 
sometimes necessary but not always attractive.)

(Well, that, and remember that this approach is slower than the stock comb 
implementation when y > 10 - so mostly I would just do require'stats' and then 
use that comb implementation.)

Then again, now that we have this variation, we could also try to reconstruct 
an explicit expression which does the same thing. For that we want to merge 
these two examples:

#3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
# 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5

Perhaps something like

Re: [Jprogramming] Partitions

2017-11-06 Thread Erling Hellenäs

Hi all!

Do we have a program or built-in  function to enumerate the permutations 
of multisets, sets with item repetitions?


Cheers,

Erling Hellenäs


Den 2017-11-06 kl. 10:37, skrev Linda Alvord:

  This is handier when there are more sets of repetions.

  (!6)%(!2)*!2
180
/
(!6)%*/!2 2
180

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Erling Hellenäs
Sent: Sunday, November 5, 2017 11:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

Even though this solution is only relevant as an answer to the Quora question, 
I want to post a correction.
Since there can be duplicates in the root sets, there is not always !n 
permutations.
The formula is here:
https://brilliant.org/wiki/permutations-with-repetition/
The corrected list:

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
perm=.3 : '(!#y)%*/!+/y=/~.y'
r5=.perm"1 r4
+/r5
)

Test output:

     v=: ((x-1)#1),q:u=:2*2*3*3
     r1=:3 parRuskeyE #v
     r2=: >r1 (*/)@:{&.>"1 0 < v
     r3=:/:~"1 r2
     [r4=: ~.r3
1 2 18
2 2  9
1 4  9
2 3  6
3 3  4
1 6  6
1 3 12
1 1 36
     *./u =*/"1 r4
1
     perm=: 3 : '(!#y)%*/!+/y=/~.y'
     [r5=:perm"1 r4
6 3 6 6 3 3 6 3
     [+/r5
36

     3 list 2*2*3*3
36

     perm 1 2 3 3
12
     (!4)%!2
12
     perm 1 2 3 3 5 5
180
     (!6)%(!2)*!2
180

Cheers,

Erling Hellenäs



On 2017-11-03 18:24, Erling Hellenäs wrote:

Hi all!

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
(!x)*#r4
)

    3 list 24
36

Cheers,
Erling Hellenäs

On 2017-11-03 17:36, Erling Hellenäs wrote:

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

    [v=: 1 1 ,q:24
1 1 2 2 2 3
    [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5    │2 3    │
├───┼───┼───┤
│0 3    │1 4 5  │2  │
├───┼───┼───┤
│0  │1 3 4 5│2  │
├───┼───┼───┤
│0  │1 4 5  │2 3    │
├───┼───┼───┤
│0 3    │1 5    │2 4    │
├───┼───┼───┤
│0  │1 3 5  │2 4    │
├───┼───┼───┤
│0  │1 5    │2 3 4  │
├───┼───┼───┤
│0 3 4  │1  │2 5    │
├───┼───┼───┤
│0 4    │1 3    │2 5    │
├───┼───┼───┤
│0 4    │1  │2 3 5  │
├───┼───┼───┤
│0 3    │1 4    │2 5    │
├───┼───┼───┤
│0  │1 3 4  │2 5    │
├───┼───┼───┤
│0  │1 4    │2 3 5  │
├───┼───┼───┤
│0 3    │1  │2 4 5  │
├───┼───┼───┤
│0  │1 3    │2 4 5  │
├───┼───┼───┤
│0  │1  │2 3 4 5│
├───┼───┼───┤
│0 2 4 5│1  │3  │
├───┼───┼───┤
│0 4 5  │1 2    │3  │
├───┼───┼───┤
│0 2 5  │1 4    │3  │
├───┼───┼───┤
│0 5    │1 2 4  │3  │
├───┼───┼───┤
│0 2 5  │1  │3 4    │
├───┼───┼───┤
│0 5    │1 2    │3 4    │
├───┼───┼───┤
│0 2 4  │1 5    │3  │
├───┼───┼───┤
│0 4    │1 2 5  │3  │
├───┼───┼───┤
│0 2    │1 4 5  │3  │
├───┼───┼───┤
│0  │1 2 4 5│3  │
├───┼───┼───┤
│0 2    │1 5    │3 4    │
├───┼───┼───┤
│0  │1 2 5  │3 4    │
├───┼───┼───┤
│0 2 4  │1  │3 5    │
├───┼───┼───┤
│0 4    │1 2    │3 5    │
├───┼───┼───┤
│0 2    │1 4    │3 5    │
├───┼───┼───┤
│0  │1 2 4  │3 5    │
├───┼───┼───┤
│0 2    │1  │3 4 5  │
├───┼───┼───┤
│0  │1 2    │3 4 5  │
├───┼───┼───┤
│0 1 4 5│2  │3  │
├───┼───┼───┤
│0 1 5  │2 4    │3  │
├───┼───┼───┤
│0 1 5  │2  │3 4    │
├───┼───┼───┤
│0 1 4  │2 5    │3  │
├───┼───┼───┤
│0 1    │2 4 5  │3  │
├───┼───┼───┤
│0 1    │2 5    │3 4    │
├───┼───┼───┤
│0 1 4  │2  │3 5    │
├───┼───┼───┤
│0 1    │2 4    │3 5    │
├───┼───┼───┤
│0 1    │2  │3 4 5  │
├───┼───┼───┤
│0 2 3 5│1  │4  │
├───┼───┼───┤
│0 3 5  │1 2    │4  │
├───┼───┼───┤
│0 2 5  │1 3    │4  │
├───┼───┼───┤
│0 5    │1 2

Re: [Jprogramming] Partitions

2017-11-06 Thread Linda Alvord
 This is handier when there are more sets of repetions.

 (!6)%(!2)*!2
180
   /
   (!6)%*/!2 2
180

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Erling Hellenäs
Sent: Sunday, November 5, 2017 11:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

Even though this solution is only relevant as an answer to the Quora question, 
I want to post a correction.
Since there can be duplicates in the root sets, there is not always !n 
permutations.
The formula is here:
https://brilliant.org/wiki/permutations-with-repetition/
The corrected list:

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
perm=.3 : '(!#y)%*/!+/y=/~.y'
r5=.perm"1 r4
+/r5
)

Test output:

    v=: ((x-1)#1),q:u=:2*2*3*3
    r1=:3 parRuskeyE #v
    r2=: >r1 (*/)@:{&.>"1 0 < v
    r3=:/:~"1 r2
    [r4=: ~.r3
1 2 18
2 2  9
1 4  9
2 3  6
3 3  4
1 6  6
1 3 12
1 1 36
    *./u =*/"1 r4
1
    perm=: 3 : '(!#y)%*/!+/y=/~.y'
    [r5=:perm"1 r4
6 3 6 6 3 3 6 3
    [+/r5
36

    3 list 2*2*3*3
36

    perm 1 2 3 3
12
    (!4)%!2
12
    perm 1 2 3 3 5 5
180
    (!6)%(!2)*!2
180

Cheers,

Erling Hellenäs



On 2017-11-03 18:24, Erling Hellenäs wrote:
> Hi all!
>
> list=:4 : 0
> v=.((x-1)#1),q: y
> r1=.x parRuskeyE #v
> r2=. >r1 (*/)@:{&.>"1 0 < v
> r3=./:~"1 r2
> r4=. ~.r3
> (!x)*#r4
> )
>
>    3 list 24
> 36
>
> Cheers,
> Erling Hellenäs
>
> On 2017-11-03 17:36, Erling Hellenäs wrote:
>> Hi all  !
>>
>> Below is the output of the run on the Quora question.
>>
>> Maybe someone can see if there is a problem.
>>
>> Cheers,
>>
>> Erling Hellenäs
>>
>>    [v=: 1 1 ,q:24
>> 1 1 2 2 2 3
>>    [r=:3 parRuskeyE #v
>> ┌───┬───┬───┐
>> │0 3 4 5│1  │2  │
>> ├───┼───┼───┤
>> │0 4 5  │1 3    │2  │
>> ├───┼───┼───┤
>> │0 4 5  │1  │2 3    │
>> ├───┼───┼───┤
>> │0 3 5  │1 4    │2  │
>> ├───┼───┼───┤
>> │0 5    │1 3 4  │2  │
>> ├───┼───┼───┤
>> │0 5    │1 4    │2 3    │
>> ├───┼───┼───┤
>> │0 3 5  │1  │2 4    │
>> ├───┼───┼───┤
>> │0 5    │1 3    │2 4    │
>> ├───┼───┼───┤
>> │0 5    │1  │2 3 4  │
>> ├───┼───┼───┤
>> │0 3 4  │1 5    │2  │
>> ├───┼───┼───┤
>> │0 4    │1 3 5  │2  │
>> ├───┼───┼───┤
>> │0 4    │1 5    │2 3    │
>> ├───┼───┼───┤
>> │0 3    │1 4 5  │2  │
>> ├───┼───┼───┤
>> │0  │1 3 4 5│2  │
>> ├───┼───┼───┤
>> │0  │1 4 5  │2 3    │
>> ├───┼───┼───┤
>> │0 3    │1 5    │2 4    │
>> ├───┼───┼───┤
>> │0  │1 3 5  │2 4    │
>> ├───┼───┼───┤
>> │0  │1 5    │2 3 4  │
>> ├───┼───┼───┤
>> │0 3 4  │1  │2 5    │
>> ├───┼───┼───┤
>> │0 4    │1 3    │2 5    │
>> ├───┼───┼───┤
>> │0 4    │1  │2 3 5  │
>> ├───┼───┼───┤
>> │0 3    │1 4    │2 5    │
>> ├───┼───┼───┤
>> │0  │1 3 4  │2 5    │
>> ├───┼───┼───┤
>> │0  │1 4    │2 3 5  │
>> ├───┼───┼───┤
>> │0 3    │1  │2 4 5  │
>> ├───┼───┼───┤
>> │0  │1 3    │2 4 5  │
>> ├───┼───┼───┤
>> │0  │1  │2 3 4 5│
>> ├───┼───┼───┤
>> │0 2 4 5│1  │3  │
>> ├───┼───┼───┤
>> │0 4 5  │1 2    │3  │
>> ├───┼───┼───┤
>> │0 2 5  │1 4    │3  │
>> ├───┼───┼───┤
>> │0 5    │1 2 4  │3  │
>> ├───┼───┼───┤
>> │0 2 5  │1  │3 4    │
>> ├───┼───┼───┤
>> │0 5    │1 2    │3 4    │
>> ├───┼───┼───┤
>> │0 2 4  │1 5    │3  │
>> ├───┼───┼───┤
>> │0 4    │1 2 5  │3  │
>> ├───┼───┼───┤
>> │0 2    │1 4 5  │3  │
>> ├───┼───┼───┤
>> │0  │1 2 4 5│3  │
>> ├───┼───┼───┤
>> │0 2    │1 5    │3 4    │
>> ├───┼───┼───┤
>> │0  │1 2 5  │3 4    │
>> ├───┼───┼───┤
>> │0 2 4  │1  │3 5    │
>> ├───┼───┼───┤
>> │0 4    │1 2    │3 5    │
>> ├───┼───┼───┤
>> │0 2    │1 4    │3 5    │
>> ├───┼───┼───┤
>> │0  │1 2 4  │3 5

Re: [Jprogramming] Partitions

2017-11-05 Thread Erling Hellenäs

Hi all!

Even though this solution is only relevant as an answer to the Quora 
question, I want to post a correction.
Since there can be duplicates in the root sets, there is not always !n 
permutations.

The formula is here:
https://brilliant.org/wiki/permutations-with-repetition/
The corrected list:

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
perm=.3 : '(!#y)%*/!+/y=/~.y'
r5=.perm"1 r4
+/r5
)

Test output:

   v=: ((x-1)#1),q:u=:2*2*3*3
   r1=:3 parRuskeyE #v
   r2=: >r1 (*/)@:{&.>"1 0 < v
   r3=:/:~"1 r2
   [r4=: ~.r3
1 2 18
2 2  9
1 4  9
2 3  6
3 3  4
1 6  6
1 3 12
1 1 36
   *./u =*/"1 r4
1
   perm=: 3 : '(!#y)%*/!+/y=/~.y'
   [r5=:perm"1 r4
6 3 6 6 3 3 6 3
   [+/r5
36

   3 list 2*2*3*3
36

   perm 1 2 3 3
12
   (!4)%!2
12
   perm 1 2 3 3 5 5
180
   (!6)%(!2)*!2
180

Cheers,

Erling Hellenäs



On 2017-11-03 18:24, Erling Hellenäs wrote:

Hi all!

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
(!x)*#r4
)

   3 list 24
36

Cheers,
Erling Hellenäs

On 2017-11-03 17:36, Erling Hellenäs wrote:

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

   [v=: 1 1 ,q:24
1 1 2 2 2 3
   [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5    │2 3    │
├───┼───┼───┤
│0 3    │1 4 5  │2  │
├───┼───┼───┤
│0  │1 3 4 5│2  │
├───┼───┼───┤
│0  │1 4 5  │2 3    │
├───┼───┼───┤
│0 3    │1 5    │2 4    │
├───┼───┼───┤
│0  │1 3 5  │2 4    │
├───┼───┼───┤
│0  │1 5    │2 3 4  │
├───┼───┼───┤
│0 3 4  │1  │2 5    │
├───┼───┼───┤
│0 4    │1 3    │2 5    │
├───┼───┼───┤
│0 4    │1  │2 3 5  │
├───┼───┼───┤
│0 3    │1 4    │2 5    │
├───┼───┼───┤
│0  │1 3 4  │2 5    │
├───┼───┼───┤
│0  │1 4    │2 3 5  │
├───┼───┼───┤
│0 3    │1  │2 4 5  │
├───┼───┼───┤
│0  │1 3    │2 4 5  │
├───┼───┼───┤
│0  │1  │2 3 4 5│
├───┼───┼───┤
│0 2 4 5│1  │3  │
├───┼───┼───┤
│0 4 5  │1 2    │3  │
├───┼───┼───┤
│0 2 5  │1 4    │3  │
├───┼───┼───┤
│0 5    │1 2 4  │3  │
├───┼───┼───┤
│0 2 5  │1  │3 4    │
├───┼───┼───┤
│0 5    │1 2    │3 4    │
├───┼───┼───┤
│0 2 4  │1 5    │3  │
├───┼───┼───┤
│0 4    │1 2 5  │3  │
├───┼───┼───┤
│0 2    │1 4 5  │3  │
├───┼───┼───┤
│0  │1 2 4 5│3  │
├───┼───┼───┤
│0 2    │1 5    │3 4    │
├───┼───┼───┤
│0  │1 2 5  │3 4    │
├───┼───┼───┤
│0 2 4  │1  │3 5    │
├───┼───┼───┤
│0 4    │1 2    │3 5    │
├───┼───┼───┤
│0 2    │1 4    │3 5    │
├───┼───┼───┤
│0  │1 2 4  │3 5    │
├───┼───┼───┤
│0 2    │1  │3 4 5  │
├───┼───┼───┤
│0  │1 2    │3 4 5  │
├───┼───┼───┤
│0 1 4 5│2  │3  │
├───┼───┼───┤
│0 1 5  │2 4    │3  │
├───┼───┼───┤
│0 1 5  │2  │3 4    │
├───┼───┼───┤
│0 1 4  │2 5    │3  │
├───┼───┼───┤
│0 1    │2 4 5  │3  │
├───┼───┼───┤
│0 1    │2 5    │3 4    │
├───┼───┼───┤
│0 1 4  │2  │3 5    │
├───┼───┼───┤
│0 1    │2 4    │3 5    │
├───┼───┼───┤
│0 1    │2  │3 4 5  │
├───┼───┼───┤
│0 2 3 5│1  │4  │
├───┼───┼───┤
│0 3 5  │1 2    │4  │
├───┼───┼───┤
│0 2 5  │1 3    │4  │
├───┼───┼───┤
│0 5    │1 2 3  │4  │
├───┼───┼───┤
│0 2 3  │1 5    │4  │
├───┼───┼───┤
│0 3    │1 2 5  │4  │
├───┼───┼───┤
│0 2    │1 3 5  │4  │
├───┼───┼───┤
│0  │1 2 3 5│4  │
├───┼───┼───┤
│0 2 3  │1  │4 5    │
├───┼───┼───┤
│0 3    │1 2    │4 5    │
├───┼───┼───┤
│0 2    │1 3    │4 5    │
├───┼───┼───┤
│0  │1 2 3  │4 5    │
├───┼───┼───┤
│0 1 3 5│2  │4  │
├───┼───┼───┤
│0 1 5  │2 3    │4  │
├───┼───┼───┤
│0 1 3  │2 5    │4  │
├───┼───┼───┤
│0 1    │2 3 5  │4  │
├───┼───┼───┤
│0 1 3  │2  │4

Re: [Jprogramming] Partitions

2017-11-05 Thread 'Mike Day' via Programming
As I pointed out some days ago,  29/10/17.

Ruskey himself,  I think,  discusses the “bijection” between the “restricted 
growth functions” and the required sets.  You can defer converting the linear 
array to boxes or omit that stage altogether according to need.

Cheers,
Mike


Please reply to mike_liz@tiscali.co.uk.  
Sent from my iPad

> On 5 Nov 2017, at 10:40, Erling Hellenäs  wrote:
> 
> Hi all!
> 
> If you remove the last statement of parRuskeyE, you get a program that is 
> much faster, uses much less memory and is more useful.
> 
> parRuskeyE =: 4 : 0
> 
> r=. (,: i.y) SE (x-1);y-1
> 
> r  
> )
> 
> 
> parRuskeyEx =: 4 : 0
> 
> (,: i.y) SE (x-1);y-1
> 
> )
> 
> 
>ts'5 parRuskeyE 10'
> 0.113852 3.89539e7
>ts'5 parRuskeyEx 10'
> 0.0392047 8.39949e6
> 
>2 parRuskeyE 3
> ┌───┬───┐
> │0 2│1  │
> ├───┼───┤
> │0  │1 2│
> ├───┼───┤
> │0 1│2  │
> └───┴───┘
>2 parRuskeyEx 3
> 0 1 0
> 0 1 1
> 0 0 1
>(2 parRuskeyEx 3) ┌───┬───┐
> │2 7│3  │
> ├───┼───┤
> │2  │3 7│
> ├───┼───┤
> │2 3│7  │
> └───┴───┘
> 
> Cheers,
> 
> Erling Hellenäs
> 
> 
> 
> 
>> On 2017-11-04 18:00, 'Skip Cave' via Programming wrote:
>> So, given the full parution set of say 3 par 4
>> 
>>]a =. 3 par 4
>> 
>> ┌───┬───┬───┐
>> 
>> │0 1│2  │3  │
>> 
>> ├───┼───┼───┤
>> 
>> │0 2│1  │3  │
>> 
>> ├───┼───┼───┤
>> 
>> │0  │1 2│3  │
>> 
>> ├───┼───┼───┤
>> 
>> │0 3│1  │2  │
>> 
>> ├───┼───┼───┤
>> 
>> │0  │1 3│2  │
>> 
>> ├───┼───┼───┤
>> 
>> │0  │1  │2 3│
>> 
>> └───┴───┴───┘
>> 
>> 
>> What would the verb 'sel' look like that would use those indices to select
>> from a different set of objects
>> 
>> 
>> a sel 'abcd'
>> 
>> ┌───┬───┬───┐
>> 
>> │a b│c  │d  │
>> 
>> ├───┼───┼───┤
>> 
>> │a c│b  │d  │
>> 
>> ├───┼───┼───┤
>> 
>> │a  │b c│d  │
>> 
>> ├───┼───┼───┤
>> 
>> │a d│b  │c  │
>> 
>> ├───┼───┼───┤
>> 
>> │a  │b d│c  │
>> 
>> ├───┼───┼───┤
>> 
>> │a  │b  │c d│
>> 
>> └───┴───┴───┘
>> 
>> 
>> Skip
>> 
>> 
>> 
>> Skip Cave
>> Cave Consulting LLC
>> 
>>> On Sat, Nov 4, 2017 at 11:09 AM, Skip Cave  wrote:
>>> 
>>> Raul,
>>> Yes, the original Quora question specified positive factors only, but i
>>> forgot to include that in the specification.
>>> 
>>> Skip
>>> 
>>> Skip Cave
>>> Cave Consulting LLC
>>> 
 On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller  wrote:
 
 Well, ok, though that was not a part of your re-specification this time.
 
 Actually, though, re-reading your spec, i left out a factor of 16 of
 the solutions: integers can be negative and as long as we include an
 even number of negatives they cancel out in a product.
 
 Thanks,
 
 --
 Raul
 
 
 On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming
  wrote:
> Raul, very nice!
> 
> Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
> course, that restricts the max number of partitions to the max number of
> prime factors of any p. That also greatly reduces the number of
 partition
> instances that will be generated. Then:
> 
> 5 par 358258
> 
> ┌─┬─┬──┬──┬───┐
> 
> │2│7│11│13│179│
> 
> └─┴─┴──┴──┴───┘
> 
> Skip
> 
> Skip Cave
> Cave Consulting LLC
> 
> On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller 
 wrote:
>> So... 358358 has five prime factors (32 integer factors). We want to
>> find all sorted sequences (not sets - values can repeat) of five of
>> those factors whose product is 358358.
>> 
>> To restrict our search, we can investigate only those sorted sequences
>> of "number of prime factors represented in the variable" whose sum is
>> five:
>> 
>>~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
>> 0 0 0 0 5
>> 0 0 0 1 4
>> 0 0 0 2 3
>> 0 0 1 1 3
>> 0 0 1 2 2
>> 0 1 1 1 2
>> 1 1 1 1 1
>> 
>> In other words, the results of these seven expressions (use
>> require'stats' first to get comb):
>> 
>>1 1 1 1
>> 
>> 358358
>>(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
>>/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
>>/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
>>~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>> /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>>q:358358
>> 
>> That's 44 different solutions:
>> 
>> 1  1  1   1 358358
>> 1  1  1 179   2002
>> 1  1  1  13  27566
>> 1  1  1  11  32578
>> 1  1  1   7  51194
>> 1  1  1   2 179179
>> 1  1  1 154   2327
>> 1  1  1 182   1969
>> 1  1  1 143   2506
>> 1  1  1 286   1253
>> 1  1  1  91   3938
>> 1  1  1  77   4654
>> 1  1  1 358   1001
>> 1  1  1  26  13783
>> 1  1  1  22  16289
>> 1  1  1  14  25597
>> 1  1 13 154179
>> 1  1 11 179182
>> 1  1 11  13   2506
>> 1  1  7 179286
>> 1  1  7  13   3938
>> 1  1  7  11   4654
>> 1  1  2 179   1001
>> 1 

Re: [Jprogramming] Partitions

2017-11-05 Thread Erling Hellenäs

And this:
   (2 parRuskeyEx 3)*//."1 [2 3 7
14  3
 2 21
 6  7
/Erling

On 2017-11-05 11:23, Erling Hellenäs wrote:
Documentation of parRuskey. Algorithm 4.23 in this book. 
http://www.1stworks.com/ref/ruskeycombgen.pdf /Erling


On 2017-11-05 11:08, Erling Hellenäs wrote:
The optimized version of parRuskeyE is here. 
http://www.jsoftware.com/pipermail/programming/2017-November/049515.html 
/Erling


On 2017-11-05 11:00, Erling Hellenäs wrote:
This is not the optimized version of parRuskeyE, but it might be the 
best to use to answer a Quora question. /Erling


On 2017-11-04 23:49, Raul Miller wrote:

Use parRuskeyE for par - defined in
http://www.jsoftware.com/pipermail/programming/2017-November/049493.html 



Thanks,



--
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

Re: [Jprogramming] Partitions

2017-11-05 Thread Erling Hellenäs

Hi all!

If you remove the last statement of parRuskeyE, you get a program that 
is much faster, uses much less memory and is more useful.


parRuskeyE =: 4 : 0

r=. (,: i.y) SE (x-1);y-1

r 
So, given the full parution set of say 3 par 4

]a =. 3 par 4

┌───┬───┬───┐

│0 1│2  │3  │

├───┼───┼───┤

│0 2│1  │3  │

├───┼───┼───┤

│0  │1 2│3  │

├───┼───┼───┤

│0 3│1  │2  │

├───┼───┼───┤

│0  │1 3│2  │

├───┼───┼───┤

│0  │1  │2 3│

└───┴───┴───┘


What would the verb 'sel' look like that would use those indices to select
from a different set of objects


 a sel 'abcd'

┌───┬───┬───┐

│a b│c  │d  │

├───┼───┼───┤

│a c│b  │d  │

├───┼───┼───┤

│a  │b c│d  │

├───┼───┼───┤

│a d│b  │c  │

├───┼───┼───┤

│a  │b d│c  │

├───┼───┼───┤

│a  │b  │c d│

└───┴───┴───┘


Skip



Skip Cave
Cave Consulting LLC

On Sat, Nov 4, 2017 at 11:09 AM, Skip Cave  wrote:


Raul,
Yes, the original Quora question specified positive factors only, but i
forgot to include that in the specification.

Skip

Skip Cave
Cave Consulting LLC

On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller  wrote:


Well, ok, though that was not a part of your re-specification this time.

Actually, though, re-reading your spec, i left out a factor of 16 of
the solutions: integers can be negative and as long as we include an
even number of negatives they cancel out in a product.

Thanks,

--
Raul


On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming
 wrote:

Raul, very nice!

Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
course, that restricts the max number of partitions to the max number of
prime factors of any p. That also greatly reduces the number of

partition

instances that will be generated. Then:

5 par 358258

┌─┬─┬──┬──┬───┐

│2│7│11│13│179│

└─┴─┴──┴──┴───┘

Skip

Skip Cave
Cave Consulting LLC

On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller 

wrote:

So... 358358 has five prime factors (32 integer factors). We want to
find all sorted sequences (not sets - values can repeat) of five of
those factors whose product is 358358.

To restrict our search, we can investigate only those sorted sequences
of "number of prime factors represented in the variable" whose sum is
five:

~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
0 0 0 0 5
0 0 0 1 4
0 0 0 2 3
0 0 1 1 3
0 0 1 2 2
0 1 1 1 2
1 1 1 1 1

In other words, the results of these seven expressions (use
require'stats' first to get comb):

1 1 1 1

358358
(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
 /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
q:358358

That's 44 different solutions:

1  1  1   1 358358
1  1  1 179   2002
1  1  1  13  27566
1  1  1  11  32578
1  1  1   7  51194
1  1  1   2 179179
1  1  1 154   2327
1  1  1 182   1969
1  1  1 143   2506
1  1  1 286   1253
1  1  1  91   3938
1  1  1  77   4654
1  1  1 358   1001
1  1  1  26  13783
1  1  1  22  16289
1  1  1  14  25597
1  1 13 154179
1  1 11 179182
1  1 11  13   2506
1  1  7 179286
1  1  7  13   3938
1  1  7  11   4654
1  1  2 179   1001
1  1  2  13  13783
1  1  2  11  16289
1  1  2   7  25597
1  1 11  14   2327
1  1  7  22   2327
1  1  7  26   1969
1  1  7 143358
1  1  2  77   2327
1  1  2  91   1969
1  1  2 143   1253
1 11 13  14179
1  7 13  22179
1  7 11  26179
1  7 11  13358
1  2 13  77179
1  2 11  91179
1  2 11  13   1253
1  2  7 143179
1  2  7  13   1969
1  2  7  11   2327
2  7 11  13179

We could of course come up with a routine which does something similar
for other examples (but we will run into prohibitive resource
limitations if we allow large enough integers).

So... just to confirm... this is the problem we are trying to solve?

Thanks,

--
Raul




--
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

Re: [Jprogramming] Partitions

2017-11-05 Thread Erling Hellenäs
Documentation of parRuskey. Algorithm 4.23 in this book. 
http://www.1stworks.com/ref/ruskeycombgen.pdf /Erling


On 2017-11-05 11:08, Erling Hellenäs wrote:
The optimized version of parRuskeyE is here. 
http://www.jsoftware.com/pipermail/programming/2017-November/049515.html 
/Erling


On 2017-11-05 11:00, Erling Hellenäs wrote:
This is not the optimized version of parRuskeyE, but it might be the 
best to use to answer a Quora question. /Erling


On 2017-11-04 23:49, Raul Miller wrote:

Use parRuskeyE for par - defined in
http://www.jsoftware.com/pipermail/programming/2017-November/049493.html 



Thanks,



--
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

Re: [Jprogramming] Partitions

2017-11-05 Thread Erling Hellenäs
This is not the optimized version of parRuskeyE, but it might be the 
best to use to answer a Quora question. /Erling


On 2017-11-04 23:49, Raul Miller wrote:

Use parRuskeyE for par - defined in
http://www.jsoftware.com/pipermail/programming/2017-November/049493.html

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-04 Thread Linda Alvord
Thanks Raul. I was interested in Skip's example:

So, given the full parution set of say 3 par 4

   ]a =. 3 par 4

┌───┬───┬───┐

│0 1│2  │3  │

├───┼───┼───┤

│0 2│1  │3  │

├───┼───┼───┤

│0  │1 2│3  │

├───┼───┼───┤

│0 3│1  │2  │

├───┼───┼───┤

│0  │1 3│2  │

├───┼───┼───┤

│0  │1  │2 3│

└───┴───┴───┘


I didn't find the definition in the Wiki page.

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Saturday, November 4, 2017 6:50 PM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

Use parRuskeyE for par - defined in
http://www.jsoftware.com/pipermail/programming/2017-November/049493.html

Thanks,

-- 
Raul


On Sat, Nov 4, 2017 at 4:25 PM, Linda Alvord  wrote:
> This thread has gotten very long. I tried to find 'par' but didn't find it.  
> Any chance you could post it again?  Linda
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
> Of 'Skip Cave' via Programming
> Sent: Saturday, November 4, 2017 4:12 PM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Partitions
>
> Raul
>
> The purpose of the partitions verb is to find all the n ways to group the 
> prime factors > 1  of an integer p Then we can */ each partition in each row 
> to find all the prime *and/or non-prime except 1 factors* that when 
> multiplied together equals p.
>
> */ f1, f2, f3, f4,  fn  = p
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Sat, Nov 4, 2017 at 12:06 PM, Raul Miller  wrote:
>
>> sel=: {each <
>>
>> Note also though:
>>
>>q: 75600
>> 2 2 2 2 3 3 3 5 5 7
>># q: 75600
>> 10
>>$N=:5 parRuskeyE 10
>> 42525 5
>>$~. /:"1~ */@> N sel q:75600
>> 798 5
>>
>> The number of factorizations using factors s greater than 1 of an
>> integer will often be different than the number of partitions as we
>> had defined them here.
>>
>> FYI,
>>
>> --
>> Raul
>>
>>
>> On Sat, Nov 4, 2017 at 1:00 PM, 'Skip Cave' via Programming
>>  wrote:
>> > So, given the full parution set of say 3 par 4
>> >
>> >]a =. 3 par 4
>> >
>> > ┌───┬───┬───┐
>> >
>> > │0 1│2  │3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0 2│1  │3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1 2│3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0 3│1  │2  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1 3│2  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1  │2 3│
>> >
>> > └───┴───┴───┘
>> >
>> >
>> > What would the verb 'sel' look like that would use those indices to
>> select
>> > from a different set of objects
>> >
>> >
>> > a sel 'abcd'
>> >
>> > ┌───┬───┬───┐
>> >
>> > │a b│c  │d  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a c│b  │d  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a  │b c│d  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a d│b  │c  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a  │b d│c  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a  │b  │c d│
>> >
>> > └───┴───┴───┘
>> >
>> >
>> > Skip
>> >
>> >
>> >
>> > Skip Cave
>> > Cave Consulting LLC
>> >
>> > On Sat, Nov 4, 2017 at 11:09 AM, Skip Cave 
>> wrote:
>> >
>> >> Raul,
>> >> Yes, the original Quora question specified positive factors only,
>> >> but i forgot to include that in the specification.
>> >>
>> >> Skip
>> >>
>> >> Skip Cave
>> >> Cave Consulting LLC
>> >>
>> >> On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller 
>> wrote:
>> >>
>> >>> Well, ok, though that was not a part of your re-specification this
>> time.
>> >>>
>> >>> Actually, though, re-reading your spec, i left out a factor of 16
>> >>> of the solutions: integers can be negative and as long as we
>> >>> include an even number of negatives they cancel out in a product.
>> >>>
>> >>> Thanks,
>> >>>
>> >>> --
>> >>> Raul
>> >>>
>> >>>
>&g

Re: [Jprogramming] Partitions

2017-11-04 Thread Raul Miller
Use parRuskeyE for par - defined in
http://www.jsoftware.com/pipermail/programming/2017-November/049493.html

Thanks,

-- 
Raul


On Sat, Nov 4, 2017 at 4:25 PM, Linda Alvord  wrote:
> This thread has gotten very long. I tried to find 'par' but didn't find it.  
> Any chance you could post it again?  Linda
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
> Of 'Skip Cave' via Programming
> Sent: Saturday, November 4, 2017 4:12 PM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Partitions
>
> Raul
>
> The purpose of the partitions verb is to find all the n ways to group the 
> prime factors > 1  of an integer p Then we can */ each partition in each row 
> to find all the prime *and/or non-prime except 1 factors* that when 
> multiplied together equals p.
>
> */ f1, f2, f3, f4,  fn  = p
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Sat, Nov 4, 2017 at 12:06 PM, Raul Miller  wrote:
>
>> sel=: {each <
>>
>> Note also though:
>>
>>q: 75600
>> 2 2 2 2 3 3 3 5 5 7
>># q: 75600
>> 10
>>$N=:5 parRuskeyE 10
>> 42525 5
>>$~. /:"1~ */@> N sel q:75600
>> 798 5
>>
>> The number of factorizations using factors s greater than 1 of an
>> integer will often be different than the number of partitions as we
>> had defined them here.
>>
>> FYI,
>>
>> --
>> Raul
>>
>>
>> On Sat, Nov 4, 2017 at 1:00 PM, 'Skip Cave' via Programming
>>  wrote:
>> > So, given the full parution set of say 3 par 4
>> >
>> >]a =. 3 par 4
>> >
>> > ┌───┬───┬───┐
>> >
>> > │0 1│2  │3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0 2│1  │3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1 2│3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0 3│1  │2  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1 3│2  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1  │2 3│
>> >
>> > └───┴───┴───┘
>> >
>> >
>> > What would the verb 'sel' look like that would use those indices to
>> select
>> > from a different set of objects
>> >
>> >
>> > a sel 'abcd'
>> >
>> > ┌───┬───┬───┐
>> >
>> > │a b│c  │d  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a c│b  │d  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a  │b c│d  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a d│b  │c  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a  │b d│c  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │a  │b  │c d│
>> >
>> > └───┴───┴───┘
>> >
>> >
>> > Skip
>> >
>> >
>> >
>> > Skip Cave
>> > Cave Consulting LLC
>> >
>> > On Sat, Nov 4, 2017 at 11:09 AM, Skip Cave 
>> wrote:
>> >
>> >> Raul,
>> >> Yes, the original Quora question specified positive factors only,
>> >> but i forgot to include that in the specification.
>> >>
>> >> Skip
>> >>
>> >> Skip Cave
>> >> Cave Consulting LLC
>> >>
>> >> On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller 
>> wrote:
>> >>
>> >>> Well, ok, though that was not a part of your re-specification this
>> time.
>> >>>
>> >>> Actually, though, re-reading your spec, i left out a factor of 16
>> >>> of the solutions: integers can be negative and as long as we
>> >>> include an even number of negatives they cancel out in a product.
>> >>>
>> >>> Thanks,
>> >>>
>> >>> --
>> >>> Raul
>> >>>
>> >>>
>> >>> On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming
>> >>>  wrote:
>> >>> > Raul, very nice!
>> >>> >
>> >>> > Actually I prefer the solution that doesn't allow 1 as a factor
>> >>> > of
>> p. Of
>> >>> > course, that restricts the max number of partitions to the max
>> number of
>> >>> > prime factors of any p. That also greatly reduces the number of
>> >>> partition
>> >>> >

Re: [Jprogramming] Partitions

2017-11-04 Thread Linda Alvord
This thread has gotten very long. I tried to find 'par' but didn't find it.  
Any chance you could post it again?  Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of 'Skip Cave' via Programming
Sent: Saturday, November 4, 2017 4:12 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Raul

The purpose of the partitions verb is to find all the n ways to group the prime 
factors > 1  of an integer p Then we can */ each partition in each row to find 
all the prime *and/or non-prime except 1 factors* that when multiplied together 
equals p.

*/ f1, f2, f3, f4,  fn  = p

Skip

Skip Cave
Cave Consulting LLC

On Sat, Nov 4, 2017 at 12:06 PM, Raul Miller  wrote:

> sel=: {each <
>
> Note also though:
>
>q: 75600
> 2 2 2 2 3 3 3 5 5 7
># q: 75600
> 10
>$N=:5 parRuskeyE 10
> 42525 5
>$~. /:"1~ */@> N sel q:75600
> 798 5
>
> The number of factorizations using factors s greater than 1 of an 
> integer will often be different than the number of partitions as we 
> had defined them here.
>
> FYI,
>
> --
> Raul
>
>
> On Sat, Nov 4, 2017 at 1:00 PM, 'Skip Cave' via Programming 
>  wrote:
> > So, given the full parution set of say 3 par 4
> >
> >]a =. 3 par 4
> >
> > ┌───┬───┬───┐
> >
> > │0 1│2  │3  │
> >
> > ├───┼───┼───┤
> >
> > │0 2│1  │3  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1 2│3  │
> >
> > ├───┼───┼───┤
> >
> > │0 3│1  │2  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1 3│2  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1  │2 3│
> >
> > └───┴───┴───┘
> >
> >
> > What would the verb 'sel' look like that would use those indices to
> select
> > from a different set of objects
> >
> >
> > a sel 'abcd'
> >
> > ┌───┬───┬───┐
> >
> > │a b│c  │d  │
> >
> > ├───┼───┼───┤
> >
> > │a c│b  │d  │
> >
> > ├───┼───┼───┤
> >
> > │a  │b c│d  │
> >
> > ├───┼───┼───┤
> >
> > │a d│b  │c  │
> >
> > ├───┼───┼───┤
> >
> > │a  │b d│c  │
> >
> > ├───┼───┼───┤
> >
> > │a  │b  │c d│
> >
> > └───┴───┴───┘
> >
> >
> > Skip
> >
> >
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> > On Sat, Nov 4, 2017 at 11:09 AM, Skip Cave 
> wrote:
> >
> >> Raul,
> >> Yes, the original Quora question specified positive factors only, 
> >> but i forgot to include that in the specification.
> >>
> >> Skip
> >>
> >> Skip Cave
> >> Cave Consulting LLC
> >>
> >> On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller 
> wrote:
> >>
> >>> Well, ok, though that was not a part of your re-specification this
> time.
> >>>
> >>> Actually, though, re-reading your spec, i left out a factor of 16 
> >>> of the solutions: integers can be negative and as long as we 
> >>> include an even number of negatives they cancel out in a product.
> >>>
> >>> Thanks,
> >>>
> >>> --
> >>> Raul
> >>>
> >>>
> >>> On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming 
> >>>  wrote:
> >>> > Raul, very nice!
> >>> >
> >>> > Actually I prefer the solution that doesn't allow 1 as a factor 
> >>> > of
> p. Of
> >>> > course, that restricts the max number of partitions to the max
> number of
> >>> > prime factors of any p. That also greatly reduces the number of
> >>> partition
> >>> > instances that will be generated. Then:
> >>> >
> >>> > 5 par 358258
> >>> >
> >>> > ┌─┬─┬──┬──┬───┐
> >>> >
> >>> > │2│7│11│13│179│
> >>> >
> >>> > └─┴─┴──┴──┴───┘
> >>> >
> >>> > Skip
> >>> >
> >>> > Skip Cave
> >>> > Cave Consulting LLC
> >>> >
> >>> > On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller 
> >>> > 
> >>> wrote:
> >>> >
> >>> >> So... 358358 has five prime factors (32 integer factors). We 
> >>> >> want to find all sorted sequences (not sets - values can 
> >>> >> repeat) of five of those factors whose product is 358358.
&

Re: [Jprogramming] Partitions

2017-11-04 Thread 'Skip Cave' via Programming
Raul

The purpose of the partitions verb is to find all the n ways to group the
prime factors > 1  of an integer p
Then we can */ each partition in each row to find all the prime *and/or
non-prime except 1 factors* that when multiplied together equals p.

*/ f1, f2, f3, f4,  fn  = p

Skip

Skip Cave
Cave Consulting LLC

On Sat, Nov 4, 2017 at 12:06 PM, Raul Miller  wrote:

> sel=: {each <
>
> Note also though:
>
>q: 75600
> 2 2 2 2 3 3 3 5 5 7
># q: 75600
> 10
>$N=:5 parRuskeyE 10
> 42525 5
>$~. /:"1~ */@> N sel q:75600
> 798 5
>
> The number of factorizations using factors s greater than 1 of an
> integer will often be different than the number of partitions as we
> had defined them here.
>
> FYI,
>
> --
> Raul
>
>
> On Sat, Nov 4, 2017 at 1:00 PM, 'Skip Cave' via Programming
>  wrote:
> > So, given the full parution set of say 3 par 4
> >
> >]a =. 3 par 4
> >
> > ┌───┬───┬───┐
> >
> > │0 1│2  │3  │
> >
> > ├───┼───┼───┤
> >
> > │0 2│1  │3  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1 2│3  │
> >
> > ├───┼───┼───┤
> >
> > │0 3│1  │2  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1 3│2  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1  │2 3│
> >
> > └───┴───┴───┘
> >
> >
> > What would the verb 'sel' look like that would use those indices to
> select
> > from a different set of objects
> >
> >
> > a sel 'abcd'
> >
> > ┌───┬───┬───┐
> >
> > │a b│c  │d  │
> >
> > ├───┼───┼───┤
> >
> > │a c│b  │d  │
> >
> > ├───┼───┼───┤
> >
> > │a  │b c│d  │
> >
> > ├───┼───┼───┤
> >
> > │a d│b  │c  │
> >
> > ├───┼───┼───┤
> >
> > │a  │b d│c  │
> >
> > ├───┼───┼───┤
> >
> > │a  │b  │c d│
> >
> > └───┴───┴───┘
> >
> >
> > Skip
> >
> >
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> > On Sat, Nov 4, 2017 at 11:09 AM, Skip Cave 
> wrote:
> >
> >> Raul,
> >> Yes, the original Quora question specified positive factors only, but i
> >> forgot to include that in the specification.
> >>
> >> Skip
> >>
> >> Skip Cave
> >> Cave Consulting LLC
> >>
> >> On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller 
> wrote:
> >>
> >>> Well, ok, though that was not a part of your re-specification this
> time.
> >>>
> >>> Actually, though, re-reading your spec, i left out a factor of 16 of
> >>> the solutions: integers can be negative and as long as we include an
> >>> even number of negatives they cancel out in a product.
> >>>
> >>> Thanks,
> >>>
> >>> --
> >>> Raul
> >>>
> >>>
> >>> On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming
> >>>  wrote:
> >>> > Raul, very nice!
> >>> >
> >>> > Actually I prefer the solution that doesn't allow 1 as a factor of
> p. Of
> >>> > course, that restricts the max number of partitions to the max
> number of
> >>> > prime factors of any p. That also greatly reduces the number of
> >>> partition
> >>> > instances that will be generated. Then:
> >>> >
> >>> > 5 par 358258
> >>> >
> >>> > ┌─┬─┬──┬──┬───┐
> >>> >
> >>> > │2│7│11│13│179│
> >>> >
> >>> > └─┴─┴──┴──┴───┘
> >>> >
> >>> > Skip
> >>> >
> >>> > Skip Cave
> >>> > Cave Consulting LLC
> >>> >
> >>> > On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller 
> >>> wrote:
> >>> >
> >>> >> So... 358358 has five prime factors (32 integer factors). We want to
> >>> >> find all sorted sequences (not sets - values can repeat) of five of
> >>> >> those factors whose product is 358358.
> >>> >>
> >>> >> To restrict our search, we can investigate only those sorted
> sequences
> >>> >> of "number of prime factors represented in the variable" whose sum
> is
> >>> >> five:
> >>> >>
> >>> >>~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
> >>> >> 0 0 0 0 5
> >>> >> 0 0 0 1 4
> >>> >> 0 0 0 2 3
> >>> >> 0 0 1 1 3
> >>> >> 0 0 1 2 2
> >>> >> 0 1 1 1 2
> >>> >> 1 1 1 1 1
> >>> >>
> >>> >> In other words, the results of these seven expressions (use
> >>> >> require'stats' first to get comb):
> >>> >>
> >>> >>1 1 1 1
> >>> >>
> >>> >> 358358
> >>> >>(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
> >>> >>/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
> >>> >>/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
> >>> >>~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
> >>> >> /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
> >>> >>q:358358
> >>> >>
> >>> >> That's 44 different solutions:
> >>> >>
> >>> >> 1  1  1   1 358358
> >>> >> 1  1  1 179   2002
> >>> >> 1  1  1  13  27566
> >>> >> 1  1  1  11  32578
> >>> >> 1  1  1   7  51194
> >>> >> 1  1  1   2 179179
> >>> >> 1  1  1 154   2327
> >>> >> 1  1  1 182   1969
> >>> >> 1  1  1 143   2506
> >>> >> 1  1  1 286   1253
> >>> >> 1  1  1  91   3938
> >>> >> 1  1  1  77   4654
> >>> >> 1  1  1 358   1001
> >>> >> 1  1  1  26  13783
> >>> >> 1  1  1  22  16289
> >>> >> 1  1  1  14  25597
> >>> >> 1  1 13 154179
> >>> >> 1  1 11 179182
> >>> >> 1  1 11  13   2506
> >>> >> 1  1  7 179286
> >>> >> 1  1  7  13   3938
> >>> >> 1  1  7  11   4654
> >>> >> 1  1  2 179   1001
> >>> >> 1  1  2  13  13783
> >>> >> 1  1  2  11  16289
> >>> >> 1  1  2   7  25597
> >>> >> 1  1 11  14   2327
> >>> >> 1  1 

Re: [Jprogramming] Partitions

2017-11-04 Thread Erling Hellenäs

Hi all!

See page 8.

http://www.kcats.org/csci/464/doc/knuth/fascicles/fasc3a.pdf

Cheers,

Erling Hellenäs

On 2017-11-04 13:36, Raul Miller wrote:

Actually, grey code is a binary sequence where only 1 bit changes
between each item.

https://en.wikipedia.org/wiki/Gray_code

http://code.jsoftware.com/wiki/Essays/Gray_Code

~:/\inv"1 #:i.8
0 0 0
0 0 1
0 1 1
0 1 0
1 1 0
1 1 1
1 0 1
1 0 0

FYI,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-04 Thread Raul Miller
sel=: {each <

Note also though:

   q: 75600
2 2 2 2 3 3 3 5 5 7
   # q: 75600
10
   $N=:5 parRuskeyE 10
42525 5
   $~. /:"1~ */@> N sel q:75600
798 5

The number of factorizations using factors s greater than 1 of an
integer will often be different than the number of partitions as we
had defined them here.

FYI,

-- 
Raul


On Sat, Nov 4, 2017 at 1:00 PM, 'Skip Cave' via Programming
 wrote:
> So, given the full parution set of say 3 par 4
>
>]a =. 3 par 4
>
> ┌───┬───┬───┐
>
> │0 1│2  │3  │
>
> ├───┼───┼───┤
>
> │0 2│1  │3  │
>
> ├───┼───┼───┤
>
> │0  │1 2│3  │
>
> ├───┼───┼───┤
>
> │0 3│1  │2  │
>
> ├───┼───┼───┤
>
> │0  │1 3│2  │
>
> ├───┼───┼───┤
>
> │0  │1  │2 3│
>
> └───┴───┴───┘
>
>
> What would the verb 'sel' look like that would use those indices to select
> from a different set of objects
>
>
> a sel 'abcd'
>
> ┌───┬───┬───┐
>
> │a b│c  │d  │
>
> ├───┼───┼───┤
>
> │a c│b  │d  │
>
> ├───┼───┼───┤
>
> │a  │b c│d  │
>
> ├───┼───┼───┤
>
> │a d│b  │c  │
>
> ├───┼───┼───┤
>
> │a  │b d│c  │
>
> ├───┼───┼───┤
>
> │a  │b  │c d│
>
> └───┴───┴───┘
>
>
> Skip
>
>
>
> Skip Cave
> Cave Consulting LLC
>
> On Sat, Nov 4, 2017 at 11:09 AM, Skip Cave  wrote:
>
>> Raul,
>> Yes, the original Quora question specified positive factors only, but i
>> forgot to include that in the specification.
>>
>> Skip
>>
>> Skip Cave
>> Cave Consulting LLC
>>
>> On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller  wrote:
>>
>>> Well, ok, though that was not a part of your re-specification this time.
>>>
>>> Actually, though, re-reading your spec, i left out a factor of 16 of
>>> the solutions: integers can be negative and as long as we include an
>>> even number of negatives they cancel out in a product.
>>>
>>> Thanks,
>>>
>>> --
>>> Raul
>>>
>>>
>>> On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming
>>>  wrote:
>>> > Raul, very nice!
>>> >
>>> > Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
>>> > course, that restricts the max number of partitions to the max number of
>>> > prime factors of any p. That also greatly reduces the number of
>>> partition
>>> > instances that will be generated. Then:
>>> >
>>> > 5 par 358258
>>> >
>>> > ┌─┬─┬──┬──┬───┐
>>> >
>>> > │2│7│11│13│179│
>>> >
>>> > └─┴─┴──┴──┴───┘
>>> >
>>> > Skip
>>> >
>>> > Skip Cave
>>> > Cave Consulting LLC
>>> >
>>> > On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller 
>>> wrote:
>>> >
>>> >> So... 358358 has five prime factors (32 integer factors). We want to
>>> >> find all sorted sequences (not sets - values can repeat) of five of
>>> >> those factors whose product is 358358.
>>> >>
>>> >> To restrict our search, we can investigate only those sorted sequences
>>> >> of "number of prime factors represented in the variable" whose sum is
>>> >> five:
>>> >>
>>> >>~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
>>> >> 0 0 0 0 5
>>> >> 0 0 0 1 4
>>> >> 0 0 0 2 3
>>> >> 0 0 1 1 3
>>> >> 0 0 1 2 2
>>> >> 0 1 1 1 2
>>> >> 1 1 1 1 1
>>> >>
>>> >> In other words, the results of these seven expressions (use
>>> >> require'stats' first to get comb):
>>> >>
>>> >>1 1 1 1
>>> >>
>>> >> 358358
>>> >>(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
>>> >>/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
>>> >>/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
>>> >>~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>>> >> /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>>> >>q:358358
>>> >>
>>> >> That's 44 different solutions:
>>> >>
>>> >> 1  1  1   1 358358
>>> >> 1  1  1 179   2002
>>> >> 1  1  1  13  27566
>>> >> 1  1  1  11  32578
>>> >> 1  1  1   7  51194
>>> >> 1  1  1   2 179179
>>> >> 1  1  1 154   2327
>>> >> 1  1  1 182   1969
>>> >> 1  1  1 143   2506
>>> >> 1  1  1 286   1253
>>> >> 1  1  1  91   3938
>>> >> 1  1  1  77   4654
>>> >> 1  1  1 358   1001
>>> >> 1  1  1  26  13783
>>> >> 1  1  1  22  16289
>>> >> 1  1  1  14  25597
>>> >> 1  1 13 154179
>>> >> 1  1 11 179182
>>> >> 1  1 11  13   2506
>>> >> 1  1  7 179286
>>> >> 1  1  7  13   3938
>>> >> 1  1  7  11   4654
>>> >> 1  1  2 179   1001
>>> >> 1  1  2  13  13783
>>> >> 1  1  2  11  16289
>>> >> 1  1  2   7  25597
>>> >> 1  1 11  14   2327
>>> >> 1  1  7  22   2327
>>> >> 1  1  7  26   1969
>>> >> 1  1  7 143358
>>> >> 1  1  2  77   2327
>>> >> 1  1  2  91   1969
>>> >> 1  1  2 143   1253
>>> >> 1 11 13  14179
>>> >> 1  7 13  22179
>>> >> 1  7 11  26179
>>> >> 1  7 11  13358
>>> >> 1  2 13  77179
>>> >> 1  2 11  91179
>>> >> 1  2 11  13   1253
>>> >> 1  2  7 143179
>>> >> 1  2  7  13   1969
>>> >> 1  2  7  11   2327
>>> >> 2  7 11  13179
>>> >>
>>> >> We could of course come up with a routine which does something similar
>>> >> for other examples (but we will run into prohibitive resource
>>> >> limitations if we allow large enough integers).
>>> >>
>>> >> So... just to confirm... this is the problem we are trying to solve?
>>> >>
>>> >> Thanks,
>>> >>
>>> >> --
>>> >> Raul
>>> >>
>>> >>
>>> >>
>>> > --

Re: [Jprogramming] Partitions

2017-11-04 Thread 'Skip Cave' via Programming
So, given the full parution set of say 3 par 4

   ]a =. 3 par 4

┌───┬───┬───┐

│0 1│2  │3  │

├───┼───┼───┤

│0 2│1  │3  │

├───┼───┼───┤

│0  │1 2│3  │

├───┼───┼───┤

│0 3│1  │2  │

├───┼───┼───┤

│0  │1 3│2  │

├───┼───┼───┤

│0  │1  │2 3│

└───┴───┴───┘


What would the verb 'sel' look like that would use those indices to select
from a different set of objects


a sel 'abcd'

┌───┬───┬───┐

│a b│c  │d  │

├───┼───┼───┤

│a c│b  │d  │

├───┼───┼───┤

│a  │b c│d  │

├───┼───┼───┤

│a d│b  │c  │

├───┼───┼───┤

│a  │b d│c  │

├───┼───┼───┤

│a  │b  │c d│

└───┴───┴───┘


Skip



Skip Cave
Cave Consulting LLC

On Sat, Nov 4, 2017 at 11:09 AM, Skip Cave  wrote:

> Raul,
> Yes, the original Quora question specified positive factors only, but i
> forgot to include that in the specification.
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller  wrote:
>
>> Well, ok, though that was not a part of your re-specification this time.
>>
>> Actually, though, re-reading your spec, i left out a factor of 16 of
>> the solutions: integers can be negative and as long as we include an
>> even number of negatives they cancel out in a product.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming
>>  wrote:
>> > Raul, very nice!
>> >
>> > Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
>> > course, that restricts the max number of partitions to the max number of
>> > prime factors of any p. That also greatly reduces the number of
>> partition
>> > instances that will be generated. Then:
>> >
>> > 5 par 358258
>> >
>> > ┌─┬─┬──┬──┬───┐
>> >
>> > │2│7│11│13│179│
>> >
>> > └─┴─┴──┴──┴───┘
>> >
>> > Skip
>> >
>> > Skip Cave
>> > Cave Consulting LLC
>> >
>> > On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller 
>> wrote:
>> >
>> >> So... 358358 has five prime factors (32 integer factors). We want to
>> >> find all sorted sequences (not sets - values can repeat) of five of
>> >> those factors whose product is 358358.
>> >>
>> >> To restrict our search, we can investigate only those sorted sequences
>> >> of "number of prime factors represented in the variable" whose sum is
>> >> five:
>> >>
>> >>~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
>> >> 0 0 0 0 5
>> >> 0 0 0 1 4
>> >> 0 0 0 2 3
>> >> 0 0 1 1 3
>> >> 0 0 1 2 2
>> >> 0 1 1 1 2
>> >> 1 1 1 1 1
>> >>
>> >> In other words, the results of these seven expressions (use
>> >> require'stats' first to get comb):
>> >>
>> >>1 1 1 1
>> >>
>> >> 358358
>> >>(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
>> >>/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
>> >>/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
>> >>~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>> >> /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>> >>q:358358
>> >>
>> >> That's 44 different solutions:
>> >>
>> >> 1  1  1   1 358358
>> >> 1  1  1 179   2002
>> >> 1  1  1  13  27566
>> >> 1  1  1  11  32578
>> >> 1  1  1   7  51194
>> >> 1  1  1   2 179179
>> >> 1  1  1 154   2327
>> >> 1  1  1 182   1969
>> >> 1  1  1 143   2506
>> >> 1  1  1 286   1253
>> >> 1  1  1  91   3938
>> >> 1  1  1  77   4654
>> >> 1  1  1 358   1001
>> >> 1  1  1  26  13783
>> >> 1  1  1  22  16289
>> >> 1  1  1  14  25597
>> >> 1  1 13 154179
>> >> 1  1 11 179182
>> >> 1  1 11  13   2506
>> >> 1  1  7 179286
>> >> 1  1  7  13   3938
>> >> 1  1  7  11   4654
>> >> 1  1  2 179   1001
>> >> 1  1  2  13  13783
>> >> 1  1  2  11  16289
>> >> 1  1  2   7  25597
>> >> 1  1 11  14   2327
>> >> 1  1  7  22   2327
>> >> 1  1  7  26   1969
>> >> 1  1  7 143358
>> >> 1  1  2  77   2327
>> >> 1  1  2  91   1969
>> >> 1  1  2 143   1253
>> >> 1 11 13  14179
>> >> 1  7 13  22179
>> >> 1  7 11  26179
>> >> 1  7 11  13358
>> >> 1  2 13  77179
>> >> 1  2 11  91179
>> >> 1  2 11  13   1253
>> >> 1  2  7 143179
>> >> 1  2  7  13   1969
>> >> 1  2  7  11   2327
>> >> 2  7 11  13179
>> >>
>> >> We could of course come up with a routine which does something similar
>> >> for other examples (but we will run into prohibitive resource
>> >> limitations if we allow large enough integers).
>> >>
>> >> So... just to confirm... this is the problem we are trying to solve?
>> >>
>> >> Thanks,
>> >>
>> >> --
>> >> Raul
>> >>
>> >>
>> >>
>> > --
>> > 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

Re: [Jprogramming] Partitions

2017-11-04 Thread 'Skip Cave' via Programming
Raul,
Yes, the original Quora question specified positive factors only, but i
forgot to include that in the specification.

Skip

Skip Cave
Cave Consulting LLC

On Sat, Nov 4, 2017 at 3:52 AM, Raul Miller  wrote:

> Well, ok, though that was not a part of your re-specification this time.
>
> Actually, though, re-reading your spec, i left out a factor of 16 of
> the solutions: integers can be negative and as long as we include an
> even number of negatives they cancel out in a product.
>
> Thanks,
>
> --
> Raul
>
>
> On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming
>  wrote:
> > Raul, very nice!
> >
> > Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
> > course, that restricts the max number of partitions to the max number of
> > prime factors of any p. That also greatly reduces the number of partition
> > instances that will be generated. Then:
> >
> > 5 par 358258
> >
> > ┌─┬─┬──┬──┬───┐
> >
> > │2│7│11│13│179│
> >
> > └─┴─┴──┴──┴───┘
> >
> > Skip
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> > On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller 
> wrote:
> >
> >> So... 358358 has five prime factors (32 integer factors). We want to
> >> find all sorted sequences (not sets - values can repeat) of five of
> >> those factors whose product is 358358.
> >>
> >> To restrict our search, we can investigate only those sorted sequences
> >> of "number of prime factors represented in the variable" whose sum is
> >> five:
> >>
> >>~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
> >> 0 0 0 0 5
> >> 0 0 0 1 4
> >> 0 0 0 2 3
> >> 0 0 1 1 3
> >> 0 0 1 2 2
> >> 0 1 1 1 2
> >> 1 1 1 1 1
> >>
> >> In other words, the results of these seven expressions (use
> >> require'stats' first to get comb):
> >>
> >>1 1 1 1
> >>
> >> 358358
> >>(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
> >>/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
> >>/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
> >>~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
> >> /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
> >>q:358358
> >>
> >> That's 44 different solutions:
> >>
> >> 1  1  1   1 358358
> >> 1  1  1 179   2002
> >> 1  1  1  13  27566
> >> 1  1  1  11  32578
> >> 1  1  1   7  51194
> >> 1  1  1   2 179179
> >> 1  1  1 154   2327
> >> 1  1  1 182   1969
> >> 1  1  1 143   2506
> >> 1  1  1 286   1253
> >> 1  1  1  91   3938
> >> 1  1  1  77   4654
> >> 1  1  1 358   1001
> >> 1  1  1  26  13783
> >> 1  1  1  22  16289
> >> 1  1  1  14  25597
> >> 1  1 13 154179
> >> 1  1 11 179182
> >> 1  1 11  13   2506
> >> 1  1  7 179286
> >> 1  1  7  13   3938
> >> 1  1  7  11   4654
> >> 1  1  2 179   1001
> >> 1  1  2  13  13783
> >> 1  1  2  11  16289
> >> 1  1  2   7  25597
> >> 1  1 11  14   2327
> >> 1  1  7  22   2327
> >> 1  1  7  26   1969
> >> 1  1  7 143358
> >> 1  1  2  77   2327
> >> 1  1  2  91   1969
> >> 1  1  2 143   1253
> >> 1 11 13  14179
> >> 1  7 13  22179
> >> 1  7 11  26179
> >> 1  7 11  13358
> >> 1  2 13  77179
> >> 1  2 11  91179
> >> 1  2 11  13   1253
> >> 1  2  7 143179
> >> 1  2  7  13   1969
> >> 1  2  7  11   2327
> >> 2  7 11  13179
> >>
> >> We could of course come up with a routine which does something similar
> >> for other examples (but we will run into prohibitive resource
> >> limitations if we allow large enough integers).
> >>
> >> So... just to confirm... this is the problem we are trying to solve?
> >>
> >> Thanks,
> >>
> >> --
> >> Raul
> >>
> >>
> >>
> > --
> > 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

Re: [Jprogramming] Partitions

2017-11-04 Thread Raul Miller
Actually, grey code is a binary sequence where only 1 bit changes
between each item.

https://en.wikipedia.org/wiki/Gray_code

http://code.jsoftware.com/wiki/Essays/Gray_Code

   ~:/\inv"1 #:i.8
0 0 0
0 0 1
0 1 1
0 1 0
1 1 0
1 1 1
1 0 1
1 0 0

FYI,

-- 
Raul


On Sat, Nov 4, 2017 at 8:26 AM, Erling Hellenäs
 wrote:
> Hi all!
>
> When you do these kind of set operations it is common to represent the set
> as a bitmap with ones for each item. A k-set {0 1 2} of the set {0 1 2 3 4}
> would then be represented like this.
> 1 1 1 0 0
> This is called GRAY CODES.
> One advantage is that you can move an item in only one operation. You don't
> have to remove it somewhere and add it somewhere else. The move can be made
> with exclusive or.
>
>1 1 ~: 0 1
> 1 0
>0 0 ~: 0 1
> 0 1
>
> You can switch both zeroes and ones with ones. Zeros do nothing.
> The first example shows a move of a one one step left.
> Two bitmaps of 64 bits can be handled in one assembler instruction. All that
> is needed to create the next set.
> Here is an example of the generation of a 3-set from a 5-set with gray
> codes.
>
>[q=:10 5 $1 1 1 0 0  0 0 1 1 0  0 0 0 1 1  0 1 1 1 1 0 0 0 1 1  1 1 0 0 0
> 0 0 1 1 0  1 1 0 0 0  1 0 1 0 0  0 1 0 0 1
> 1 1 1 0 0
> 0 0 1 1 0
> 0 0 0 1 1
> 0 1 1 1 1
> 0 0 0 1 1
> 1 1 0 0 0
> 0 0 1 1 0
> 1 1 0 0 0
> 1 0 1 0 0
> 0 1 0 0 1
>~:/\ q
> 1 1 1 0 0
> 1 1 0 1 0
> 1 1 0 0 1
> 1 0 1 1 0
> 1 0 1 0 1
> 0 1 1 0 1
> 0 1 0 1 1
> 1 0 0 1 1
> 0 0 1 1 1
> 0 1 1 1 0
>/:~>(~:/\ q) <@#"1 i.5
> 0 1 2
> 0 1 3
> 0 1 4
> 0 2 3
> 0 2 4
> 0 3 4
> 1 2 3
> 1 2 4
> 1 3 4
> 2 3 4
>
> Cheers,
>
> Erling Hellenäs
>
> On 2017-11-03 18:16, Linda Alvord wrote:
>>
>> It seems that you mighg want to use a diferent name for your combE
>>
>> load 'stats'
>> (3 comb 4);3 combE 4
>> ┌─┬───┐
>> │0 1 2│0 0 0 1│
>> │0 1 3│0 0 0 2│
>> │0 2 3│0 0 1 1│
>> │1 2 3│0 0 1 2│
>> │ │0 0 2 1│
>> │ │0 0 2 2│
>> │ │0 1 0 1│
>> │ │0 1 0 2│
>> │ │0 1 1 1│
>> │ │0 1 1 2│
>> │ │0 1 2 1│
>> │ │0 1 2 2│
>> │ │0 2 0 1│
>> │ │0 2 0 2│
>> │ │0 2 1 1│
>> │ │0 2 1 2│
>> │ │0 2 2 1│
>> │ │0 2 2 2│
>> │ │1 0 0 1│
>> │ │1 0 0 2│
>> │ │1 0 1 1│
>> │ │1 0 1 2│
>> │ │1 0 2 1│
>> │ │1 0 2 2│
>> │ │1 1 0 1│
>> │ │1 1 0 2│
>> │ │1 1 1 1│
>> │ │1 1 1 2│
>> │ │1 1 2 1│
>> │ │1 1 2 2│
>> │ │1 2 0 1│
>> │ │1 2 0 2│
>> │ │1 2 1 1│
>> │ │1 2 1 2│
>> │ │1 2 2 1│
>> │ │1 2 2 2│
>> └─┴───┘
>> Linda
>>
>>
>> -Original Message-
>> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On
>> Behalf Of Erling Hellenäs
>> Sent: Friday, November 3, 2017 12:44 PM
>> To: programm...@jsoftware.com
>> Subject: Re: [Jprogramming] Partitions
>>
>> Hi all!
>>
>> I did not correctly understand the e. verb
>>
>>  24 e. r4
>> 0
>>  24 e. ,r4
>> 1
>>
>> So 358358 surely was there and was double-counted.
>>
>> Cheers,
>>
>> Erling Hellenäs
>>
>> On 2017-11-03 17:07, Erling Hellenäs wrote:
>>>
>>> No, its not. It seems it should have bin there. Maybe something is
>>> wrong. /Erling
>>>
>>> On 2017-11-03 16:56, Erling Hellenäs wrote:
>>>>
>>>> Lol. This root is double-counted. 1 1 1 1 358358 /Erling
>>>>
>>>> On 2017-11-03 16:42, Erling Hellenäs wrote:
>>>>>
>>>>> Hi all!
>>>>>
>>>>> My take:
>>>>>
>>>>> v=:1 1 1 1 2 7 11 13 179
>>>>> r=:5 parRuskeyE 9
>>>>> r2=: >r (*/)@:{&.>"1 0 < v
>>>>> r3=:/:~"1 r2
>>>>> r4=: ~.r3
>>>>> NB. One root is 1 1 1 1 358358
>>>>> NB. All permutations
>>>>> (!5)*1+#r4
>>>>> 6360
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Erling Hellenäs
>>>>>
>>>>> On 2017-11-03 15:03, Erling Hellenäs wrote:
>>>>>>
>>>>>> Sorry. Add ones. /Erling
>>>>>>
>>>>>> On 2017-11-03 15:00, Erling Hellenäs wrote:
>>>>>>>
>>>>>>> OK. 

Re: [Jprogramming] Partitions

2017-11-04 Thread Erling Hellenäs

Hi all!

When you do these kind of set operations it is common to represent the 
set as a bitmap with ones for each item. A k-set {0 1 2} of the set {0 1 
2 3 4} would then be represented like this.

1 1 1 0 0
This is called GRAY CODES.
One advantage is that you can move an item in only one operation. You 
don't have to remove it somewhere and add it somewhere else. The move 
can be made with exclusive or.


   1 1 ~: 0 1
1 0
   0 0 ~: 0 1
0 1

You can switch both zeroes and ones with ones. Zeros do nothing.
The first example shows a move of a one one step left.
Two bitmaps of 64 bits can be handled in one assembler instruction. All 
that is needed to create the next set.
Here is an example of the generation of a 3-set from a 5-set with gray 
codes.


   [q=:10 5 $1 1 1 0 0  0 0 1 1 0  0 0 0 1 1  0 1 1 1 1 0 0 0 1 1  1 1 
0 0 0  0 0 1 1 0  1 1 0 0 0  1 0 1 0 0  0 1 0 0 1

1 1 1 0 0
0 0 1 1 0
0 0 0 1 1
0 1 1 1 1
0 0 0 1 1
1 1 0 0 0
0 0 1 1 0
1 1 0 0 0
1 0 1 0 0
0 1 0 0 1
   ~:/\ q
1 1 1 0 0
1 1 0 1 0
1 1 0 0 1
1 0 1 1 0
1 0 1 0 1
0 1 1 0 1
0 1 0 1 1
1 0 0 1 1
0 0 1 1 1
0 1 1 1 0
   /:~>(~:/\ q) <@#"1 i.5
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4

Cheers,

Erling Hellenäs

On 2017-11-03 18:16, Linda Alvord wrote:

It seems that you mighg want to use a diferent name for your combE

load 'stats'



(3 comb 4);3 combE 4

┌─┬───┐
│0 1 2│0 0 0 1│
│0 1 3│0 0 0 2│
│0 2 3│0 0 1 1│
│1 2 3│0 0 1 2│
│ │0 0 2 1│
│ │0 0 2 2│
│ │0 1 0 1│
│ │0 1 0 2│
│ │0 1 1 1│
│ │0 1 1 2│
│ │0 1 2 1│
│ │0 1 2 2│
│ │0 2 0 1│
│ │0 2 0 2│
│ │0 2 1 1│
│ │0 2 1 2│
│ │0 2 2 1│
│ │0 2 2 2│
│ │1 0 0 1│
│ │1 0 0 2│
│ │1 0 1 1│
│ │1 0 1 2│
│ │1 0 2 1│
│ │1 0 2 2│
│ │1 1 0 1│
│ │1 1 0 2│
│ │1 1 1 1│
│ │1 1 1 2│
│ │1 1 2 1│
│ │1 1 2 2│
│ │1 2 0 1│
│ │1 2 0 2│
│ │1 2 1 1│
│ │1 2 1 2│
│ │1 2 2 1│
│ │1 2 2 2│
└─┴───┘

Linda



-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Erling Hellenäs
Sent: Friday, November 3, 2017 12:44 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

I did not correctly understand the e. verb

     24 e. r4
0
     24 e. ,r4
1

So 358358 surely was there and was double-counted.

Cheers,

Erling Hellenäs

On 2017-11-03 17:07, Erling Hellenäs wrote:

No, its not. It seems it should have bin there. Maybe something is
wrong. /Erling

On 2017-11-03 16:56, Erling Hellenäs wrote:

Lol. This root is double-counted. 1 1 1 1 358358 /Erling

On 2017-11-03 16:42, Erling Hellenäs wrote:

Hi all!

My take:

    v=:1 1 1 1 2 7 11 13 179
    r=:5 parRuskeyE 9
    r2=: >r (*/)@:{&.>"1 0 < v
    r3=:/:~"1 r2
    r4=: ~.r3
    NB. One root is 1 1 1 1 358358
    NB. All permutations
    (!5)*1+#r4
6360

Cheers,

Erling Hellenäs

On 2017-11-03 15:03, Erling Hellenäs wrote:

Sorry. Add ones. /Erling

On 2017-11-03 15:00, Erling Hellenäs wrote:

OK. The five prime factors are needed if you want to multiply 5
numbers and get 358358, except that you can possibly add zeros and
358358 itself? /Erling

On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms
“factor” and “divisor” for the same thing,  when “divisor” is
perhaps to be preferred.  However,  Pari GP provides a library
function “factor” to deliver the prime factorisation of its
argument,  in a similar fashion to J’s q: .

So, strictly speaking,  perhaps,  the factors of 358358 are 2 7
11 13 179 and its divisors are 1 2 7 11 13 14 22 etc...

You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad


On 3 Nov 2017, at 11:25, Erling Hellenäs
 wrote:

Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is
not efficient enough for this example. 5 parRuskeyE 32 is too
big of a result, I think. (358358 has 5 distinct prime factors
and, thus, 32 integer factors.)"

However there are only 5 integer factors:

    q: 358358
2 7 11 13 179
    */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization
of 358358 unless you count 1 and 358358 as factors.
In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,



--

For information about J forums see
http://www.jsoftware.com/forums.htm

-
-

For information about J forums see
http://www.jsoftware.com/forums.htm


--
--

Re: [Jprogramming] Partitions

2017-11-04 Thread Erling Hellenäs

Hi all!

A simple recursive definition of the problem to find all k-sets in a set 
of n items.


S=: 4 : 0
NB.log=:,.:x do.
    for_i. (<:x)+i.>:y-x do.
NB.log=:log,
It seems that you mighg want to use a diferent name for your combE

load 'stats'



(3 comb 4);3 combE 4

┌─┬───┐
│0 1 2│0 0 0 1│
│0 1 3│0 0 0 2│
│0 2 3│0 0 1 1│
│1 2 3│0 0 1 2│
│ │0 0 2 1│
│ │0 0 2 2│
│ │0 1 0 1│
│ │0 1 0 2│
│ │0 1 1 1│
│ │0 1 1 2│
│ │0 1 2 1│
│ │0 1 2 2│
│ │0 2 0 1│
│ │0 2 0 2│
│ │0 2 1 1│
│ │0 2 1 2│
│ │0 2 2 1│
│ │0 2 2 2│
│ │1 0 0 1│
│ │1 0 0 2│
│ │1 0 1 1│
│ │1 0 1 2│
│ │1 0 2 1│
│ │1 0 2 2│
│ │1 1 0 1│
│ │1 1 0 2│
│ │1 1 1 1│
│ │1 1 1 2│
│ │1 1 2 1│
│ │1 1 2 2│
│ │1 2 0 1│
│ │1 2 0 2│
│ │1 2 1 1│
│ │1 2 1 2│
│ │1 2 2 1│
│ │1 2 2 2│
└─┴───┘

Linda



-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Erling Hellenäs
Sent: Friday, November 3, 2017 12:44 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

I did not correctly understand the e. verb

     24 e. r4
0
     24 e. ,r4
1

So 358358 surely was there and was double-counted.

Cheers,

Erling Hellenäs

On 2017-11-03 17:07, Erling Hellenäs wrote:

No, its not. It seems it should have bin there. Maybe something is
wrong. /Erling

On 2017-11-03 16:56, Erling Hellenäs wrote:

Lol. This root is double-counted. 1 1 1 1 358358 /Erling

On 2017-11-03 16:42, Erling Hellenäs wrote:

Hi all!

My take:

    v=:1 1 1 1 2 7 11 13 179
    r=:5 parRuskeyE 9
    r2=: >r (*/)@:{&.>"1 0 < v
    r3=:/:~"1 r2
    r4=: ~.r3
    NB. One root is 1 1 1 1 358358
    NB. All permutations
    (!5)*1+#r4
6360

Cheers,

Erling Hellenäs

On 2017-11-03 15:03, Erling Hellenäs wrote:

Sorry. Add ones. /Erling

On 2017-11-03 15:00, Erling Hellenäs wrote:

OK. The five prime factors are needed if you want to multiply 5
numbers and get 358358, except that you can possibly add zeros and
358358 itself? /Erling

On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms
“factor” and “divisor” for the same thing,  when “divisor” is
perhaps to be preferred.  However,  Pari GP provides a library
function “factor” to deliver the prime factorisation of its
argument,  in a similar fashion to J’s q: .

So, strictly speaking,  perhaps,  the factors of 358358 are 2 7
11 13 179 and its divisors are 1 2 7 11 13 14 22 etc...

You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad


On 3 Nov 2017, at 11:25, Erling Hellenäs
 wrote:

Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is
not efficient enough for this example. 5 parRuskeyE 32 is too
big of a result, I think. (358358 has 5 distinct prime factors
and, thus, 32 integer factors.)"

However there are only 5 integer factors:

    q: 358358
2 7 11 13 179
    */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization
of 358358 unless you count 1 and 358358 as factors.
In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,



--

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


--
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

Re: [Jprogramming] Partitions

2017-11-04 Thread Erling Hellenäs

Hi all!

This is a questionable case:

   1 list 358358
358358

Cheers,

Erling Hellenäs

On 2017-11-04 07:28, 'Skip Cave' via Programming wrote:

Raul, very nice!

Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
course, that restricts the max number of partitions to the max number of
prime factors of any p. That also greatly reduces the number of partition
instances that will be generated. Then:

5 par 358258

┌─┬─┬──┬──┬───┐

│2│7│11│13│179│

└─┴─┴──┴──┴───┘

Skip

Skip Cave
Cave Consulting LLC

On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller  wrote:


So... 358358 has five prime factors (32 integer factors). We want to
find all sorted sequences (not sets - values can repeat) of five of
those factors whose product is 358358.

To restrict our search, we can investigate only those sorted sequences
of "number of prime factors represented in the variable" whose sum is
five:

~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
0 0 0 0 5
0 0 0 1 4
0 0 0 2 3
0 0 1 1 3
0 0 1 2 2
0 1 1 1 2
1 1 1 1 1

In other words, the results of these seven expressions (use
require'stats' first to get comb):

1 1 1 1
​​
358358
(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
 /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
q:358358

That's 44 different solutions:

1  1  1   1 358358
1  1  1 179   2002
1  1  1  13  27566
1  1  1  11  32578
1  1  1   7  51194
1  1  1   2 179179
1  1  1 154   2327
1  1  1 182   1969
1  1  1 143   2506
1  1  1 286   1253
1  1  1  91   3938
1  1  1  77   4654
1  1  1 358   1001
1  1  1  26  13783
1  1  1  22  16289
1  1  1  14  25597
1  1 13 154179
1  1 11 179182
1  1 11  13   2506
1  1  7 179286
1  1  7  13   3938
1  1  7  11   4654
1  1  2 179   1001
1  1  2  13  13783
1  1  2  11  16289
1  1  2   7  25597
1  1 11  14   2327
1  1  7  22   2327
1  1  7  26   1969
1  1  7 143358
1  1  2  77   2327
1  1  2  91   1969
1  1  2 143   1253
1 11 13  14179
1  7 13  22179
1  7 11  26179
1  7 11  13358
1  2 13  77179
1  2 11  91179
1  2 11  13   1253
1  2  7 143179
1  2  7  13   1969
1  2  7  11   2327
2  7 11  13179

We could of course come up with a routine which does something similar
for other examples (but we will run into prohibitive resource
limitations if we allow large enough integers).

So... just to confirm... this is the problem we are trying to solve?

Thanks,

--
Raul




--
For information about J forums see http://www.jsoftware.com/forums.htm



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-04 Thread Erling Hellenäs

Hi all!

New list, which in my opinion does not answer the quora question.

list=:4 : 0
v=.q: y
if. (#v)r1 (*/)@:{&.>"1 0 < v
  r3=./:~"1 r2
  r=. ~.r3
end.
r
)

Cheers,

Erling Hellenäs

On 2017-11-04 07:28, 'Skip Cave' via Programming wrote:

Raul, very nice!

Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
course, that restricts the max number of partitions to the max number of
prime factors of any p. That also greatly reduces the number of partition
instances that will be generated. Then:

5 par 358258

┌─┬─┬──┬──┬───┐

│2│7│11│13│179│

└─┴─┴──┴──┴───┘

Skip

Skip Cave
Cave Consulting LLC

On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller  wrote:


So... 358358 has five prime factors (32 integer factors). We want to
find all sorted sequences (not sets - values can repeat) of five of
those factors whose product is 358358.

To restrict our search, we can investigate only those sorted sequences
of "number of prime factors represented in the variable" whose sum is
five:

~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
0 0 0 0 5
0 0 0 1 4
0 0 0 2 3
0 0 1 1 3
0 0 1 2 2
0 1 1 1 2
1 1 1 1 1

In other words, the results of these seven expressions (use
require'stats' first to get comb):

1 1 1 1
​​
358358
(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
 /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
q:358358

That's 44 different solutions:

1  1  1   1 358358
1  1  1 179   2002
1  1  1  13  27566
1  1  1  11  32578
1  1  1   7  51194
1  1  1   2 179179
1  1  1 154   2327
1  1  1 182   1969
1  1  1 143   2506
1  1  1 286   1253
1  1  1  91   3938
1  1  1  77   4654
1  1  1 358   1001
1  1  1  26  13783
1  1  1  22  16289
1  1  1  14  25597
1  1 13 154179
1  1 11 179182
1  1 11  13   2506
1  1  7 179286
1  1  7  13   3938
1  1  7  11   4654
1  1  2 179   1001
1  1  2  13  13783
1  1  2  11  16289
1  1  2   7  25597
1  1 11  14   2327
1  1  7  22   2327
1  1  7  26   1969
1  1  7 143358
1  1  2  77   2327
1  1  2  91   1969
1  1  2 143   1253
1 11 13  14179
1  7 13  22179
1  7 11  26179
1  7 11  13358
1  2 13  77179
1  2 11  91179
1  2 11  13   1253
1  2  7 143179
1  2  7  13   1969
1  2  7  11   2327
2  7 11  13179

We could of course come up with a routine which does something similar
for other examples (but we will run into prohibitive resource
limitations if we allow large enough integers).

So... just to confirm... this is the problem we are trying to solve?

Thanks,

--
Raul




--
For information about J forums see http://www.jsoftware.com/forums.htm



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-04 Thread Raul Miller
Well, ok, though that was not a part of your re-specification this time.

Actually, though, re-reading your spec, i left out a factor of 16 of
the solutions: integers can be negative and as long as we include an
even number of negatives they cancel out in a product.

Thanks,

-- 
Raul


On Sat, Nov 4, 2017 at 2:28 AM, 'Skip Cave' via Programming
 wrote:
> Raul, very nice!
>
> Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
> course, that restricts the max number of partitions to the max number of
> prime factors of any p. That also greatly reduces the number of partition
> instances that will be generated. Then:
>
> 5 par 358258
>
> ┌─┬─┬──┬──┬───┐
>
> │2│7│11│13│179│
>
> └─┴─┴──┴──┴───┘
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller  wrote:
>
>> So... 358358 has five prime factors (32 integer factors). We want to
>> find all sorted sequences (not sets - values can repeat) of five of
>> those factors whose product is 358358.
>>
>> To restrict our search, we can investigate only those sorted sequences
>> of "number of prime factors represented in the variable" whose sum is
>> five:
>>
>>~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
>> 0 0 0 0 5
>> 0 0 0 1 4
>> 0 0 0 2 3
>> 0 0 1 1 3
>> 0 0 1 2 2
>> 0 1 1 1 2
>> 1 1 1 1 1
>>
>> In other words, the results of these seven expressions (use
>> require'stats' first to get comb):
>>
>>1 1 1 1
>>
>> 358358
>>(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
>>/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
>>/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
>>~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>> /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>>q:358358
>>
>> That's 44 different solutions:
>>
>> 1  1  1   1 358358
>> 1  1  1 179   2002
>> 1  1  1  13  27566
>> 1  1  1  11  32578
>> 1  1  1   7  51194
>> 1  1  1   2 179179
>> 1  1  1 154   2327
>> 1  1  1 182   1969
>> 1  1  1 143   2506
>> 1  1  1 286   1253
>> 1  1  1  91   3938
>> 1  1  1  77   4654
>> 1  1  1 358   1001
>> 1  1  1  26  13783
>> 1  1  1  22  16289
>> 1  1  1  14  25597
>> 1  1 13 154179
>> 1  1 11 179182
>> 1  1 11  13   2506
>> 1  1  7 179286
>> 1  1  7  13   3938
>> 1  1  7  11   4654
>> 1  1  2 179   1001
>> 1  1  2  13  13783
>> 1  1  2  11  16289
>> 1  1  2   7  25597
>> 1  1 11  14   2327
>> 1  1  7  22   2327
>> 1  1  7  26   1969
>> 1  1  7 143358
>> 1  1  2  77   2327
>> 1  1  2  91   1969
>> 1  1  2 143   1253
>> 1 11 13  14179
>> 1  7 13  22179
>> 1  7 11  26179
>> 1  7 11  13358
>> 1  2 13  77179
>> 1  2 11  91179
>> 1  2 11  13   1253
>> 1  2  7 143179
>> 1  2  7  13   1969
>> 1  2  7  11   2327
>> 2  7 11  13179
>>
>> We could of course come up with a routine which does something similar
>> for other examples (but we will run into prohibitive resource
>> limitations if we allow large enough integers).
>>
>> So... just to confirm... this is the problem we are trying to solve?
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread 'Skip Cave' via Programming
Raul, very nice!

Actually I prefer the solution that doesn't allow 1 as a factor of p. Of
course, that restricts the max number of partitions to the max number of
prime factors of any p. That also greatly reduces the number of partition
instances that will be generated. Then:

5 par 358258

┌─┬─┬──┬──┬───┐

│2│7│11│13│179│

└─┴─┴──┴──┴───┘

Skip

Skip Cave
Cave Consulting LLC

On Fri, Nov 3, 2017 at 2:40 AM, Raul Miller  wrote:

> So... 358358 has five prime factors (32 integer factors). We want to
> find all sorted sequences (not sets - values can repeat) of five of
> those factors whose product is 358358.
>
> To restrict our search, we can investigate only those sorted sequences
> of "number of prime factors represented in the variable" whose sum is
> five:
>
>~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
> 0 0 0 0 5
> 0 0 0 1 4
> 0 0 0 2 3
> 0 0 1 1 3
> 0 0 1 2 2
> 0 1 1 1 2
> 1 1 1 1 1
>
> In other words, the results of these seven expressions (use
> require'stats' first to get comb):
>
>1 1 1 1
> ​​
> 358358
>(1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
>/:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
>/:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
>~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
> /:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
>q:358358
>
> That's 44 different solutions:
>
> 1  1  1   1 358358
> 1  1  1 179   2002
> 1  1  1  13  27566
> 1  1  1  11  32578
> 1  1  1   7  51194
> 1  1  1   2 179179
> 1  1  1 154   2327
> 1  1  1 182   1969
> 1  1  1 143   2506
> 1  1  1 286   1253
> 1  1  1  91   3938
> 1  1  1  77   4654
> 1  1  1 358   1001
> 1  1  1  26  13783
> 1  1  1  22  16289
> 1  1  1  14  25597
> 1  1 13 154179
> 1  1 11 179182
> 1  1 11  13   2506
> 1  1  7 179286
> 1  1  7  13   3938
> 1  1  7  11   4654
> 1  1  2 179   1001
> 1  1  2  13  13783
> 1  1  2  11  16289
> 1  1  2   7  25597
> 1  1 11  14   2327
> 1  1  7  22   2327
> 1  1  7  26   1969
> 1  1  7 143358
> 1  1  2  77   2327
> 1  1  2  91   1969
> 1  1  2 143   1253
> 1 11 13  14179
> 1  7 13  22179
> 1  7 11  26179
> 1  7 11  13358
> 1  2 13  77179
> 1  2 11  91179
> 1  2 11  13   1253
> 1  2  7 143179
> 1  2  7  13   1969
> 1  2  7  11   2327
> 2  7 11  13179
>
> We could of course come up with a routine which does something similar
> for other examples (but we will run into prohibitive resource
> limitations if we allow large enough integers).
>
> So... just to confirm... this is the problem we are trying to solve?
>
> Thanks,
>
> --
> Raul
>
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Hi all!

list=:4 : 0
v=.((x-1)#1),q: y
r1=.x parRuskeyE #v
r2=. >r1 (*/)@:{&.>"1 0 < v
r3=./:~"1 r2
r4=. ~.r3
(!x)*#r4
)

   3 list 24
36

Cheers,
Erling Hellenäs

On 2017-11-03 17:36, Erling Hellenäs wrote:

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

   [v=: 1 1 ,q:24
1 1 2 2 2 3
   [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5    │2 3    │
├───┼───┼───┤
│0 3    │1 4 5  │2  │
├───┼───┼───┤
│0  │1 3 4 5│2  │
├───┼───┼───┤
│0  │1 4 5  │2 3    │
├───┼───┼───┤
│0 3    │1 5    │2 4    │
├───┼───┼───┤
│0  │1 3 5  │2 4    │
├───┼───┼───┤
│0  │1 5    │2 3 4  │
├───┼───┼───┤
│0 3 4  │1  │2 5    │
├───┼───┼───┤
│0 4    │1 3    │2 5    │
├───┼───┼───┤
│0 4    │1  │2 3 5  │
├───┼───┼───┤
│0 3    │1 4    │2 5    │
├───┼───┼───┤
│0  │1 3 4  │2 5    │
├───┼───┼───┤
│0  │1 4    │2 3 5  │
├───┼───┼───┤
│0 3    │1  │2 4 5  │
├───┼───┼───┤
│0  │1 3    │2 4 5  │
├───┼───┼───┤
│0  │1  │2 3 4 5│
├───┼───┼───┤
│0 2 4 5│1  │3  │
├───┼───┼───┤
│0 4 5  │1 2    │3  │
├───┼───┼───┤
│0 2 5  │1 4    │3  │
├───┼───┼───┤
│0 5    │1 2 4  │3  │
├───┼───┼───┤
│0 2 5  │1  │3 4    │
├───┼───┼───┤
│0 5    │1 2    │3 4    │
├───┼───┼───┤
│0 2 4  │1 5    │3  │
├───┼───┼───┤
│0 4    │1 2 5  │3  │
├───┼───┼───┤
│0 2    │1 4 5  │3  │
├───┼───┼───┤
│0  │1 2 4 5│3  │
├───┼───┼───┤
│0 2    │1 5    │3 4    │
├───┼───┼───┤
│0  │1 2 5  │3 4    │
├───┼───┼───┤
│0 2 4  │1  │3 5    │
├───┼───┼───┤
│0 4    │1 2    │3 5    │
├───┼───┼───┤
│0 2    │1 4    │3 5    │
├───┼───┼───┤
│0  │1 2 4  │3 5    │
├───┼───┼───┤
│0 2    │1  │3 4 5  │
├───┼───┼───┤
│0  │1 2    │3 4 5  │
├───┼───┼───┤
│0 1 4 5│2  │3  │
├───┼───┼───┤
│0 1 5  │2 4    │3  │
├───┼───┼───┤
│0 1 5  │2  │3 4    │
├───┼───┼───┤
│0 1 4  │2 5    │3  │
├───┼───┼───┤
│0 1    │2 4 5  │3  │
├───┼───┼───┤
│0 1    │2 5    │3 4    │
├───┼───┼───┤
│0 1 4  │2  │3 5    │
├───┼───┼───┤
│0 1    │2 4    │3 5    │
├───┼───┼───┤
│0 1    │2  │3 4 5  │
├───┼───┼───┤
│0 2 3 5│1  │4  │
├───┼───┼───┤
│0 3 5  │1 2    │4  │
├───┼───┼───┤
│0 2 5  │1 3    │4  │
├───┼───┼───┤
│0 5    │1 2 3  │4  │
├───┼───┼───┤
│0 2 3  │1 5    │4  │
├───┼───┼───┤
│0 3    │1 2 5  │4  │
├───┼───┼───┤
│0 2    │1 3 5  │4  │
├───┼───┼───┤
│0  │1 2 3 5│4  │
├───┼───┼───┤
│0 2 3  │1  │4 5    │
├───┼───┼───┤
│0 3    │1 2    │4 5    │
├───┼───┼───┤
│0 2    │1 3    │4 5    │
├───┼───┼───┤
│0  │1 2 3  │4 5    │
├───┼───┼───┤
│0 1 3 5│2  │4  │
├───┼───┼───┤
│0 1 5  │2 3    │4  │
├───┼───┼───┤
│0 1 3  │2 5    │4  │
├───┼───┼───┤
│0 1    │2 3 5  │4  │
├───┼───┼───┤
│0 1 3  │2  │4 5    │
├───┼───┼───┤
│0 1    │2 3    │4 5    │
├───┼───┼───┤
│0 1 2 5│3  │4  │
├───┼───┼───┤
│0 1 2  │3 5    │4  │
├───┼───┼───┤
│0 1 2  │3  │4 5    │
├───┼───┼───┤
│0 2 3 4│1  │5  │
├───┼───┼───┤
│0 3 4  │1 2    │5  │
├───┼───┼───┤
│0 2 4  │1 3    │5  │
├───┼───┼───┤
│0 4    │1 2 3  │5  │
├───┼───┼───┤
│0 2 3  │1 4    │5  │
├───┼───┼───┤
│0 3    │1 2 4  │5  │
├───┼───┼───┤
│0 2    │1 3 4  │5  │
├───┼───┼───┤
│0  │1 2 3 4│5  │
├───┼───┼───┤
│0 1 3 4│2  │5  │
├───┼───┼───┤
│0 1 4  │2 3    │5  │
├───┼───┼───┤
│0 1 3  │2 4    │5  │
├───┼───┼───┤
│0 1    │2 3 4  │5  │
├───┼───┼───┤
│0 1 2 4│3  │5  │
├───┼───┼─

Re: [Jprogramming] Partitions

2017-11-03 Thread Raul Miller
There are only 5 prime integer factors.

There are 44 integer factors. These guys:

1 1 1 1 358358
1 1 1 11 32578
1 1 1 13 27566
1 1 1 14 25597
1 1 1 143 2506
1 1 1 154 2327
1 1 1 179 2002
1 1 1 182 1969
1 1 1 2 179179
1 1 1 22 16289
1 1 1 26 13783
1 1 1 286 1253
1 1 1 358 1001
1 1 1 7 51194
1 1 1 77 4654
1 1 1 91 3938
1 1 11 13 2506
1 1 11 14 2327
1 1 11 179 182
1 1 13 154 179
1 1 2 11 16289
1 1 2 13 13783
1 1 2 143 1253
1 1 2 179 1001
1 1 2 7 25597
1 1 2 77 2327
1 1 2 91 1969
1 1 7 11 4654
1 1 7 13 3938
1 1 7 143 358
1 1 7 179 286
1 1 7 22 2327
1 1 7 26 1969
1 11 13 14 179
1 2 11 13 1253
1 2 11 91 179
1 2 13 77 179
1 2 7 11 2327
1 2 7 13 1969
1 2 7 143 179
1 7 11 13 358
1 7 11 26 179
1 7 13 22 179
2 7 11 13 179

Each of those examples has the product 358358 and each of those
examples is composed of integers. With one exception, they are not all
prime numbers, but remember that Skip asked for:

> 358358=*/x1, x2, x3, x4, x5
> How many different combinations of 5 integersx1, x2, x3, x4, x5  solve this
> equality? (Different orders don't count)

And it seems to me that there are 44 of those?

Thanks,

-- 
Raul

On Fri, Nov 3, 2017 at 7:25 AM, Erling Hellenäs
 wrote:
> Hi all!
>
> Raul:
>
> "Hmm... actually, thinking about it, the par approach here is not
> efficient enough for this example. 5 parRuskeyE 32 is too big of a
> result, I think. (358358 has 5 distinct prime factors and, thus, 32
> integer factors.)"
>
> However there are only 5 integer factors:
>
>q: 358358
> 2 7 11 13 179
>*/q:358358
> 358358
>
> Now you ask me for 44 5 integer factorizations.
>
> As far as I understand there is only one 5 integer factorization of 358358
> unless you count 1 and 358358 as factors.
> In any case it can be handled by parRuskeyE.
>
> Cheers,
>
> Erling Hellenäs
>
>
>
> Den 2017-11-03 kl. 10:58, skrev Raul Miller:
>>
>> I'm not sure where you showed the 44 different 5 integer
>> factorizations of 358358?
>>
>> Thanks,
>>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

The result should have been:
   NB. All permutations
   (!3)*#r4
36
/Erling

On 2017-11-03 17:36, Erling Hellenäs wrote:

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

   [v=: 1 1 ,q:24
1 1 2 2 2 3
   [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5    │2 3    │
├───┼───┼───┤
│0 3    │1 4 5  │2  │
├───┼───┼───┤
│0  │1 3 4 5│2  │
├───┼───┼───┤
│0  │1 4 5  │2 3    │
├───┼───┼───┤
│0 3    │1 5    │2 4    │
├───┼───┼───┤
│0  │1 3 5  │2 4    │
├───┼───┼───┤
│0  │1 5    │2 3 4  │
├───┼───┼───┤
│0 3 4  │1  │2 5    │
├───┼───┼───┤
│0 4    │1 3    │2 5    │
├───┼───┼───┤
│0 4    │1  │2 3 5  │
├───┼───┼───┤
│0 3    │1 4    │2 5    │
├───┼───┼───┤
│0  │1 3 4  │2 5    │
├───┼───┼───┤
│0  │1 4    │2 3 5  │
├───┼───┼───┤
│0 3    │1  │2 4 5  │
├───┼───┼───┤
│0  │1 3    │2 4 5  │
├───┼───┼───┤
│0  │1  │2 3 4 5│
├───┼───┼───┤
│0 2 4 5│1  │3  │
├───┼───┼───┤
│0 4 5  │1 2    │3  │
├───┼───┼───┤
│0 2 5  │1 4    │3  │
├───┼───┼───┤
│0 5    │1 2 4  │3  │
├───┼───┼───┤
│0 2 5  │1  │3 4    │
├───┼───┼───┤
│0 5    │1 2    │3 4    │
├───┼───┼───┤
│0 2 4  │1 5    │3  │
├───┼───┼───┤
│0 4    │1 2 5  │3  │
├───┼───┼───┤
│0 2    │1 4 5  │3  │
├───┼───┼───┤
│0  │1 2 4 5│3  │
├───┼───┼───┤
│0 2    │1 5    │3 4    │
├───┼───┼───┤
│0  │1 2 5  │3 4    │
├───┼───┼───┤
│0 2 4  │1  │3 5    │
├───┼───┼───┤
│0 4    │1 2    │3 5    │
├───┼───┼───┤
│0 2    │1 4    │3 5    │
├───┼───┼───┤
│0  │1 2 4  │3 5    │
├───┼───┼───┤
│0 2    │1  │3 4 5  │
├───┼───┼───┤
│0  │1 2    │3 4 5  │
├───┼───┼───┤
│0 1 4 5│2  │3  │
├───┼───┼───┤
│0 1 5  │2 4    │3  │
├───┼───┼───┤
│0 1 5  │2  │3 4    │
├───┼───┼───┤
│0 1 4  │2 5    │3  │
├───┼───┼───┤
│0 1    │2 4 5  │3  │
├───┼───┼───┤
│0 1    │2 5    │3 4    │
├───┼───┼───┤
│0 1 4  │2  │3 5    │
├───┼───┼───┤
│0 1    │2 4    │3 5    │
├───┼───┼───┤
│0 1    │2  │3 4 5  │
├───┼───┼───┤
│0 2 3 5│1  │4  │
├───┼───┼───┤
│0 3 5  │1 2    │4  │
├───┼───┼───┤
│0 2 5  │1 3    │4  │
├───┼───┼───┤
│0 5    │1 2 3  │4  │
├───┼───┼───┤
│0 2 3  │1 5    │4  │
├───┼───┼───┤
│0 3    │1 2 5  │4  │
├───┼───┼───┤
│0 2    │1 3 5  │4  │
├───┼───┼───┤
│0  │1 2 3 5│4  │
├───┼───┼───┤
│0 2 3  │1  │4 5    │
├───┼───┼───┤
│0 3    │1 2    │4 5    │
├───┼───┼───┤
│0 2    │1 3    │4 5    │
├───┼───┼───┤
│0  │1 2 3  │4 5    │
├───┼───┼───┤
│0 1 3 5│2  │4  │
├───┼───┼───┤
│0 1 5  │2 3    │4  │
├───┼───┼───┤
│0 1 3  │2 5    │4  │
├───┼───┼───┤
│0 1    │2 3 5  │4  │
├───┼───┼───┤
│0 1 3  │2  │4 5    │
├───┼───┼───┤
│0 1    │2 3    │4 5    │
├───┼───┼───┤
│0 1 2 5│3  │4  │
├───┼───┼───┤
│0 1 2  │3 5    │4  │
├───┼───┼───┤
│0 1 2  │3  │4 5    │
├───┼───┼───┤
│0 2 3 4│1  │5  │
├───┼───┼───┤
│0 3 4  │1 2    │5  │
├───┼───┼───┤
│0 2 4  │1 3    │5  │
├───┼───┼───┤
│0 4    │1 2 3  │5  │
├───┼───┼───┤
│0 2 3  │1 4    │5  │
├───┼───┼───┤
│0 3    │1 2 4  │5  │
├───┼───┼───┤
│0 2    │1 3 4  │5  │
├───┼───┼───┤
│0  │1 2 3 4│5  │
├───┼───┼───┤
│0 1 3 4│2  │5  │
├───┼───┼───┤
│0 1 4  │2 3    │5  │
├───┼───┼───┤
│0 1 3  │2 4    │5  │
├───┼───┼───┤
│0 1    │2 3 4  │5  │
├───┼───┼───┤
│0 1 2 4│3  │5  │
├───┼───┼───┤
│0 1 2  │3 4    │5  │
├───┼───┼───┤
│0 1 2 3│4  │5  │
└

Re: [Jprogramming] Partitions

2017-11-03 Thread Linda Alvord
It seems that you mighg want to use a diferent name for your combE

load 'stats'
   
   
   
   (3 comb 4);3 combE 4
┌─┬───┐
│0 1 2│0 0 0 1│
│0 1 3│0 0 0 2│
│0 2 3│0 0 1 1│
│1 2 3│0 0 1 2│
│ │0 0 2 1│
│ │0 0 2 2│
│ │0 1 0 1│
│ │0 1 0 2│
│ │0 1 1 1│
│ │0 1 1 2│
│ │0 1 2 1│
│ │0 1 2 2│
│ │0 2 0 1│
│ │0 2 0 2│
│ │0 2 1 1│
│ │0 2 1 2│
│ │0 2 2 1│
│ │0 2 2 2│
│ │1 0 0 1│
│ │1 0 0 2│
│ │1 0 1 1│
│ │1 0 1 2│
│ │1 0 2 1│
│ │1 0 2 2│
│ │1 1 0 1│
│ │1 1 0 2│
│ │1 1 1 1│
│ │1 1 1 2│
│ │1 1 2 1│
│ │1 1 2 2│
│ │1 2 0 1│
│ │1 2 0 2│
│ │1 2 1 1│
│ │1 2 1 2│
│ │1 2 2 1│
│ │1 2 2 2│
└─┴───┘
   
Linda


-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Erling Hellenäs
Sent: Friday, November 3, 2017 12:44 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

I did not correctly understand the e. verb

    24 e. r4
0
    24 e. ,r4
1

So 358358 surely was there and was double-counted.

Cheers,

Erling Hellenäs

On 2017-11-03 17:07, Erling Hellenäs wrote:
> No, its not. It seems it should have bin there. Maybe something is 
> wrong. /Erling
>
> On 2017-11-03 16:56, Erling Hellenäs wrote:
>> Lol. This root is double-counted. 1 1 1 1 358358 /Erling
>>
>> On 2017-11-03 16:42, Erling Hellenäs wrote:
>>> Hi all!
>>>
>>> My take:
>>>
>>>    v=:1 1 1 1 2 7 11 13 179
>>>    r=:5 parRuskeyE 9
>>>    r2=: >r (*/)@:{&.>"1 0 < v
>>>    r3=:/:~"1 r2
>>>    r4=: ~.r3
>>>    NB. One root is 1 1 1 1 358358
>>>    NB. All permutations
>>>    (!5)*1+#r4
>>> 6360
>>>
>>> Cheers,
>>>
>>> Erling Hellenäs
>>>
>>> On 2017-11-03 15:03, Erling Hellenäs wrote:
>>>> Sorry. Add ones. /Erling
>>>>
>>>> On 2017-11-03 15:00, Erling Hellenäs wrote:
>>>>> OK. The five prime factors are needed if you want to multiply 5 
>>>>> numbers and get 358358, except that you can possibly add zeros and  
>>>>> 358358 itself? /Erling
>>>>>
>>>>> On 2017-11-03 14:35, 'Mike Day' via Programming wrote:
>>>>>> Language differences?
>>>>>>
>>>>>> Personally,  I tend to be rather careless,  using the terms 
>>>>>> “factor” and “divisor” for the same thing,  when “divisor” is 
>>>>>> perhaps to be preferred.  However,  Pari GP provides a library 
>>>>>> function “factor” to deliver the prime factorisation of its 
>>>>>> argument,  in a similar fashion to J’s q: .
>>>>>>
>>>>>> So, strictly speaking,  perhaps,  the factors of 358358 are 2 7
>>>>>> 11 13 179 and its divisors are 1 2 7 11 13 14 22 etc...
>>>>>>
>>>>>> You’re both right!
>>>>>>
>>>>>> Mike
>>>>>>
>>>>>> Please reply to mike_liz@tiscali.co.uk.
>>>>>> Sent from my iPad
>>>>>>
>>>>>>> On 3 Nov 2017, at 11:25, Erling Hellenäs 
>>>>>>>  wrote:
>>>>>>>
>>>>>>> Hi all!
>>>>>>>
>>>>>>> Raul:
>>>>>>>
>>>>>>> "Hmm... actually, thinking about it, the par approach here is 
>>>>>>> not efficient enough for this example. 5 parRuskeyE 32 is too 
>>>>>>> big of a result, I think. (358358 has 5 distinct prime factors 
>>>>>>> and, thus, 32 integer factors.)"
>>>>>>>
>>>>>>> However there are only 5 integer factors:
>>>>>>>
>>>>>>>    q: 358358
>>>>>>> 2 7 11 13 179
>>>>>>>    */q:358358
>>>>>>> 358358
>>>>>>>
>>>>>>> Now you ask me for 44 5 integer factorizations.
>>>>>>>
>>>>>>> As far as I understand there is only one 5 integer factorization 
>>>>>>> of 358358 unless you count 1 and 358358 as factors.
>>>>>>> In any case it can be handled by parRuskeyE.
>>>>>>>
>>>>>>> Cheers,
>>>>>>>
>>>>>>> Erling Hellenäs
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> Den 2017

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Hi all!

I did not correctly understand the e. verb

   24 e. r4
0
   24 e. ,r4
1

So 358358 surely was there and was double-counted.

Cheers,

Erling Hellenäs

On 2017-11-03 17:07, Erling Hellenäs wrote:
No, its not. It seems it should have bin there. Maybe something is 
wrong. /Erling


On 2017-11-03 16:56, Erling Hellenäs wrote:

Lol. This root is double-counted. 1 1 1 1 358358 /Erling

On 2017-11-03 16:42, Erling Hellenäs wrote:

Hi all!

My take:

   v=:1 1 1 1 2 7 11 13 179
   r=:5 parRuskeyE 9
   r2=: >r (*/)@:{&.>"1 0 < v
   r3=:/:~"1 r2
   r4=: ~.r3
   NB. One root is 1 1 1 1 358358
   NB. All permutations
   (!5)*1+#r4
6360

Cheers,

Erling Hellenäs

On 2017-11-03 15:03, Erling Hellenäs wrote:

Sorry. Add ones. /Erling

On 2017-11-03 15:00, Erling Hellenäs wrote:
OK. The five prime factors are needed if you want to multiply 5 
numbers and get 358358, except that you can possibly add zeros 
and  358358 itself? /Erling


On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms 
“factor” and “divisor” for the same thing,  when “divisor” is 
perhaps to be preferred.  However,  Pari GP provides a library 
function “factor” to deliver the prime factorisation of its 
argument,  in a similar fashion to J’s q: .


So, strictly speaking,  perhaps,  the factors of 358358 are 2 7 
11 13 179 and its divisors are 1 2 7 11 13 14 22 etc...


You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad

On 3 Nov 2017, at 11:25, Erling Hellenäs 
 wrote:


Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)"

However there are only 5 integer factors:

   q: 358358
2 7 11 13 179
   */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization 
of 358358 unless you count 1 and 358358 as factors.

In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,

-- 

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



--
For information about J forums see http://www.jsoftware.com/forums.htm



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Hi all  !

Below is the output of the run on the Quora question.

Maybe someone can see if there is a problem.

Cheers,

Erling Hellenäs

   [v=: 1 1 ,q:24
1 1 2 2 2 3
   [r=:3 parRuskeyE #v
┌───┬───┬───┐
│0 3 4 5│1  │2  │
├───┼───┼───┤
│0 4 5  │1 3    │2  │
├───┼───┼───┤
│0 4 5  │1  │2 3    │
├───┼───┼───┤
│0 3 5  │1 4    │2  │
├───┼───┼───┤
│0 5    │1 3 4  │2  │
├───┼───┼───┤
│0 5    │1 4    │2 3    │
├───┼───┼───┤
│0 3 5  │1  │2 4    │
├───┼───┼───┤
│0 5    │1 3    │2 4    │
├───┼───┼───┤
│0 5    │1  │2 3 4  │
├───┼───┼───┤
│0 3 4  │1 5    │2  │
├───┼───┼───┤
│0 4    │1 3 5  │2  │
├───┼───┼───┤
│0 4    │1 5    │2 3    │
├───┼───┼───┤
│0 3    │1 4 5  │2  │
├───┼───┼───┤
│0  │1 3 4 5│2  │
├───┼───┼───┤
│0  │1 4 5  │2 3    │
├───┼───┼───┤
│0 3    │1 5    │2 4    │
├───┼───┼───┤
│0  │1 3 5  │2 4    │
├───┼───┼───┤
│0  │1 5    │2 3 4  │
├───┼───┼───┤
│0 3 4  │1  │2 5    │
├───┼───┼───┤
│0 4    │1 3    │2 5    │
├───┼───┼───┤
│0 4    │1  │2 3 5  │
├───┼───┼───┤
│0 3    │1 4    │2 5    │
├───┼───┼───┤
│0  │1 3 4  │2 5    │
├───┼───┼───┤
│0  │1 4    │2 3 5  │
├───┼───┼───┤
│0 3    │1  │2 4 5  │
├───┼───┼───┤
│0  │1 3    │2 4 5  │
├───┼───┼───┤
│0  │1  │2 3 4 5│
├───┼───┼───┤
│0 2 4 5│1  │3  │
├───┼───┼───┤
│0 4 5  │1 2    │3  │
├───┼───┼───┤
│0 2 5  │1 4    │3  │
├───┼───┼───┤
│0 5    │1 2 4  │3  │
├───┼───┼───┤
│0 2 5  │1  │3 4    │
├───┼───┼───┤
│0 5    │1 2    │3 4    │
├───┼───┼───┤
│0 2 4  │1 5    │3  │
├───┼───┼───┤
│0 4    │1 2 5  │3  │
├───┼───┼───┤
│0 2    │1 4 5  │3  │
├───┼───┼───┤
│0  │1 2 4 5│3  │
├───┼───┼───┤
│0 2    │1 5    │3 4    │
├───┼───┼───┤
│0  │1 2 5  │3 4    │
├───┼───┼───┤
│0 2 4  │1  │3 5    │
├───┼───┼───┤
│0 4    │1 2    │3 5    │
├───┼───┼───┤
│0 2    │1 4    │3 5    │
├───┼───┼───┤
│0  │1 2 4  │3 5    │
├───┼───┼───┤
│0 2    │1  │3 4 5  │
├───┼───┼───┤
│0  │1 2    │3 4 5  │
├───┼───┼───┤
│0 1 4 5│2  │3  │
├───┼───┼───┤
│0 1 5  │2 4    │3  │
├───┼───┼───┤
│0 1 5  │2  │3 4    │
├───┼───┼───┤
│0 1 4  │2 5    │3  │
├───┼───┼───┤
│0 1    │2 4 5  │3  │
├───┼───┼───┤
│0 1    │2 5    │3 4    │
├───┼───┼───┤
│0 1 4  │2  │3 5    │
├───┼───┼───┤
│0 1    │2 4    │3 5    │
├───┼───┼───┤
│0 1    │2  │3 4 5  │
├───┼───┼───┤
│0 2 3 5│1  │4  │
├───┼───┼───┤
│0 3 5  │1 2    │4  │
├───┼───┼───┤
│0 2 5  │1 3    │4  │
├───┼───┼───┤
│0 5    │1 2 3  │4  │
├───┼───┼───┤
│0 2 3  │1 5    │4  │
├───┼───┼───┤
│0 3    │1 2 5  │4  │
├───┼───┼───┤
│0 2    │1 3 5  │4  │
├───┼───┼───┤
│0  │1 2 3 5│4  │
├───┼───┼───┤
│0 2 3  │1  │4 5    │
├───┼───┼───┤
│0 3    │1 2    │4 5    │
├───┼───┼───┤
│0 2    │1 3    │4 5    │
├───┼───┼───┤
│0  │1 2 3  │4 5    │
├───┼───┼───┤
│0 1 3 5│2  │4  │
├───┼───┼───┤
│0 1 5  │2 3    │4  │
├───┼───┼───┤
│0 1 3  │2 5    │4  │
├───┼───┼───┤
│0 1    │2 3 5  │4  │
├───┼───┼───┤
│0 1 3  │2  │4 5    │
├───┼───┼───┤
│0 1    │2 3    │4 5    │
├───┼───┼───┤
│0 1 2 5│3  │4  │
├───┼───┼───┤
│0 1 2  │3 5    │4  │
├───┼───┼───┤
│0 1 2  │3  │4 5    │
├───┼───┼───┤
│0 2 3 4│1  │5  │
├───┼───┼───┤
│0 3 4  │1 2    │5  │
├───┼───┼───┤
│0 2 4  │1 3    │5  │
├───┼───┼───┤
│0 4    │1 2 3  │5  │
├───┼───┼───┤
│0 2 3  │1 4    │5  │
├───┼───┼───┤
│0 3    │1 2 4  │5  │
├───┼───┼───┤
│0 2    │1 3 4  │5  │
├───┼───┼───┤
│0  │1 2 3 4│5  │
├───┼───┼───┤
│0 1 3 4│2  │5  │
├───┼───┼───┤
│0 1 4  │2 3    │5  │
├───┼───┼───┤
│0 1 3  │2 4    │5  │
├───┼───┼───┤
│0 1    │2 3 4  │5  │
├───┼───┼───┤
│0 1 2 4│3  │5  │
├───┼───┼───┤
│0 1 2  │3 4    │5  │
├───┼───┼───┤
│0 1 2 3│4  │5  │
└───┴───┴───┘
   [r2=: >r (*/)@:{&.>"1 0 < v
12  1  2
 6  2  2
 6  1  4
 6  2  2
 3  4  2
 3  2  4
 6  1  4
 3  2  

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs
No, its not. It seems it should have bin there. Maybe something is 
wrong. /Erling


On 2017-11-03 16:56, Erling Hellenäs wrote:

Lol. This root is double-counted. 1 1 1 1 358358 /Erling

On 2017-11-03 16:42, Erling Hellenäs wrote:

Hi all!

My take:

   v=:1 1 1 1 2 7 11 13 179
   r=:5 parRuskeyE 9
   r2=: >r (*/)@:{&.>"1 0 < v
   r3=:/:~"1 r2
   r4=: ~.r3
   NB. One root is 1 1 1 1 358358
   NB. All permutations
   (!5)*1+#r4
6360

Cheers,

Erling Hellenäs

On 2017-11-03 15:03, Erling Hellenäs wrote:

Sorry. Add ones. /Erling

On 2017-11-03 15:00, Erling Hellenäs wrote:
OK. The five prime factors are needed if you want to multiply 5 
numbers and get 358358, except that you can possibly add zeros and  
358358 itself? /Erling


On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms 
“factor” and “divisor” for the same thing,  when “divisor” is 
perhaps to be preferred.  However,  Pari GP provides a library 
function “factor” to deliver the prime factorisation of its 
argument,  in a similar fashion to J’s q: .


So, strictly speaking,  perhaps,  the factors of 358358 are 2 7 11 
13 179 and its divisors are 1 2 7 11 13 14 22 etc...


You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad

On 3 Nov 2017, at 11:25, Erling Hellenäs 
 wrote:


Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)"

However there are only 5 integer factors:

   q: 358358
2 7 11 13 179
   */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization 
of 358358 unless you count 1 and 358358 as factors.

In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,

-- 

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



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Lol. This root is double-counted. 1 1 1 1 358358 /Erling

On 2017-11-03 16:42, Erling Hellenäs wrote:

Hi all!

My take:

   v=:1 1 1 1 2 7 11 13 179
   r=:5 parRuskeyE 9
   r2=: >r (*/)@:{&.>"1 0 < v
   r3=:/:~"1 r2
   r4=: ~.r3
   NB. One root is 1 1 1 1 358358
   NB. All permutations
   (!5)*1+#r4
6360

Cheers,

Erling Hellenäs

On 2017-11-03 15:03, Erling Hellenäs wrote:

Sorry. Add ones. /Erling

On 2017-11-03 15:00, Erling Hellenäs wrote:
OK. The five prime factors are needed if you want to multiply 5 
numbers and get 358358, except that you can possibly add zeros and  
358358 itself? /Erling


On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms 
“factor” and “divisor” for the same thing,  when “divisor” is 
perhaps to be preferred.  However,  Pari GP provides a library 
function “factor” to deliver the prime factorisation of its 
argument,  in a similar fashion to J’s q: .


So, strictly speaking,  perhaps,  the factors of 358358 are 2 7 11 
13 179 and its divisors are 1 2 7 11 13 14 22 etc...


You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad

On 3 Nov 2017, at 11:25, Erling Hellenäs 
 wrote:


Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)"

However there are only 5 integer factors:

   q: 358358
2 7 11 13 179
   */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization 
of 358358 unless you count 1 and 358358 as factors.

In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,

-- 

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

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Hi all!

My take:

   v=:1 1 1 1 2 7 11 13 179
   r=:5 parRuskeyE 9
   r2=: >r (*/)@:{&.>"1 0 < v
   r3=:/:~"1 r2
   r4=: ~.r3
   NB. One root is 1 1 1 1 358358
   NB. All permutations
   (!5)*1+#r4
6360

Cheers,

Erling Hellenäs

On 2017-11-03 15:03, Erling Hellenäs wrote:

Sorry. Add ones. /Erling

On 2017-11-03 15:00, Erling Hellenäs wrote:
OK. The five prime factors are needed if you want to multiply 5 
numbers and get 358358, except that you can possibly add zeros and  
358358 itself? /Erling


On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms “factor” 
and “divisor” for the same thing,  when “divisor” is perhaps to be 
preferred.  However,  Pari GP provides a library function “factor” 
to deliver the prime factorisation of its argument,  in a similar 
fashion to J’s q: .


So, strictly speaking,  perhaps,  the factors of 358358 are 2 7 11 
13 179 and its divisors are 1 2 7 11 13 14 22 etc...


You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad

On 3 Nov 2017, at 11:25, Erling Hellenäs  
wrote:


Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)"

However there are only 5 integer factors:

   q: 358358
2 7 11 13 179
   */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization of 
358358 unless you count 1 and 358358 as factors.

In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,


--
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

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs
The limits of around 6 par 12 in these solutions is caused by the sheer 
amount of data generated. /Erling


On 2017-11-03 15:03, Erling Hellenäs wrote:

Sorry. Add ones. /Erling

On 2017-11-03 15:00, Erling Hellenäs wrote:
OK. The five prime factors are needed if you want to multiply 5 
numbers and get 358358, except that you can possibly add zeros and  
358358 itself? /Erling


On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms “factor” 
and “divisor” for the same thing,  when “divisor” is perhaps to be 
preferred.  However,  Pari GP provides a library function “factor” 
to deliver the prime factorisation of its argument,  in a similar 
fashion to J’s q: .


So, strictly speaking,  perhaps,  the factors of 358358 are 2 7 11 
13 179 and its divisors are 1 2 7 11 13 14 22 etc...


You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad

On 3 Nov 2017, at 11:25, Erling Hellenäs  
wrote:


Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)"

However there are only 5 integer factors:

   q: 358358
2 7 11 13 179
   */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization of 
358358 unless you count 1 and 358358 as factors.

In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,


--
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

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Sorry. Add ones. /Erling

On 2017-11-03 15:00, Erling Hellenäs wrote:
OK. The five prime factors are needed if you want to multiply 5 
numbers and get 358358, except that you can possibly add zeros and  
358358 itself? /Erling


On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms “factor” 
and “divisor” for the same thing,  when “divisor” is perhaps to be 
preferred.  However,  Pari GP provides a library function “factor” to 
deliver the prime factorisation of its argument,  in a similar 
fashion to J’s q: .


So, strictly speaking,  perhaps,  the factors of 358358 are 2 7 11 13 
179 and its divisors are 1 2 7 11 13 14 22 etc...


You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad

On 3 Nov 2017, at 11:25, Erling Hellenäs  
wrote:


Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)"

However there are only 5 integer factors:

   q: 358358
2 7 11 13 179
   */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization of 
358358 unless you count 1 and 358358 as factors.

In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,


--
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

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs
OK. The five prime factors are needed if you want to multiply 5 numbers 
and get 358358, except that you can possibly add zeros and  358358 
itself? /Erling


On 2017-11-03 14:35, 'Mike Day' via Programming wrote:

Language differences?

Personally,  I tend to be rather careless,  using the terms “factor” and 
“divisor” for the same thing,  when “divisor” is perhaps to be preferred.  
However,  Pari GP provides a library function “factor” to deliver the prime 
factorisation of its argument,  in a similar fashion to J’s q: .

So, strictly speaking,  perhaps,  the factors of 358358 are 2 7 11 13 179 and 
its divisors are 1 2 7 11 13 14 22 etc...

You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.
Sent from my iPad


On 3 Nov 2017, at 11:25, Erling Hellenäs  wrote:

Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)"

However there are only 5 integer factors:

   q: 358358
2 7 11 13 179
   */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization of 358358 
unless you count 1 and 358358 as factors.
In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs




Den 2017-11-03 kl. 10:58, skrev Raul Miller:
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,


--
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

Re: [Jprogramming] Partitions

2017-11-03 Thread 'Mike Day' via Programming
Language differences?  

Personally,  I tend to be rather careless,  using the terms “factor” and 
“divisor” for the same thing,  when “divisor” is perhaps to be preferred.  
However,  Pari GP provides a library function “factor” to deliver the prime 
factorisation of its argument,  in a similar fashion to J’s q: .

So, strictly speaking,  perhaps,  the factors of 358358 are 2 7 11 13 179 and 
its divisors are 1 2 7 11 13 14 22 etc...

You’re both right!

Mike

Please reply to mike_liz@tiscali.co.uk.  
Sent from my iPad

> On 3 Nov 2017, at 11:25, Erling Hellenäs  wrote:
> 
> Hi all!
> 
> Raul:
> 
> "Hmm... actually, thinking about it, the par approach here is not
> efficient enough for this example. 5 parRuskeyE 32 is too big of a
> result, I think. (358358 has 5 distinct prime factors and, thus, 32
> integer factors.)"
> 
> However there are only 5 integer factors:
> 
>   q: 358358
> 2 7 11 13 179
>   */q:358358
> 358358
> 
> Now you ask me for 44 5 integer factorizations.
> 
> As far as I understand there is only one 5 integer factorization of 358358 
> unless you count 1 and 358358 as factors.
> In any case it can be handled by parRuskeyE.
> 
> Cheers,
> 
> Erling Hellenäs
> 
> 
> 
>> Den 2017-11-03 kl. 10:58, skrev Raul Miller:
>> I'm not sure where you showed the 44 different 5 integer
>> factorizations of 358358?
>> 
>> Thanks,
>> 
> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Hi all!

Raul:

"Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)"

However there are only 5 integer factors:

   q: 358358
2 7 11 13 179
   */q:358358
358358

Now you ask me for 44 5 integer factorizations.

As far as I understand there is only one 5 integer factorization of 358358 
unless you count 1 and 358358 as factors.
In any case it can be handled by parRuskeyE.

Cheers,

Erling Hellenäs
 




Den 2017-11-03 kl. 10:58, skrev Raul Miller:

I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread Raul Miller
I'm not sure where you showed the 44 different 5 integer
factorizations of 358358?

Thanks,

-- 
Raul

On Fri, Nov 3, 2017 at 5:27 AM, Erling Hellenäs
 wrote:
> Hi all !
>
>*/q:358358
> 2 7 11 13 179
>*/q:358358
> 358358
>q: 40
> 2 2 2 5
>
> Which 32 integer factors?
>
> It seems to be equivalent to the solution I showed?
>
> We don't have to write factorization programs since it is built in?
>
> So, it's solved?
>
> Cheers,
>
> Erling Hellenäs
>
> Den 2017-11-03 kl. 08:14, skrev Raul Miller:
>>
>> Hmm... actually, thinking about it, the par approach here is not
>> efficient enough for this example. 5 parRuskeyE 32 is too big of a
>> result, I think. (358358 has 5 distinct prime factors and, thus, 32
>> integer factors.)
>>
>> So, ok, we can do another pass at this problem.
>>
>> (But, also, this should be a caution about trying to generalize - an
>> approach which solves a problem and which solves a generalization of
>> that problem will quite often be useless for an instance of a
>> different generalization of that problem.)
>>
>> Thanks,
>>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Hi all !

   */q:358358
2 7 11 13 179
   */q:358358
358358
   q: 40
2 2 2 5

Which 32 integer factors?

It seems to be equivalent to the solution I showed?

We don't have to write factorization programs since it is built in?

So, it's solved?

Cheers,

Erling Hellenäs

Den 2017-11-03 kl. 08:14, skrev Raul Miller:

Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)

So, ok, we can do another pass at this problem.

(But, also, this should be a caution about trying to generalize - an
approach which solves a problem and which solves a generalization of
that problem will quite often be useless for an instance of a
different generalization of that problem.)

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-03 Thread Erling Hellenäs

Hi all !

You want to factorize a number. If there are less factors than n, you 
can't solve the problem ?


If there are more factors you want to multiply factors to get n left?

You want to enumerate the possible factor combinations?

The factors have to be unique? 20 = 2 *2 * 5 has the two factors  4 and 5 ?

For n=5 there is no solution, for n=2 there is one solution, 4 5?

1 is considered a factor? A number is considered a factor of itself?

21945 = */3 5 7 11 19 has several solutions for n=3, those below?

You possibly have to sort and filter them to make sure they are unique?

   [a=:3 parRuskeyE 5
┌─┬─┬─┐
│0 3 4│1    │2    │
├─┼─┼─┤
│0 4  │1 3  │2    │
├─┼─┼─┤
│0 4  │1    │2 3  │
├─┼─┼─┤
│0 2 4│1    │3    │
├─┼─┼─┤
│0 4  │1 2  │3    │
├─┼─┼─┤
│0 1 4│2    │3    │
├─┼─┼─┤
│0 3  │1 4  │2    │
├─┼─┼─┤
│0    │1 3 4│2    │
├─┼─┼─┤
│0    │1 4  │2 3  │
├─┼─┼─┤
│0 2  │1 4  │3    │
├─┼─┼─┤
│0    │1 2 4│3    │
├─┼─┼─┤
│0 1  │2 4  │3    │
├─┼─┼─┤
│0 3  │1    │2 4  │
├─┼─┼─┤
│0    │1 3  │2 4  │
├─┼─┼─┤
│0    │1    │2 3 4│
├─┼─┼─┤
│0 2  │1    │3 4  │
├─┼─┼─┤
│0    │1 2  │3 4  │
├─┼─┼─┤
│0 1  │2    │3 4  │
├─┼─┼─┤
│0 2 3│1    │4    │
├─┼─┼─┤
│0 3  │1 2  │4    │
├─┼─┼─┤
│0 1 3│2    │4    │
├─┼─┼─┤
│0 2  │1 3  │4    │
├─┼─┼─┤
│0    │1 2 3│4    │
├─┼─┼─┤
│0 1  │2 3  │4    │
├─┼─┼─┤
│0 1 2│3    │4    │
└─┴─┴─┘
   [r=:a (*/)@:{&.>"1 0 < 3 5 7 11 19
┌───┬┬┐
│627│5   │7   │
├───┼┼┤
│57 │55  │7   │
├───┼┼┤
│57 │5   │77  │
├───┼┼┤
│399│5   │11  │
├───┼┼┤
│57 │35  │11  │
├───┼┼┤
│285│7   │11  │
├───┼┼┤
│33 │95  │7   │
├───┼┼┤
│3  │1045│7   │
├───┼┼┤
│3  │95  │77  │
├───┼┼┤
│21 │95  │11  │
├───┼┼┤
│3  │665 │11  │
├───┼┼┤
│15 │133 │11  │
├───┼┼┤
│33 │5   │133 │
├───┼┼┤
│3  │55  │133 │
├───┼┼┤
│3  │5   │1463│
├───┼┼┤
│21 │5   │209 │
├───┼┼┤
│3  │35  │209 │
├───┼┼┤
│15 │7   │209 │
├───┼┼┤
│231│5   │19  │
├───┼┼┤
│33 │35  │19  │
├───┼┼┤
│165│7   │19  │
├───┼┼┤
│21 │55  │19  │
├───┼┼┤
│3  │385 │19  │
├───┼┼┤
│15 │77  │19  │
├───┼┼┤
│105│11  │19  │
└───┴┴┘

Of the problem remains how to factorize and putting it all together?

Cheers,

Erling Hellenäs


Den 2017-11-03 kl. 06:10, skrev 'Skip Cave' via Programming:

Raul,

Here's another try to state the rules of this problem:of the n objects

I have n objects. Each object has a single numeric value.
More than one object can have the same numeric value.
The "containers" I talk about must each contain one or more of the objects.
The "value" of each specific  container is obtained by multiplying together
the numeric values of all the objects in that container.
The value of the complete set of containers is "p" and p is found by
multiplying together all the values in each container.

The order of objects in a container does not change the value of the
container, and the order of containers with the same objects in them do not
consist of a new configuration.

So here's  the problem I was trying to solve:

given a set of variables x1, x2, x3, x4 xn

Show all the different sets of x1 - xn that solves the equality:
p = */ x1, x2, x3, x4, xn

All permutations of the same set of x1-xn is considered the same solution

The "unique objects" I describe are really the factors of some integer. An
example question:

358358=*/x1, x2, x3, x4, x5
How many different combinations of 5 integersx1, x2, x3, x4, x5  solve this
equality? (Different orders don't count)

What about:
358360=*/x1, x2, x3, x4, x5  ?

Skip

Skip Cave
Cave Consulting LLC

On Thu, Nov 2, 2017 at 7:54 PM, Raul Miller  wrote:


Since that problem is so small, it would be tempting to just brute
force it. (Build out all copies of 3 integers, 1 .. 24 and then select
those whose product is 24. That's less than 2 million tests, so a
computer can run through them in a fraction of a second.)

Though, as other posters on that quora page have noted, the question
is ambiguous. (is x=1, y=2, z=12 the same as x=12, y=1, z=2? Why or
why not?)

So to be thorough, you sort of have to supply answers for "x is a
different variable from y and z" and "it does not really matter which
variable you use for whichever integer". And, since the problem is
small, it's trivial to go from the permutations answer to the
combinations answer:

#(#~ 24 = */"1)1+24 24 24 #:i.24^3
30
#~./:~"1(#~ 24 = */"1)1+24 24 24 #:i.24^3
6

Still... fun problem.

Thanks,

--
Raul


On Thu, Nov 2, 2017 at 8:15 PM, 'Skip Cave' via Programming
 wrote:

Wow! I'm amazed at the response my partition problem got on the

programming

forum. I have learned quite a

Re: [Jprogramming] Partitions

2017-11-03 Thread 'Mike Day' via Programming
Part ot the reason for all the discussion is that the Quora Problem is 
ill-defined - as stated in that link,

https://www.quora.com/What-is-total-number-of-positive-integral-solutions-for-x-y-z-such-that-xyz-24

Better:
a) what is the number of sets {x,y,z} such that 24 = */x,y,z,  1 <: x <: 
y <: z <: 24 for integers x,y,z

OR
b) what is the number of sets {x,y,z} such that 24 = */x,y,z,  1 < x <: 
y <: z < 24 for integers x,y,z

OR
c) what is the number of sets {x,y,z} such that 24 = */x,y,z,  1 < x < y 
< z < 24 for integers x,y,z

OR
d) what is the number of sets {x,y,z} such that 24 = */x,y,z,  1 <: 
x,y,z <: 24

  for integers x,y,z for all permutations of x,y,z
OR
e f g 
In each case,  the requirement is for only the number of sets,  not the 
sets themselves!



   */ every (3 par 4){each < 2 2 2 3 yields some but not all 
permutations for 1 < x,y,x < 24:

(for all our definitions of par, as far as I can see)
6 2 2

2 6 2

2 2 6

4 2 3

2 4 3

4 2 3

so it can't be used directly for any of these enumerations;  sorting 
rows and taking the nub


yields just

2 2 6

2 3 4

so that the answer to (c) is 2


Similarly, |:/:~~./:~"1 */every (3 par 6){each <1 1 2 2 2 3

1   1 1 1 2 2

1   2 3 4 2 3

24 12 8 6 6 4

so that the answer to (a) is 6,  although we find, eg,

    #3 parRuskey 6

90


showing that using par-type verbs is not always efficient for the 
problem which they


might have envisaged!!!


They're very interesting and pretty important,  of course,

cheers,

Mike






etc...






On 03/11/2017 00:15, 'Skip Cave' via Programming wrote:

Wow! I'm amazed at the response my partition problem got on the programming
forum. I have learned quite a lot about various ways to optimize a
combination verb, as well as the partition verb.

I think that it might be good to look at the original problem that caused
me to come up with the partition solution:

I was trying to solve a Quora problem that asks:
What is total number of positive integer solutions for (x, y, z) such that
xyz=24?


I wanted to eventually generalize the problem to handle a list of n
integers whose product [image: \prod] or +/  is equal to integer p.
so given the equation [image: \prod] (x1, x2, x3, ... xn ) = p
What is total number of positive integer solutions sets for x1, x2,x3 ...xn?

So for our original problem first we need to factor the number:

q:24

2 2 2 3 - these are the factors of 24.

A reasonable way to solve this is to build a function that will find all
the ways to partition the list of factors into three groups:

   ]a =.3 par 4

┌───┬───┬───┐

│0 1│2  │3  │

├───┼───┼───┤

│0 2│1  │3  │

├───┼───┼───┤

│0  │1 2│3  │

├───┼───┼───┤

│0 3│1  │2  │

├───┼───┼───┤

│0  │1 3│2  │

├───┼───┼───┤

│0  │1  │2 3│

└───┴───┴───┘


Now replace the indices with the actual prime factors of 24


]b =. a cvt q:24

┌───┬───┬───┐

│2 2│2  │3  │

├───┼───┼───┤

│2 2│2  │3  │

├───┼───┼───┤

│2  │2 2│3  │

├───┼───┼───┤

│2 3│2  │2  │

├───┼───┼───┤

│2  │2 3│2  │

├───┼───┼───┤

│2  │2  │2 3│

└───┴───┴───┘


]c=. */ each b

┌─┬─┬─┐

│4│2│3│

├─┼─┼─┤

│4│2│3│

├─┼─┼─┤

│2│4│3│

├─┼─┼─┤

│6│2│2│

├─┼─┼─┤

│2│6│2│

├─┼─┼─┤

│2│2│6│

└─┴─┴─┘

Now sort the lists and get rid of the copies:


  ~. c/:"1 c

┌─┬─┬─┐

│2│3│4│

├─┼─┼─┤

│2│2│6│

└─┴─┴─┘


So the answer to the question: What is total number of positive integer
solutions for (x, y, z) such that xyz=24?

  is:

2 3 4,  &  2 2 6


So now can we build a generalized verb that does it all in one step for any
n?

3 list 24

2 3 4

2 2 6



Skip

Skip Cave
Cave Consulting LLC

On Thu, Nov 2, 2017 at 5:32 PM, Raul Miller  wrote:


Oops, no... the 1 partition results are not from comb, and 1 comb y
won't get them.

I was just using ,.< i.y

And, the 2 partition results were also not from comb, I was using

((y#2)#:"1 0 }.i.2^y-1)  wrote:

The performance of your parRuskeyE is looking really nice.

That said, for 1 or 2 partitions, a comb based approach (using the
comb from require'stats') is still tends to be significantly faster
(except for 2 parRuskeyE 2). (And, once the number of values in a
partition has reached like 13 or 14, this speed advantage starts
creeping into results involving more partitions, but it's not a factor
of 2 speed advantage for any practical result size so it's probably
not worrying about.)

The 1 partition results would be trivial to incorporate - it's just
<"1]1 comb y where y is the number of partitions.

Thanks,

--
Raul


On Thu, Nov 2, 2017 at 9:28 AM, Erling Hellenäs
 wrote:

Hi all !

My partition projects are parRuskeyE, parE and parE2.

parRuskeyE

Frank Ruskeys algorithm, now with massively parallel recursion.

parE

Similar to parELMDE, but works with bitmaps and creates less

combinations.

parE2

Creates unique bucket groups, combines th

Re: [Jprogramming] Partitions

2017-11-03 Thread Linda Alvord
Raul, I found it interesting that when I used debug on your function, there 
were no signs of @ or @: in the display.



-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Linda Alvord
Sent: Friday, November 3, 2017 3:19 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

You can compare the tree versions of comb3a and comb4 to see their differences:

comb3a
  ┌─ [
  │  ┌─ = 
  │   ┌──┤  ┌─ / ─── +
  │   │  └─ " ──┴─ 1  
  │   │   
  ├───┤ ┌─ |. 
──┤   │  ┌─ @: ─┴─ I. 
  │   ├─ @ ──┴─ # 
  │   └─ ]
  │   
  │   ┌─ 2
  │   │ ┌─ #: 
  └───┤  ┌─ @ ──┴─ i. 
  ├─ @: ─┴─ ^ 
  └─ ]
   
   comb4
  ┌─ [:   
  ├─ |.   
  │┌─ [:  
  │├─ I.  
──┤│┌─ [  
  ││├─ =  
  │││┌─ [:
  ││┌───┤│ ┌─ / ─── + 
  └┤│   │├─ " ─┴─ 1   
   ││   └┤
   │││ ┌─ [:  
   │││ ├─ #:  
   ││└─┤ ┌─ [:
   ││  │ ├─ i.
   └┤  └─┤┌─ 2
│└┼─ ^
│ └─ ]
├─ #  
│   ┌─ [: 
│   ├─ #: 
└───┤┌─ [:
│├─ i.
└┤ ┌─ 2   
 └─┼─ ^   
   └─ ]   

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Linda Alvord
Sent: Friday, November 3, 2017 2:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Oops, this should be better:


   comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.2^y'
   comb4
[: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
   #3 comb4  5
10
   
Linda


-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Thursday, November 2, 2017 2:54 AM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

No, you did not test your work.

   #3 comb 5
10
   #3 comb4 5
56

Probably the simplest way to approach what I think you are trying to do 
involves expanding the part in parenthesis independent of the rest of it.

And, personally, when I am working on a line of J code, I like to have a little 
test rig so that I can quickly see when I have gone astray.
Doing that here (and clipping out my mistakes), then adding comments gets me 
this:

First, I set up a test rig with the original expression:

   #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
10

Then, I rephrase the outer part as an explicit expression for 13 :

  #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
10

Since that worked, I take a look at what 13 : gave me

   13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
[ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]

Next, I try that out in my test rig:

   #3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
10

So, now that I have that, I do a rephrase of the inner part for another 13 :

   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
10

And, since that works, I take a look at what it gave me:

   [ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ] [ ([: |. [: I. ] #~ [ = [: 
+/"1 ]) [: #: [: i. 2 ^ ]

And, voila, I've got another variation that I can use in a word definition:

   comb4a=: [ ([: |. [: I. ] #~ [ = [: +/"1 ]) [: #: [: i. 2 ^ ]

That's a bit ugly, but ascii is ugly (but, also, standardized and - thus - 
widely available).

So, we can try that out and see it in operation:

   3 comb4a 5
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4

Also... note that when working with "real life" mechanisms (not just J), having 
some sort of test rig to make sure that what you are doing behaves like you 
think it does can be an invaluable time saver. (The alternative - putting a lot 
of work into something, only to find out that it doesn't work and that you have 
to start over again - is sometimes necessary but not always attractive.)

(Well, that, and remember that this approach is slower than the stock comb 
implementation when y > 10 - so mostly I would just do require'stats' and then 
use that comb implementation.)

Then again, now that we have this var

Re: [Jprogramming] Partitions

2017-11-03 Thread Raul Miller
So... 358358 has five prime factors (32 integer factors). We want to
find all sorted sequences (not sets - values can repeat) of five of
those factors whose product is 358358.

To restrict our search, we can investigate only those sorted sequences
of "number of prime factors represented in the variable" whose sum is
five:

   ~./:~"1 (#~ 5=+/"1) 6 #.inv i.6^5
0 0 0 0 5
0 0 0 1 4
0 0 0 2 3
0 0 1 1 3
0 0 1 2 2
0 1 1 1 2
1 1 1 1 1

In other words, the results of these seven expressions (use
require'stats' first to get comb):

   1 1 1 1 358358
   (1 1 1,(358358%*/),*/)"1 (4 comb 5){q:358358
   /:~"1 (1 1 1,(358358%*/),*/)"1 (3 comb 5){q:358358
   /:~"1 (1 1,q:@(358358%*/),*/)"1 (3 comb 5){q:358358
   ~./:~"1 (1 1,({.,*/@}.)@q:@(358358%*/),*/)"1 (2 comb 5){q:358358
/:~"1 (1,q:@(358358%*/),*/)"1 (2 comb 5){q:358358
   q:358358

That's 44 different solutions:

1  1  1   1 358358
1  1  1 179   2002
1  1  1  13  27566
1  1  1  11  32578
1  1  1   7  51194
1  1  1   2 179179
1  1  1 154   2327
1  1  1 182   1969
1  1  1 143   2506
1  1  1 286   1253
1  1  1  91   3938
1  1  1  77   4654
1  1  1 358   1001
1  1  1  26  13783
1  1  1  22  16289
1  1  1  14  25597
1  1 13 154179
1  1 11 179182
1  1 11  13   2506
1  1  7 179286
1  1  7  13   3938
1  1  7  11   4654
1  1  2 179   1001
1  1  2  13  13783
1  1  2  11  16289
1  1  2   7  25597
1  1 11  14   2327
1  1  7  22   2327
1  1  7  26   1969
1  1  7 143358
1  1  2  77   2327
1  1  2  91   1969
1  1  2 143   1253
1 11 13  14179
1  7 13  22179
1  7 11  26179
1  7 11  13358
1  2 13  77179
1  2 11  91179
1  2 11  13   1253
1  2  7 143179
1  2  7  13   1969
1  2  7  11   2327
2  7 11  13179

We could of course come up with a routine which does something similar
for other examples (but we will run into prohibitive resource
limitations if we allow large enough integers).

So... just to confirm... this is the problem we are trying to solve?

Thanks,

-- 
Raul


On Fri, Nov 3, 2017 at 3:14 AM, Raul Miller  wrote:
> Hmm... actually, thinking about it, the par approach here is not
> efficient enough for this example. 5 parRuskeyE 32 is too big of a
> result, I think. (358358 has 5 distinct prime factors and, thus, 32
> integer factors.)
>
> So, ok, we can do another pass at this problem.
>
> (But, also, this should be a caution about trying to generalize - an
> approach which solves a problem and which solves a generalization of
> that problem will quite often be useless for an instance of a
> different generalization of that problem.)
>
> Thanks,
>
> --
> Raul
>
> On Fri, Nov 3, 2017 at 3:00 AM, Raul Miller  wrote:
>> Sure - and I think we have addressed that (parRuskyE by Erling
>> Hellenäs being possibly the best implementation) - I was just pointing
>> out the differences between this problem statement and the quora
>> question which inspired it.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>> On Fri, Nov 3, 2017 at 1:10 AM, 'Skip Cave' via Programming
>>  wrote:
>>> Raul,
>>>
>>> Here's another try to state the rules of this problem:of the n objects
>>>
>>> I have n objects. Each object has a single numeric value.
>>> More than one object can have the same numeric value.
>>> The "containers" I talk about must each contain one or more of the objects.
>>> The "value" of each specific  container is obtained by multiplying together
>>> the numeric values of all the objects in that container.
>>> The value of the complete set of containers is "p" and p is found by
>>> multiplying together all the values in each container.
>>>
>>> The order of objects in a container does not change the value of the
>>> container, and the order of containers with the same objects in them do not
>>> consist of a new configuration.
>>>
>>> So here's  the problem I was trying to solve:
>>>
>>> given a set of variables x1, x2, x3, x4 xn
>>>
>>> Show all the different sets of x1 - xn that solves the equality:
>>> p = */ x1, x2, x3, x4, xn
>>>
>>> All permutations of the same set of x1-xn is considered the same solution
>>>
>>> The "unique objects" I describe are really the factors of some integer. An
>>> example question:
>>>
>>> 358358=*/x1, x2, x3, x4, x5
>>> How many different combinations of 5 integersx1, x2, x3, x4, x5  solve this
>>> equality? (Different orders don't count)
>>>
>>> What about:
>>> 358360=*/x1, x2, x3, x4, x5  ?
>>>
>>> Skip
>>>
>>> Skip Cave
>>> Cave Consulting LLC
>>>
>>> On Thu, Nov 2, 2017 at 7:54 PM, Raul Miller  wrote:
>>>
 Since that problem is so small, it would be tempting to just brute
 force it. (Build out all copies of 3 integers, 1 .. 24 and then select
 those whose product is 24. That's less than 2 million tests, so a
 computer can run through them in a fraction of a second.)

 Though, as other posters on that quora page have noted, the question
 is ambiguous. (is x=1, y=2, z=12 the same as x=12, y=1, z=2? Why or
 why not?)

 So to be thorough, you sort of have to supply answe

Re: [Jprogramming] Partitions

2017-11-03 Thread Linda Alvord
You can compare the tree versions of comb3a and comb4 to see their differences:

comb3a
  ┌─ [
  │  ┌─ = 
  │   ┌──┤  ┌─ / ─── +
  │   │  └─ " ──┴─ 1  
  │   │   
  ├───┤ ┌─ |. 
──┤   │  ┌─ @: ─┴─ I. 
  │   ├─ @ ──┴─ # 
  │   └─ ]
  │   
  │   ┌─ 2
  │   │ ┌─ #: 
  └───┤  ┌─ @ ──┴─ i. 
  ├─ @: ─┴─ ^ 
  └─ ]
   
   comb4
  ┌─ [:   
  ├─ |.   
  │┌─ [:  
  │├─ I.  
──┤│┌─ [  
  ││├─ =  
  │││┌─ [:
  ││┌───┤│ ┌─ / ─── + 
  └┤│   │├─ " ─┴─ 1   
   ││   └┤
   │││ ┌─ [:  
   │││ ├─ #:  
   ││└─┤ ┌─ [:
   ││  │ ├─ i.
   └┤  └─┤┌─ 2
│└┼─ ^
│ └─ ]
├─ #  
│   ┌─ [: 
│   ├─ #: 
└───┤┌─ [:
│├─ i.
└┤ ┌─ 2   
 └─┼─ ^   
   └─ ]   

Linda

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Linda Alvord
Sent: Friday, November 3, 2017 2:28 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Oops, this should be better:


   comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.2^y'
   comb4
[: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
   #3 comb4  5
10
   
Linda


-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Thursday, November 2, 2017 2:54 AM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

No, you did not test your work.

   #3 comb 5
10
   #3 comb4 5
56

Probably the simplest way to approach what I think you are trying to do 
involves expanding the part in parenthesis independent of the rest of it.

And, personally, when I am working on a line of J code, I like to have a little 
test rig so that I can quickly see when I have gone astray.
Doing that here (and clipping out my mistakes), then adding comments gets me 
this:

First, I set up a test rig with the original expression:

   #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
10

Then, I rephrase the outer part as an explicit expression for 13 :

  #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
10

Since that worked, I take a look at what 13 : gave me

   13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
[ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]

Next, I try that out in my test rig:

   #3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
10

So, now that I have that, I do a rephrase of the inner part for another 13 :

   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
10

And, since that works, I take a look at what it gave me:

   [ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ] [ ([: |. [: I. ] #~ [ = [: 
+/"1 ]) [: #: [: i. 2 ^ ]

And, voila, I've got another variation that I can use in a word definition:

   comb4a=: [ ([: |. [: I. ] #~ [ = [: +/"1 ]) [: #: [: i. 2 ^ ]

That's a bit ugly, but ascii is ugly (but, also, standardized and - thus - 
widely available).

So, we can try that out and see it in operation:

   3 comb4a 5
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4

Also... note that when working with "real life" mechanisms (not just J), having 
some sort of test rig to make sure that what you are doing behaves like you 
think it does can be an invaluable time saver. (The alternative - putting a lot 
of work into something, only to find out that it doesn't work and that you have 
to start over again - is sometimes necessary but not always attractive.)

(Well, that, and remember that this approach is slower than the stock comb 
implementation when y > 10 - so mostly I would just do require'stats' and then 
use that comb implementation.)

Then again, now that we have this variation, we could also try to reconstruct 
an explicit expression which does the same thing. For that we want to merge 
these two examples:

   #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5

Perhaps something like:
   #3 (13 :'|.I.(x = +/"1 t) # t=. 

Re: [Jprogramming] Partitions

2017-11-03 Thread Raul Miller
Hmm... actually, thinking about it, the par approach here is not
efficient enough for this example. 5 parRuskeyE 32 is too big of a
result, I think. (358358 has 5 distinct prime factors and, thus, 32
integer factors.)

So, ok, we can do another pass at this problem.

(But, also, this should be a caution about trying to generalize - an
approach which solves a problem and which solves a generalization of
that problem will quite often be useless for an instance of a
different generalization of that problem.)

Thanks,

-- 
Raul

On Fri, Nov 3, 2017 at 3:00 AM, Raul Miller  wrote:
> Sure - and I think we have addressed that (parRuskyE by Erling
> Hellenäs being possibly the best implementation) - I was just pointing
> out the differences between this problem statement and the quora
> question which inspired it.
>
> Thanks,
>
> --
> Raul
>
> On Fri, Nov 3, 2017 at 1:10 AM, 'Skip Cave' via Programming
>  wrote:
>> Raul,
>>
>> Here's another try to state the rules of this problem:of the n objects
>>
>> I have n objects. Each object has a single numeric value.
>> More than one object can have the same numeric value.
>> The "containers" I talk about must each contain one or more of the objects.
>> The "value" of each specific  container is obtained by multiplying together
>> the numeric values of all the objects in that container.
>> The value of the complete set of containers is "p" and p is found by
>> multiplying together all the values in each container.
>>
>> The order of objects in a container does not change the value of the
>> container, and the order of containers with the same objects in them do not
>> consist of a new configuration.
>>
>> So here's  the problem I was trying to solve:
>>
>> given a set of variables x1, x2, x3, x4 xn
>>
>> Show all the different sets of x1 - xn that solves the equality:
>> p = */ x1, x2, x3, x4, xn
>>
>> All permutations of the same set of x1-xn is considered the same solution
>>
>> The "unique objects" I describe are really the factors of some integer. An
>> example question:
>>
>> 358358=*/x1, x2, x3, x4, x5
>> How many different combinations of 5 integersx1, x2, x3, x4, x5  solve this
>> equality? (Different orders don't count)
>>
>> What about:
>> 358360=*/x1, x2, x3, x4, x5  ?
>>
>> Skip
>>
>> Skip Cave
>> Cave Consulting LLC
>>
>> On Thu, Nov 2, 2017 at 7:54 PM, Raul Miller  wrote:
>>
>>> Since that problem is so small, it would be tempting to just brute
>>> force it. (Build out all copies of 3 integers, 1 .. 24 and then select
>>> those whose product is 24. That's less than 2 million tests, so a
>>> computer can run through them in a fraction of a second.)
>>>
>>> Though, as other posters on that quora page have noted, the question
>>> is ambiguous. (is x=1, y=2, z=12 the same as x=12, y=1, z=2? Why or
>>> why not?)
>>>
>>> So to be thorough, you sort of have to supply answers for "x is a
>>> different variable from y and z" and "it does not really matter which
>>> variable you use for whichever integer". And, since the problem is
>>> small, it's trivial to go from the permutations answer to the
>>> combinations answer:
>>>
>>>#(#~ 24 = */"1)1+24 24 24 #:i.24^3
>>> 30
>>>#~./:~"1(#~ 24 = */"1)1+24 24 24 #:i.24^3
>>> 6
>>>
>>> Still... fun problem.
>>>
>>> Thanks,
>>>
>>> --
>>> Raul
>>>
>>>
>>> On Thu, Nov 2, 2017 at 8:15 PM, 'Skip Cave' via Programming
>>>  wrote:
>>> > Wow! I'm amazed at the response my partition problem got on the
>>> programming
>>> > forum. I have learned quite a lot about various ways to optimize a
>>> > combination verb, as well as the partition verb.
>>> >
>>> > I think that it might be good to look at the original problem that caused
>>> > me to come up with the partition solution:
>>> >
>>> > I was trying to solve a Quora problem that asks:
>>> > What is total number of positive integer solutions for (x, y, z) such
>>> that
>>> > xyz=24?
>>> > >> integral-solutions-for-x-y-z-such-that-xyz-24>
>>> >
>>> > I wanted to eventually generalize the problem to handle a list of n
>>> > integers whose product [image: \prod] or +/  is equal to integer p.
>>> > so given the equation [image: \prod] (x1, x2, x3, ... xn ) = p
>>> > What is total number of positive integer solutions sets for x1, x2,x3
>>> ...xn?
>>> >
>>> > So for our original problem first we need to factor the number:
>>> >
>>> > q:24
>>> >
>>> > 2 2 2 3 - these are the factors of 24.
>>> >
>>> > A reasonable way to solve this is to build a function that will find all
>>> > the ways to partition the list of factors into three groups:
>>> >
>>> >   ]a =.3 par 4
>>> >
>>> > ┌───┬───┬───┐
>>> >
>>> > │0 1│2  │3  │
>>> >
>>> > ├───┼───┼───┤
>>> >
>>> > │0 2│1  │3  │
>>> >
>>> > ├───┼───┼───┤
>>> >
>>> > │0  │1 2│3  │
>>> >
>>> > ├───┼───┼───┤
>>> >
>>> > │0 3│1  │2  │
>>> >
>>> > ├───┼───┼───┤
>>> >
>>> > │0  │1 3│2  │
>>> >
>>> > ├───┼───┼───┤
>>> >
>>> > │0  │1  │2 3│
>>> >
>>> > └───┴───┴───┘
>>> >
>>> >
>>> > Now r

Re: [Jprogramming] Partitions

2017-11-03 Thread Raul Miller
Sure - and I think we have addressed that (parRuskyE by Erling
Hellenäs being possibly the best implementation) - I was just pointing
out the differences between this problem statement and the quora
question which inspired it.

Thanks,

-- 
Raul

On Fri, Nov 3, 2017 at 1:10 AM, 'Skip Cave' via Programming
 wrote:
> Raul,
>
> Here's another try to state the rules of this problem:of the n objects
>
> I have n objects. Each object has a single numeric value.
> More than one object can have the same numeric value.
> The "containers" I talk about must each contain one or more of the objects.
> The "value" of each specific  container is obtained by multiplying together
> the numeric values of all the objects in that container.
> The value of the complete set of containers is "p" and p is found by
> multiplying together all the values in each container.
>
> The order of objects in a container does not change the value of the
> container, and the order of containers with the same objects in them do not
> consist of a new configuration.
>
> So here's  the problem I was trying to solve:
>
> given a set of variables x1, x2, x3, x4 xn
>
> Show all the different sets of x1 - xn that solves the equality:
> p = */ x1, x2, x3, x4, xn
>
> All permutations of the same set of x1-xn is considered the same solution
>
> The "unique objects" I describe are really the factors of some integer. An
> example question:
>
> 358358=*/x1, x2, x3, x4, x5
> How many different combinations of 5 integersx1, x2, x3, x4, x5  solve this
> equality? (Different orders don't count)
>
> What about:
> 358360=*/x1, x2, x3, x4, x5  ?
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Thu, Nov 2, 2017 at 7:54 PM, Raul Miller  wrote:
>
>> Since that problem is so small, it would be tempting to just brute
>> force it. (Build out all copies of 3 integers, 1 .. 24 and then select
>> those whose product is 24. That's less than 2 million tests, so a
>> computer can run through them in a fraction of a second.)
>>
>> Though, as other posters on that quora page have noted, the question
>> is ambiguous. (is x=1, y=2, z=12 the same as x=12, y=1, z=2? Why or
>> why not?)
>>
>> So to be thorough, you sort of have to supply answers for "x is a
>> different variable from y and z" and "it does not really matter which
>> variable you use for whichever integer". And, since the problem is
>> small, it's trivial to go from the permutations answer to the
>> combinations answer:
>>
>>#(#~ 24 = */"1)1+24 24 24 #:i.24^3
>> 30
>>#~./:~"1(#~ 24 = */"1)1+24 24 24 #:i.24^3
>> 6
>>
>> Still... fun problem.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Thu, Nov 2, 2017 at 8:15 PM, 'Skip Cave' via Programming
>>  wrote:
>> > Wow! I'm amazed at the response my partition problem got on the
>> programming
>> > forum. I have learned quite a lot about various ways to optimize a
>> > combination verb, as well as the partition verb.
>> >
>> > I think that it might be good to look at the original problem that caused
>> > me to come up with the partition solution:
>> >
>> > I was trying to solve a Quora problem that asks:
>> > What is total number of positive integer solutions for (x, y, z) such
>> that
>> > xyz=24?
>> > > integral-solutions-for-x-y-z-such-that-xyz-24>
>> >
>> > I wanted to eventually generalize the problem to handle a list of n
>> > integers whose product [image: \prod] or +/  is equal to integer p.
>> > so given the equation [image: \prod] (x1, x2, x3, ... xn ) = p
>> > What is total number of positive integer solutions sets for x1, x2,x3
>> ...xn?
>> >
>> > So for our original problem first we need to factor the number:
>> >
>> > q:24
>> >
>> > 2 2 2 3 - these are the factors of 24.
>> >
>> > A reasonable way to solve this is to build a function that will find all
>> > the ways to partition the list of factors into three groups:
>> >
>> >   ]a =.3 par 4
>> >
>> > ┌───┬───┬───┐
>> >
>> > │0 1│2  │3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0 2│1  │3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1 2│3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0 3│1  │2  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1 3│2  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │0  │1  │2 3│
>> >
>> > └───┴───┴───┘
>> >
>> >
>> > Now replace the indices with the actual prime factors of 24
>> >
>> >
>> > ]b =. a cvt q:24
>> >
>> > ┌───┬───┬───┐
>> >
>> > │2 2│2  │3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │2 2│2  │3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │2  │2 2│3  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │2 3│2  │2  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │2  │2 3│2  │
>> >
>> > ├───┼───┼───┤
>> >
>> > │2  │2  │2 3│
>> >
>> > └───┴───┴───┘
>> >
>> >
>> >]c=. */ each b
>> >
>> > ┌─┬─┬─┐
>> >
>> > │4│2│3│
>> >
>> > ├─┼─┼─┤
>> >
>> > │4│2│3│
>> >
>> > ├─┼─┼─┤
>> >
>> > │2│4│3│
>> >
>> > ├─┼─┼─┤
>> >
>> > │6│2│2│
>> >
>> > ├─┼─┼─┤
>> >
>> > │2│6│2│
>> >
>> > ├─┼─┼─┤
>> >
>> > │2│2│6│
>> >
>> > └─┴─┴─┘
>> >
>> > Now sort the lists and get rid of the copies:
>> >
>> >
>> 

Re: [Jprogramming] Partitions

2017-11-02 Thread Linda Alvord
Oops, this should be better:


   comb4=: 13 :'|.I.(x=+/"1#:i.2^y)##:i.2^y'
   comb4
[: |. [: I. ([ = [: +/"1 [: #: [: i. 2 ^ ]) # [: #: [: i. 2 ^ ]
   #3 comb4  5
10
   
Linda


-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Thursday, November 2, 2017 2:54 AM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

No, you did not test your work.

   #3 comb 5
10
   #3 comb4 5
56

Probably the simplest way to approach what I think you are trying to do 
involves expanding the part in parenthesis independent of the rest of it.

And, personally, when I am working on a line of J code, I like to have a little 
test rig so that I can quickly see when I have gone astray.
Doing that here (and clipping out my mistakes), then adding comments gets me 
this:

First, I set up a test rig with the original expression:

   #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
10

Then, I rephrase the outer part as an explicit expression for 13 :

  #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
10

Since that worked, I take a look at what 13 : gave me

   13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
[ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]

Next, I try that out in my test rig:

   #3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
10

So, now that I have that, I do a rephrase of the inner part for another 13 :

   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
10

And, since that works, I take a look at what it gave me:

   [ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ] [ ([: |. [: I. ] #~ [ = [: 
+/"1 ]) [: #: [: i. 2 ^ ]

And, voila, I've got another variation that I can use in a word definition:

   comb4a=: [ ([: |. [: I. ] #~ [ = [: +/"1 ]) [: #: [: i. 2 ^ ]

That's a bit ugly, but ascii is ugly (but, also, standardized and - thus - 
widely available).

So, we can try that out and see it in operation:

   3 comb4a 5
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4

Also... note that when working with "real life" mechanisms (not just J), having 
some sort of test rig to make sure that what you are doing behaves like you 
think it does can be an invaluable time saver. (The alternative - putting a lot 
of work into something, only to find out that it doesn't work and that you have 
to start over again - is sometimes necessary but not always attractive.)

(Well, that, and remember that this approach is slower than the stock comb 
implementation when y > 10 - so mostly I would just do require'stats' and then 
use that comb implementation.)

Then again, now that we have this variation, we could also try to reconstruct 
an explicit expression which does the same thing. For that we want to merge 
these two examples:

   #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5

Perhaps something like:
   #3 (13 :'|.I.(x = +/"1 t) # t=. #:i. 2^y') 5
10

(But I would not blindly enshrine results just because they were generated by 
an automated mechanism - such things can be useful tools, of course, but if you 
abandon your own understanding that's not good.)

I hope this helps,

--
Raul

On Wed, Nov 1, 2017 at 11:55 PM, Linda Alvord  wrote:
> This is another way to get to Raul's ideas in a tacit soluion:
>
> comb4=: 13 :'|.I.(x=+/"1#:i.x^y)##:i.x^y'
>2 comb4 4
> 0 1
> 0 2
> 0 3
> 1 2
> 1 3
> 2 3
>comb4
> [: |. [: I. ([ = [: +/"1 [: #: [: i. ^) # [: #: [: i. ^
>
> Linda
>
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On 
> Behalf Of Lippu Esa
> Sent: Wednesday, November 1, 2017 5:53 PM
> To: 'programm...@jsoftware.com' 
> Subject: Re: [Jprogramming] Partitions
>
> Thank you, Raul! I knew that there would be a tacit solution. But comb is 
> better with big y as you said.
>
> Esa
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On 
> Behalf Of Raul Miller
> Sent: Wednesday, November 1, 2017 11:26 PM
> To: Programming forum 
> Subject: Re: [Jprogramming] Partitions
>
> comb3 performs well for y<10, but bogs down (compared to comb) for 
> y>10
>
> That said, a=.[: #: [: i. 2 ^ ] is a verb, not a noun.
>
> That said, you do not have to compute a twice, for example:
>
> comb3a=:   [ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]
>
> (but comb3a is still slower than comb, when I time it, for y>10)
>
> Thanks,
>
> --
> Raul
>
>
> On Wed, Nov 1, 2017 at 4:52 PM, Lippu Esa  wrote:
>> Yes, interesting! Thank you Linda.
>>
>> Just for practice, I tried to isolate the common part:

Re: [Jprogramming] Partitions

2017-11-02 Thread 'Skip Cave' via Programming
Raul,

Here's another try to state the rules of this problem:of the n objects

I have n objects. Each object has a single numeric value.
More than one object can have the same numeric value.
The "containers" I talk about must each contain one or more of the objects.
The "value" of each specific  container is obtained by multiplying together
the numeric values of all the objects in that container.
The value of the complete set of containers is "p" and p is found by
multiplying together all the values in each container.

The order of objects in a container does not change the value of the
container, and the order of containers with the same objects in them do not
consist of a new configuration.

So here's  the problem I was trying to solve:

given a set of variables x1, x2, x3, x4 xn

Show all the different sets of x1 - xn that solves the equality:
p = */ x1, x2, x3, x4, xn

All permutations of the same set of x1-xn is considered the same solution

The "unique objects" I describe are really the factors of some integer. An
example question:

358358=*/x1, x2, x3, x4, x5
How many different combinations of 5 integersx1, x2, x3, x4, x5  solve this
equality? (Different orders don't count)

What about:
358360=*/x1, x2, x3, x4, x5  ?

Skip

Skip Cave
Cave Consulting LLC

On Thu, Nov 2, 2017 at 7:54 PM, Raul Miller  wrote:

> Since that problem is so small, it would be tempting to just brute
> force it. (Build out all copies of 3 integers, 1 .. 24 and then select
> those whose product is 24. That's less than 2 million tests, so a
> computer can run through them in a fraction of a second.)
>
> Though, as other posters on that quora page have noted, the question
> is ambiguous. (is x=1, y=2, z=12 the same as x=12, y=1, z=2? Why or
> why not?)
>
> So to be thorough, you sort of have to supply answers for "x is a
> different variable from y and z" and "it does not really matter which
> variable you use for whichever integer". And, since the problem is
> small, it's trivial to go from the permutations answer to the
> combinations answer:
>
>#(#~ 24 = */"1)1+24 24 24 #:i.24^3
> 30
>#~./:~"1(#~ 24 = */"1)1+24 24 24 #:i.24^3
> 6
>
> Still... fun problem.
>
> Thanks,
>
> --
> Raul
>
>
> On Thu, Nov 2, 2017 at 8:15 PM, 'Skip Cave' via Programming
>  wrote:
> > Wow! I'm amazed at the response my partition problem got on the
> programming
> > forum. I have learned quite a lot about various ways to optimize a
> > combination verb, as well as the partition verb.
> >
> > I think that it might be good to look at the original problem that caused
> > me to come up with the partition solution:
> >
> > I was trying to solve a Quora problem that asks:
> > What is total number of positive integer solutions for (x, y, z) such
> that
> > xyz=24?
> >  integral-solutions-for-x-y-z-such-that-xyz-24>
> >
> > I wanted to eventually generalize the problem to handle a list of n
> > integers whose product [image: \prod] or +/  is equal to integer p.
> > so given the equation [image: \prod] (x1, x2, x3, ... xn ) = p
> > What is total number of positive integer solutions sets for x1, x2,x3
> ...xn?
> >
> > So for our original problem first we need to factor the number:
> >
> > q:24
> >
> > 2 2 2 3 - these are the factors of 24.
> >
> > A reasonable way to solve this is to build a function that will find all
> > the ways to partition the list of factors into three groups:
> >
> >   ]a =.3 par 4
> >
> > ┌───┬───┬───┐
> >
> > │0 1│2  │3  │
> >
> > ├───┼───┼───┤
> >
> > │0 2│1  │3  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1 2│3  │
> >
> > ├───┼───┼───┤
> >
> > │0 3│1  │2  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1 3│2  │
> >
> > ├───┼───┼───┤
> >
> > │0  │1  │2 3│
> >
> > └───┴───┴───┘
> >
> >
> > Now replace the indices with the actual prime factors of 24
> >
> >
> > ]b =. a cvt q:24
> >
> > ┌───┬───┬───┐
> >
> > │2 2│2  │3  │
> >
> > ├───┼───┼───┤
> >
> > │2 2│2  │3  │
> >
> > ├───┼───┼───┤
> >
> > │2  │2 2│3  │
> >
> > ├───┼───┼───┤
> >
> > │2 3│2  │2  │
> >
> > ├───┼───┼───┤
> >
> > │2  │2 3│2  │
> >
> > ├───┼───┼───┤
> >
> > │2  │2  │2 3│
> >
> > └───┴───┴───┘
> >
> >
> >]c=. */ each b
> >
> > ┌─┬─┬─┐
> >
> > │4│2│3│
> >
> > ├─┼─┼─┤
> >
> > │4│2│3│
> >
> > ├─┼─┼─┤
> >
> > │2│4│3│
> >
> > ├─┼─┼─┤
> >
> > │6│2│2│
> >
> > ├─┼─┼─┤
> >
> > │2│6│2│
> >
> > ├─┼─┼─┤
> >
> > │2│2│6│
> >
> > └─┴─┴─┘
> >
> > Now sort the lists and get rid of the copies:
> >
> >
> >  ~. c/:"1 c
> >
> > ┌─┬─┬─┐
> >
> > │2│3│4│
> >
> > ├─┼─┼─┤
> >
> > │2│2│6│
> >
> > └─┴─┴─┘
> >
> >
> > So the answer to the question: What is total number of positive integer
> > solutions for (x, y, z) such that xyz=24?
> >  integral-solutions-for-x-y-z-such-that-xyz-24>
> >  is:
> >
> > 2 3 4,  &  2 2 6
> >
> >
> > So now can we build a generalized verb that does it all in one step for
> any
> > n?
> >
> >3 list 24
> >
> > 2 3 4
> >
> > 2 2 6
> >
> >
> >
> > Skip
> >

Re: [Jprogramming] Partitions

2017-11-02 Thread Raul Miller
Since that problem is so small, it would be tempting to just brute
force it. (Build out all copies of 3 integers, 1 .. 24 and then select
those whose product is 24. That's less than 2 million tests, so a
computer can run through them in a fraction of a second.)

Though, as other posters on that quora page have noted, the question
is ambiguous. (is x=1, y=2, z=12 the same as x=12, y=1, z=2? Why or
why not?)

So to be thorough, you sort of have to supply answers for "x is a
different variable from y and z" and "it does not really matter which
variable you use for whichever integer". And, since the problem is
small, it's trivial to go from the permutations answer to the
combinations answer:

   #(#~ 24 = */"1)1+24 24 24 #:i.24^3
30
   #~./:~"1(#~ 24 = */"1)1+24 24 24 #:i.24^3
6

Still... fun problem.

Thanks,

-- 
Raul


On Thu, Nov 2, 2017 at 8:15 PM, 'Skip Cave' via Programming
 wrote:
> Wow! I'm amazed at the response my partition problem got on the programming
> forum. I have learned quite a lot about various ways to optimize a
> combination verb, as well as the partition verb.
>
> I think that it might be good to look at the original problem that caused
> me to come up with the partition solution:
>
> I was trying to solve a Quora problem that asks:
> What is total number of positive integer solutions for (x, y, z) such that
> xyz=24?
> 
>
> I wanted to eventually generalize the problem to handle a list of n
> integers whose product [image: \prod] or +/  is equal to integer p.
> so given the equation [image: \prod] (x1, x2, x3, ... xn ) = p
> What is total number of positive integer solutions sets for x1, x2,x3 ...xn?
>
> So for our original problem first we need to factor the number:
>
> q:24
>
> 2 2 2 3 - these are the factors of 24.
>
> A reasonable way to solve this is to build a function that will find all
> the ways to partition the list of factors into three groups:
>
>   ]a =.3 par 4
>
> ┌───┬───┬───┐
>
> │0 1│2  │3  │
>
> ├───┼───┼───┤
>
> │0 2│1  │3  │
>
> ├───┼───┼───┤
>
> │0  │1 2│3  │
>
> ├───┼───┼───┤
>
> │0 3│1  │2  │
>
> ├───┼───┼───┤
>
> │0  │1 3│2  │
>
> ├───┼───┼───┤
>
> │0  │1  │2 3│
>
> └───┴───┴───┘
>
>
> Now replace the indices with the actual prime factors of 24
>
>
> ]b =. a cvt q:24
>
> ┌───┬───┬───┐
>
> │2 2│2  │3  │
>
> ├───┼───┼───┤
>
> │2 2│2  │3  │
>
> ├───┼───┼───┤
>
> │2  │2 2│3  │
>
> ├───┼───┼───┤
>
> │2 3│2  │2  │
>
> ├───┼───┼───┤
>
> │2  │2 3│2  │
>
> ├───┼───┼───┤
>
> │2  │2  │2 3│
>
> └───┴───┴───┘
>
>
>]c=. */ each b
>
> ┌─┬─┬─┐
>
> │4│2│3│
>
> ├─┼─┼─┤
>
> │4│2│3│
>
> ├─┼─┼─┤
>
> │2│4│3│
>
> ├─┼─┼─┤
>
> │6│2│2│
>
> ├─┼─┼─┤
>
> │2│6│2│
>
> ├─┼─┼─┤
>
> │2│2│6│
>
> └─┴─┴─┘
>
> Now sort the lists and get rid of the copies:
>
>
>  ~. c/:"1 c
>
> ┌─┬─┬─┐
>
> │2│3│4│
>
> ├─┼─┼─┤
>
> │2│2│6│
>
> └─┴─┴─┘
>
>
> So the answer to the question: What is total number of positive integer
> solutions for (x, y, z) such that xyz=24?
> 
>  is:
>
> 2 3 4,  &  2 2 6
>
>
> So now can we build a generalized verb that does it all in one step for any
> n?
>
>3 list 24
>
> 2 3 4
>
> 2 2 6
>
>
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Thu, Nov 2, 2017 at 5:32 PM, Raul Miller  wrote:
>
>> Oops, no... the 1 partition results are not from comb, and 1 comb y
>> won't get them.
>>
>> I was just using ,.< i.y
>>
>> And, the 2 partition results were also not from comb, I was using
>>
>> ((y#2)#:"1 0 }.i.2^y-1) >
>> Still... tends to be faster than parRuskeyE.
>>
>> Sorry about that, I'm just waking up from a nap...
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>> On Thu, Nov 2, 2017 at 6:29 PM, Raul Miller  wrote:
>> > The performance of your parRuskeyE is looking really nice.
>> >
>> > That said, for 1 or 2 partitions, a comb based approach (using the
>> > comb from require'stats') is still tends to be significantly faster
>> > (except for 2 parRuskeyE 2). (And, once the number of values in a
>> > partition has reached like 13 or 14, this speed advantage starts
>> > creeping into results involving more partitions, but it's not a factor
>> > of 2 speed advantage for any practical result size so it's probably
>> > not worrying about.)
>> >
>> > The 1 partition results would be trivial to incorporate - it's just
>> > <"1]1 comb y where y is the number of partitions.
>> >
>> > Thanks,
>> >
>> > --
>> > Raul
>> >
>> >
>> > On Thu, Nov 2, 2017 at 9:28 AM, Erling Hellenäs
>> >  wrote:
>> >> Hi all !
>> >>
>> >> My partition projects are parRuskeyE, parE and parE2.
>> >>
>> >> parRuskeyE
>> >>
>> >> Frank Ruskeys algorithm, now with massively parallel recursion.
>> >>
>> >> parE
>> >>
>> >> Similar to parELMDE, but works with bitmaps and creates less
>> combinations.
>> >>
>> >> parE2
>> >>
>> >> Creates unique bucket groups, combines the buckets within each bucket
>> group
>> >>
>> >> with sets

Re: [Jprogramming] Partitions

2017-11-02 Thread 'Skip Cave' via Programming
Wow! I'm amazed at the response my partition problem got on the programming
forum. I have learned quite a lot about various ways to optimize a
combination verb, as well as the partition verb.

I think that it might be good to look at the original problem that caused
me to come up with the partition solution:

I was trying to solve a Quora problem that asks:
What is total number of positive integer solutions for (x, y, z) such that
xyz=24?


I wanted to eventually generalize the problem to handle a list of n
integers whose product [image: \prod] or +/  is equal to integer p.
so given the equation [image: \prod] (x1, x2, x3, ... xn ) = p
What is total number of positive integer solutions sets for x1, x2,x3 ...xn?

So for our original problem first we need to factor the number:

q:24

2 2 2 3 - these are the factors of 24.

A reasonable way to solve this is to build a function that will find all
the ways to partition the list of factors into three groups:

  ]a =.3 par 4

┌───┬───┬───┐

│0 1│2  │3  │

├───┼───┼───┤

│0 2│1  │3  │

├───┼───┼───┤

│0  │1 2│3  │

├───┼───┼───┤

│0 3│1  │2  │

├───┼───┼───┤

│0  │1 3│2  │

├───┼───┼───┤

│0  │1  │2 3│

└───┴───┴───┘


Now replace the indices with the actual prime factors of 24


]b =. a cvt q:24

┌───┬───┬───┐

│2 2│2  │3  │

├───┼───┼───┤

│2 2│2  │3  │

├───┼───┼───┤

│2  │2 2│3  │

├───┼───┼───┤

│2 3│2  │2  │

├───┼───┼───┤

│2  │2 3│2  │

├───┼───┼───┤

│2  │2  │2 3│

└───┴───┴───┘


   ]c=. */ each b

┌─┬─┬─┐

│4│2│3│

├─┼─┼─┤

│4│2│3│

├─┼─┼─┤

│2│4│3│

├─┼─┼─┤

│6│2│2│

├─┼─┼─┤

│2│6│2│

├─┼─┼─┤

│2│2│6│

└─┴─┴─┘

Now sort the lists and get rid of the copies:


 ~. c/:"1 c

┌─┬─┬─┐

│2│3│4│

├─┼─┼─┤

│2│2│6│

└─┴─┴─┘


So the answer to the question: What is total number of positive integer
solutions for (x, y, z) such that xyz=24?

 is:

2 3 4,  &  2 2 6


So now can we build a generalized verb that does it all in one step for any
n?

   3 list 24

2 3 4

2 2 6



Skip

Skip Cave
Cave Consulting LLC

On Thu, Nov 2, 2017 at 5:32 PM, Raul Miller  wrote:

> Oops, no... the 1 partition results are not from comb, and 1 comb y
> won't get them.
>
> I was just using ,.< i.y
>
> And, the 2 partition results were also not from comb, I was using
>
> ((y#2)#:"1 0 }.i.2^y-1) 
> Still... tends to be faster than parRuskeyE.
>
> Sorry about that, I'm just waking up from a nap...
>
> Thanks,
>
> --
> Raul
>
>
> On Thu, Nov 2, 2017 at 6:29 PM, Raul Miller  wrote:
> > The performance of your parRuskeyE is looking really nice.
> >
> > That said, for 1 or 2 partitions, a comb based approach (using the
> > comb from require'stats') is still tends to be significantly faster
> > (except for 2 parRuskeyE 2). (And, once the number of values in a
> > partition has reached like 13 or 14, this speed advantage starts
> > creeping into results involving more partitions, but it's not a factor
> > of 2 speed advantage for any practical result size so it's probably
> > not worrying about.)
> >
> > The 1 partition results would be trivial to incorporate - it's just
> > <"1]1 comb y where y is the number of partitions.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> > On Thu, Nov 2, 2017 at 9:28 AM, Erling Hellenäs
> >  wrote:
> >> Hi all !
> >>
> >> My partition projects are parRuskeyE, parE and parE2.
> >>
> >> parRuskeyE
> >>
> >> Frank Ruskeys algorithm, now with massively parallel recursion.
> >>
> >> parE
> >>
> >> Similar to parELMDE, but works with bitmaps and creates less
> combinations.
> >>
> >> parE2
> >>
> >> Creates unique bucket groups, combines the buckets within each bucket
> group
> >>
> >> with sets of combinations with the correct number of items.
> >>
> >> Combinations are filtered to avoid duplication.
> >>
> >> Performance
> >>
> >> ParRuskeyE is the winner in performance with parE not far behind.
> >>
> >> They can all handle high x combined with high y.
> >>
> >>x=:5
> >>y=:7
> >>ts'x parRuskeyE y'
> >> 0.000265134 127232
> >>ts'x parE y'
> >> 0.000889053 794496
> >>ts'x parE2 y'
> >> 0.00687637 217600
> >>
> >>x=:5
> >>y=:10
> >>ts'x parRuskeyE y'
> >> 0.0683502 3.8954e7
> >>ts'x parE y'
> >> 0.224765 1.70531e8
> >>ts'x parE2 y'
> >> 1.50793 6.50278e7
> >>
> >>x=:9
> >>y=:10
> >>ts'x parRuskeyE y'
> >> 0.00013385 75136
> >>ts'x parE y'
> >> 0.0668154 5.03395e7
> >>ts'x parE2 y'
> >> 0.0767498 5.86112e6
> >>
> >> You can see the programs below.
> >>
> >> Cheers,
> >>
> >> Erling Hellenäs
> >>
> >> ---Project---
> >>
> >> NB. parRuskeyE
> >>
> >> parRuskeyE =: 4 : 0
> >> r=. (,: i.y) SE (x-1);y-1
> >> r  >> )
> >>
> >> SE =: 4 : 0
> >> 'k n' =. y
> >> r=. (0,_1{.$x)$0
> >> if. k=n do.
> >>   r=.x
> >> else.
> >>   s=.n {."1 x
> >>   e=.(n+1)}."1 x
> >>   a=.,/s ( [,"1 1 (i.k+1),"0 1 ])"1 e
> >>   r=.r, a SE k

Re: [Jprogramming] Partitions

2017-11-02 Thread Raul Miller
Oops, no... the 1 partition results are not from comb, and 1 comb y
won't get them.

I was just using ,.< i.y

And, the 2 partition results were also not from comb, I was using

((y#2)#:"1 0 }.i.2^y-1)  wrote:
> The performance of your parRuskeyE is looking really nice.
>
> That said, for 1 or 2 partitions, a comb based approach (using the
> comb from require'stats') is still tends to be significantly faster
> (except for 2 parRuskeyE 2). (And, once the number of values in a
> partition has reached like 13 or 14, this speed advantage starts
> creeping into results involving more partitions, but it's not a factor
> of 2 speed advantage for any practical result size so it's probably
> not worrying about.)
>
> The 1 partition results would be trivial to incorporate - it's just
> <"1]1 comb y where y is the number of partitions.
>
> Thanks,
>
> --
> Raul
>
>
> On Thu, Nov 2, 2017 at 9:28 AM, Erling Hellenäs
>  wrote:
>> Hi all !
>>
>> My partition projects are parRuskeyE, parE and parE2.
>>
>> parRuskeyE
>>
>> Frank Ruskeys algorithm, now with massively parallel recursion.
>>
>> parE
>>
>> Similar to parELMDE, but works with bitmaps and creates less combinations.
>>
>> parE2
>>
>> Creates unique bucket groups, combines the buckets within each bucket group
>>
>> with sets of combinations with the correct number of items.
>>
>> Combinations are filtered to avoid duplication.
>>
>> Performance
>>
>> ParRuskeyE is the winner in performance with parE not far behind.
>>
>> They can all handle high x combined with high y.
>>
>>x=:5
>>y=:7
>>ts'x parRuskeyE y'
>> 0.000265134 127232
>>ts'x parE y'
>> 0.000889053 794496
>>ts'x parE2 y'
>> 0.00687637 217600
>>
>>x=:5
>>y=:10
>>ts'x parRuskeyE y'
>> 0.0683502 3.8954e7
>>ts'x parE y'
>> 0.224765 1.70531e8
>>ts'x parE2 y'
>> 1.50793 6.50278e7
>>
>>x=:9
>>y=:10
>>ts'x parRuskeyE y'
>> 0.00013385 75136
>>ts'x parE y'
>> 0.0668154 5.03395e7
>>ts'x parE2 y'
>> 0.0767498 5.86112e6
>>
>> You can see the programs below.
>>
>> Cheers,
>>
>> Erling Hellenäs
>>
>> ---Project---
>>
>> NB. parRuskeyE
>>
>> parRuskeyE =: 4 : 0
>> r=. (,: i.y) SE (x-1);y-1
>> r > )
>>
>> SE =: 4 : 0
>> 'k n' =. y
>> r=. (0,_1{.$x)$0
>> if. k=n do.
>>   r=.x
>> else.
>>   s=.n {."1 x
>>   e=.(n+1)}."1 x
>>   a=.,/s ( [,"1 1 (i.k+1),"0 1 ])"1 e
>>   r=.r, a SE k;n-1
>>   if. k > 0 do.
>> a=.s,.k,.e
>> r=.r, a SE (k-1);n-1
>>   end.
>> end.
>> r
>> )
>>
>> NB. parE
>>
>> combE=: 4 : 0
>> u=:(-y){.i.x-1
>> w=:(y#x)-u+|.u
>> o=:u <@([+[:i.])"0 w
>> p=:>([:,/[,"0 1 "0 _] )&.>/ (}:o),<,.>{:o
>> )
>>
>>
>> parE=: 4 : 0
>> NB. Assume a table with x rows and y columns.
>> NB. Each row is a bucket, each column an item.
>> NB. Two buckets can not contain the same item.
>> NB. This means there can only be one item in each column.
>> NB. Each column can be rotated in x ways.
>> NB. Generate all combinations of the possible rotations
>> NB. except for the first and last x-1 columns.
>> o=: x combE y
>> NB. Pick the rotation from a bitmap where each
>> NB. row is a possible rotation
>> NB. We now have a three-dimensional bitmap of
>> NB. combination, items in the bucket and bucket
>> NB. True means the bucket contains the corresponding item
>> v=:o{(i.x)|."0 1 x{.1
>> NB. Select the combination where each bucket contains at least
>> NB. one item.
>> b=:(*./"1+./"2 v)#v
>> NB. Reorder the dimensions
>> NB. Now they are combination, bucket and items in the bucket.
>> c=:0 2 1|:b
>> NB. Sort the buckets within the combinations so that
>> NB. buckets with the same contents also are in the same place
>> NB. in bucket order
>> d=:/:~"2 c
>> NB. Remove duplicates
>> e=: ~.d
>> NB. Display
>> e<@# i.y
>> )
>>
>> NB. parE2
>>
>> NB. All combinations of y items
>> combE2=: 3 : 'm{.#:i.m=.(0~:#y)*<.2^y'
>>
>> NB. Select from y where there are no item duplicates in the buckets of x
>> NB. and the buckets of y.
>> filter=: 4 : '(x -.@:(+./)@:*.&(+./)"2 y)#y'
>>
>> NB. Cartesian product
>> NB. If y is empty after filter the result will be empty
>> cpE=: 4 : 'x,"2 y'
>>
>>
>> NB. The argument is a boxed array of combinations
>> NB. Combine each combination in the last box with all combinations in box
>> two
>> NB. from the right.
>> NB. Continue until all box contents are combined.
>> NB. BUT - Filter the incoming combinations before the cartesian product
>> NB. AND - AFTER the cartesian product -
>> NB. -Sort the buckets in each bucket combination to get equal bucket
>> combinations in
>> NB. the same bucket number.
>> NB. -Remove duplicates.
>> filterMerge=:[: > [: ([: ~.@:(/:~"2)@:; <"2@:] ([ cpE [ filter ])&.>
>> <@:[)&.>/ ]
>>
>> bCombE=: 4 :0
>> NB. All combinations of bucket sizes
>> NB. Which sum to y
>> v=.1+y-x
>> p=.>:(x#v)#:i.v^x
>> r=.(y= +/"1 p)#p
>> NB. sort them in size order
>> t=./:~"1 r
>> NB. Remove duplicates
>> ~. t
>> )
>>
>> parE2=: 4 : 0
>> NB. All combinations of all items
>> v=.}.combE2 y
>> NB.All unique combinations of x buckets with y ite

Re: [Jprogramming] Partitions

2017-11-02 Thread Raul Miller
The performance of your parRuskeyE is looking really nice.

That said, for 1 or 2 partitions, a comb based approach (using the
comb from require'stats') is still tends to be significantly faster
(except for 2 parRuskeyE 2). (And, once the number of values in a
partition has reached like 13 or 14, this speed advantage starts
creeping into results involving more partitions, but it's not a factor
of 2 speed advantage for any practical result size so it's probably
not worrying about.)

The 1 partition results would be trivial to incorporate - it's just
<"1]1 comb y where y is the number of partitions.

Thanks,

-- 
Raul


On Thu, Nov 2, 2017 at 9:28 AM, Erling Hellenäs
 wrote:
> Hi all !
>
> My partition projects are parRuskeyE, parE and parE2.
>
> parRuskeyE
>
> Frank Ruskeys algorithm, now with massively parallel recursion.
>
> parE
>
> Similar to parELMDE, but works with bitmaps and creates less combinations.
>
> parE2
>
> Creates unique bucket groups, combines the buckets within each bucket group
>
> with sets of combinations with the correct number of items.
>
> Combinations are filtered to avoid duplication.
>
> Performance
>
> ParRuskeyE is the winner in performance with parE not far behind.
>
> They can all handle high x combined with high y.
>
>x=:5
>y=:7
>ts'x parRuskeyE y'
> 0.000265134 127232
>ts'x parE y'
> 0.000889053 794496
>ts'x parE2 y'
> 0.00687637 217600
>
>x=:5
>y=:10
>ts'x parRuskeyE y'
> 0.0683502 3.8954e7
>ts'x parE y'
> 0.224765 1.70531e8
>ts'x parE2 y'
> 1.50793 6.50278e7
>
>x=:9
>y=:10
>ts'x parRuskeyE y'
> 0.00013385 75136
>ts'x parE y'
> 0.0668154 5.03395e7
>ts'x parE2 y'
> 0.0767498 5.86112e6
>
> You can see the programs below.
>
> Cheers,
>
> Erling Hellenäs
>
> ---Project---
>
> NB. parRuskeyE
>
> parRuskeyE =: 4 : 0
> r=. (,: i.y) SE (x-1);y-1
> r  )
>
> SE =: 4 : 0
> 'k n' =. y
> r=. (0,_1{.$x)$0
> if. k=n do.
>   r=.x
> else.
>   s=.n {."1 x
>   e=.(n+1)}."1 x
>   a=.,/s ( [,"1 1 (i.k+1),"0 1 ])"1 e
>   r=.r, a SE k;n-1
>   if. k > 0 do.
> a=.s,.k,.e
> r=.r, a SE (k-1);n-1
>   end.
> end.
> r
> )
>
> NB. parE
>
> combE=: 4 : 0
> u=:(-y){.i.x-1
> w=:(y#x)-u+|.u
> o=:u <@([+[:i.])"0 w
> p=:>([:,/[,"0 1 "0 _] )&.>/ (}:o),<,.>{:o
> )
>
>
> parE=: 4 : 0
> NB. Assume a table with x rows and y columns.
> NB. Each row is a bucket, each column an item.
> NB. Two buckets can not contain the same item.
> NB. This means there can only be one item in each column.
> NB. Each column can be rotated in x ways.
> NB. Generate all combinations of the possible rotations
> NB. except for the first and last x-1 columns.
> o=: x combE y
> NB. Pick the rotation from a bitmap where each
> NB. row is a possible rotation
> NB. We now have a three-dimensional bitmap of
> NB. combination, items in the bucket and bucket
> NB. True means the bucket contains the corresponding item
> v=:o{(i.x)|."0 1 x{.1
> NB. Select the combination where each bucket contains at least
> NB. one item.
> b=:(*./"1+./"2 v)#v
> NB. Reorder the dimensions
> NB. Now they are combination, bucket and items in the bucket.
> c=:0 2 1|:b
> NB. Sort the buckets within the combinations so that
> NB. buckets with the same contents also are in the same place
> NB. in bucket order
> d=:/:~"2 c
> NB. Remove duplicates
> e=: ~.d
> NB. Display
> e<@# i.y
> )
>
> NB. parE2
>
> NB. All combinations of y items
> combE2=: 3 : 'm{.#:i.m=.(0~:#y)*<.2^y'
>
> NB. Select from y where there are no item duplicates in the buckets of x
> NB. and the buckets of y.
> filter=: 4 : '(x -.@:(+./)@:*.&(+./)"2 y)#y'
>
> NB. Cartesian product
> NB. If y is empty after filter the result will be empty
> cpE=: 4 : 'x,"2 y'
>
>
> NB. The argument is a boxed array of combinations
> NB. Combine each combination in the last box with all combinations in box
> two
> NB. from the right.
> NB. Continue until all box contents are combined.
> NB. BUT - Filter the incoming combinations before the cartesian product
> NB. AND - AFTER the cartesian product -
> NB. -Sort the buckets in each bucket combination to get equal bucket
> combinations in
> NB. the same bucket number.
> NB. -Remove duplicates.
> filterMerge=:[: > [: ([: ~.@:(/:~"2)@:; <"2@:] ([ cpE [ filter ])&.>
> <@:[)&.>/ ]
>
> bCombE=: 4 :0
> NB. All combinations of bucket sizes
> NB. Which sum to y
> v=.1+y-x
> p=.>:(x#v)#:i.v^x
> r=.(y= +/"1 p)#p
> NB. sort them in size order
> t=./:~"1 r
> NB. Remove duplicates
> ~. t
> )
>
> parE2=: 4 : 0
> NB. All combinations of all items
> v=.}.combE2 y
> NB.All unique combinations of x buckets with y items
> b=.x bCombE y
> NB. Unique bucket sizes in all bucket combinations
> c=. ~. ,b
> NB. Number of items in each combination
> d=.+/"1 v
> NB. Remove unneded combinations
> q=: d e.c
> v1=: q#v
> d1=: q#d
> NB. Insert a bucket dimension. The dimensions are now
> NB. bucket combination, bucket and item combination in the bucket
> v2=.((#v1),1,y)$,v1
> NB. Pack sets of combinations with number of items correspondi

Re: [Jprogramming] Partitions

2017-11-02 Thread Erling Hellenäs

Hi all !

My partition projects are parRuskeyE, parE and parE2.

parRuskeyE

Frank Ruskeys algorithm, now with massively parallel recursion.

parE

Similar to parELMDE, but works with bitmaps and creates less combinations.

parE2

Creates unique bucket groups, combines the buckets within each bucket group

with sets of combinations with the correct number of items.

Combinations are filtered to avoid duplication.

Performance

ParRuskeyE is the winner in performance with parE not far behind.

They can all handle high x combined with high y.

   x=:5
   y=:7
   ts'x parRuskeyE y'
0.000265134 127232
   ts'x parE y'
0.000889053 794496
   ts'x parE2 y'
0.00687637 217600

   x=:5
   y=:10
   ts'x parRuskeyE y'
0.0683502 3.8954e7
   ts'x parE y'
0.224765 1.70531e8
   ts'x parE2 y'
1.50793 6.50278e7

   x=:9
   y=:10
   ts'x parRuskeyE y'
0.00013385 75136
   ts'x parE y'
0.0668154 5.03395e7
   ts'x parE2 y'
0.0767498 5.86112e6

You can see the programs below.

Cheers,

Erling Hellenäs

---Project---

NB. parRuskeyE

parRuskeyE =: 4 : 0
r=. (,: i.y) SE (x-1);y-1
r  0 do.
    a=.s,.k,.e
    r=.r, a SE (k-1);n-1
  end.
end.
r
)

NB. parE

combE=: 4 : 0
u=:(-y){.i.x-1
w=:(y#x)-u+|.u
o=:u <@([+[:i.])"0 w
p=:>([:,/[,"0 1 "0 _] )&.>/ (}:o),<,.>{:o
)


parE=: 4 : 0
NB. Assume a table with x rows and y columns.
NB. Each row is a bucket, each column an item.
NB. Two buckets can not contain the same item.
NB. This means there can only be one item in each column.
NB. Each column can be rotated in x ways.
NB. Generate all combinations of the possible rotations
NB. except for the first and last x-1 columns.
o=: x combE y
NB. Pick the rotation from a bitmap where each
NB. row is a possible rotation
NB. We now have a three-dimensional bitmap of
NB. combination, items in the bucket and bucket
NB. True means the bucket contains the corresponding item
v=:o{(i.x)|."0 1 x{.1
NB. Select the combination where each bucket contains at least
NB. one item.
b=:(*./"1+./"2 v)#v
NB. Reorder the dimensions
NB. Now they are combination, bucket and items in the bucket.
c=:0 2 1|:b
NB. Sort the buckets within the combinations so that
NB. buckets with the same contents also are in the same place
NB. in bucket order
d=:/:~"2 c
NB. Remove duplicates
e=: ~.d
NB. Display
e<@# i.y
)

NB. parE2

NB. All combinations of y items
combE2=: 3 : 'm{.#:i.m=.(0~:#y)*<.2^y'

NB. Select from y where there are no item duplicates in the buckets of x
NB. and the buckets of y.
filter=: 4 : '(x -.@:(+./)@:*.&(+./)"2 y)#y'

NB. Cartesian product
NB. If y is empty after filter the result will be empty
cpE=: 4 : 'x,"2 y'


NB. The argument is a boxed array of combinations
NB. Combine each combination in the last box with all combinations in 
box two

NB. from the right.
NB. Continue until all box contents are combined.
NB. BUT - Filter the incoming combinations before the cartesian product
NB. AND - AFTER the cartesian product -
NB. -Sort the buckets in each bucket combination to get equal bucket 
combinations in

NB. the same bucket number.
NB. -Remove duplicates.
filterMerge=:[: > [: ([: ~.@:(/:~"2)@:; <"2@:] ([ cpE [ filter ])&.> 
<@:[)&.>/ ]


bCombE=: 4 :0
NB. All combinations of bucket sizes
NB. Which sum to y
v=.1+y-x
p=.>:(x#v)#:i.v^x
r=.(y= +/"1 p)#p
NB. sort them in size order
t=./:~"1 r
NB. Remove duplicates
~. t
)

parE2=: 4 : 0
NB. All combinations of all items
v=.}.combE2 y
NB.All unique combinations of x buckets with y items
b=.x bCombE y
NB. Unique bucket sizes in all bucket combinations
c=. ~. ,b
NB. Number of items in each combination
d=.+/"1 v
NB. Remove unneded combinations
q=: d e.c
v1=: q#v
d1=: q#d
NB. Insert a bucket dimension. The dimensions are now
NB. bucket combination, bucket and item combination in the bucket
v2=.((#v1),1,y)$,v1
NB. Pack sets of combinations with number of items corresponding to
NB. the bucket sizes in the classes in c1
w=.d1http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Partitions

2017-11-02 Thread Erling Hellenäs

Hi all!

I have a new parE that is slightly faster. It also takes care of the 
problem of too many combinations when x AND y are both high.


If you want you can look at combE and see if you can improve the 
combination generation so that fewer redundant combinations are


generated.

combE generates fewer combinations for the x-1 first and last columns. 
On the low part combinations are reduced for


high number buckets. On the high end combinations are reduced for low 
number buckets.


I don't have a logical explanation for this. I just had a feeling of a 
symmetry, tried it and it passed my tests.


   x=:5
   y=:10
   ts'x parE y'
0.226541 1.70998e8
   ts'x parEOld y'
0.252278 6.71126e7
   ts'x parELMDE y'
0.296869 1.09056e8

   x=:8
   y=:9
   ts'x parE y'
0.0083671 5632
   ts'x parEOld y'
0.0973421 6.76699e7
   ts'x parELMDE y'
0.116581 1.09055e8

combE=: 4 : 0
u=:(-y){.i.x-1
w=:(y#x)-u+|.u
o=:u <@([+[:i.])"0 w
p=:>([:,/[,"0 1 "0 _] )&.>/ (}:o),<,.>{:o
)

parE=: 4 : 0
NB. Assume a table with x rows and y columns.
NB. Each row is a bucket, each column an item.
NB. Two buckets can not contain the same item.
NB. This means there can only be one item in each column.
NB. Each column can be rotated in x ways.
NB. Generate all combinations of the possible rotations
NB. except for the first x and last x-1 columns.
o=: x combE y
NB. Pick the rotation from a bitmap where each
NB. row is a possible rotation
NB. We now have a three-dimensional bitmap of
NB. combination, items in the bucket and bucket
NB. True means the bucket contains the corresponding item
v=:o{(i.x)|."0 1 x{.1
NB. Select the combination where each bucket contains at least
NB. one item.
b=:(*./"1+./"2 v)#v
NB. Reorder the dimensions
NB. Now they are combination, bucket and items in the bucket.
c=:0 2 1|:b
NB. Sort the buckets within the combinations so that
NB. buckets with the same contents also are in the same place
NB. in bucket order
d=:/:~"2 c
NB. Remove duplicates
e=: ~.d
NB. Display
e<@# i.y
)

Cheers,

Erling Hellenäs



Den 2017-11-01 kl. 11:41, skrev Erling Hellenäs:

Hi all !

I have a new and different parE that is slightly better than parELMDE.

parE=: 4 : 0

NB. Assume a table with x rows and y columns.

NB. Each row is a bucket, each column an item.

NB. Two buckets can not contain the same item.

NB. This means there can only be one item in each column.

NB. Each column can be rotated in x ways.

NB. Generate all combinations of the possible rotations

NB. except for the first x columns.

NB. o=:(y#x)#:i.x^y

o=:iy#:i.*/iy=:(1+i.x),(y-x)$x

NB. Pick the rotation from a bitmap where each

NB. row is a possible rotation

NB. We now have a three-dimensional bitmap of

NB. combination, items in the bucket and bucket

NB. True means the bucket contains the corresponding item

v=:o{(i.x)|."0 1 x{.1

NB. Select the combination where each bucket contains at least

NB. one item.

b=:(*./"1+./"2 v)#v

NB. Reorder the dimensions

NB. Now they are combination, bucket and items in the bucket.

c=:0 2 1|:b

NB. Sort the buckets within the combinations so that

NB. buckets with the same contents also are in the same place

NB. in bucket order

d=:/:~"2 c

NB. Remove duplicates

e=: ~.d

NB. Display

e<@# i.y

)


   x=:5
   y=:11
   (x parE y)compare x parELMDE y
1
   ts'x parE y'
1.55969 3.32636e8
   ts'x parELMDE y'
1.79359 8.38865e8


Cheers,


Erling Hellenäs


Den 2017-10-31 kl. 20:17, skrev 'Mike Day' via Programming:

Thanks, Raul.

NB - mods to parRuskey below!

I'm not sure my latest effort (mdconst) merits much study.
If you do look,  you might notice that the filtering check can be 
done slightly more
efficiently by building only the first column of the new comparand 
and then constructing
all columns only for required rows, but at the cost of greater code 
complexity and even less

transparency.  Congrats if you understand this!

Erling might like to look at this modification of his own recent 
amended version of parRuskey.
It manages to avoid some recursion. The calling routine is as he 
posted earlier today,
but I'll reproduce it here,  with subscripts "new" for it and for the 
"S" verb:


parRuskeynew =: 4 : 0
NB. L =: 0$~0, 2 + y   NB. debug/understand array of call parameters
r=. (i.y) Snew (x-1),y-1
NB. R =: r NB. debug/understand output
r   r =. r, ,/ (Snew&(k,n-1))"1 (i.k+1) n }"0 1 a NB.apply "1 instead 
of do loop

end.
if. k > 0 do.
  r=.r, (k n } a) Snew (k-1),n-1
end.
r
)


   (parRuskeynew -:parRuskey) /6 9

1


Getting more J-ish?

Cheers,

Mike






On 31/10/2017 16:31, Raul Miller wrote:

Well... I did get as far as doing basic timings:

tim=:2 :0
:
   u ratetime v"0
)

ratetime=:2 :0
   u NB. force x and y to be verb args
:
   try.
 assert. x<:y
 tV=.6!:2 'rV=. x v y'
 tU=.6!:2 'rU=. x u y'
 tU%tV
   catch.
 rV=.rU=.0
 _
   end.
   assert. rV -:&(/:~)&:(/:~"1)&:(/:~&.>) rU
)


    9!:11]2  NB. shrink precision to be more social

 G=:parRDM tim mdconst
    (1+i.10) G table

Re: [Jprogramming] Partitions

2017-11-01 Thread Raul Miller
No, you did not test your work.

   #3 comb 5
10
   #3 comb4 5
56

Probably the simplest way to approach what I think you are trying to
do involves expanding the part in parenthesis independent of the rest
of it.

And, personally, when I am working on a line of J code, I like to have
a little test rig so that I can quickly see when I have gone astray.
Doing that here (and clipping out my mistakes), then adding comments
gets me this:

First, I set up a test rig with the original expression:

   #3 ([ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]) 5
10

Then, I rephrase the outer part as an explicit expression for 13 :

  #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
10

Since that worked, I take a look at what 13 : gave me

   13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y'
[ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]

Next, I try that out in my test rig:

   #3 ([ ((= +/"1) |.@:I.@# ]) [: #: [: i. 2 ^ ]) 5
10

So, now that I have that, I do a rephrase of the inner part for another 13 :

   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5
10

And, since that works, I take a look at what it gave me:

   [ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]
[ ([: |. [: I. ] #~ [ = [: +/"1 ]) [: #: [: i. 2 ^ ]

And, voila, I've got another variation that I can use in a word definition:

   comb4a=: [ ([: |. [: I. ] #~ [ = [: +/"1 ]) [: #: [: i. 2 ^ ]

That's a bit ugly, but ascii is ugly (but, also, standardized and -
thus - widely available).

So, we can try that out and see it in operation:

   3 comb4a 5
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4

Also... note that when working with "real life" mechanisms (not just
J), having some sort of test rig to make sure that what you are doing
behaves like you think it does can be an invaluable time saver. (The
alternative - putting a lot of work into something, only to find out
that it doesn't work and that you have to start over again - is
sometimes necessary but not always attractive.)

(Well, that, and remember that this approach is slower than the stock
comb implementation when y > 10 - so mostly I would just do
require'stats' and then use that comb implementation.)

Then again, now that we have this variation, we could also try to
reconstruct an explicit expression which does the same thing. For that
we want to merge these two examples:

   #3 (13 :'x ((= +/"1) |.@:I.@# ]) #:i. 2^y') 5
   # 3([ (13 :'|.I.(x = +/"1 y) # y') [: #: [: i. 2 ^ ]) 5

Perhaps something like:
   #3 (13 :'|.I.(x = +/"1 t) # t=. #:i. 2^y') 5
10

(But I would not blindly enshrine results just because they were
generated by an automated mechanism - such things can be useful tools,
of course, but if you abandon your own understanding that's not good.)

I hope this helps,

-- 
Raul

On Wed, Nov 1, 2017 at 11:55 PM, Linda Alvord  wrote:
> This is another way to get to Raul's ideas in a tacit soluion:
>
> comb4=: 13 :'|.I.(x=+/"1#:i.x^y)##:i.x^y'
>2 comb4 4
> 0 1
> 0 2
> 0 3
> 1 2
> 1 3
> 2 3
>comb4
> [: |. [: I. ([ = [: +/"1 [: #: [: i. ^) # [: #: [: i. ^
>
> Linda
>
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
> Of Lippu Esa
> Sent: Wednesday, November 1, 2017 5:53 PM
> To: 'programm...@jsoftware.com' 
> Subject: Re: [Jprogramming] Partitions
>
> Thank you, Raul! I knew that there would be a tacit solution. But comb is 
> better with big y as you said.
>
> Esa
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
> Of Raul Miller
> Sent: Wednesday, November 1, 2017 11:26 PM
> To: Programming forum 
> Subject: Re: [Jprogramming] Partitions
>
> comb3 performs well for y<10, but bogs down (compared to comb) for y>10
>
> That said, a=.[: #: [: i. 2 ^ ] is a verb, not a noun.
>
> That said, you do not have to compute a twice, for example:
>
> comb3a=:   [ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]
>
> (but comb3a is still slower than comb, when I time it, for y>10)
>
> Thanks,
>
> --
> Raul
>
>
> On Wed, Nov 1, 2017 at 4:52 PM, Lippu Esa  wrote:
>> Yes, interesting! Thank you Linda.
>>
>> Just for practice, I tried to isolate the common part: [: #: [: i. 2 ^ ] but 
>> had to use a noun as didn't manage to find a tacit solution.
>>
>> comb3=:([ = [: +/"1 a) ([: |. [: I. #) a=.[: #: [: i. 2 ^ ]
>>
>> Anyone?
>>
>> Esa
>>
>> -Original Message-
>> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On 
>> Behalf Of Linda Alvord
>> Sent: Wednesday, November 1, 2017 1:49 PM
&

Re: [Jprogramming] Partitions

2017-11-01 Thread Linda Alvord
This is another way to get to Raul's ideas in a tacit soluion:

comb4=: 13 :'|.I.(x=+/"1#:i.x^y)##:i.x^y'
   2 comb4 4
0 1
0 2
0 3
1 2
1 3
2 3
   comb4
[: |. [: I. ([ = [: +/"1 [: #: [: i. ^) # [: #: [: i. ^
   
Linda


-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Lippu Esa
Sent: Wednesday, November 1, 2017 5:53 PM
To: 'programm...@jsoftware.com' 
Subject: Re: [Jprogramming] Partitions

Thank you, Raul! I knew that there would be a tacit solution. But comb is 
better with big y as you said.

Esa

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Wednesday, November 1, 2017 11:26 PM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

comb3 performs well for y<10, but bogs down (compared to comb) for y>10

That said, a=.[: #: [: i. 2 ^ ] is a verb, not a noun.

That said, you do not have to compute a twice, for example:

comb3a=:   [ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]

(but comb3a is still slower than comb, when I time it, for y>10)

Thanks,

-- 
Raul


On Wed, Nov 1, 2017 at 4:52 PM, Lippu Esa  wrote:
> Yes, interesting! Thank you Linda.
>
> Just for practice, I tried to isolate the common part: [: #: [: i. 2 ^ ] but 
> had to use a noun as didn't manage to find a tacit solution.
>
> comb3=:([ = [: +/"1 a) ([: |. [: I. #) a=.[: #: [: i. 2 ^ ]
>
> Anyone?
>
> Esa
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
> Of Linda Alvord
> Sent: Wednesday, November 1, 2017 1:49 PM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Partitions
>
> Maybe you will find comb2 interesfing.
>
> load 'stats'
>
> comb2=:([ = [: +/"1 [: #: [: i. 2 ^ ]) ([: |. [: I. #) [: #: [: i. 2 ^ ]
>
> (4 comb2 7)-:4 comb 7
>
>
> Li nda
>
>
>
> Get Outlook for Android<https://aka.ms/ghei36>
>
> ____
> From: Programming  on behalf of 
> Erling Hellenäs 
> Sent: Wednesday, November 1, 2017 7:13:33 AM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Partitions
>
> Hi all!
>
> parRuskey comparison.
>
> Mike Days new version is slightly faster than the Frank Ruskey version.
>
> Cheers,
>
> Erling Hellenäs
>
> --Project--
>
> ts=: 6!:2 , 7!:2@]   NB. Time and space
>
> normalize=: 3 :0
> NB. The idea here is to normalize the representation so that
> NB. the copies are adjacent.
> NB. Sort buckets within each combination after first item in each bucket
> v31=.(] /: {.&.>)"1 y
> NB. Sort buckets within each combination after number of items in each
> bucket
> v4=.(] /: #&.>)"1 v31
> NB. Sort
> v5=. /:~  v4
> (/: #&.> v5){ v5
> )
>
> compare=: -:&:normalize
>
> NB. parELMDE for comparison
>
> parELMDE=: 4 : 0
> a =. ~. i.~"1 iy #: i. */ iy =. (1+i.x),(y-x)$x
> a =. a#~ x = #@~."1 a
> sort a  )
>
> NB. Original Frank Ruskey version.
>
> parRuskey =: 4 : 0
> a=: i. y
> r=: (0,y)$0
> (x-1) S y-1
> r  )
>
>
> S =: 4 : 0
> if. x=y do.
>r=:r,a
> else.
>for_i. i.x+1 do.
>  a=: i y } a
>  x S y-1
>  a=: y y } a
>end.
>if. x > 0 do.
>  a=: x y } a
>  (x-1) S y-1
>  a=: y y } a
>end.
> end.
> )
>
> NB. Slightly modified by Erling to remove global variables.
>
> parRuskeyE =: 4 : 0
> r=. (i.y) SE (x-1);y-1
> r  )
>
> SE =: 4 : 0
> 'k n' =. y
> r=. 0{.,:x
> if. k=n do.
>r=.,:x
> else.
>for_i. i.k+1 do.
>  r=.r, (i n } x) SE k;n-1
> end.
>if. k > 0 do.
>  r=.r, (k n } x) SE (k-1);n-1
>end.
> end.
> r
> )
>
> NB. Modified by Mike Day
>
> parRuskeyMD =: 4 : 0
> NB. L =: 0$~0, 2 + y   NB. debug/understand array of call parameters
> r=. (i.y) SMD (x-1),y-1
> NB. R =: r NB. debug/understand output
> r  )
>
> SMD =: 4 : 0
> NB. L =: L, y, x   NB. debug/understand array of call parameters
> 'k n' =. y
> a =.x
> r =. 0$~ 0, #a
> if. k = n - 1 do.  NB. replace repeated calls with k = n (on entry)
>r =. (i.k+1) n }"0 1 (k+1)# ,:a  NB. don't need to use recursion here!
> else.
>   NB. is there a way to avoid recursion here,  too?
>r =. r, ,/ (SMD&(k,n-1))"1 (i.k+1) n }"0 1 a NB.apply "1 instead of
> do loop
> end.
> if. k > 0 do.
>r=.r, (k n } a) SMD (k-1),n-1
> end.
> r
> )
>
> x=:1
> y=:1
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x

Re: [Jprogramming] Partitions

2017-11-01 Thread Lippu Esa
Thank you, Raul! I knew that there would be a tacit solution. But comb is 
better with big y as you said.

Esa

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Raul Miller
Sent: Wednesday, November 1, 2017 11:26 PM
To: Programming forum 
Subject: Re: [Jprogramming] Partitions

comb3 performs well for y<10, but bogs down (compared to comb) for y>10

That said, a=.[: #: [: i. 2 ^ ] is a verb, not a noun.

That said, you do not have to compute a twice, for example:

comb3a=:   [ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]

(but comb3a is still slower than comb, when I time it, for y>10)

Thanks,

-- 
Raul


On Wed, Nov 1, 2017 at 4:52 PM, Lippu Esa  wrote:
> Yes, interesting! Thank you Linda.
>
> Just for practice, I tried to isolate the common part: [: #: [: i. 2 ^ ] but 
> had to use a noun as didn't manage to find a tacit solution.
>
> comb3=:([ = [: +/"1 a) ([: |. [: I. #) a=.[: #: [: i. 2 ^ ]
>
> Anyone?
>
> Esa
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
> Of Linda Alvord
> Sent: Wednesday, November 1, 2017 1:49 PM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Partitions
>
> Maybe you will find comb2 interesfing.
>
> load 'stats'
>
> comb2=:([ = [: +/"1 [: #: [: i. 2 ^ ]) ([: |. [: I. #) [: #: [: i. 2 ^ ]
>
> (4 comb2 7)-:4 comb 7
>
>
> Li nda
>
>
>
> Get Outlook for Android<https://aka.ms/ghei36>
>
> 
> From: Programming  on behalf of 
> Erling Hellenäs 
> Sent: Wednesday, November 1, 2017 7:13:33 AM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Partitions
>
> Hi all!
>
> parRuskey comparison.
>
> Mike Days new version is slightly faster than the Frank Ruskey version.
>
> Cheers,
>
> Erling Hellenäs
>
> --Project--
>
> ts=: 6!:2 , 7!:2@]   NB. Time and space
>
> normalize=: 3 :0
> NB. The idea here is to normalize the representation so that
> NB. the copies are adjacent.
> NB. Sort buckets within each combination after first item in each bucket
> v31=.(] /: {.&.>)"1 y
> NB. Sort buckets within each combination after number of items in each
> bucket
> v4=.(] /: #&.>)"1 v31
> NB. Sort
> v5=. /:~  v4
> (/: #&.> v5){ v5
> )
>
> compare=: -:&:normalize
>
> NB. parELMDE for comparison
>
> parELMDE=: 4 : 0
> a =. ~. i.~"1 iy #: i. */ iy =. (1+i.x),(y-x)$x
> a =. a#~ x = #@~."1 a
> sort a  )
>
> NB. Original Frank Ruskey version.
>
> parRuskey =: 4 : 0
> a=: i. y
> r=: (0,y)$0
> (x-1) S y-1
> r  )
>
>
> S =: 4 : 0
> if. x=y do.
>r=:r,a
> else.
>for_i. i.x+1 do.
>  a=: i y } a
>  x S y-1
>  a=: y y } a
>end.
>if. x > 0 do.
>  a=: x y } a
>  (x-1) S y-1
>  a=: y y } a
>end.
> end.
> )
>
> NB. Slightly modified by Erling to remove global variables.
>
> parRuskeyE =: 4 : 0
> r=. (i.y) SE (x-1);y-1
> r  )
>
> SE =: 4 : 0
> 'k n' =. y
> r=. 0{.,:x
> if. k=n do.
>r=.,:x
> else.
>for_i. i.k+1 do.
>  r=.r, (i n } x) SE k;n-1
> end.
>if. k > 0 do.
>  r=.r, (k n } x) SE (k-1);n-1
>end.
> end.
> r
> )
>
> NB. Modified by Mike Day
>
> parRuskeyMD =: 4 : 0
> NB. L =: 0$~0, 2 + y   NB. debug/understand array of call parameters
> r=. (i.y) SMD (x-1),y-1
> NB. R =: r NB. debug/understand output
> r  )
>
> SMD =: 4 : 0
> NB. L =: L, y, x   NB. debug/understand array of call parameters
> 'k n' =. y
> a =.x
> r =. 0$~ 0, #a
> if. k = n - 1 do.  NB. replace repeated calls with k = n (on entry)
>r =. (i.k+1) n }"0 1 (k+1)# ,:a  NB. don't need to use recursion here!
> else.
>   NB. is there a way to avoid recursion here,  too?
>r =. r, ,/ (SMD&(k,n-1))"1 (i.k+1) n }"0 1 a NB.apply "1 instead of
> do loop
> end.
> if. k > 0 do.
>r=.r, (k n } a) SMD (k-1),n-1
> end.
> r
> )
>
> x=:1
> y=:1
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> NB.(x parELMDE y) compare x parRuskeyMD y - Error
> x=:1
> y=:2
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> (x parELMDE y) compare x parRuskeyMD y
> x=:2
> y=:3
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> (x parELMDE y) compare x parRuskeyMD y
> x=:3
> y=:5
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> (x parE

Re: [Jprogramming] Partitions

2017-11-01 Thread Raul Miller
comb3 performs well for y<10, but bogs down (compared to comb) for y>10

That said, a=.[: #: [: i. 2 ^ ] is a verb, not a noun.

That said, you do not have to compute a twice, for example:

comb3a=:   [ ((= +/"1) |.@:I.@# ]) 2 #:@i.@:^ ]

(but comb3a is still slower than comb, when I time it, for y>10)

Thanks,

-- 
Raul


On Wed, Nov 1, 2017 at 4:52 PM, Lippu Esa  wrote:
> Yes, interesting! Thank you Linda.
>
> Just for practice, I tried to isolate the common part: [: #: [: i. 2 ^ ] but 
> had to use a noun as didn't manage to find a tacit solution.
>
> comb3=:([ = [: +/"1 a) ([: |. [: I. #) a=.[: #: [: i. 2 ^ ]
>
> Anyone?
>
> Esa
>
> -Original Message-
> From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
> Of Linda Alvord
> Sent: Wednesday, November 1, 2017 1:49 PM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Partitions
>
> Maybe you will find comb2 interesfing.
>
> load 'stats'
>
> comb2=:([ = [: +/"1 [: #: [: i. 2 ^ ]) ([: |. [: I. #) [: #: [: i. 2 ^ ]
>
> (4 comb2 7)-:4 comb 7
>
>
> Li nda
>
>
>
> Get Outlook for Android<https://aka.ms/ghei36>
>
> 
> From: Programming  on behalf of 
> Erling Hellenäs 
> Sent: Wednesday, November 1, 2017 7:13:33 AM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Partitions
>
> Hi all!
>
> parRuskey comparison.
>
> Mike Days new version is slightly faster than the Frank Ruskey version.
>
> Cheers,
>
> Erling Hellenäs
>
> --Project--
>
> ts=: 6!:2 , 7!:2@]   NB. Time and space
>
> normalize=: 3 :0
> NB. The idea here is to normalize the representation so that
> NB. the copies are adjacent.
> NB. Sort buckets within each combination after first item in each bucket
> v31=.(] /: {.&.>)"1 y
> NB. Sort buckets within each combination after number of items in each
> bucket
> v4=.(] /: #&.>)"1 v31
> NB. Sort
> v5=. /:~  v4
> (/: #&.> v5){ v5
> )
>
> compare=: -:&:normalize
>
> NB. parELMDE for comparison
>
> parELMDE=: 4 : 0
> a =. ~. i.~"1 iy #: i. */ iy =. (1+i.x),(y-x)$x
> a =. a#~ x = #@~."1 a
> sort a  )
>
> NB. Original Frank Ruskey version.
>
> parRuskey =: 4 : 0
> a=: i. y
> r=: (0,y)$0
> (x-1) S y-1
> r  )
>
>
> S =: 4 : 0
> if. x=y do.
>r=:r,a
> else.
>for_i. i.x+1 do.
>  a=: i y } a
>  x S y-1
>  a=: y y } a
>end.
>if. x > 0 do.
>  a=: x y } a
>  (x-1) S y-1
>  a=: y y } a
>end.
> end.
> )
>
> NB. Slightly modified by Erling to remove global variables.
>
> parRuskeyE =: 4 : 0
> r=. (i.y) SE (x-1);y-1
> r  )
>
> SE =: 4 : 0
> 'k n' =. y
> r=. 0{.,:x
> if. k=n do.
>r=.,:x
> else.
>for_i. i.k+1 do.
>  r=.r, (i n } x) SE k;n-1
> end.
>if. k > 0 do.
>  r=.r, (k n } x) SE (k-1);n-1
>end.
> end.
> r
> )
>
> NB. Modified by Mike Day
>
> parRuskeyMD =: 4 : 0
> NB. L =: 0$~0, 2 + y   NB. debug/understand array of call parameters
> r=. (i.y) SMD (x-1),y-1
> NB. R =: r NB. debug/understand output
> r  )
>
> SMD =: 4 : 0
> NB. L =: L, y, x   NB. debug/understand array of call parameters
> 'k n' =. y
> a =.x
> r =. 0$~ 0, #a
> if. k = n - 1 do.  NB. replace repeated calls with k = n (on entry)
>r =. (i.k+1) n }"0 1 (k+1)# ,:a  NB. don't need to use recursion here!
> else.
>   NB. is there a way to avoid recursion here,  too?
>r =. r, ,/ (SMD&(k,n-1))"1 (i.k+1) n }"0 1 a NB.apply "1 instead of
> do loop
> end.
> if. k > 0 do.
>r=.r, (k n } a) SMD (k-1),n-1
> end.
> r
> )
>
> x=:1
> y=:1
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> NB.(x parELMDE y) compare x parRuskeyMD y - Error
> x=:1
> y=:2
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> (x parELMDE y) compare x parRuskeyMD y
> x=:2
> y=:3
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> (x parELMDE y) compare x parRuskeyMD y
> x=:3
> y=:5
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> (x parELMDE y) compare x parRuskeyMD y
> x=:3
> y=:6
> (x parELMDE y) compare x parRuskey y
> (x parELMDE y) compare x parRuskeyE y
> (x parELMDE y) compare x parRuskeyMD y
>
> x=:5
> y=:10
> ts'x parRuskey y'
> ts'x parRuskeyE y'
> ts'x parRuskeyMD y'
>
>
> ---Output--

Re: [Jprogramming] Partitions

2017-11-01 Thread Lippu Esa
Yes, interesting! Thank you Linda.

Just for practice, I tried to isolate the common part: [: #: [: i. 2 ^ ] but 
had to use a noun as didn't manage to find a tacit solution.

comb3=:([ = [: +/"1 a) ([: |. [: I. #) a=.[: #: [: i. 2 ^ ]

Anyone?

Esa

-Original Message-
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of Linda Alvord
Sent: Wednesday, November 1, 2017 1:49 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Maybe you will find comb2 interesfing.

load 'stats'

comb2=:([ = [: +/"1 [: #: [: i. 2 ^ ]) ([: |. [: I. #) [: #: [: i. 2 ^ ]

(4 comb2 7)-:4 comb 7


Li nda



Get Outlook for Android<https://aka.ms/ghei36>


From: Programming  on behalf of 
Erling Hellenäs 
Sent: Wednesday, November 1, 2017 7:13:33 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Partitions

Hi all!

parRuskey comparison.

Mike Days new version is slightly faster than the Frank Ruskey version.

Cheers,

Erling Hellenäs

--Project--

ts=: 6!:2 , 7!:2@]   NB. Time and space

normalize=: 3 :0
NB. The idea here is to normalize the representation so that
NB. the copies are adjacent.
NB. Sort buckets within each combination after first item in each bucket
v31=.(] /: {.&.>)"1 y
NB. Sort buckets within each combination after number of items in each
bucket
v4=.(] /: #&.>)"1 v31
NB. Sort
v5=. /:~  v4
(/: #&.> v5){ v5
)

compare=: -:&:normalize

NB. parELMDE for comparison

parELMDE=: 4 : 0
a =. ~. i.~"1 iy #: i. */ iy =. (1+i.x),(y-x)$x
a =. a#~ x = #@~."1 a
sort a  0 do.
 a=: x y } a
 (x-1) S y-1
 a=: y y } a
   end.
end.
)

NB. Slightly modified by Erling to remove global variables.

parRuskeyE =: 4 : 0
r=. (i.y) SE (x-1);y-1
r  0 do.
 r=.r, (k n } x) SE (k-1);n-1
   end.
end.
r
)

NB. Modified by Mike Day

parRuskeyMD =: 4 : 0
NB. L =: 0$~0, 2 + y   NB. debug/understand array of call parameters
r=. (i.y) SMD (x-1),y-1
NB. R =: r NB. debug/understand output
r  0 do.
   r=.r, (k n } a) SMD (k-1),n-1
end.
r
)

x=:1
y=:1
(x parELMDE y) compare x parRuskey y
(x parELMDE y) compare x parRuskeyE y
NB.(x parELMDE y) compare x parRuskeyMD y - Error
x=:1
y=:2
(x parELMDE y) compare x parRuskey y
(x parELMDE y) compare x parRuskeyE y
(x parELMDE y) compare x parRuskeyMD y
x=:2
y=:3
(x parELMDE y) compare x parRuskey y
(x parELMDE y) compare x parRuskeyE y
(x parELMDE y) compare x parRuskeyMD y
x=:3
y=:5
(x parELMDE y) compare x parRuskey y
(x parELMDE y) compare x parRuskeyE y
(x parELMDE y) compare x parRuskeyMD y
x=:3
y=:6
(x parELMDE y) compare x parRuskey y
(x parELMDE y) compare x parRuskeyE y
(x parELMDE y) compare x parRuskeyMD y

x=:5
y=:10
ts'x parRuskey y'
ts'x parRuskeyE y'
ts'x parRuskeyMD y'


---Output---


x=:1
y=:1
(x parELMDE y) compare x parRuskey y
1
(x parELMDE y) compare x parRuskeyE y
1
NB.(x parELMDE y) compare x parRuskeyMD y - Error
x=:1
y=:2
(x parELMDE y) compare x parRuskey y
1
(x parELMDE y) compare x parRuskeyE y
1
(x parELMDE y) compare x parRuskeyMD y
1
x=:2
y=:3
(x parELMDE y) compare x parRuskey y
1
(x parELMDE y) compare x parRuskeyE y
1
(x parELMDE y) compare x parRuskeyMD y
1
x=:3
y=:5
(x parELMDE y) compare x parRuskey y
1
(x parELMDE y) compare x parRuskeyE y
1
(x parELMDE y) compare x parRuskeyMD y
1
x=:3
y=:6
(x parELMDE y) compare x parRuskey y
1
(x parELMDE y) compare x parRuskeyE y
1
(x parELMDE y) compare x parRuskeyMD y
1

x=:5
y=:10
ts'x parRuskey y'
0.204245 3.89459e7
ts'x parRuskeyE y'
0.316044 3.8954e7
ts'x parRuskeyMD y'
0.173341 3.8954e7


Cheers,


Erling Hellenäs


Den 2017-10-31 kl. 20:17, skrev 'Mike Day' via Programming:
> parRuskeynew =: 4 : 0
> NB. L =: 0$~0, 2 + y   NB. debug/understand array of call parameters
> r=. (i.y) Snew (x-1),y-1
> NB. R =: r NB. debug/understand output
> r  )
>
> Snew =: 4 : 0
> NB. L =: L, y, x   NB. debug/understand array of call parameters
> 'k n' =. y
> a =.x
> r =. 0$~ 0, #a
> if. k = n - 1 do.  NB. replace repeated calls with k = n (on entry)
>   r =. (i.k+1) n }"0 1 (k+1)# ,:a  NB. don't need to use recursion here!
> else.
>  NB. is there a way to avoid recursion here,  too?
>   r =. r, ,/ (Snew&(k,n-1))"1 (i.k+1) n }"0 1 a NB.apply "1 instead of
> do loop
> end.
> if. k > 0 do.
>   r=.r, (k n } a) Snew (k-1),n-1
> end.
> r
> )

--
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

  1   2   >