Fixed calculation of root-isolating intervals and tests

This commit is contained in:
Stefan Müller 2024-05-25 02:50:24 +02:00
parent 748964c871
commit ae30889bbb
2 changed files with 9 additions and 7 deletions

View File

@ -28,8 +28,8 @@ type
{ TIsolatingInterval }
// Represents an isolating interval of the form [C / 2^K, (C + H) / 2^K] in respect to [0, 1] or [A / 2^K, B / 2^K] in
// respect to [0, bound], with A = C * bound and B = (C + H) * bound.
// Represents an isolating interval of the form [C / 2^K, (C + H) / 2^K] in respect to [0, 1] or [A, B] in respect to
// [0, bound], with A = C * bound / 2^K and B = (C + H) * bound / 2^K.
TIsolatingInterval = record
C, K, H: Cardinal;
Bound, A, B: TBigInt;
@ -82,8 +82,8 @@ begin
Result.K := AK;
Result.H := AH;
Result.Bound := ABound;
Result.A := AC * ABound;
Result.B := (AC + AH) * ABound;
Result.A := (AC * ABound) >> AK;
Result.B := ((AC + AH) * ABound) >> AK;
end;
function TRootIsolation.Bisect(constref APolynomial: TBigIntPolynomial): TIsolatingIntervals;

View File

@ -49,20 +49,22 @@ procedure TPolynomialRootsTestCase.AssertBisectResult(constref AIsolatingInterva
AExpectedRoots: array of Cardinal);
var
exp: Cardinal;
ri: TIsolatingInterval;
found: Boolean;
i, foundIndex: Integer;
begin
AssertEquals('Unexpected number of isolating intervals.', Length(AExpectedRoots), AIsolatingIntervals.Count);
for exp in AExpectedRoots do
begin
found := False;
for ri in AIsolatingIntervals do
if (ri.A <= exp) and (exp <= ri.B) then
for i := 0 to AIsolatingIntervals.Count - 1 do
if (AIsolatingIntervals[i].A <= exp) and (exp <= AIsolatingIntervals[i].B) then
begin
found := True;
foundIndex := i;
Break;
end;
AssertTrue('No isolating interval for expected root ' + IntToStr(exp) + ' found.', found);
AIsolatingIntervals.Delete(foundIndex);
end;
end;