Click here to Skip to main content
13,143,637 members (32,400 online)
Rate this:
Please Sign up or sign in to vote.
See more:

How could I represent multiple subsets of a set of real numbers?

The problem is that,I want to remove some parts of real numbers in range : [0,2*pi) for example,after removal I will have like this:
Result set = [0,0.1] U [.2,2.65] U [2.66,2.86] U ... U [3.0,3.1]

in fact the result set,consists of several non-overlapping subsets(we don't know the exact count of these subsets.may be they are up to 200).

how could I implement "union" and "subtraction" and "overlapping" operations?
Posted 1-Oct-12 10:30am
I must say, you ask pretty interesting questions so far. I voted 5 for this one.
In the first question, you made another mistake which I explained in my answer, with a fix.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use HashSet<t></t>[^] to represent sets.

You're right, this won't work for a continuous set. Seems you may have to brew your own Range<T> class.

CyrusT 1-Oct-12 16:58pm
HashSet is used for discrete sets only! :(
I want to represent continuous sets!
You both are not quite right. The situation is more delicate.

First of all, nothing in a computer presents a continuous set. The whole computer is the finite-state machine, like it or not. You should also understand, that there are no real numbers (a set of those would be a continuous set) -- you have only the model approximating that, such as the set of all double of float numbers.

Now, the real problem is how to build a model of real number or other "potentially continues" objects to make some help from the computer. This is the completely different, quite correct problem, but only if strictly formulated.

In other words, the solution of OP's is most likely quite solvable. He only need to provide complete and strict description of required operations. Listing of those set-theory primitives is not enough. I would need to know how the set is used. I assume the use is realistic, and in this case I can almost guarantee the solution. I would recommend to start with explanation of the ultimate purpose.

Ravi Bhavnani 1-Oct-12 17:51pm
> You should also understand, that there are no real numbers
Quite correct. Any usage of Range<decimal> would be an approximation.

> I would recommend to start with explanation of the ultimate purpose.

Absolutely. Thank you very much.
I did not down-vote this answer even in its original version, because it is not completely wrong (and it was not completely wrong before); the question just needs some more detail and it all needs some analysis based on that.
And the use of the Range is a good idea. The set could be represented by the set of instances of, say, Range<double>.
Depending on expected use of the set class, even the modified use of HashSet could be appropriate. Let's learn about the prospective usage of it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100