(0..3) == (0...4) returning false?

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and`…’ to be considered
different in a comparison?

Massimiliano

Hi,

···

In message “(0…3) == (0…4) returning false?” on 02/07/02, Massimiliano Mirra list@NOSPAMchromatic-harp.com writes:

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Although they have same range, they are still different.

``````						matz.
``````

I think you are right in your surprise. The confusion comes when one group
sees a range of integers as a set of integers and another group sees a range
as a continuum of floats. The “correct” answer depends of first determining
the definition of a range: (1) a collection or (2) a single continuum.

···

On Tuesday 02 July 2002 02:57 am, Massimiliano Mirra wrote:

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Massimiliano

Yukihiro Matsumoto wrote:

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Although they have same range, they are still different.

This seem to go against Ruby’s principal of least surprise, please
elaborate…

Thanks,

···

Bil

In what?

Massimiliano

···

On Tue, Jul 02, 2002 at 05:27:08PM +0900, Yukihiro Matsumoto wrote:

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Although they have same range, they are still different.

Hi,

···

In message “Re: (0…3) == (0…4) returning false?” on 02/07/03, Albert Wagner alwagner@tcac.net writes:

I think you are right in your surprise. The confusion comes when one group
sees a range of integers as a set of integers and another group sees a range
as a continuum of floats. The “correct” answer depends of first determining
the definition of a range: (1) a collection or (2) a single continuum.

That’s the point. My guess is a Range should work as both, depending
on a method called. I think I have to define useful / natural set of
method names for each definition of a range.

``````						matz.
``````

Albert Wagner wrote:

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Massimiliano

I think you are right in your surprise. The confusion comes when one group
sees a range of integers as a set of integers and another group sees a range
as a continuum of floats. The “correct” answer depends of first determining
the definition of a range: (1) a collection or (2) a single continuum.

If I understand the pickaxe book correctly, Ranges must be made of
objects with a succ method, and Range#=== returns true if the object is
an element of the range. To me, this implies that a Range can’t be made
up of Floats, and that (0…4) === 3.2 should return false. A continuum
would be an entirely different kind of object. Or am I being overly
pedantic?

···

On Tuesday 02 July 2002 02:57 am, Massimiliano Mirra wrote:

Hi,

In mail “Re: (0…3) == (0…4) returning false?”

···

Massimiliano Mirra list@NOSPAMchromatic-harp.com wrote:

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Although they have same range, they are still different.

In what?

(0…3) === 3.2 # false
(0…4) === 3.2 # true

– Minero Aoki

And your guess is usually right.

Take this as just thinking out loud:

FiniteSet < OrderedSet < DiscreteRange

InfiniteSet < Continuum

FiniteSet holds a finite number of elements, OrderedSet does the same
but they are sorted, DiscreteRange does the same but all the items
between the maximum and the minimum are present and at a fixed step
from the previous one and the next one.

InfiniteSet would hold an infinite number of elements (not really
useful), Continuum holds all the elements between a minimum and a
maximum.

Another thought:

Continuum < DiscreteRange

DiscreteRange adds a condition to Continuum. While Continuum is all
the numbers between a minimum and a maximum, DiscreteRange is all the
numbers between a minimum and a maximum such that n % 1 == 0 (or n %
2 == 0 for the range to include only even numbers, and so on).
DiscreteRange#include?(n) is true when n satisfies the condition.

A block could be used for building the range (and an exception thrown
when the return value of the block does not match the rule):

min, max, step = 0, 10, 1
range = DiscreteRange.new(min, max) do |index| # index takes on 0,1,2…
min + step*index
end
range.include?(5) # true
range.include?(1.5) # false
range.include?(11) # false

It wouldn’t be limited to uniformly stepped ranges. Acceleration
against space, for example…

mix, max, acceleration = 0, 100, 9.81

space_travelled = DiscreteRange.new(min, max) do |time|
acceleration * time ** 2
end
range.include?(39.24) # true
range.include?(40) # false
range.include?(245.25) # false

Again, just thinking out loud…

Massimiliano

···

On Thu, Jul 04, 2002 at 01:38:44AM +0900, Yukihiro Matsumoto wrote:

I think you are right in your surprise. The confusion comes when one group
sees a range of integers as a set of integers and another group sees a range
as a continuum of floats. The “correct” answer depends of first determining
the definition of a range: (1) a collection or (2) a single continuum.

That’s the point. My guess is a Range should work as both, depending
on a method called. I think I have to define useful / natural set of
method names for each definition of a range.

I think you are absolutely right. The succ test is appropriate.

···

On Thursday 04 July 2002 03:27 am, T.M. Sommers wrote:

Albert Wagner wrote:

On Tuesday 02 July 2002 02:57 am, Massimiliano Mirra wrote:

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Massimiliano

I think you are right in your surprise. The confusion comes when one
group sees a range of integers as a set of integers and another group
sees a range as a continuum of floats. The “correct” answer depends of
first determining the definition of a range: (1) a collection or (2) a
single continuum.

If I understand the pickaxe book correctly, Ranges must be made of
objects with a succ method, and Range#=== returns true if the object is
an element of the range. To me, this implies that a Range can’t be made
up of Floats, and that (0…4) === 3.2 should return false. A continuum
would be an entirely different kind of object. Or am I being overly
pedantic?

Yukihiro Matsumoto wrote:

That’s the point. My guess is a Range should work as both, depending
on a method called. I think I have to define useful / natural set of
method names for each definition of a range.

What about a class Continuum and a class Sequence?
(naming is not important now)
Perhaps as subclasses of Range.

A little more complex, but less confusing.

Tobi

···

In mail “Re: (0…3) == (0…4) returning false?”

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Although they have same range, they are still different.

In what?

(0…3) === 3.2 # false
(0…4) === 3.2 # true

and, of course, the differentiating predicate:

(0…3).exclude_end? #=> false
(0…4).exclude_end? #=> true

best,
raja

···

Massimiliano Mirra list@NOSPAMchromatic-harp.com wrote:

Ahhh. Very interesting. I would not have thought
of that.

Hal Fulton

···

----- Original Message -----
From: “Minero Aoki” aamine@mx.edit.ne.jp
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 02, 2002 7:01 AM
Subject: Re: (0…3) == (0…4) returning false?

In mail “Re: (0…3) == (0…4) returning false?”
Massimiliano Mirra list@NOSPAMchromatic-harp.com wrote:

Is there a reason for two ranges holding the same extension but
initialized respectively with `..' and `…’ to be considered
different in a comparison?

Although they have same range, they are still different.

In what?

(0…3) === 3.2 # false
(0…4) === 3.2 # true

I see! So I should think of them as:

(0…3) 0 <= x <= 3
(0…4) 0 <= x < 4

That makes (a lot of) sense.

Massimiliano

···

On Tue, Jul 02, 2002 at 09:01:41PM +0900, Minero Aoki wrote:

Although they have same range, they are still different.
In what?

(0…3) === 3.2 # false
(0…4) === 3.2 # true

Tobias Reif wrote:

What about a class Continuum and a class Sequence?

Though you suggested that naming isn’t important, I’d like to suggest
that Sequence would be too general a name. To indicate how different an
meaning of “Sequence” could be, I’ve used it to name a container class
(like Hash) implemented using AVL trees to maintain the keys in sorted
order. Your sequence name would need to connote consecutive integers.

···

Clifford Heath

That explains why they’re considered different, but can someone explain what
the 3.2 is in the first section of code above? How did Minero know to use
that as the value to test against?

···

On Wed, 3 Jul 2002 03:19, you wrote:

On Tue, Jul 02, 2002 at 09:01:41PM +0900, Minero Aoki wrote:

Although they have same range, they are still different.

In what?

(0…3) === 3.2 # false
(0…4) === 3.2 # true

I see! So I should think of them as:

(0…3) 0 <= x <= 3
(0…4) 0 <= x < 4

That makes (a lot of) sense.

“Massimiliano Mirra” wrote

I see! So I should think of them as:

(0…3) 0 <= x <= 3
(0…4) 0 <= x < 4

There is a pitfall you must be aware of.
Although (0…4) === 3.2 produces true (which means 3.2 is
included in (0…4) ) 3.2 is no element of (0…4) in terms of
(0…4).each (which means 3.2 is NOT included in (0…4) ).
It is a little bit illogical. Look out!

Juergen Katins

Clifford Heath wrote:

Tobias Reif wrote:

What about a class Continuum and a class Sequence?

Though you suggested that naming isn’t important, I’d like to suggest
that Sequence would be too general a name. To indicate how different an
meaning of “Sequence” could be, I’ve used it to name a container class
(like Hash) implemented using AVL trees to maintain the keys in sorted
order. Your sequence name would need to connote consecutive integers.

… or simply Array.new (4…15)

Tobi

···

Clifford Heath wrote:

Though you suggested that naming isn’t important,

nope; I said
“(naming is not important now)”
^^^

Naming is very important, but it’s step that can be completed after
modeling.

Tobi

···

3.2 is the number 3.2, three and two tenths, three point two.
It is greater than three and less than four so it matches only one of
the two above expressions. 3.7, 3.1, etc. would work just as well.

···

On Wed, Jul 03, 2002 at 06:22:09AM +0900, Harry Ohlsen wrote:

(0…3) === 3.2 # false
(0…4) === 3.2 # true

I see! So I should think of them as:

(0…3) 0 <= x <= 3
(0…4) 0 <= x < 4

That makes (a lot of) sense.

That explains why they’re considered different, but can someone explain what
the 3.2 is in the first section of code above? How did Minero know to use
that as the value to test against?

Evan Martin
martine@cs.washington.edu
http://neugierig.org