Looking for a variation of the 'cmat' DFN

For users of dfns, both novice and expert

Looking for a variation of the 'cmat' DFN

Postby PGilbert on Mon Jun 10, 2013 12:49 am

With the cmat DFN you can obtain the ⍺-combination matrix of ⍳⍵. I am looking for a DFN that will produce the following result:

1 2 3 4 6
1 2 3 5 8
1 2 4 7 8
1 3 6 7 8
1 4 5 6 7
2 3 4 5 7
2 5 6 7 8
3 4 5 6 8

where every 3 number combinations of ⍳8 (this would be equal to 3{⍵[⍺ cmat ⍴⍵]}⍳8 ) is present in the smallest amount possible of permutations of 5 numbers. Ideally all three argument (3, 8 and 5) should be a variable.

Thanks in advance for any help.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Looking for a variation of the 'cmat' DFN

Postby Roger|Dyalog on Mon Jun 10, 2013 4:56 am

How do you know that the table you provided has the smallest number of combinations of 5 numbers with that property? I assume you meant combinations rather than permutations because the ordering within each row does not seem to matter.
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Looking for a variation of the 'cmat' DFN

Postby Roger|Dyalog on Mon Jun 10, 2013 6:20 am

cspan p q n is a subset of q cmat n which "spans" p cmat n.

Code: Select all
cspan←{                                                                                     
     p q n ← ⍵                                                                                   
     c ← p cmat n                                                                               
     d ← q cmat n                                                                               
     j ← p cmat q                                                                               
     m ← p!n                                                                                     
                                                                                               
     iteration ← {c d←⍺ ⋄ 0∊⍴c:⍵ ⋄ ((~(↓c)∊↓d[i;j])⌿c)((i≠⍳1↑⍴d)⌿d) ∇ ⍵⍪d[i←m⍳⌈/m←+/(↓d[;j])∊↓c;]}
     cover     ← {⍬⍴⍴∪↓,[⎕io+0 1]⍵[;j]}                                                             
     reduce    ← {∧/m>k←cover¨⊂[⎕io+1 2]⍵[i←⊃cmat/¯1 0+1↑⍴⍵;]:⍵ ⋄ ∇ ⍵[i[k⍳m;];]}                   
                                                                                               
     {⍵[⍋⍵;]} reduce (c d) iteration 0⌿d                                                         
 }

For example:

      cspan 3 5 8
1 2 3 4 7
1 2 3 5 6
1 2 6 7 8
1 3 4 6 8
1 4 5 7 8
2 3 5 7 8
2 4 5 6 8
3 4 5 6 7

My previous question remains: I don't know that the result of cspan is minimal.
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Looking for a variation of the 'cmat' DFN

Postby PGilbert on Mon Jun 10, 2013 2:56 pm

Many thanks Roger this answer my question, and you are correct the first post should read combinations instead of permutations.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Looking for a variation of the 'cmat' DFN

Postby Roger|Dyalog on Mon Jun 10, 2013 5:45 pm

Functions cover and reduce:

Code: Select all
     cover  ← {⍬⍴⍴∪↓,[⎕io+0 1]⍵[;j]}                                                             
     reduce ← {∧/m>k←cover¨⊂[⎕io+1 2]⍵[i←⊃cmat/¯1 0+1↑⍴⍵;]:⍵ ⋄ ∇ ⍵[i[k⍳m;];]}

can be made clearer and shorter:

Code: Select all
     cover  ← {⍬⍴⍴∪,↓⍵[(⍳⍬⍴⍴⍵)~⍺;j]}                                                             
     reduce ← {⍵[i~m⍳⍨(i←⍳⍬⍴⍴⍵)cover¨⊂⍵;]}⍣≡

In Dyalog v14.0 there will be a new monad ≢⍵ ←→ ⍬⍴(⍴⍵),1. With that, all the uses of ⍬⍴⍴ in cspan can be made clear and shorter and:

Code: Select all
 cspan←{                                                                                     
     p q n ← ⍵                                                                                   
     c ← p cmat n                                                                               
     d ← q cmat n                                                                               
     j ← p cmat q                                                                               
     m ← p!n                                                                                     
                                                                                               
     iteration ← {c d←⍺ ⋄ 0=≢c:⍵ ⋄ ((~(↓c)∊↓d[i;j])⌿c)((i≠⍳≢d)⌿d) ∇ ⍵⍪d[i←m⍳⌈/m←+/(↓d[;j])∊↓c;]}
     cover     ← {≢∪,↓⍵[(⍳≢⍵)~⍺;j]}                                                                 
     reduce    ← {⍵[i~m⍳⍨(i←⍳≢⍵)cover¨⊂⍵;]}⍣≡                                                       
                                                                                               
     {⍵[⍋⍵;]} reduce (c d) iteration 0⌿d                                                         
 }                                                                                             
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am


Return to Functional Programming

Who is online

Users browsing this forum: No registered users and 1 guest