Upgraded AngouriMath to v2.8.0 (#1235)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-25 18:45:24 +01:00
1 parent fae3ceb840
commit 506c06fbfc
24 files changed
+974 -105

No files matched your search

@@ -9,6 +9,16 @@ public sealed class NumericCheckTests
{
private static NumericCheckOutcome Check(string left, string right) => NumericCheck.AreEqual(MathExpressionReader.Read(left, "left"), MathExpressionReader.Read(right, "right"));
/// <summary>
/// The values an index takes across the sample points.
/// </summary>
private static List<Entity> ValuesOf(SolutionIndex index) => Enumerable.Range(0, 6)
.Select(point => NumericCheck.SampleAssignment(point, [index.Variable], [index]))
.Where(assignment => assignment.ContainsKey(index.Variable))
.Select(assignment => assignment[index.Variable])
.Distinct()
.ToList();
[Test]
public void PassesWhatIsEqual()
{
@@ -93,16 +103,42 @@ public sealed class NumericCheckTests
}
[Test]
public void GivesAnIntegerParameterIntegerValues()
public void ChecksADerivativeOfAFunctionFarLargerThanIt()
{
var parameter = MathS.Var("n_1");
var values = Enumerable.Range(0, 6).Select(point => NumericCheck.SampleAssignment(point, [parameter])[parameter]).Distinct().ToList();
var x = MathS.Var("x");
using (Assert.EnterMultipleScope())
{
Assert.That(values, Is.EquivalentTo(new Entity[] { -1, 0, 1 }));
Assert.That(NumericCheck.IsIntegerParameter(MathS.Var("n_12")), Is.True);
Assert.That(NumericCheck.IsIntegerParameter(MathS.Var("n")), Is.False);
Assert.That(NumericCheck.IsIntegerParameter(MathS.Var("n_x")), Is.False);
Assert.That(NumericCheck.IsDerivativeOf(MathExpressionReader.Read("cos(x)", "derivative"), MathExpressionReader.Read("100! + sin(x)", "function"), x), Is.EqualTo(NumericCheckOutcome.PASSED), "100! has 158 digits, so 60 of them leave nothing of sin(x).");
Assert.That(NumericCheck.IsDerivativeOf(MathExpressionReader.Read("-x^99 * e^(-x)", "derivative"), MathExpressionReader.Read("gamma(100, x)", "function"), x), Is.EqualTo(NumericCheckOutcome.PASSED), "gamma(100, x) is about 99!, and its derivative about 1e-21.");
Assert.That(NumericCheck.IsDerivativeOf(MathExpressionReader.Read("cos(x) + 10^-15", "derivative"), MathExpressionReader.Read("100! + sin(x)", "function"), x), Is.EqualTo(NumericCheckOutcome.FAILED));
Assert.That(NumericCheck.IsDerivativeOf(MathExpressionReader.Read("cos(x)", "derivative"), MathExpressionReader.Read("10^2000 + sin(x)", "function"), x), Is.EqualTo(NumericCheckOutcome.NOT_POSSIBLE), "It would take over 2,000 digits.");
}
}
[Test]
public void GivesAVariableNamedLikeAnIndexNoIntegers()
{
// The index of a family is known by its family, not by its name:
var parameter = MathS.Var("n_1");
var values = Enumerable.Range(0, 6).Select(point => NumericCheck.SampleAssignment(point, [parameter])[parameter]).Distinct().ToList();
Assert.That(values, Has.None.InstanceOf<Entity.Number.Integer>());
}
[Test]
public void GivesAnIndexIntegersOfItsSet()
{
var n = MathS.Var("n");
var integers = new SolutionIndex(n, MathS.Sets.Z);
var withoutZero = new SolutionIndex(n, (Entity.Set)MathExpressionReader.Read("ZZ \\ { 0 }", "set"));
var none = new SolutionIndex(n, (Entity.Set)MathExpressionReader.Read("{ 1/2 }", "set"));
using (Assert.EnterMultipleScope())
{
Assert.That(ValuesOf(integers), Is.EquivalentTo(new Entity[] { -1, 0, 1 }));
Assert.That(ValuesOf(withoutZero), Is.EquivalentTo(new Entity[] { -1, 1, 2 }));
Assert.That(ValuesOf(none), Is.Empty);
Assert.That(NumericCheck.AreEqual(MathExpressionReader.Read("sin(pi/6 + 2*pi*n)", "left"), MathExpressionReader.Read("1/2", "right"), [integers]), Is.EqualTo(NumericCheckOutcome.PASSED));
Assert.That(NumericCheck.AreEqual(MathExpressionReader.Read("sin(pi/6 + pi*n)", "left"), MathExpressionReader.Read("1/2", "right"), [integers]), Is.EqualTo(NumericCheckOutcome.FAILED), "At n = -1 and 1, the sine is -1/2.");
Assert.That(NumericCheck.AreEqual(MathExpressionReader.Read("n", "left"), MathExpressionReader.Read("n", "right"), [none]), Is.EqualTo(NumericCheckOutcome.NOT_POSSIBLE), "An index which takes none of the integers tried leaves no point.");
}
}