Skip to content

Commit

Permalink
polynomial: spelling typos and minor refactoring (thanks to Christian…
Browse files Browse the repository at this point in the history
… Schlotter!)
  • Loading branch information
cdrnet committed Aug 17, 2008
1 parent 1d839e5 commit e0e60af
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions src/app/MathNet.Iridium/Library/Polynomial.cs
Expand Up @@ -500,7 +500,7 @@ public static

#region Inplace Arithmetic Methods

/// <summary>Add anoter polynomial inplace to this polynomial.</summary>
/// <summary>Add another polynomial inplace to this polynomial.</summary>
/// <remarks>This method operates inplace and thus alters this instance.</remarks>
public
void
Expand Down Expand Up @@ -592,14 +592,16 @@ Polynomial polynomial
/// Multiply two polynomials.
/// </summary>
/// <remarks>
/// If both polynomials have an order > 3, the faster karatsua algorithm is used.
/// If both polynomials have an order > 3, the faster karatsuba algorithm is used.
/// </remarks>
public
Polynomial
Multiply(
Polynomial polynomial
)
{
// TODO: Measure the smallest order where karatsuba is really faster.
// (the current ">3" is currently not based on hard measured numbers!)
int orderMin = Math.Min(Order, polynomial.Order);
if(orderMin > 3)
{
Expand All @@ -616,19 +618,9 @@ Polynomial polynomial
0
);
}
else
{
double[] coeff = new double[1 + Order + polynomial.Order];
for(int i = 0; i <= order; i++)
{
for(int j = 0; j <= polynomial.order; j++)
{
coeff[i + j] += coefficients[i] * polynomial.coefficients[j];
}
}

return new Polynomial(coeff);
}
// TODO: Measure whether hard inlining would bring enough advantage to justify it.
return MultiplySlow(polynomial);
}

Polynomial
Expand Down Expand Up @@ -748,15 +740,15 @@ int n
}

/// <summary>
/// Multiplies this polynomial with x-a
/// Multiplies this polynomial with x-c0
/// where x is its base and c0 a constant.
/// This process is the counterpart to synthetic division.
/// </summary>
/// <remarks>This method operates inplace and thus alters this instance.</remarks>
public
void
MultiplySyntheticInplace(
double a
double c0
)
{
EnsureSupportForOrder(order + 1);
Expand All @@ -765,10 +757,10 @@ int n

for(int j = order - 1; j >= 1; j--)
{
coefficients[j] = coefficients[j - 1] - a * coefficients[j];
coefficients[j] = coefficients[j - 1] - c0 * coefficients[j];
}

coefficients[0] *= -a;
coefficients[0] *= -c0;
}

/// <summary>
Expand All @@ -795,7 +787,7 @@ int n


/// <summary>
/// Divides this polynomial with anoter polynomial.
/// Divides this polynomial with another polynomial.
/// </summary>
public
Rational
Expand Down Expand Up @@ -836,18 +828,18 @@ Polynomial polynomial
void
DivideShiftInplace(
int n,
out double[] reminder
out double[] remainder
)
{
if(n <= 0)
{
throw new ArgumentOutOfRangeException("n", n, Resources.ArgumentPositive);
}

reminder = new double[n];
remainder = new double[n];
for(int i = 0; i < n; i++)
{
reminder[i] = coefficients[i];
remainder[i] = coefficients[i];
}

order -= n;
Expand All @@ -868,26 +860,26 @@ Polynomial polynomial
}

/// <summary>
/// Divides this polynomial with x-a
/// Divides this polynomial with x-c0
/// where x is its base and c0 a constant.
/// This process is often called synthetic division.
/// </summary>
/// <remarks>This method operates inplace and thus alters this instance.</remarks>
public
void
DivideSyntheticInplace(
double a,
out double reminder
double c0,
out double remainder
)
{
double swap;
reminder = coefficients[order];
remainder = coefficients[order];
coefficients[order--] = 0;
for(int i = order; i >= 0; i--)
{
swap = coefficients[i];
coefficients[i] = reminder;
reminder = swap + a * reminder;
coefficients[i] = remainder;
remainder = swap + c0 * remainder;
}

NormalizeOrder();
Expand All @@ -902,19 +894,19 @@ Polynomial polynomial
DivideLinearInplace(
double c0,
double c1,
out double reminder
out double remainder
)
{
if(Number.AlmostZero(c1))
{
DivideInplace(c0);
reminder = 0d;
remainder = 0d;
return;
}

double a = -c0 / c1;
DivideInplace(c1);
DivideSyntheticInplace(a, out reminder);
DivideSyntheticInplace(a, out remainder);
}
#endregion

Expand Down

0 comments on commit e0e60af

Please sign in to comment.