Set of real numbers

FCC link

All real numbers form the uncountable set ℝ. Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers a and b where ab. There are actually four cases for the meaning of "between", depending on open or closed boundary:

  • [a, _b_]: {x | ax and xb }
  • (a, b): {x | a < x and x < b }
  • [a, b): {x | ax and x < b }
  • (a, _b_]: {x | a < x and xb }

Note that if a = b, of the four only [a, _a_] would be non-empty.

Task

  • Devise a way to represent any set of real numbers, for the definition of "any" in the implementation notes below.

  • Provide methods for these common set operations (x is a real number; A and B are sets):

  • xA: determine if x is an element of A

    example: 1 is in [1, 2), while 2, 3, ... are not.

  • AB: union of A and B, i.e. {x | xA or xB}

    example: [0, 2) ∪ (1, 3) = [0, 3); [0, 1) ∪ (2, 3] = well, [0, 1) ∪ (2, 3]

  • AB: intersection of A and B, i.e. {x | xA and xB}

    example: [0, 2) ∩ (1, 3) = (1, 2); [0, 1) ∩ (2, 3] = empty set

  • A - B: difference between A and B, also written as A \ B, i.e. {x | xA and xB}

    example: [0, 2) − (1, 3) = [0, 1]

Test

{{test}}

Console output