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
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[AngouriMath/Functions/NumberTheory/ResidueClasses.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

[AngouriMath/Functions/NumberTheory/GreatestCommonDivisor.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

[Tests/UnitTests/Calculus/APowerTimesAFunctionOfItsPowerTest.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

Expand Down
2 changes: 1 addition & 1 deletion Sources/AngouriMath/Convenience/MathS.Polynomials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private static bool SameAsOne(MultivariatePolynomial poly)
var denominator = EInteger.One;
foreach (var coefficient in rational)
denominator = coefficient.Denominator
.Divide(coefficient.Denominator.Gcd(denominator)).Multiply(denominator);
.Divide(coefficient.Denominator.GreatestCommonDivisor(denominator)).Multiply(denominator);
var whole = new EInteger[rational.Length];
for (var i = 0; i < whole.Length; i++)
whole[i] = rational[i].Numerator.Multiply(denominator.Divide(rational[i].Denominator));
Expand Down
2 changes: 1 addition & 1 deletion Sources/AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static class NumberTheory
/// </code>
/// </example>
public static Integer GreatestCommonDivisor(Integer a, Integer b)
=> a.EInteger.Gcd(b.EInteger);
=> a.EInteger.GreatestCommonDivisor(b.EInteger);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ public static Rational Create(ERational value)
+ $"use {nameof(Real)}.{nameof(Real.Create)} instead");

if (!MathS.Settings.DowncastingEnabled)
return new Rational(value.ToLowestTerms());
return new Rational(value.InLowestTerms());

// Call ToLowestTerms() through new RationalNumber first
// Call InLowestTerms() through new RationalNumber first
// before determining whether the denominator equals one
var @return = new Rational(value.ToLowestTerms());
var @return = new Rational(value.InLowestTerms());
if (@return.ERational.Denominator.Equals(1))
return Integer.Create(@return.ERational.Numerator);
else
Expand Down Expand Up @@ -208,7 +208,7 @@ public static Rational Create(ERational value)
var rat = FindRationalExactly(inv, iterCount - 1);
if (rat is null)
return null;
return new Rational((intPart * sign + sign / rat.ERational).ToLowestTerms());
return new Rational((intPart * sign + sign / rat.ERational).InLowestTerms());
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/AngouriMath/Functions/Algebra/Groebner/Fglm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ internal static class Fglm
continue;
var factor = vector[pivot].Divide(rowVectors[row][pivot]);
for (var i = 0; i < vector.Length; i++)
vector[i] = vector[i].Subtract(factor.Multiply(rowVectors[row][i])).ToLowestTerms();
vector[i] = vector[i].Subtract(factor.Multiply(rowVectors[row][i])).InLowestTerms();
for (var i = 0; i < rowCombinations[row].Length && i < combination.Length; i++)
combination[i] = combination[i].Add(factor.Multiply(rowCombinations[row][i])).ToLowestTerms();
combination[i] = combination[i].Add(factor.Multiply(rowCombinations[row][i])).InLowestTerms();
}

var pivotAt = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal static MultivariatePolynomial Term(int variableCount, ulong monomial, E
{
var built = new Dictionary<ulong, ERational>();
if (!coefficient.IsZero)
built[monomial] = coefficient.ToLowestTerms();
built[monomial] = coefficient.InLowestTerms();
return new(variableCount, built);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,6 @@ private static RationalPolynomial Derivative(RationalPolynomial poly)

private static EInteger Lcm(EInteger left, EInteger right)
=> left.IsZero || right.IsZero ? EInteger.One
: left.Divide(left.Gcd(right)).Multiply(right);
: left.Divide(left.GreatestCommonDivisor(right)).Multiply(right);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ private static bool NextPoint(int[] point, int attempt, int count)
if (Evaluate(pair.Value, others, point, depth + 1) is not { } inner)
return null;
total = total.Add(inner.Multiply(ERational.Create(at.Pow(pair.Key), EInteger.One)))
.ToLowestTerms();
.InLowestTerms();
}
return total;
}

private static EInteger Lcm(EInteger left, EInteger right)
=> left.Divide(left.Gcd(right)).Multiply(right);
=> left.Divide(left.GreatestCommonDivisor(right)).Multiply(right);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ internal EInteger Content()
{
var content = EInteger.Zero;
foreach (var coefficient in coefficients)
content = content.Gcd(coefficient);
content = content.GreatestCommonDivisor(coefficient);
return content;
}

Expand Down Expand Up @@ -276,7 +276,7 @@ internal static IntegerPolynomial Gcd(IntegerPolynomial left, IntegerPolynomial
if (right.IsZero)
return left.PrimitivePart().ScaleBy(left.Content());

var contentGcd = left.Content().Gcd(right.Content());
var contentGcd = left.Content().GreatestCommonDivisor(right.Content());
var a = left.PrimitivePart();
var b = right.PrimitivePart();
if (a.Degree < b.Degree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private static (EInteger Residue, EInteger Modulus)? Residue(Entity divisor, Ent
return null;
// s k + e = 0 mod m: solvable where g = gcd(s, m) divides e, and then k is one class
// modulo m / g, found by trying its members.
var g = s.EInteger.Gcd(m);
var g = s.EInteger.GreatestCommonDivisor(m);
if (!e.EInteger.Remainder(g).IsZero)
return (EInteger.Zero, EInteger.Zero);
var classModulus = m.Divide(g);
Expand All @@ -408,7 +408,7 @@ private static (EInteger Residue, EInteger Modulus)? Residue(Entity divisor, Ent
/// </summary>
private static (EInteger Residue, EInteger Modulus)? Combined(EInteger r1, EInteger m1, EInteger r2, EInteger m2)
{
var combined = m1.Divide(m1.Gcd(m2)).Multiply(m2);
var combined = m1.Divide(m1.GreatestCommonDivisor(m2)).Multiply(m2);
if (combined.CompareTo(EInteger.FromInt32(MaxModulus)) > 0)
return null;
for (var t = r1; t.CompareTo(combined) < 0; t = t.Add(m1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ bool Peel(MultivariatePolynomial rest, int depth, int at)
}

private static EInteger Lcm(EInteger left, EInteger right)
=> left.Divide(left.Gcd(right)).Multiply(right);
=> left.Divide(left.GreatestCommonDivisor(right)).Multiply(right);

/// <summary>
/// Reading each exponent back as one digit of the numeral — or <see langword="null"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal static MultivariatePolynomial Constant(int variableCount, ERational val
{
var terms = new Dictionary<ulong, ERational>();
if (!value.IsZero)
terms[0] = value.ToLowestTerms();
terms[0] = value.InLowestTerms();
return new(variableCount, terms);
}

Expand Down Expand Up @@ -177,7 +177,7 @@ private static void Accumulate(Dictionary<ulong, ERational> into, ulong monomial
into[monomial] = value;
return;
}
var sum = existing.Add(value).ToLowestTerms();
var sum = existing.Add(value).InLowestTerms();
if (sum.IsZero)
into.Remove(monomial);
else
Expand All @@ -194,7 +194,7 @@ private static void Accumulate(Dictionary<ulong, ERational> into, ulong monomial
{
if (!TryMultiplyMonomials(left.Key, right.Key, VariableCount, out var monomial))
return null;
Accumulate(result, monomial, left.Value.Multiply(right.Value).ToLowestTerms());
Accumulate(result, monomial, left.Value.Multiply(right.Value).InLowestTerms());
if (result.Count > maxTerms)
return null;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ internal MultivariatePolynomial ScaleBy(ERational factor)
return Zero(VariableCount);
var result = new Dictionary<ulong, ERational>(terms.Count);
foreach (var term in terms)
result[term.Key] = term.Value.Multiply(factor).ToLowestTerms();
result[term.Key] = term.Value.Multiply(factor).InLowestTerms();
return new(VariableCount, result);
}

Expand Down Expand Up @@ -324,7 +324,7 @@ internal MultivariatePolynomial DerivativeIn(int variable)
if (power == 0)
continue;
Accumulate(result, Without(term.Key, variable) | Pack(variable, power - 1),
term.Value.Multiply(ERational.FromInt32(power)).ToLowestTerms());
term.Value.Multiply(ERational.FromInt32(power)).InLowestTerms());
}
return new(VariableCount, result);
}
Expand All @@ -347,7 +347,7 @@ internal MultivariatePolynomial DerivativeIn(int variable)
return this;
if (IsConstant)
{
var value = ConstantValue.ToLowestTerms();
var value = ConstantValue.InLowestTerms();
if (value.Sign < 0)
return null;
var (above, below) = (value.Numerator.Sqrt(), value.Denominator.Sqrt());
Expand Down Expand Up @@ -443,7 +443,7 @@ internal MultivariatePolynomial LeadingCoefficientIn(int variable)
// no later step can make it one -- so this is a "no" and not a "gave up".
if (!TryDivideMonomials(lead, divisorLead, VariableCount, out var monomial))
return null;
var value = rest.terms[lead].Divide(divisorValue).ToLowestTerms();
var value = rest.terms[lead].Divide(divisorValue).InLowestTerms();
quotient[monomial] = value;
if (divisor.MultiplyByTerm(monomial, value) is not { } product)
{
Expand All @@ -468,7 +468,7 @@ internal MultivariatePolynomial LeadingCoefficientIn(int variable)
{
if (!TryMultiplyMonomials(term.Key, monomial, VariableCount, out var product))
return null;
result[product] = term.Value.Multiply(value).ToLowestTerms();
result[product] = term.Value.Multiply(value).InLowestTerms();
}
return new(VariableCount, result);
}
Expand Down Expand Up @@ -526,7 +526,7 @@ internal MultivariatePolynomial Normalized(out ERational scale)
denominators = Lcm(denominators, term.Value.Denominator);
var numerators = EInteger.Zero;
foreach (var term in terms)
numerators = numerators.Gcd(
numerators = numerators.GreatestCommonDivisor(
term.Value.Numerator.Multiply(denominators.Divide(term.Value.Denominator)));
if (numerators.IsZero)
return this;
Expand All @@ -536,7 +536,7 @@ internal MultivariatePolynomial Normalized(out ERational scale)
return ScaleBy(scale);
}

private static EInteger Lcm(EInteger a, EInteger b) => a.Divide(a.Gcd(b)).Multiply(b);
private static EInteger Lcm(EInteger a, EInteger b) => a.Divide(a.GreatestCommonDivisor(b)).Multiply(b);

internal bool SameAs(MultivariatePolynomial other)
{
Expand Down Expand Up @@ -606,7 +606,7 @@ internal bool SameAs(MultivariatePolynomial other)
var inverse = ERational.One.Divide(parsed.ConstantValue);
var result = ERational.One;
for (var i = 0; i < -power; i++)
result = result.Multiply(inverse).ToLowestTerms();
result = result.Multiply(inverse).InLowestTerms();
return Constant(variables.Count, result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1849,13 +1849,13 @@ private static bool TrySolveByLifting(ERational[][] augmented, int rows, int wid
var common = EInteger.One;
for (var column = 0; column <= width; column++)
{
var reduced = augmented[row][column].ToLowestTerms();
var reduced = augmented[row][column].InLowestTerms();
augmented[row][column] = reduced;
common = common.Multiply(reduced.Denominator).Divide(common.Gcd(reduced.Denominator));
common = common.Multiply(reduced.Denominator).Divide(common.GreatestCommonDivisor(reduced.Denominator));
}
a[row] = new EInteger[width + 1];
for (var column = 0; column <= width; column++)
a[row][column] = augmented[row][column].Multiply(ERational.FromEInteger(common)).ToLowestTerms().Numerator;
a[row][column] = augmented[row][column].Multiply(ERational.FromEInteger(common)).InLowestTerms().Numerator;
}
var prime = EInteger.FromInt64(LiftingPrime);
static long Mod(EInteger value, EInteger prime)
Expand Down Expand Up @@ -2032,7 +2032,7 @@ static long Inverse(long value)
var sum = ERational.Zero;
for (var j = 0; j < rank; j++)
sum = sum.Add(solution[j].Multiply(ERational.FromEInteger(s[i][j])));
holds = sum.Subtract(ERational.FromEInteger(t[i])).ToLowestTerms().IsZero;
holds = sum.Subtract(ERational.FromEInteger(t[i])).InLowestTerms().IsZero;
}
if (holds)
break;
Expand All @@ -2047,14 +2047,14 @@ static long Inverse(long value)
var sum = ERational.Zero;
for (var j = 0; j < rank; j++)
sum = sum.Add(solution[j].Multiply(ERational.FromEInteger(a[row][pivotColumns[j]])));
if (!sum.Subtract(ERational.FromEInteger(a[row][width])).ToLowestTerms().IsZero)
if (!sum.Subtract(ERational.FromEInteger(a[row][width])).InLowestTerms().IsZero)
return false;
}
values = new Entity[width];
for (var column = 0; column < width; column++)
values[column] = Integer.Zero;
for (var j = 0; j < rank; j++)
values[pivotColumns[j]] = Rational.Create(solution[j].ToLowestTerms());
values[pivotColumns[j]] = Rational.Create(solution[j].InLowestTerms());
return true;
}

Expand All @@ -2079,7 +2079,7 @@ private static bool TryReconstructRational(EInteger u, EInteger m, out ERational
}
if (t1.IsZero || t1.Abs().CompareTo(bound) > 0)
return false;
value = ERational.Create(t1.Sign < 0 ? r1.Negate() : r1, t1.Abs()).ToLowestTerms();
value = ERational.Create(t1.Sign < 0 ? r1.Negate() : r1, t1.Abs()).InLowestTerms();
return true;
}

Expand Down Expand Up @@ -2132,7 +2132,7 @@ private static bool TrySolveOverRationals(Entity[][] matrix, Entity[] rhs, [NotN
// that is not grows with every row it is used against.
var pivotValue = augmented[rank][column];
for (var k = 0; k <= width; k++)
augmented[rank][k] = augmented[rank][k].Divide(pivotValue).ToLowestTerms();
augmented[rank][k] = augmented[rank][k].Divide(pivotValue).InLowestTerms();
for (var row = 0; row < rows; row++)
{
if (row == rank)
Expand All @@ -2141,7 +2141,7 @@ private static bool TrySolveOverRationals(Entity[][] matrix, Entity[] rhs, [NotN
if (factor.IsZero)
continue;
for (var k = 0; k <= width; k++)
augmented[row][k] = augmented[row][k].Subtract(factor.Multiply(augmented[rank][k])).ToLowestTerms();
augmented[row][k] = augmented[row][k].Subtract(factor.Multiply(augmented[rank][k])).InLowestTerms();
}
pivotColumnOfRow[rank] = column;
rank++;
Expand All @@ -2153,7 +2153,7 @@ private static bool TrySolveOverRationals(Entity[][] matrix, Entity[] rhs, [NotN
for (var column = 0; column < width; column++)
values[column] = Integer.Zero;
for (var row = 0; row < rank; row++)
values[pivotColumnOfRow[row]] = Rational.Create(augmented[row][width].ToLowestTerms());
values[pivotColumnOfRow[row]] = Rational.Create(augmented[row][width].InLowestTerms());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private static IEnumerable<ERational> RationalRootCandidates(ERational[] coeffic
return candidates.Distinct();
}

private static EInteger Lcm(EInteger a, EInteger b) => a.Divide(a.Gcd(b)).Multiply(b);
private static EInteger Lcm(EInteger a, EInteger b) => a.Divide(a.GreatestCommonDivisor(b)).Multiply(b);

private static IEnumerable<EInteger> Divisors(EInteger n)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ internal static bool IsWorthFactoringToSolve(Entity expr, Variable x)
if (FactorPrimitive(primitive) is not { } parts)
return null;

return new Factorization(ERational.Create(content, denominator).ToLowestTerms(), parts);
return new Factorization(ERational.Create(content, denominator).InLowestTerms(), parts);
}

/// <summary>
Expand Down Expand Up @@ -577,7 +577,7 @@ private static bool NextCombination(int[] indices, int poolCount)
return true;
}

private static EInteger Lcm(EInteger a, EInteger b) => a.Divide(a.Gcd(b)).Multiply(b);
private static EInteger Lcm(EInteger a, EInteger b) => a.Divide(a.GreatestCommonDivisor(b)).Multiply(b);

/// <summary>A polynomial written as a rational constant times powers of irreducibles.</summary>
internal readonly struct Factorization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal static bool TryCanonicalize(Entity expr, [NotNullWhen(true)] out Entity
return false;
if (leading.CompareTo(ERational.One) != 0)
{
var inverse = ERational.One.Divide(leading).ToLowestTerms();
var inverse = ERational.One.Divide(leading).InLowestTerms();
numerator = numerator.ScaleBy(inverse);
denominator = denominator.ScaleBy(inverse);
}
Expand Down
Loading
Loading