Looking for a variation of the 'cmat' DFN
5 posts
• Page 1 of 1
Looking for a variation of the 'cmat' DFN
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.
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.
-
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
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
cspan p q n is a subset of q cmat n which "spans" p cmat n.
For example:
My previous question remains: I don't know that the result of cspan is minimal.
- 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
Many thanks Roger this answer my question, and you are correct the first post should read combinations instead of permutations.
-
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
Functions cover and reduce:
can be made clearer and shorter:
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
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
5 posts
• Page 1 of 1
Return to Functional Programming
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group