Talk:Symmetric difference: Difference between revisions

m
added a section header to the first topic to properly place the table-of-contents (TOC) --- (this happens more often than one would think).
m (added a section header to the first topic to properly place the table-of-contents (TOC) --- (this happens more often than one would think).)
 
(14 intermediate revisions by 4 users not shown)
Line 1:
== symmetric difference should ... ==
 
The symmetric difference should give one list which is the union of the two differences of the lists. The Perl example shows two lists. --[[User:Mwn3d|Mwn3d]] 23:19, 2 December 2009 (UTC)
 
Line 65 ⟶ 67:
 
::::::Yes, a note in each example using lists for input would work too. --[[User:Paddy3118|Paddy3118]] 16:58, 10 February 2010 (UTC)
 
::::::+1 --[[User:Rldrenth|Rldrenth]] 17:37, 10 February 2010 (UTC)
 
:: Paddy3118 wrote:<br />
Line 77 ⟶ 81:
 
:::Hi Rldrenth, ''"...then it is an error to call the function with a list containing duplicate elmeents."''. I would go further. An example should state how and why their algorithms can use lists instead of sets; or constrain arbitrary lists as part of their routine. --[[User:Paddy3118|Paddy3118]] 16:58, 10 February 2010 (UTC)
 
== REXX Version 2 ==
 
the task says
"If your code uses lists.." and I don't.
What is WRONG with my program (except for th items containing blanks (which is not in the requirements.
There is also no requirement to show the UNION of the sets.
Please remove the incorrect tag or be more specific. --[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 06:38, 16 December 2013 (UTC)
 
: The REXX version 2 ''does'' use a list of items (two lists, in fact). Any item is allowed to have blanks, the fact that none of the lists have names with special characters doesn't mean they aren't allowed. The REXX version 2 doesn't have blanks in the items, the blanks are separating the items (as delimiters). The REXX version 2 has words that are delimited by blanks instead of values within quotes, separated by commas. Because of the items are in a list, it should be able to handle duplicates (items) correctly. It doesn't. Try and add a duplicate item to both of the lists and observe the output. The list that version 2 uses is a list of words within a variable. That's a list. If they were a true set, then duplicates won't be a problem. So, again referring to note 1 (in the task requirements), introduce a duplicate (to each list), and observe if the duplicates are handled correctly. I agree with you there is no requirement to show the UNION of the sets. Perhaps you are referring to the optional part of the requirement: give the individual differences (symmetric difference of sets A and B). You may also want to peruse the GAP, Pike, and Prolog examples (among others), although all of those appear to use true SETs. The PL/I example also suffers from the same problem as the Rexx version 2, although the list is stored in a fixed array (which seems problematic that the array size is hard-coded), and each value has a varying length; it also can't handle duplicates in the lists. If a language can use a true SET(s), it automatically handles duplicates (essentially by ignoring the duplicates). -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 07:34, 16 December 2013 (UTC)
:: to me 'a b c' is a representation of a set (a, b, and c) and duplicate elements aren't a problem in this particular case/algorithm. --[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 07:47, 16 December 2013 (UTC)
::: oops, I see that there IS a problem if invalid sets (with duplicate elements) are specified. Some other points are moot, however, --[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 07:59, 16 December 2013 (UTC)
 
:::: ''No duplicate values would ever exist in any result from a set based solution.'' Paddy wrote that (above). To me, the key word is '''result''' from a set-based solution. Note that Wiki uses the word ''replicated value'' instead of ''duplicated value''. Six of one, half-dozen of the other. Note that every program solution (example) that actually ''uses'' duplicates in a list or SET handles duplications correctly. Stating that a list IS a SET doesn't make it so. 'A B C' is a list of three values (delimited by blanks, and of course, the values in this case can't contain blanks). ["A", "B", "C"] is a better representation of that set. The list 'A B C B' is also represented by the set ["A", "B", "C"] (in any order). Also, if you could specify which points you think are moot, it would help minimize any confusion about which points are being discussed (or being dismissed as moot). I'm trying to express my opinions about lists versus SETs and the handling of duplicates in the list(s). How a list is expressed and (or) translated/transliterated to a representative SET is germane to this discussion. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 08:35, 16 December 2013 (UTC)
 
::: My (corrected) version 3 works perfectly with 'my' representation of sets:
<lang>setb='["Jim", "Mary", "John", "Jim", "Bob"]'
a=myset(seta)
b=myset(setb)
Say difference(a,b)
...
myset:
Parse Arg li
Return space(translate(li,' ','"[],'))</lang>
Your only valid point is that my algorithm can't handle elements containing blanks.
<br>And, of coursem your '["Jim", "Mary", "John", "Jim", "Bob"]' is not a set!?!??--[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 19:19, 16 December 2013 (UTC)
 
-----
 
Er, no. I had other valid points.
 
As for what isn't a set, again, peruse the GAP, Pike, and Prolog programming entries (solutions). Whether or not the representation (of values and/or a SET) is a valid set or not doesn't reduce the fact that Rexx version 1 and 1.5, GAP, Pike, and Prolog entries correctly handle duplicates (or ''replicated values'', as Wiki uses). I used the SET dictated by ''note 1'' in the task's requirements as well as others solutions doing the same.
 
As for the '''translate''' that you used (above), it removes commas (''','''), quotes ('''"'''), right and left brackets ('''][''') from the values, not just the delimiters. Now, the values shown don't have any of those characters, but still, it's good to program ''as if'' those values had them.
Once those characters are handled correctly, it's one small step to handle blanks and nulls. That's why the REXX versions 1 and 1.5 took extra precautions (more REXX code) to only ''strip'' those characters used as delimiters and not ''translate'' them out of existence. (well, translate them to blanks). Furthermore, the older REXX entries can also handle ''null'' values, which are legal in SETs. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 19:40, 16 December 2013 (UTC)
 
: Note 1 starts with: " If your code uses lists of items to represent sets ..."
Mine does not!
<br>Please let's end the discussion. My version handles sets that consist of elements not containing blanks (or maybe whitespace) period (The task descripion uses exactly such elements.) Prove the opposite or delete the invalid tag --[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 20:09, 16 December 2013 (UTC)
 
Well, yes, Walter, it does use lists. Saying it doesn't use a list doesn't make it so. The lists used can look like SET elements, and indeed, represent elements in a SET. All you have to do is use the lists that ''note 1'' suggests to use (stating again, as does GAP, Pike, and Prolog use, among others, including REXX version 1 and 1.5). I have already executed the earlier version of the REXX version 2 with duplicates and it failed. I haven't gone through that process and validated it for you since the REXX version 2 was changed. If you could incorporate the new lists (using duplicates) as per the task's requirements (''note 1'') and post the output to show that it handles duplicates correctly, than you can delete the tag, and we all know thereafter that duplicates in the lists are handled correctly. (I don't want to modify your program nor its output.) If you want me to modify the REXX version 2 program and its output, I can do that for you, but since you have your moniker on it, I left them intact.) Note that other programming examples do use SETs, and some of them still incorporated duplicates in the element lists, and handled them correctly, even though they didn't use lists to represent SETs. I know it seems to be a nit, but I shouldn't have to prove it wrong (what if I or others don't have a REXX interpreter that could execute/interpret the code?), all is needed is to show that the REXX version 2 code can handle duplicates. That's why output is shown, as a verification. There isn't a need to have this discussion; if it's that hard to add duplicates to the lists and verify the output, just remove the tag. It would be much simpler to just add the duplicates (as per what ''note 1'' suggests) and show the output from using those lists. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 21:03, 16 December 2013 (UTC)
:: but I DID change the program! It handles duplicates now correctly. --[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 21:13, 16 December 2013 (UTC)
 
::: Yes, good work! -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 21:25, 16 December 2013 (UTC)