Forum: Ruby-core [ruby-trunk - Feature #7738][Open] Deprecate Set#+ as an alias of Set#|, use it for symmetric differ

Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2013-01-24 12:36
(Received via mailing list)
Issue #7738 has been reported by alexeymuranov (Alexey Muranov).

----------------------------------------
Feature #7738: Deprecate Set#+ as an alias of Set#|, use it for 
symmetric difference.  Introduce Hash#| for Hash#reverse_merge in Rails.
https://bugs.ruby-lang.org/issues/7738

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: Next Major


=begin
I am almost sure this will be rejected, but i want to try anyway.  My 
goal is to propose a more efficient and consistent use of binary 
operator symbols for some classes, in this case for (({Set})) and 
(({Hash})).

I propose to deprecate (({Set#+})) as an alias of (({Set#|})), and use 
(({Set#+})) later for the ((*symmetric difference*)) of sets.  I think 
that operator symbols like (({+})) and (({|})) are too precious to alias 
one another.

Currently (({Set#+})) is probably the only use of (({#+})) for an 
operation which is not ((*injective*)) in each of the arguments: for 
sets (({a})), (({b})), (({c})), the equality

  a + b == a + c

does not currently imply

  b == c

The natural binary operation on sets that is injective in each argument 
is the ((*symmetric difference*)), it corresponds to the bitwise XOR.  I 
have also noticed that the "(({+}))" for sets is used in "Lectures on 
ergodic theory " by P. Halmos to denote the symmetric difference.

I also suggest for to define (({Hash#|})) as Hash#reverse_merge in 
Rails, in my opinion this would correspond nicely to (({Set#|})).
=end
Posted by Thomas Sawyer (7rans)
on 2013-01-24 13:22
(Received via mailing list)
Issue #7738 has been updated by trans (Thomas Sawyer).


It would help if you gave some examples of what "symmetric difference" 
actually meant.


Put the last "I also suggest" in another issue. Ok?


----------------------------------------
Feature #7738: Deprecate Set#+ as an alias of Set#|, use it for 
symmetric difference.  Introduce Hash#| for Hash#reverse_merge in Rails.
https://bugs.ruby-lang.org/issues/7738#change-35579

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: Next Major


=begin
I am almost sure this will be rejected, but i want to try anyway.  My 
goal is to propose a more efficient and consistent use of binary 
operator symbols for some classes, in this case for (({Set})) and 
(({Hash})).

I propose to deprecate (({Set#+})) as an alias of (({Set#|})), and use 
(({Set#+})) later for the ((*symmetric difference*)) of sets.  I think 
that operator symbols like (({+})) and (({|})) are too precious to alias 
one another.

Currently (({Set#+})) is probably the only use of (({#+})) for an 
operation which is not ((*injective*)) in each of the arguments: for 
sets (({a})), (({b})), (({c})), the equality

  a + b == a + c

does not currently imply

  b == c

The natural binary operation on sets that is injective in each argument 
is the ((*symmetric difference*)), it corresponds to the bitwise XOR.  I 
have also noticed that the "(({+}))" for sets is used in "Lectures on 
ergodic theory " by P. Halmos to denote the symmetric difference.

I also suggest for to define (({Hash#|})) as Hash#reverse_merge in 
Rails, in my opinion this would correspond nicely to (({Set#|})).
=end
Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2013-01-24 13:53
(Received via mailing list)
Issue #7738 has been updated by alexeymuranov (Alexey Muranov).


Sorry for not being clear. The symmetric difference of A and B is the 
set of all those elements which belong to exactly one of the two sets A 
or B.  It is like the bitwise "exclusive or".

Ok, i'll open a separate issue for `Hash#|`.
----------------------------------------
Feature #7738: Deprecate Set#+ as an alias of Set#|, use it for 
symmetric difference.  Introduce Hash#| for Hash#reverse_merge in Rails.
https://bugs.ruby-lang.org/issues/7738#change-35582

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: Next Major


=begin
I am almost sure this will be rejected, but i want to try anyway.  My 
goal is to propose a more efficient and consistent use of binary 
operator symbols for some classes, in this case for (({Set})) and 
(({Hash})).

I propose to deprecate (({Set#+})) as an alias of (({Set#|})), and use 
(({Set#+})) later for the ((*symmetric difference*)) of sets.  I think 
that operator symbols like (({+})) and (({|})) are too precious to alias 
one another.

Currently (({Set#+})) is probably the only use of (({#+})) for an 
operation which is not ((*injective*)) in each of the arguments: for 
sets (({a})), (({b})), (({c})), the equality

  a + b == a + c

does not currently imply

  b == c

The natural binary operation on sets that is injective in each argument 
is the ((*symmetric difference*)), it corresponds to the bitwise XOR.  I 
have also noticed that the "(({+}))" for sets is used in "Lectures on 
ergodic theory " by P. Halmos to denote the symmetric difference.

I also suggest for to define (({Hash#|})) as Hash#reverse_merge in 
Rails, in my opinion this would correspond nicely to (({Set#|})).
=end
Posted by Thomas Sawyer (7rans)
on 2013-01-24 15:43
(Received via mailing list)
Issue #7738 has been updated by trans (Thomas Sawyer).


I see. Thanks.

Well, I hate to mention b/c I don't like it, but Ruby uses #^ for xor. 
So wouldn't that be the more appropriate operator for this? Using :+ for 
this seems strange.

----------------------------------------
Feature #7738: Deprecate Set#+ as an alias of Set#|, use it for 
symmetric difference.  Introduce Hash#| for Hash#reverse_merge in Rails.
https://bugs.ruby-lang.org/issues/7738#change-35583

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: Next Major


=begin
I am almost sure this will be rejected, but i want to try anyway.  My 
goal is to propose a more efficient and consistent use of binary 
operator symbols for some classes, in this case for (({Set})) and 
(({Hash})).

I propose to deprecate (({Set#+})) as an alias of (({Set#|})), and use 
(({Set#+})) later for the ((*symmetric difference*)) of sets.  I think 
that operator symbols like (({+})) and (({|})) are too precious to alias 
one another.

Currently (({Set#+})) is probably the only use of (({#+})) for an 
operation which is not ((*injective*)) in each of the arguments: for 
sets (({a})), (({b})), (({c})), the equality

  a + b == a + c

does not currently imply

  b == c

The natural binary operation on sets that is injective in each argument 
is the ((*symmetric difference*)), it corresponds to the bitwise XOR.  I 
have also noticed that the "(({+}))" for sets is used in "Lectures on 
ergodic theory " by P. Halmos to denote the symmetric difference.

I also suggest for to define (({Hash#|})) as Hash#reverse_merge in 
Rails, in my opinion this would correspond nicely to (({Set#|})).
=end
Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2013-01-25 11:08
(Received via mailing list)
Issue #7738 has been updated by alexeymuranov (Alexey Muranov).


I agree that having the same symbol for the symmetric difference as for 
XOR would be nice, given that there are not so many different ASCII 
symbols. However, the main part of my request is to *not use '+' for the 
union of set*. This use is inconsistent with set theory notation (or i 
have not yet met '+' for the union), and is not very consistent in my 
opinion with other uses of '+' in Ruby. Also it looks redundant to alias 
one symbol with another: a half of rubists will be using one, and 
another half will be using another.

If `Set#+` is used, in my opinion it should be the symmetric difference. 
(The problem with this is that i cannot come up with a good use case for 
the symmetric difference operation. I was thinking about flipping a 
subset of binary options, but do not see how it can be useful.)

About the inconsistency with the `Fixnum#^` (i don't like `#^` for XOR 
either, i proposed `#><` some time but it was rejected), i can say that 
this is in a sense a secondary operation on `Fixnum`, which violates to 
some extent the Single Responsibility Principle. In my opinion, for 
bitwise operations it would be natural to have some `BitSet` class, and 
use, for example, `BitSet#+` for XOR. There seem to be no special reason 
for `Fixnum` to be stored internally in the binary form, there existed 
ternary computers once upon a time: http://en.wikipedia.org/wiki/Setun
----------------------------------------
Feature #7738: Deprecate Set#+ as an alias of Set#|, use it for 
symmetric difference.  Introduce Hash#| for Hash#reverse_merge in Rails.
https://bugs.ruby-lang.org/issues/7738#change-35633

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: Next Major


=begin
I am almost sure this will be rejected, but i want to try anyway.  My 
goal is to propose a more efficient and consistent use of binary 
operator symbols for some classes, in this case for (({Set})) and 
(({Hash})).

I propose to deprecate (({Set#+})) as an alias of (({Set#|})), and use 
(({Set#+})) later for the ((*symmetric difference*)) of sets.  I think 
that operator symbols like (({+})) and (({|})) are too precious to alias 
one another.

Currently (({Set#+})) is probably the only use of (({#+})) for an 
operation which is not ((*injective*)) in each of the arguments: for 
sets (({a})), (({b})), (({c})), the equality

  a + b == a + c

does not currently imply

  b == c

The natural binary operation on sets that is injective in each argument 
is the ((*symmetric difference*)), it corresponds to the bitwise XOR.  I 
have also noticed that the "(({+}))" for sets is used in "Lectures on 
ergodic theory " by P. Halmos to denote the symmetric difference.

I also suggest for to define (({Hash#|})) as Hash#reverse_merge in 
Rails, in my opinion this would correspond nicely to (({Set#|})).
=end
Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2013-02-20 12:12
(Received via mailing list)
Issue #7738 has been updated by alexeymuranov (Alexey Muranov).


In fact, sets (or rather subsets of a given set) form a Boolean ring ( 
http://en.wikipedia.org/wiki/Boolean_ring ) under the following two 
operations:
 - the product is the set intersection and
 - the sum is the set symmetric difference.
However, according to the Wikipedia article, it is accepted to use `+` 
for the union (which is not the ring addition) in this case, contrary to 
what i thought.

So maybe it is alright to have it this way in Ruby, except that there 
are two symbols for the same operation.
----------------------------------------
Feature #7738: Deprecate Set#+ as an alias of Set#|, use it for 
symmetric difference.  Introduce Hash#| for Hash#reverse_merge in Rails.
https://bugs.ruby-lang.org/issues/7738#change-36669

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: Next Major


=begin
I am almost sure this will be rejected, but i want to try anyway.  My 
goal is to propose a more efficient and consistent use of binary 
operator symbols for some classes, in this case for (({Set})) and 
(({Hash})).

I propose to deprecate (({Set#+})) as an alias of (({Set#|})), and use 
(({Set#+})) later for the ((*symmetric difference*)) of sets.  I think 
that operator symbols like (({+})) and (({|})) are too precious to alias 
one another.

Currently (({Set#+})) is probably the only use of (({#+})) for an 
operation which is not ((*injective*)) in each of the arguments: for 
sets (({a})), (({b})), (({c})), the equality

  a + b == a + c

does not currently imply

  b == c

The natural binary operation on sets that is injective in each argument 
is the ((*symmetric difference*)), it corresponds to the bitwise XOR.  I 
have also noticed that the "(({+}))" for sets is used in "Lectures on 
ergodic theory " by P. Halmos to denote the symmetric difference.

I also suggest for to define (({Hash#|})) as Hash#reverse_merge in 
Rails, in my opinion this would correspond nicely to (({Set#|})).
=end
Posted by ko1 (Koichi Sasada) (Guest)
on 2013-02-22 01:06
(Received via mailing list)
Issue #7738 has been updated by ko1 (Koichi Sasada).

Category set to lib
Assignee set to knu (Akinori MUSHA)


----------------------------------------
Feature #7738: Deprecate Set#+ as an alias of Set#|, use it for 
symmetric difference.  Introduce Hash#| for Hash#reverse_merge in Rails.
https://bugs.ruby-lang.org/issues/7738#change-36734

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: knu (Akinori MUSHA)
Category: lib
Target version: Next Major


=begin
I am almost sure this will be rejected, but i want to try anyway.  My 
goal is to propose a more efficient and consistent use of binary 
operator symbols for some classes, in this case for (({Set})) and 
(({Hash})).

I propose to deprecate (({Set#+})) as an alias of (({Set#|})), and use 
(({Set#+})) later for the ((*symmetric difference*)) of sets.  I think 
that operator symbols like (({+})) and (({|})) are too precious to alias 
one another.

Currently (({Set#+})) is probably the only use of (({#+})) for an 
operation which is not ((*injective*)) in each of the arguments: for 
sets (({a})), (({b})), (({c})), the equality

  a + b == a + c

does not currently imply

  b == c

The natural binary operation on sets that is injective in each argument 
is the ((*symmetric difference*)), it corresponds to the bitwise XOR.  I 
have also noticed that the "(({+}))" for sets is used in "Lectures on 
ergodic theory " by P. Halmos to denote the symmetric difference.

I also suggest for to define (({Hash#|})) as Hash#reverse_merge in 
Rails, in my opinion this would correspond nicely to (({Set#|})).
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.