require_relative 'interval_notation/version' require_relative 'interval_notation/error' require_relative 'interval_notation/basic_intervals' require_relative 'interval_notation/combiners' require_relative 'interval_notation/interval_set' require_relative 'interval_notation/operations' module IntervalNotation UNION_SYMBOL = '∪'.freeze PLUS_INFINITY_SYMBOL = '+∞'.freeze MINUS_INFINITY_SYMBOL = '-∞'.freeze EMPTY_SET_SYMBOL = '∅'.freeze R = IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(-Float::INFINITY, Float::INFINITY)] ) Empty = IntervalSet.new_unsafe([]) module Syntax # Long syntax for interval factory methods module Short R = ::IntervalNotation::R Empty = ::IntervalNotation::Empty def int(str) IntervalSet.from_string(str) end def oo(from, to) IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(from, to)] ) end def co(from, to) IntervalSet.new_unsafe( [BasicIntervals::ClosedOpenInterval.new(from, to)] ) end def oc(from, to) IntervalSet.new_unsafe( [BasicIntervals::OpenClosedInterval.new(from, to)] ) end def cc(from, to) if from != to IntervalSet.new_unsafe( [BasicIntervals::ClosedClosedInterval.new(from, to)] ) else IntervalSet.new_unsafe( [BasicIntervals::Point.new(from)] ) end end def pt(value) IntervalSet.new_unsafe( [BasicIntervals::Point.new(value)] ) end def lt(value) IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(-Float::INFINITY, value)] ) end def le(value) IntervalSet.new_unsafe( [BasicIntervals::OpenClosedInterval.new(-Float::INFINITY, value)] ) end def gt(value) IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(value, Float::INFINITY)] ) end def ge(value) IntervalSet.new_unsafe( [BasicIntervals::ClosedOpenInterval.new(value, Float::INFINITY)] ) end module_function :oo, :co, :oc, :cc, :pt, :lt, :le, :gt, :ge, :int end # Long syntax for interval factory methods module Long R = ::IntervalNotation::R Empty = ::IntervalNotation::Empty def interval(str) IntervalSet.from_string(str) end def open_open(from, to) IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(from, to)] ) end def closed_open(from, to) IntervalSet.new_unsafe( [BasicIntervals::ClosedOpenInterval.new(from, to)] ) end def open_closed(from, to) IntervalSet.new_unsafe( [BasicIntervals::OpenClosedInterval.new(from, to)] ) end def closed_closed(from, to) if from != to IntervalSet.new_unsafe( [BasicIntervals::ClosedClosedInterval.new(from, to)] ) else IntervalSet.new_unsafe( [BasicIntervals::Point.new(from)] ) end end def point(value) IntervalSet.new_unsafe( [BasicIntervals::Point.new(value)] ) end def less_than(value) IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(-Float::INFINITY, value)] ) end def less_than_or_equal_to(value) IntervalSet.new_unsafe( [BasicIntervals::OpenClosedInterval.new(-Float::INFINITY, value)] ) end def greater_than(value) IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(value, Float::INFINITY)] ) end def greater_than_or_equal_to(value) IntervalSet.new_unsafe( [BasicIntervals::ClosedOpenInterval.new(value, Float::INFINITY)] ) end module_function :open_open, :closed_open, :open_closed, :closed_closed, :point, :less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to, :interval end end end