Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1170,10 +1170,10 @@ private static (Entity P, Entity Q)[]? OverTheGaussianRoots(
|| Read(2) is not { } leading || leading.IsZero || Read(1) is not { } linear || Read(0) is not { } free)
return null;
// M = x^2 + s x + t = (x - ρ)^2 + σ^2.
var s = linear.Divide(leading).ToLowestTerms();
var t = free.Divide(leading).ToLowestTerms();
var rho = s.Negate().Divide(ERational.FromInt32(2)).ToLowestTerms();
var sigmaSquared = t.Subtract(rho.Multiply(rho)).ToLowestTerms();
var s = linear.Divide(leading).InLowestTerms();
var t = free.Divide(leading).InLowestTerms();
var rho = s.Negate().Divide(ERational.FromInt32(2)).InLowestTerms();
var sigmaSquared = t.Subtract(rho.Multiply(rho)).InLowestTerms();
if (sigmaSquared.Sign <= 0)
return null;
var (sigmaAbove, sigmaBelow) = (sigmaSquared.Numerator.Sqrt(), sigmaSquared.Denominator.Sqrt());
Expand Down Expand Up @@ -1296,8 +1296,8 @@ bool TakeIn(Entity side, bool above)
next[m].Im.Add(binomial[m].Im.Multiply(rho.Negate())).Add(binomial[m].Re.Multiply(sigma)));
}
binomial = next;
real[j] = binomial.Select(c => c.Re.ToLowestTerms()).ToArray();
imaginary[j] = binomial.Select(c => c.Im.ToLowestTerms()).ToArray();
real[j] = binomial.Select(c => c.Re.InLowestTerms()).ToArray();
imaginary[j] = binomial.Select(c => c.Im.InLowestTerms()).ToArray();
}

// The digits in powers of M: c_j (x - r)^(-j) and its conjugate are 2 Re(c_j (x - r̄)^j)/M^j,
Expand Down Expand Up @@ -1343,7 +1343,7 @@ private static ERational Power(ERational value, int exponent)
{
var result = ERational.One;
for (var k = 0; k < exponent; k++)
result = result.Multiply(value).ToLowestTerms();
result = result.Multiply(value).InLowestTerms();
return result;
}

Expand All @@ -1364,8 +1364,8 @@ private static ERational Power(ERational value, int exponent)
{
var coefficient = remainder[k];
quotient[k - 2] = coefficient;
remainder[k - 1] = remainder[k - 1].Subtract(coefficient.Multiply(s)).ToLowestTerms();
remainder[k - 2] = remainder[k - 2].Subtract(coefficient.Multiply(t)).ToLowestTerms();
remainder[k - 1] = remainder[k - 1].Subtract(coefficient.Multiply(s)).InLowestTerms();
remainder[k - 2] = remainder[k - 2].Subtract(coefficient.Multiply(t)).InLowestTerms();
}
digits.Add((remainder[0], remainder.Length > 1 ? remainder[1] : ERational.Zero));
current = quotient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ static bool APowerOfAQuotientOfLinearsVanishingAtPlusOrMinusOne(Entity inU, Vari
var kappa = Functions.PartialFractions.Bare((a2 / (qs * ss)).Simplify());
if (!VanishesIdentically(b2 - kappa * (ps * ss + qs * rs)) || !VanishesIdentically(c2 - kappa * ps * rs) || VanishesIdentically(c2))
return null;
var half = quadraticPower.Negate().Subtract(ERational.FromInt32(1).Divide(ERational.FromInt32(2))).ToLowestTerms();
var half = quadraticPower.Negate().Subtract(ERational.FromInt32(1).Divide(ERational.FromInt32(2))).InLowestTerms();
if (!half.Denominator.Equals(EInteger.One) || !half.Numerator.CanFitInInt32() || half.Numerator.Abs().CompareTo(EInteger.FromInt32(12)) > 0)
return null;
var bigK = half.Numerator.ToInt32Checked();
Expand Down Expand Up @@ -1178,9 +1178,9 @@ static bool APowerOfAQuotientOfLinearsVanishingAtPlusOrMinusOne(Entity inU, Vari
}
// L the largest exponent every one is a whole multiple of: the first times g/d, with d the
// denominators' least common multiple and g the numerators' greatest common divisor over it.
var denominator = ratios.Aggregate(EInteger.One, (lcm, r) => lcm * r.Denominator / lcm.Gcd(r.Denominator));
var denominator = ratios.Aggregate(EInteger.One, (lcm, r) => lcm * r.Denominator / lcm.GreatestCommonDivisor(r.Denominator));
var wholes = ratios.Select(r => r.Numerator * (denominator / r.Denominator)).ToList();
var divisor = wholes.Aggregate(EInteger.Zero, (gcd, n) => gcd.Gcd(n.Abs()));
var divisor = wholes.Aggregate(EInteger.Zero, (gcd, n) => gcd.GreatestCommonDivisor(n.Abs()));
if (divisor.IsZero)
return null;
var unit = Number.Rational.Create(divisor, denominator);
Expand Down Expand Up @@ -1279,7 +1279,7 @@ static bool AFactorAboveAQuadratic(List<KeyValuePair<EInteger, Entity>> terms, b
if (coefficient.Evaled is not Number.Rational rational || !power.CanFitInInt32() || power.ToInt32Checked() > 2 * IntegerPolynomial.MaxDegree)
return false;
rationals[halved ? power.ToInt32Checked() / 2 : power.ToInt32Checked()] = rational.ERational;
denominator = denominator * rational.ERational.Denominator / denominator.Gcd(rational.ERational.Denominator);
denominator = denominator * rational.ERational.Denominator / denominator.GreatestCommonDivisor(rational.ERational.Denominator);
}
var whole = new EInteger[rationals.Keys.Max() + 1];
for (var k = 0; k < whole.Length; k++)
Expand Down Expand Up @@ -18192,7 +18192,7 @@ private static bool IsAFunctionToRaise(Entity factor, Entity.Variable x)
var (exponent, coefficient) = (ERational.Zero, term);
if (term.ContainsNode(x) && !TryReadAMonomial(term, x, out exponent, out coefficient))
return null;
read.Add((coefficient, exponent.ToLowestTerms()));
read.Add((coefficient, exponent.InLowestTerms()));
}
if (read.Count < 2)
return null;
Expand All @@ -18204,7 +18204,7 @@ private static bool IsAFunctionToRaise(Entity factor, Entity.Variable x)
var (degree, coefficient) = (ERational.Zero, term);
if (term.ContainsNode(x) && !TryReadAMonomial(term, x, out degree, out coefficient))
return null;
degree = degree.ToLowestTerms();
degree = degree.InLowestTerms();
inB[degree] = inB.TryGetValue(degree, out var was) ? was + coefficient : coefficient;
}
var degrees = inB.Keys.Where(degree => !degree.IsZero).OrderBy(degree => degree).ToList();
Expand All @@ -18231,7 +18231,7 @@ private static bool IsAFunctionToRaise(Entity factor, Entity.Variable x)
var inU = new Dictionary<int, Entity>();
foreach (var (coefficient, exponent) in read)
{
var scaled = exponent.Multiply(ERational.FromInt32(k)).Add(ERational.FromInt32(k - 1)).ToLowestTerms();
var scaled = exponent.Multiply(ERational.FromInt32(k)).Add(ERational.FromInt32(k - 1)).InLowestTerms();
if (!scaled.Denominator.Equals(EInteger.One) || !scaled.Numerator.CanFitInInt32())
return null;
var e = scaled.Numerator.ToInt32Unchecked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ internal static bool WantsASumOverRootsAlone(Entity numerator, Entity denominato
private static bool InAPowerOfAShift(IntegerPolynomial poly)
{
var n = poly.Degree;
var shift = ERational.Create(poly[n - 1], poly[n].Multiply(EInteger.FromInt32(n))).ToLowestTerms();
var shift = ERational.Create(poly[n - 1], poly[n].Multiply(EInteger.FromInt32(n))).InLowestTerms();
// Horner in y - s: g = g (y - s) + a_i, from the leading coefficient down.
var g = new ERational[n + 1];
for (var i = 0; i <= n; i++)
Expand Down
Loading