I present a solution for
M equalset M u N
0
but wonder whether Raul has noticed a deeper problem I haven't noticed. Please
see my analysis below the quote. /Kip
Raul Miller wrote:
> On Thu, Aug 13, 2009 at 10:58 PM, Kip Murray<[email protected]> wrote:
>> NB. but (as we already know from the counts)
>> M equalset M u N
>> 0
> ...
>> The error is somewhere in
>
> Here:
>
>> NB. A "set" is 0$<1 or a non-empty list of boxes with no duplicates.
>> NB. An "element" is the open of a box. As 0$<1 has no box it has no
>> element.
>
> equalset requires that the list be sorted.
My analysis:
The idea of verb realset is that
realset 3;1;4
+-+-+-+
|1|3|4|
+-+-+-+
is supposed to be the "real set" of which 1;3;4 1;4;3 3;1;4 3;4;1 4;1;3 and
4;3;1 are instances. When I'm doing set theory and see 3;1;4 I think to myself
"It's really 1;3;4". As
realset 1;0
+-+-+
|0|1|
+-+-+
sets M and N below have the same elements and so are the same set.
]M =: pwrSet 0;1
++---+---+-----+
||+-+|+-+|+-+-+|
|||1|||0|||0|1||
||+-+|+-+|+-+-+|
++---+---+-----+
]N =: pwrSet 1;0
++---+---+-----+
||+-+|+-+|+-+-+|
|||0|||1|||1|0||
||+-+|+-+|+-+-+|
++---+---+-----+
M equalset N
1
Verb equalset works by comparing the "real sets":
equalset
-:&realset
realset M
++---+-----+---+
||+-+|+-+-+|+-+|
|||0|||0|1|||1||
||+-+|+-+-+|+-+|
++---+-----+---+
realset N
++---+-----+---+
||+-+|+-+-+|+-+|
|||0|||0|1|||1||
||+-+|+-+-+|+-+|
++---+-----+---+
M equalset N
1
But verb -. in
u
-. , ]
doesn't care that 0;1 equalset 1;0 , so
M
++---+---+-----+
||+-+|+-+|+-+-+|
|||1|||0|||0|1||
||+-+|+-+|+-+-+|
++---+---+-----+
N
++---+---+-----+
||+-+|+-+|+-+-+|
|||0|||1|||1|0||
||+-+|+-+|+-+-+|
++---+---+-----+
M -. N NB. sets ,<1 and ,<0 are removed from M, but set 0;1 is not
+-----+
|+-+-+|
||0|1||
|+-+-+|
+-----+
As a result (remember u =: -. , ])
M (-. , ]) N NB. five elements, incorrect for M union N which has four
+-----++---+---+-----+
|+-+-+||+-+|+-+|+-+-+|
||0|1||||0|||1|||1|0||
|+-+-+||+-+|+-+|+-+-+|
+-----++---+---+-----+
We can fix this with
less =: -.&realset
u =: less , ] NB. REDEFINING u
M u N
++---+---+-----+
||+-+|+-+|+-+-+|
|||0|||1|||1|0||
||+-+|+-+|+-+-+|
++---+---+-----+
M equalset M u N NB. error seems repaired
1
By the way,
(0$<1) -: M less N NB. as desired
1
The lesson seems to be that every verb that may need to compare sets to do its
work needs &realset . --I say "seems", I wouldn't be surprised if Raul has
spotted a deeper problem I haven't noticed. If so, Raul, will you amplify your
remark about equalset and the model's definition of "set"?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm