Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/27/20 07:34:25 (5 years ago)
Author:
chaider
Message:

#2971 removed root/power symbols

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17549 r17562  
    7878    }
    7979
    80 
    81 
    8280    public override string ToString() {
    8381      return "Interval: [" + LowerBound + ", " + UpperBound + "]";
     
    228226    }
    229227
    230     public static Interval Power(Interval a, Interval b) {
    231       if (a.Contains(0.0) && b.LowerBound < 0) return new Interval(double.NaN, double.NaN);
    232 
    233       int bLower = (int)Math.Round(b.LowerBound);
    234       int bUpper = (int)Math.Round(b.UpperBound);
    235 
    236       List<double> powerValues = new List<double>();
    237       powerValues.Add(Math.Pow(a.UpperBound, bUpper));
    238       powerValues.Add(Math.Pow(a.UpperBound, bUpper - 1));
    239       powerValues.Add(Math.Pow(a.UpperBound, bLower));
    240       powerValues.Add(Math.Pow(a.UpperBound, bLower + 1));
    241 
    242       powerValues.Add(Math.Pow(a.LowerBound, bUpper));
    243       powerValues.Add(Math.Pow(a.LowerBound, bUpper - 1));
    244       powerValues.Add(Math.Pow(a.LowerBound, bLower));
    245       powerValues.Add(Math.Pow(a.LowerBound, bLower + 1));
    246 
    247       return new Interval(powerValues.Min(), powerValues.Max());
    248     }
    249 
    250228    public static Interval Square(Interval a) {
    251229      if (a.UpperBound <= 0) return new Interval(a.UpperBound * a.UpperBound, a.LowerBound * a.LowerBound);     // interval is negative
     
    258236    }
    259237
    260     public static Interval Root(Interval a, Interval b) {
    261       int lower = (int)Math.Round(b.LowerBound);
    262       int higher = (int)Math.Round(b.UpperBound);
    263 
    264       //Root root(0,0) = 0
    265       if (a.LowerBound == 0 && b.LowerBound == 0 && lower == 0 && higher == 0)
    266         return new Interval(0, 0);
    267 
    268       //Root is zero ==> undefined ==> 5^-(1.0/0)
    269       if (higher == 0 || lower == 0)
    270         return new Interval(double.NaN, double.NaN);
    271 
    272       if (lower < 0 || higher < 0) {
    273         List<double> vals = new List<double>();
    274 
    275         vals.Add(Math.Pow(a.LowerBound, 1.0 / lower));
    276         vals.Add(Math.Pow(a.LowerBound, 1.0 / higher));
    277 
    278         vals.Add(Math.Pow(a.UpperBound, 1.0 / lower));
    279         vals.Add(Math.Pow(a.UpperBound, 1.0 / higher));
    280 
    281         return new Interval(vals.Min(), vals.Max());
    282       }
    283 
    284       return new Interval(Math.Pow(a.LowerBound, 1.0 / higher), Math.Pow(a.UpperBound, 1.0 / lower));
    285     }
    286 
     238    /// <summary>
     239    /// Calculates the principal square root of a given interval. Discards the second possible result of root, because
     240    /// all interpreters just calculate the positive principal root.
     241    /// </summary>
     242    /// <param name="a">Interval to build square root from.</param>
     243    /// <returns></returns>
    287244    public static Interval SquareRoot(Interval a) {
    288245      if (a.LowerBound < 0) return new Interval(double.NaN, double.NaN);
Note: See TracChangeset for help on using the changeset viewer.