one possible traslation in APL of the set build from one other set could be: the key for me it is
I←{(⍺⍺¨⍵)/⍵}
in math mode { x : xeA and P(x)} would be in APL just P I A
in math mode {f(x): xeA and P(x)} would be in APL just f P I A
c is count v is the function return the first set , t return the second set
c←{+/⍵=⍺}
v←{∪{0≠2∣⍵c a}I a←⍵}
t←{a←⍵⋄b←{0≠⌊2÷⍨⍵c a}I∪⍵⋄b,¨{⌊2÷⍨⍵c a}¨b}
f←{(⊂t⍵),⊂v⍵}
⎕fmt f 1 2 1
┌2────────────┐
│┌1─────┐ ┌1─┐│
││┌2───┐│ │ 2││
│││ 1 1││ └~─┘│
││└~───┘2 │
│└∊─────┘ 3