intervals 0.3.56 → 0.3.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,3 @@
1
- #!/usr/bin/ruby
2
- =begin rdoc
3
1
  = Intervals -- Interval arithmetic in Ruby
4
2
 
5
3
  Besides making obvious a possible loss of precision during floating
@@ -54,7 +52,7 @@ results.
54
52
  Using interval arithmetic it is possible to detect the loss of
55
53
  precision due to floating-point roundings.
56
54
 
57
- require "intervals" # you must have installed this package, obviously
55
+ require "interval" # you must have this library installed, obviously
58
56
 
59
57
  1/Interval[3.0] # => Interval[0.333333333333333, 0.333333333333333]
60
58
 
@@ -206,7 +204,3 @@ under the terms of LGPL.
206
204
 
207
205
  RDoc template by {Jamis Buck}[http://rubyforge.org/frs/?group_id=1458].
208
206
 
209
- =end
210
- require 'interval'
211
-
212
- Test::Unit.run = (__FILE__ != $0)
@@ -1 +1 @@
1
- 0.3.56
1
+ 0.3.61
@@ -68,7 +68,7 @@ class Interval
68
68
  if l.size == 1
69
69
  l.first
70
70
  else
71
- Interval::Complex.new(l)
71
+ Interval::Multiple.new(l)
72
72
  end
73
73
  end
74
74
 
@@ -508,6 +508,18 @@ class Interval::Simple < Interval
508
508
  self.class.new(-sup,-inf)
509
509
  end
510
510
 
511
+ # Dependent subtraction, i.e., the inverse of the addition
512
+ #
513
+ # Interval[3,4].dsub Interval[1,2]
514
+ # # => Interval[2]
515
+ # Interval[1,2] + Interval[2]
516
+ # # => Interval[3,4]
517
+ def dsub(other)
518
+ Interval[
519
+ FPU.down{inf - other.inf},
520
+ FPU.up {sup - other.sup}]
521
+ end
522
+
511
523
  # Used to implement Interval's multiplicative operator (\*).
512
524
  def multiply (other)
513
525
  self.class.new(
@@ -663,7 +675,7 @@ class Interval::Simple < Interval
663
675
  end
664
676
 
665
677
  # Implements an interval with multiple components.
666
- class Interval::Complex < Interval
678
+ class Interval::Multiple < Interval
667
679
 
668
680
  # The array with the interval's components.
669
681
  attr :components
@@ -734,7 +746,7 @@ module Interval::Assertions
734
746
  # Did something spectacarly unexpected happen?
735
747
  assert(res.simple?, res)
736
748
  # Is it a solution?
737
- assert(res.include?(0), res)
749
+ assert_include(res, 0)
738
750
  # Is it minimal?
739
751
  assert(s.all? {|x| x.extrema.all? {|y| f.call(Interval[y]).include?(0)}}, s.inspect +
740
752
  " is non minmal")
@@ -743,13 +755,28 @@ module Interval::Assertions
743
755
  # check the granularity
744
756
  assert_equal(expected.components.size, s.components.size, [expected,s].inspect)
745
757
  # check for inclusion
746
- assert_equal(expected, s & expected, s)
758
+ assert_subset(expected, s)
747
759
  else
748
760
  # check for equality
749
761
  assert_equal(expected,s)
750
762
  end
751
763
  end
752
764
 
765
+ # Assert that the interval +i+ includes +x+.
766
+ def assert_include(i, x)
767
+ assert(i.include?(x), i.inspect + " should include " + x.inspect)
768
+ end
769
+
770
+ # Assert that the interval +i+ does not include +x+.
771
+ def assert_outside(i, x)
772
+ assert(!i.include?(x), i.inspect + " should not include " + x.inspect)
773
+ end
774
+
775
+ # Assert that +x+ is a subset of +y+.
776
+ def assert_subset(x,y)
777
+ assert(x == x & y, x.inspect + " should be a subset of " + y.inspect)
778
+ end
779
+
753
780
  end
754
781
 
755
782
  # Tests Interval fundamentals: construction, equality and inspection.
@@ -764,12 +791,12 @@ class Interval::TestFundamentals < Test::Unit::TestCase
764
791
 
765
792
  tester.call Interval[1], [1], Interval::Simple
766
793
  tester.call Interval[1,2], [1,2], Interval::Simple
767
- tester.call Interval[[1,2],[3,4]], [[1,2],[3,4]], Interval::Complex
768
- tester.call Interval[[1],[2]], [[1],[2]], Interval::Complex
794
+ tester.call Interval[[1,2],[3,4]], [[1,2],[3,4]], Interval::Multiple
795
+ tester.call Interval[[1],[2]], [[1],[2]], Interval::Multiple
769
796
  tester.call Interval[[1]], [1], Interval::Simple
770
797
  tester.call Interval[2,0/0.0], [-Infinity,+Infinity], Interval::Simple
771
798
  tester.call Interval[0/0.0,9], [-Infinity,+Infinity], Interval::Simple
772
- tester.call Interval[[1,3],[4,6],[2,5],[9,9]], [[1,6],[9]], Interval::Complex
799
+ tester.call Interval[[1,3],[4,6],[2,5],[9,9]], [[1,6],[9]], Interval::Multiple
773
800
  end
774
801
 
775
802
  def test_construction_failure
@@ -780,11 +807,11 @@ class Interval::TestFundamentals < Test::Unit::TestCase
780
807
  end
781
808
 
782
809
  def test_inequality
783
- assert(Interval[1,2] != Interval[1,3])
784
- assert(Interval[1,2] != Interval[0,2])
785
- assert(Interval[1,2] != Interval[0,3])
786
- assert(Interval[1,2] != 3)
787
- assert(Interval[[1,2],[3,4]] != Interval[[1,0],[3,4]])
810
+ assert_not_equal(Interval[1,2], Interval[1,3])
811
+ assert_not_equal(Interval[1,2], Interval[0,2])
812
+ assert_not_equal(Interval[1,2], Interval[0,3])
813
+ assert_not_equal(Interval[1,2], 3)
814
+ assert_not_equal(Interval[[1,2],[3,4]], Interval[[1,0],[3,4]])
788
815
  end
789
816
 
790
817
  def test_inspect_and_to_s
@@ -817,6 +844,13 @@ class Interval::TestSimpleArithmetic < Test::Unit::TestCase
817
844
  assert_equal(Interval[-2,-1], -Interval[1,2])
818
845
  end
819
846
 
847
+ def test_dsub
848
+ assert_equal(Interval[2], Interval[3,4].dsub(Interval[1,2]))
849
+ assert_equal(Interval[3,4], Interval[4,6].dsub(Interval[1,2]))
850
+ assert_equal(Interval[], Interval[3,4].dsub(Interval[0,2]))
851
+
852
+ end
853
+
820
854
  def test_times
821
855
  assert_equal(Interval[-Infinity,+Infinity],Interval[Infinity] * Interval[0])
822
856
  assert_equal(Interval[+Infinity],Interval[Infinity] * Interval[3])
@@ -935,11 +969,11 @@ class Interval::TestMethods < Test::Unit::TestCase
935
969
  include Interval::Assertions
936
970
 
937
971
  def test_include?
938
- assert(Interval[1,2].include?(1.5),"1")
939
- assert(Interval[1,2].include?(1),"2")
940
- assert(Interval[1,2].include?(2),"3")
941
- assert(!Interval[1,2].include?(0),"4")
942
- assert(!Interval[1,2].include?(4),"5")
972
+ assert_include(Interval[1,2], 1.5)
973
+ assert_include(Interval[1,2], 1)
974
+ assert_include(Interval[1,2], 2)
975
+ assert_outside(Interval[1,2], 0)
976
+ assert_outside(Interval[1,2], 4)
943
977
  end
944
978
 
945
979
  def test_simple?
@@ -1070,7 +1104,7 @@ class Interval::TestTranscendental < Test::Unit::TestCase
1070
1104
  assert_equal(Interval[], Interval[-2,-1].log)
1071
1105
  assert_equal(Interval[-Infinity], Interval[-2,0].log)
1072
1106
  assert_equal(Interval[-Infinity,0], Interval[0,1].log)
1073
- assert(Interval::E.log.include?(1))
1107
+ assert_include(Interval::E.log, 1)
1074
1108
  assert_equal(3 * 2 ** -53, Interval[1].exp.log.width)
1075
1109
  end
1076
1110
 
@@ -1081,7 +1115,7 @@ class Interval::TestTranscendental < Test::Unit::TestCase
1081
1115
  end
1082
1116
 
1083
1117
  def test_cosh
1084
- assert(Interval[1].cosh.sharp?)
1118
+ assert_sharp(Interval[1].cosh)
1085
1119
  assert_equal(Interval[1], Interval[0].cosh)
1086
1120
  assert_equal((Interval[1].cosh | Interval[3].cosh).hull, Interval[1,3].cosh)
1087
1121
  assert_equal(Interval[1,3].cosh, Interval[-3,-1].cosh)
@@ -1091,7 +1125,7 @@ class Interval::TestTranscendental < Test::Unit::TestCase
1091
1125
  end
1092
1126
 
1093
1127
  def test_sinh
1094
- assert(Interval[1].sinh.sharp?)
1128
+ assert_sharp(Interval[1].sinh)
1095
1129
  assert_equal(Interval[0], Interval[0].sinh)
1096
1130
  assert_equal((Interval[-1].sinh | Interval[3].sinh).hull, Interval[-1,3].sinh)
1097
1131
  assert_equal(Interval[-Infinity, Infinity], Interval[-Infinity,Infinity].sinh)
@@ -1103,10 +1137,10 @@ class Interval::TestTranscendental < Test::Unit::TestCase
1103
1137
  assert_equal(Interval[-1,1], Interval[Infinity].cos)
1104
1138
  assert_equal(Interval[-1,1], Interval[-Infinity].cos)
1105
1139
  onehalf = (Interval::PI/3).cos
1106
- assert( onehalf.include?(0.5))
1140
+ assert_include(onehalf, 0.5)
1107
1141
  assert_equal(Interval[onehalf.inf,1], (-Interval::PI/4 | Interval::PI/3).hull.cos)
1108
1142
  minusonehalf = (2*Interval::PI/3).cos
1109
- assert(minusonehalf.include?(-0.5))
1143
+ assert_include(minusonehalf, -0.5)
1110
1144
  assert_equal(Interval[-1,minusonehalf.sup], (5*Interval::PI/4 | 2*Interval::PI/3).hull.cos)
1111
1145
  assert_equal((minusonehalf | onehalf).hull, ((Interval::PI | 2*Interval::PI).hull/3).cos)
1112
1146
  full = (5 * Interval::PI/3 | 3.5 * Interval::PI).hull
@@ -1127,10 +1161,10 @@ class Interval::TestTranscendental < Test::Unit::TestCase
1127
1161
  assert_equal(Interval[-1,1], Interval[Infinity].sin)
1128
1162
  assert_equal(Interval[-1,1], Interval[-Infinity].sin)
1129
1163
  onehalf = (Interval::PI/6).sin
1130
- assert( onehalf.include?(0.5))
1164
+ assert_include(onehalf, 0.5)
1131
1165
  assert_equal(Interval[onehalf.inf,1], (3 * Interval::PI/4 | Interval::PI/6).hull.sin)
1132
1166
  minusonehalf = (7*Interval::PI/6).sin
1133
- assert(minusonehalf.include?(-0.5))
1167
+ assert_include(minusonehalf, -0.5)
1134
1168
  assert_equal(Interval[-1,minusonehalf.sup], (7*Interval::PI/4 | 7*Interval::PI/6).hull.sin)
1135
1169
  assert_equal((-onehalf | onehalf).hull, ((Interval::PI | -Interval::PI).hull/6.0).sin)
1136
1170
  full = ((5 * Interval::PI/3 | 3.5 * Interval::PI) + Interval::PI/2).hull
@@ -1154,9 +1188,9 @@ class Interval::TestTranscendental < Test::Unit::TestCase
1154
1188
  assert_equal(Interval[-Infinity, Infinity], (4.75 *Interval::PI | Interval::PI * 6.25).hull.tan)
1155
1189
 
1156
1190
  assert_equal(2 ** -51, Interval::PI.tan.width)
1157
- assert(Interval::PI.tan.include?(0))
1191
+ assert_include(Interval::PI.tan, 0)
1158
1192
  assert_equal(3 * 2 ** -53, (Interval::PI/4).tan.width)
1159
- assert((Interval::PI/4).tan.include?(1) )
1193
+ assert_include((Interval::PI/4).tan, 1)
1160
1194
 
1161
1195
  x = (Interval::PI/4 | Interval::PI * 0.75).hull
1162
1196
  assert_equal((Interval[x.sup].tan | -Infinity).hull | (Interval[x.inf].tan | Infinity).hull, x.tan)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: intervals
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.56
7
- date: 2006-03-29 00:00:00 +02:00
6
+ version: 0.3.61
7
+ date: 2006-03-30 00:00:00 +02:00
8
8
  summary: Interval arithmetic in Ruby.
9
9
  require_paths:
10
10
  - lib
@@ -160,9 +160,9 @@ files:
160
160
  - ext/crlibm/triple-double.h
161
161
  - ext/crlibm/VERSION
162
162
  - lib/interval.rb
163
- - lib/intervals.rb
164
163
  - lib/struct_float.rb
165
164
  - lib/fpu.rb
165
+ - README.txt
166
166
  - VERSION.txt
167
167
  test_files:
168
168
  - lib/interval.rb
@@ -173,9 +173,9 @@ rdoc_options:
173
173
  - --title
174
174
  - "Intervals: Interval arithmetic in Ruby"
175
175
  - --main
176
- - lib/intervals.rb
177
- extra_rdoc_files: []
178
-
176
+ - README.txt
177
+ extra_rdoc_files:
178
+ - README.txt
179
179
  executables: []
180
180
 
181
181
  extensions: