Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-1067

Stack overflow in Beta.regularizedBeta

Rank to TopRank to BottomBulk Copy AttachmentsBulk Move AttachmentsVotersWatch issueWatchersConvert to sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.2
    • 3.3
    • None
    • Java build 1.7.0_45-b18

    Description

      In org.apache.commons.math3.special.Beta.regularizedBeta(double,double,double,double,int), the case

      } else if (x > (a + 1.0) / (a + b + 2.0)) {
      ret = 1.0 - regularizedBeta(1.0 - x, b, a, epsilon, maxIterations);
      }

      is prone to infinite recursion: If x is approximately the tested value, then 1-x is approximately the tested value in the recursion. Thus, due to loss of precision after the subtraction, this condition can be true for the recursive call as well.

      Example:
      double x= Double.longBitsToDouble(4597303555101269224L);
      double a= Double.longBitsToDouble(4634227472812299606L);
      double b = Double.longBitsToDouble(4642050131540049920L);
      System.out.println(x > (a + 1.0) / (a + b + 2.0));
      System.out.println(1-x>(b + 1.0) / (b + a + 2.0));
      System.out.println(1-(1-x)>(a + 1.0) / (a + b + 2.0));

      Possible solution: change the condition to
      x > (a + 1.0) / (a + b + 2.0) && 1-x<=(b + 1.0) / (b + a + 2.0)

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            florian.erhard Florian Erhard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified

                Slack

                  Issue deployment