Changeset 17970 for branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
- Timestamp:
- 04/30/21 12:18:19 (3 years ago)
- Location:
- branches/3106_AnalyticContinuedFractionsRegression
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3106_AnalyticContinuedFractionsRegression
- Property svn:mergeinfo changed
-
branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
- Property svn:mergeinfo changed
r17583 r17970 33 33 [Storable] 34 34 public double UpperBound { get; private set; } 35 36 public double Width => UpperBound - LowerBound; 35 37 36 38 [StorableConstructor] … … 67 69 } 68 70 71 private Interval(double v) : this(v, v) { } 72 69 73 public bool Contains(double value) { 70 74 return LowerBound <= value && value <= UpperBound; … … 74 78 if (double.IsNegativeInfinity(LowerBound) && double.IsPositiveInfinity(UpperBound)) return true; 75 79 if (other.LowerBound >= LowerBound && other.UpperBound <= UpperBound) return true; 76 80 77 81 return false; 78 82 } … … 93 97 /// </summary> 94 98 public bool IsPositive { 95 get => LowerBound > 0.0; 99 get => LowerBound > 0.0; 96 100 } 97 101 … … 126 130 return false; 127 131 128 return (UpperBound .IsAlmost(other.UpperBound)|| (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound)))129 && (LowerBound .IsAlmost(other.LowerBound)|| (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound)));132 return (UpperBound == other.UpperBound || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound))) 133 && (LowerBound == other.LowerBound || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound))); 130 134 } 131 135 … … 234 238 public static Interval Cube(Interval a) { 235 239 return new Interval(Math.Pow(a.LowerBound, 3), Math.Pow(a.UpperBound, 3)); 240 } 241 242 public static Interval Power(Interval a, int b) { 243 if (b < 0) return Power(1.0 / a, -b); // a^(-b) = 1/(a^b) 244 if (b == 0 && (a.Contains(0.0) || a.IsInfiniteOrUndefined)) return new Interval(double.NaN, double.NaN); // 0^0, +/-inf^0 are undefined 245 if (b == 0) return new Interval(1.0, 1.0); // x^0 = 1 246 if (b == 1) return a; 247 if (b % 2 == 0) { 248 // even powers (see x²) 249 if (a.UpperBound <= 0) return new Interval(Math.Pow(a.UpperBound, b), Math.Pow(a.LowerBound, b)); // interval is negative 250 if (a.LowerBound >= 0) return new Interval(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b)); // interval is positive 251 return new Interval(0, Math.Max(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b))); // interval goes over zero 252 } else { 253 // odd powers (see x³) 254 return new Interval(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b)); 255 } 236 256 } 237 257 … … 267 287 } 268 288 269 public static Interval Analytic alQuotient(Interval a, Interval b) {289 public static Interval AnalyticQuotient(Interval a, Interval b) { 270 290 var dividend = a; 271 291 var divisor = Add(Square(b), new Interval(1.0, 1.0)); … … 276 296 } 277 297 #endregion 298 299 #region arithmetic overloads 300 public static Interval operator +(Interval a, Interval b) => Add(a, b); 301 public static Interval operator +(Interval a, double b) => Add(a, new Interval(b)); 302 public static Interval operator +(double a, Interval b) => Add(new Interval(a), b); 303 public static Interval operator -(Interval a, Interval b) => Subtract(a, b); 304 public static Interval operator -(Interval a, double b) => Subtract(a, new Interval(b)); 305 public static Interval operator -(double a, Interval b) => Subtract(new Interval(a), b); 306 public static Interval operator -(Interval a) => Subtract(new Interval(0), a); 307 public static Interval operator *(Interval a, Interval b) => Multiply(a, b); 308 public static Interval operator *(Interval a, double b) => Multiply(a, new Interval(b)); 309 public static Interval operator *(double a, Interval b) => Multiply(new Interval(a), b); 310 public static Interval operator /(Interval a, Interval b) => Divide(a, b); 311 public static Interval operator /(Interval a, double b) => Divide(a, new Interval(b)); 312 public static Interval operator /(double a, Interval b) => Divide(new Interval(a), b); 313 public static Interval Exponential(double a) { return Exponential(new Interval(a)); } 314 public static Interval Logarithm(double a) { return Logarithm(new Interval(a)); } 315 public static Interval Sine(double a) { return Sine(new Interval(a)); } 316 public static Interval Cosine(double a) { return Cosine(new Interval(a)); } 317 public static Interval Tangens(double a) { return Tangens(new Interval(a)); } 318 public static Interval HyperbolicTangent(double a) { return HyperbolicTangent(new Interval(a)); } 319 public static Interval Square(double a) { return Square(new Interval(a)); } 320 public static Interval Cube(double a) { return Cube(new Interval(a)); } 321 public static Interval SquareRoot(double a) { return SquareRoot(new Interval(a)); } 322 public static Interval CubicRoot(double a) { return CubicRoot(new Interval(a)); } 323 public static Interval Absolute(double a) { return Absolute(new Interval(a)); } 324 public static Interval AnalyticQuotient(Interval a, double b) { return AnalyticQuotient(a, new Interval(b)); } 325 public static Interval AnalyticQuotient(double a, Interval b) { return AnalyticQuotient(new Interval(a), b); } 326 public static Interval AnalyticQuotient(double a, double b) { return AnalyticQuotient(new Interval(a), new Interval(b)); } 327 #endregion 278 328 } 279 329 }
Note: See TracChangeset
for help on using the changeset viewer.