Difference between revisions of "Multisets"
(Created page with "== Definition == In mathematics, an unordered collection of distinct objects is called a [http://en.wikipedia.org/wiki/Set_%28mathematics%29 set]. If duplicates are allowed, the...") 

Line 1:  Line 1:  
−  ==  +  == Introduction == 
−  +  
+  The concept of a multiset is applied to the set function symbols in APL which yields unexpected benefits of additional and useful functions. The multisetsensitive primitives are discussed along with their algorithms.  
+  
+  For decades the several set symbols have languished on APL keyboards either unused or underused. Sometimes the vendor has assigned no dyadic function to that symbol and sometimes the assigned function isn't very useful. All vendors have implemented Set Difference (<apll>L~R</apll>), one has implemented Set Union (<apll>L∪R</apll>) and Set Intersection (<apll>L∩R</apll>), and, up to now, no APL vendor has implemented the missing fourth function.  
+  
+  Part of the reason the socalled set functions in APL are in an odd state is that they are defined on sets, but implemented on nonsets.  
+  
+  From Wikipedia, “in computer science, a set is an abstract data structure that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set”.  
+  
+  However, APL implementations of the set functions don't enforce the “no repeated value” requirement. Moreover, allowing repeated values is quite useful giving rise to useful idioms such as <apll>L~' '</apll> to remove all blanks from a vector.  
+  
+  Interestingly, sets with repeated values have a long history in mathematics and are known as multisets. The usual set functions have identical counterparts as multiset functions with the same definitions except the multiset version takes into account the multiplicity of the unique values. Multisets in an APL context are scalars or vectors of arbitrary items with various operations defined on them (monadically), but mostly between them (dyadically).  
+  
+  More formally, if <apll>L</apll> and <apll>R</apll> are multisets and the function <apll>m(x,M)</apll> returns the multiplicity of element <apll>x</apll> in the multiset <apll>M</apll>, then  
+  
+  * The Union of multisets (<apll>L∪R</apll>) is the multiset whose unique elements are the unique elements of <apll>L,R</apll> where the multiplicity of element <apll>x</apll> in the result is the larger of <apll>m(x,L)</apll> and <apll>m(x,R)</apll>,  
+  * The Intersection of multisets (<apll>L∩R</apll>) is the multiset similar to Union, but with larger replaced by smaller, and  
+  * The Difference (also called Asymmetric Difference and Relative Complement) of multisets (<apll>L~R</apll>) is similar to Union and Intersection, but where the multiplicity calculation is <apll>max(0,m(x,L)m(x,R))</apll>, that is if element <apll>x</apll> is in the result if it occurs more in <apll>L</apll> than in <apll>R</apll> with multiplicity of the difference of the left and right multiplicities.  
+  
+  For multisets with no repeated elements, the multiset function and the corresponding set function produce the same results.  
== Example ==  == Example ==  
Line 7:  Line 26:  
Two useful properties of a multiset (from which the original multiset may be reconstructed) is the '''Underlying Set of Unique Elements''' along their '''Multiplicities'''. For the two multisets above the two properties are  Two useful properties of a multiset (from which the original multiset may be reconstructed) is the '''Underlying Set of Unique Elements''' along their '''Multiplicities'''. For the two multisets above the two properties are  
−  
<table summary="">  <table summary="">  
<tr>  <tr>  
−  <td><apll> 3  +  <td><apll> 2 3 5<br /> 3 1 2</apll></td> 
<td valign="top"> and </td>  <td valign="top"> and </td>  
−  <td><apll> 2  +  <td><apll> 2 3 5 7<br /> 2 1 2 1</apll></td> 
−  <tr>  +  </tr> 
</table>  </table>  
Two common operations performed between multisets are '''Union''' and '''Intersection'''.  Two common operations performed between multisets are '''Union''' and '''Intersection'''.  
−  '''Multiset Union''' on <apll>L</apll> and <apll>R</apll> is defined as the  +  '''Multiset Union''' on <apll>L</apll> and <apll>R</apll> is defined as the Multiset whose underlying set is the set union of the underlying sets of <apll>L</apll> and <apll>R</apll>, and whose multiplicities are the larger of the multiplicities of the corresponding elements of <apll>L</apll> and <apll>R</apll>. 
−  For <apll>L←2 2 2 3 5 5</apll> and <apll>R←2 2 3 5 5 7</apll> the  +  For <apll>L←2 2 2 3 5 5</apll> and <apll>R←2 2 3 5 5 7</apll> the Multiset Union is <apll>2 2 2 3 5 5 7</apll>. Note that, for example, there are three <apll>2</apll>s in the result because that is the larger of the number of <apll>2</apll>s in <apll>L</apll> (3) and <apll>R</apll> (2). 
−  '''Multiset Intersection''' on <apll>L</apll> and <apll>R</apll> is defined the same as for '''Multiset Union''' except that the smaller of the multiplicities is taken instead of the larger. For the two  +  '''Multiset Intersection''' on <apll>L</apll> and <apll>R</apll> is defined the same as for '''Multiset Union''' except that the smaller of the multiplicities is taken instead of the larger. For the two Multisets above, the Multiset Intersection is <apll>2 2 3 5 5</apll> where there are two <apll>2</apll>s in the result because that's the smaller of the number of <apll>2</apll>s in <apll>L</apll> (3) and <apll>R</apll> (2), and there are no <apll>7</apll>s in the result because that's the smaller of the number of <apll>7</apll>s in <apll>L</apll> (0) and <apll>R</apll> (1). 
−  Interestingly, in the context of prime factorization, Multiset Union is the direct  +  Interestingly, in the context of prime factorization, Multiset Union is the direct analog of '''Least Common Multiple''' and Multiset Intersection is '''Greatest Common Divisor'''. Using the notation of <apll>∪⍦</apll> for Multiset Union and <apll>∩⍦</apll> for Multiset Intersection, then for the two Multisets above, 
<apll>L∪⍦R ←→ 2 2 2 3 5 5 7</apll> and<br /><apll>L∩⍦R ←→ 2 2 3 5 5</apll>  <apll>L∪⍦R ←→ 2 2 2 3 5 5 7</apll> and<br /><apll>L∩⍦R ←→ 2 2 3 5 5</apll>  
Line 40:  Line 58:  
×/L∩⍦R<br />  ×/L∩⍦R<br />  
300</apll>  300</apll>  
+  
+  Moreover, using <apll>P←2 2 2 3 3 5 7</apll> and <apll>Q←2 2 3 5</apll> where as in this case <apll>P</apll> is a superset of <apll>Q</apll> then '''Multiset Asymmetric Difference''' is the direct analog of division. That is,  
+  
+  <apll> P~⍦Q<br />  
+  2 3 7<br />  
+  ×/P~⍦Q<br />  
+  42<br />  
+  (×/P)÷×/Q<br />  
+  42</apll>  
+  
+  Other examples illustrate the distinction between the multiset and nonmultiset functions  
+  
+  <apll> 'mississippi'~'miss'<br />  
+  pp<br />  
+  'mississippi'~⍦'miss'<br />  
+  issippi</apll>  
+  
+  == Subscripts ==  
+  
+  One way to understand Multisets and the operations performed on them is to view them with equal elements having unique subscripts. That is, for the Multisets <apll>2 2 2 3 5 5</apll> and <apll>2 2 3 5 5 7</apll>, write them as  
+  {  
+    
+  <apll>2</apll><sub>1</sub>  
+  <apll>2</apll><sub>2</sub>  
+  <apll>2</apll><sub>3</sub>  
+  <apll>3</apll><sub>1</sub>  
+  <apll>5</apll><sub>1</sub>  
+  <apll>5</apll><sub>2</sub>  
+    
+    
+  and  
+    
+  <apll>2</apll><sub>1</sub>  
+  <apll>2</apll><sub>2</sub>  
+    
+  <apll>3</apll><sub>1</sub>  
+  <apll>5</apll><sub>1</sub>  
+  <apll>5</apll><sub>2</sub>  
+  <apll>7</apll><sub>1</sub>  
+  }  
+  Now Multiset Union reduces to simple union where only one copy of like elements is kept, and similarly for Multiset Intersection. That is,  
+  {  
+    
+  <apll>L</apll>  
+    
+  <apll>←</apll>  
+    
+  <apll>2</apll><sub>1</sub>  
+  <apll>2</apll><sub>2</sub>  
+  <apll>2</apll><sub>3</sub>  
+  <apll>3</apll><sub>1</sub>  
+  <apll>5</apll><sub>1</sub>  
+  <apll>5</apll><sub>2</sub>  
+    
+  <apll>R</apll>  
+    
+  <apll>←</apll>  
+    
+  <apll>2</apll><sub>1</sub>  
+  <apll>2</apll><sub>2</sub>  
+    
+  <apll>3</apll><sub>1</sub>  
+  <apll>5</apll><sub>1</sub>  
+  <apll>5</apll><sub>2</sub>  
+  <apll>7</apll><sub>1</sub>  
+    
+  <apll>L∪⍦R</apll>  
+    
+  <apll>←→</apll>  
+    
+  <apll>2</apll><sub>1</sub>  
+  <apll>2</apll><sub>2</sub>  
+  <apll>2</apll><sub>3</sub>  
+  <apll>3</apll><sub>1</sub>  
+  <apll>5</apll><sub>1</sub>  
+  <apll>5</apll><sub>2</sub>  
+  <apll>7</apll><sub>1</sub>  
+    
+  <apll>L∩⍦R</apll>  
+    
+  <apll>←→</apll>  
+    
+  <apll>2</apll><sub>1</sub>  
+  <apll>2</apll><sub>2</sub>  
+    
+  <apll>3</apll><sub>1</sub>  
+  <apll>5</apll><sub>1</sub>  
+  <apll>5</apll><sub>2</sub>  
+  }  
+  
+  == Missing Function ==  
+  
+  To see if we have covered all of the possible set/multiset results, look at the usual Venn diagram for two sets – all seven results (excluding the empty set) appear as follows:  
+  
+  {  
+    
+  <apll>L∪R</apll>  
+    
+  [[image:Venn123.png40px]]  
+    
+  Union  
+    
+  <apll>L,R~L</apll>  
+    
+  <apll>L∩R</apll>  
+    
+  [[image:Venn2.png40px]]  
+    
+  Intersection  
+    
+  <apll>L~L~R</apll>  
+    
+  <apll>L~R</apll>  
+    
+  [[image:Venn1.png40px]]  
+    
+  Asymmetric Difference Left  
+    
+  <apll>L~R</apll>  
+    
+  <apll>R~L</apll>  
+    
+  [[image:Venn3.png40px]]  
+    
+  Asymmetric Difference Right  
+    
+  <apll>R~L</apll>  
+    
+  <apll>L</apll>  
+    
+  [[image:Venn12.png40px]]  
+    
+  Left  
+    
+  <apll>L</apll>  
+    
+  <apll>R</apll>  
+    
+  [[image:Venn23.png40px]]  
+    
+  Right  
+    
+  <apll>R</apll>  
+    
+  <apll>L∆R</apll>  
+    
+  [[image:Venn13.png40px]]  
+    
+  Symmetric Difference  
+    
+  <apll>(L~R)∪R~L</apll>  
+  }  
+  
+  The last diagram shows the missing function along with its name and effect. The mathematical symbol for this function is delta (<apll>∆</apll>), however because old APL programs use this symbol as another alphabetic character, we use the Section symbol (<apll>§</apll>) instead.  
+  
+  
+  
+  
+  
== Notation ==  == Notation ==  
−  We slipped in a symbol in the  +  We slipped in a new symbol in the examples above that needs to be explained. There are a dozen or so APL primitive functions we'd like to define on Multisets. One way to do this is to come up with a dozen new symbols to represent those Multiset functions; another is to define a single '''Multiset Operator''' that can be applied to the APL primitives which is the approach taken here, and that symbol is (<apll>⍦</apll>) which can be typed with <b>Alt'm'</b>, a keystroke previously used for the stile symbol (<apll></apll>) which was duplicated elsewhere on the keyboard. This operator is different from previous operators in APL in that it applies to a select set of primitive functions and no others — no system functions, no userdefined functions, and no derived functions. In that sense it's more like an [http://jsoftware.com/help/dictionary/dict1.htm inflection] such as how J uses <apll>.</apll> and <apll>:</apll>. Nonetheless, it is a (monadic) operator in the full mathematical (and APL) sense of it taking a function as an operand and returning a (derived) function. 
+  The APL functions defined on Multisets are as follows:  
+  <table summary="">  
+  <tr>  
+  <td><apll>L∪⍦R</apll></td> <td> </td> <td>Multiset Union</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L∩⍦R</apll></td> <td> </td> <td>Multiset Intersection</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L~⍦R</apll></td> <td> </td> <td>Multiset Asymmetric Difference</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L§⍦R</apll></td> <td> </td> <td>Multiset Symmetric Difference</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L⍳⍦R</apll></td> <td> </td> <td>Multiset Index Of</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L∊⍦R</apll></td> <td> </td> <td>Multiset Member Of</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L≡⍦R</apll></td> <td> </td> <td>Multiset Match</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L≢⍦R</apll></td> <td> </td> <td>Multiset Mismatch (same as <apll>~L≡⍦R</apll>)</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L⊂⍦R</apll></td> <td> </td> <td>Multiset Proper Subset Of</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L⊆⍦R</apll></td> <td> </td> <td>Multiset Subset Of</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L⊃⍦R</apll></td> <td> </td> <td>Multiset Proper Superset Of</td>  
+  </tr>  
+  <tr>  
+  <td><apll>L⊇⍦R</apll></td> <td> </td> <td>Multiset Superset Of</td>  
+  </tr>  
+  <tr>  
+  <td><apll> ∪⍦R</apll></td> <td> </td> <td>Multiset Multiplicities (<apll>⍴∪⍦R ←→ ⍴∪R</apll>)</td>  
+  </tr>  
+  </table>  
+  == Multiset Member Of and Index Of ==  
+  The key to understanding the meaning of the Multiset Operator as it is applied to the above APL primitive functions is Multiset Member Of (<apll>∊⍦</apll>), so we'll investigate that first.  
+  Using the subscript approach above the definition is straightforward,  
+  {  
+    
+  <apll>L</apll>  
+    
+  <apll>←</apll>  
+    
+  <apll>2</apll><sub>1</sub>  
+  <apll>2</apll><sub>2</sub>  
+  <apll>2</apll><sub>3</sub>  
+  <apll>3</apll><sub>1</sub>  
+  <apll>5</apll><sub>1</sub>  
+  <apll>5</apll><sub>2</sub>  
+    
+  <apll>R</apll>  
+    
+  <apll>←</apll>  
+    
+  <apll>2</apll><sub>1</sub>  
+  <apll>2</apll><sub>2</sub>  
+    
+  <apll>3</apll><sub>1</sub>  
+  <apll>5</apll><sub>1</sub>  
+  <apll>5</apll><sub>2</sub>  
+  <apll>7</apll><sub>1</sub>  
+    
+  <apll>L∊⍦R</apll>  
+    
+  <apll>←→</apll>  
+    
+  <apll>1</apll>  
+  <apll>1</apll>  
+  <apll>0</apll>  
+  <apll>1</apll>  
+  <apll>1</apll>  
+  <apll>1</apll>  
+  }  
+  again, matching like elements with like elements between the two arguments.  
+  We'll use this definition many times over in defining how the Multiset Operator applies to various APL primitive functions.  
+  In a similar manner, Multiset Index Of can be understood best by writing the two arguments with subscripts. For a more detailed coverage of this see [http://www.sudleyplace.com/APL/AnatomyOfAnIdiom.ahtml Anatomy of An Idiom].  
+  == APL Definitions ==  
+  
+  Each of the above dyadic Multiset functions has a simple analog in a nonMultiset context:  
+  
+  <table summary="">  
+  <tr>  
+  <td style="fontweight: bold;" valign="bottom">Function<br /><apll> <i>f</i></apll></td>  
+  <td style="fontweight: bold;" valign="bottom"> </td>  
+  <td style="fontweight: bold;" valign="bottom">NonMultiset<br />Definition<br /><apll>L <i>f</i> R</apll></td>  
+  <td style="fontweight: bold;" valign="bottom"> </td>  
+  <td style="fontweight: bold;" valign="bottom">Multiset<br />Definition<br /><apll>L <i>f</i>⍦ R</apll></td>  
+  </tr>  
+  <tr>  
+  <td colspan="5"><hr /></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ∪</apll></td> <td> </td> <td><apll>L,R~L</apll></td> <td> </td> <td><apll>L,R~⍦L</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ∩</apll></td> <td> </td> <td><apll>(L∊R)/L</apll></td> <td> </td> <td><apll>(L∊⍦R)/L</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ~</apll></td> <td> </td> <td><apll>(~L∊R)/L</apll></td> <td> </td> <td><apll>(~L∊⍦R)/L</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> §</apll></td> <td> </td> <td><apll>(L~R),R~L</apll></td> <td> </td> <td><apll>(L~⍦R),R~⍦L</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ⍳</apll></td> <td> </td> <td><apll>L⍳R</apll></td> <td> </td> <td><apll>L⍳⍦R</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ∊</apll></td> <td> </td> <td><apll>L∊R</apll></td> <td> </td> <td><apll>L∊⍦R</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ≡</apll></td> <td> </td> <td><apll>((>L)≡>R)∧∧/L∊R</apll></td> <td> </td> <td><apll>((>L)≡>R)∧∧/L∊⍦R</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ≢</apll></td> <td> </td> <td><apll>~L≡R</apll></td> <td> </td> <td><apll>~L≡⍦R</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ⊂</apll></td> <td> </td> <td><apll>(L⊆R)∧L≢R</apll> †</td> <td> </td> <td><apll>(L⊆⍦R)∧L≢⍦R</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ⊆</apll></td> <td> </td> <td><apll>∧/L∊R</apll></td> <td> </td> <td><apll>∧/L∊⍦R</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ⊃</apll></td> <td> </td> <td><apll>(R⊆L)∧R≢L</apll> †</td> <td> </td> <td><apll>(R⊆⍦L)∧R≢⍦L</apll></td>  
+  </tr>  
+  <tr>  
+  <td><apll> ⊇</apll></td> <td> </td> <td><apll>∧/R∊L</apll></td> <td> </td> <td><apll>∧/R∊⍦L</apll></td>  
+  </tr>  
+  </table>  
+  † = This is the meaning this symbol would have as a set function if it didn't have another meaning in a nonMultiset context.  
+  Note that in every case the Multiset definition may be obtained from the nonMultiset definition by introducing the Multiset Operator at the appropriate place(s). Beyond the above explanations for Multiset Member Of and Multiset Index Of, all of the other Multiset definitions can be reduced to the definition of Multiset Member Of.  
+  Finishing out the list of Multiset functions, Multiset Multiplicities <apll>∪⍦R</apll> is defined to be <apll>¯2/⍸1,(2≠/R[⍋R⍳R]),1</apll>. For the two Multisets used above  
+  <apll>L←2 2 2 3 5 5</apll> and <apll>R←2 2 3 5 5 7</apll>  
+  {  
+    
+  <apll> (∪L),[0.5] ∪⍦L</apll>  
+    
+  <apll> (∪R),[0.5] ∪⍦R</apll>  
+    
+  <apll> 2 3 5</apll>  
+    
+  <apll> 2 3 5 7</apll>  
+    
+  <apll> 3 1 2</apll>  
+    
+  <apll> 2 1 1 1</apll>  
+  }  
−  
Revision as of 12:55, 6 February 2011
Contents
Introduction
The concept of a multiset is applied to the set function symbols in APL which yields unexpected benefits of additional and useful functions. The multisetsensitive primitives are discussed along with their algorithms.
For decades the several set symbols have languished on APL keyboards either unused or underused. Sometimes the vendor has assigned no dyadic function to that symbol and sometimes the assigned function isn't very useful. All vendors have implemented Set Difference (L~R), one has implemented Set Union (L∪R) and Set Intersection (L∩R), and, up to now, no APL vendor has implemented the missing fourth function.
Part of the reason the socalled set functions in APL are in an odd state is that they are defined on sets, but implemented on nonsets.
From Wikipedia, “in computer science, a set is an abstract data structure that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set”.
However, APL implementations of the set functions don't enforce the “no repeated value” requirement. Moreover, allowing repeated values is quite useful giving rise to useful idioms such as L~' ' to remove all blanks from a vector.
Interestingly, sets with repeated values have a long history in mathematics and are known as multisets. The usual set functions have identical counterparts as multiset functions with the same definitions except the multiset version takes into account the multiplicity of the unique values. Multisets in an APL context are scalars or vectors of arbitrary items with various operations defined on them (monadically), but mostly between them (dyadically).
More formally, if L and R are multisets and the function m(x,M) returns the multiplicity of element x in the multiset M, then
 The Union of multisets (L∪R) is the multiset whose unique elements are the unique elements of L,R where the multiplicity of element x in the result is the larger of m(x,L) and m(x,R),
 The Intersection of multisets (L∩R) is the multiset similar to Union, but with larger replaced by smaller, and
 The Difference (also called Asymmetric Difference and Relative Complement) of multisets (L~R) is similar to Union and Intersection, but where the multiplicity calculation is max(0,m(x,L)m(x,R)), that is if element x is in the result if it occurs more in L than in R with multiplicity of the difference of the left and right multiplicities.
For multisets with no repeated elements, the multiset function and the corresponding set function produce the same results.
Example
A common example of a multiset is the decomposition of an integer into its prime factors, each of which may occur multiple times. For example, 600 may be factored into the multiset 2 2 2 3 5 5, and 2100 into 2 2 3 5 5 7.
Two useful properties of a multiset (from which the original multiset may be reconstructed) is the Underlying Set of Unique Elements along their Multiplicities. For the two multisets above the two properties are
2 3 5 3 1 2 
and  2 3 5 7 2 1 2 1 
Two common operations performed between multisets are Union and Intersection.
Multiset Union on L and R is defined as the Multiset whose underlying set is the set union of the underlying sets of L and R, and whose multiplicities are the larger of the multiplicities of the corresponding elements of L and R.
For L←2 2 2 3 5 5 and R←2 2 3 5 5 7 the Multiset Union is 2 2 2 3 5 5 7. Note that, for example, there are three 2s in the result because that is the larger of the number of 2s in L (3) and R (2).
Multiset Intersection on L and R is defined the same as for Multiset Union except that the smaller of the multiplicities is taken instead of the larger. For the two Multisets above, the Multiset Intersection is 2 2 3 5 5 where there are two 2s in the result because that's the smaller of the number of 2s in L (3) and R (2), and there are no 7s in the result because that's the smaller of the number of 7s in L (0) and R (1).
Interestingly, in the context of prime factorization, Multiset Union is the direct analog of Least Common Multiple and Multiset Intersection is Greatest Common Divisor. Using the notation of ∪⍦ for Multiset Union and ∩⍦ for Multiset Intersection, then for the two Multisets above,
L∪⍦R ←→ 2 2 2 3 5 5 7 and
L∩⍦R ←→ 2 2 3 5 5
The Least Common Multiple of two original numbers ×/L ←→ 600 and ×/R ←→ 2100 is
(×/L)∧×/R
4200
×/L∪⍦R
4200
and the Greatest Common Divisor is
(×/L)∨×/R
300
×/L∩⍦R
300
Moreover, using P←2 2 2 3 3 5 7 and Q←2 2 3 5 where as in this case P is a superset of Q then Multiset Asymmetric Difference is the direct analog of division. That is,
P~⍦Q
2 3 7
×/P~⍦Q
42
(×/P)÷×/Q
42
Other examples illustrate the distinction between the multiset and nonmultiset functions
'mississippi'~'miss'
pp
'mississippi'~⍦'miss'
issippi
Subscripts
One way to understand Multisets and the operations performed on them is to view them with equal elements having unique subscripts. That is, for the Multisets 2 2 2 3 5 5 and 2 2 3 5 5 7, write them as
2_{1}  2_{2}  2_{3}  3_{1}  5_{1}  5_{2}  and  
2_{1}  2_{2}  3_{1}  5_{1}  5_{2}  7_{1} 
Now Multiset Union reduces to simple union where only one copy of like elements is kept, and similarly for Multiset Intersection. That is,
L  ←  2_{1}  2_{2}  2_{3}  3_{1}  5_{1}  5_{2}  
R  ←  2_{1}  2_{2}  3_{1}  5_{1}  5_{2}  7_{1}  
L∪⍦R  ←→  2_{1}  2_{2}  2_{3}  3_{1}  5_{1}  5_{2}  7_{1}  
L∩⍦R  ←→  2_{1}  2_{2}  3_{1}  5_{1}  5_{2} 
Missing Function
To see if we have covered all of the possible set/multiset results, look at the usual Venn diagram for two sets – all seven results (excluding the empty set) appear as follows:
L∪R  Error creating thumbnail: File missing

Union  L,R~L  
L∩R  Error creating thumbnail: File missing

Intersection  L~L~R  
L~R  Error creating thumbnail: File missing

Asymmetric Difference Left  L~R  
R~L  Error creating thumbnail: File missing

Asymmetric Difference Right  R~L  
L  Error creating thumbnail: File missing

Left  L  
R  Error creating thumbnail: File missing

Right  R  
L∆R  Error creating thumbnail: File missing

Symmetric Difference  (L~R)∪R~L 
The last diagram shows the missing function along with its name and effect. The mathematical symbol for this function is delta (∆), however because old APL programs use this symbol as another alphabetic character, we use the Section symbol (§) instead.
Notation
We slipped in a new symbol in the examples above that needs to be explained. There are a dozen or so APL primitive functions we'd like to define on Multisets. One way to do this is to come up with a dozen new symbols to represent those Multiset functions; another is to define a single Multiset Operator that can be applied to the APL primitives which is the approach taken here, and that symbol is (⍦) which can be typed with Alt'm', a keystroke previously used for the stile symbol () which was duplicated elsewhere on the keyboard. This operator is different from previous operators in APL in that it applies to a select set of primitive functions and no others — no system functions, no userdefined functions, and no derived functions. In that sense it's more like an inflection such as how J uses . and :. Nonetheless, it is a (monadic) operator in the full mathematical (and APL) sense of it taking a function as an operand and returning a (derived) function.
The APL functions defined on Multisets are as follows:
L∪⍦R  Multiset Union  
L∩⍦R  Multiset Intersection  
L~⍦R  Multiset Asymmetric Difference  
L§⍦R  Multiset Symmetric Difference  
L⍳⍦R  Multiset Index Of  
L∊⍦R  Multiset Member Of  
L≡⍦R  Multiset Match  
L≢⍦R  Multiset Mismatch (same as ~L≡⍦R)  
L⊂⍦R  Multiset Proper Subset Of  
L⊆⍦R  Multiset Subset Of  
L⊃⍦R  Multiset Proper Superset Of  
L⊇⍦R  Multiset Superset Of  
∪⍦R  Multiset Multiplicities (⍴∪⍦R ←→ ⍴∪R) 
Multiset Member Of and Index Of
The key to understanding the meaning of the Multiset Operator as it is applied to the above APL primitive functions is Multiset Member Of (∊⍦), so we'll investigate that first.
Using the subscript approach above the definition is straightforward,
L  ←  2_{1}  2_{2}  2_{3}  3_{1}  5_{1}  5_{2}  
R  ←  2_{1}  2_{2}  3_{1}  5_{1}  5_{2}  7_{1}  
L∊⍦R  ←→  1  1  0  1  1  1 
again, matching like elements with like elements between the two arguments.
We'll use this definition many times over in defining how the Multiset Operator applies to various APL primitive functions.
In a similar manner, Multiset Index Of can be understood best by writing the two arguments with subscripts. For a more detailed coverage of this see Anatomy of An Idiom.
APL Definitions
Each of the above dyadic Multiset functions has a simple analog in a nonMultiset context:
Function f 
NonMultiset Definition L f R 
Multiset Definition L f⍦ R 

∪  L,R~L  L,R~⍦L  
∩  (L∊R)/L  (L∊⍦R)/L  
~  (~L∊R)/L  (~L∊⍦R)/L  
§  (L~R),R~L  (L~⍦R),R~⍦L  
⍳  L⍳R  L⍳⍦R  
∊  L∊R  L∊⍦R  
≡  ((>L)≡>R)∧∧/L∊R  ((>L)≡>R)∧∧/L∊⍦R  
≢  ~L≡R  ~L≡⍦R  
⊂  (L⊆R)∧L≢R †  (L⊆⍦R)∧L≢⍦R  
⊆  ∧/L∊R  ∧/L∊⍦R  
⊃  (R⊆L)∧R≢L †  (R⊆⍦L)∧R≢⍦L  
⊇  ∧/R∊L  ∧/R∊⍦L 
† = This is the meaning this symbol would have as a set function if it didn't have another meaning in a nonMultiset context.
Note that in every case the Multiset definition may be obtained from the nonMultiset definition by introducing the Multiset Operator at the appropriate place(s). Beyond the above explanations for Multiset Member Of and Multiset Index Of, all of the other Multiset definitions can be reduced to the definition of Multiset Member Of.
Finishing out the list of Multiset functions, Multiset Multiplicities ∪⍦R is defined to be ¯2/⍸1,(2≠/R[⍋R⍳R]),1. For the two Multisets used above
L←2 2 2 3 5 5 and R←2 2 3 5 5 7
(∪L),[0.5] ∪⍦L  (∪R),[0.5] ∪⍦R  
2 3 5  2 3 5 7  
3 1 2  2 1 1 1 
Acknowledgments
The idea of defining Multisets in an APL context is due to Patrick Parks of APL2000, Inc.