Skip to content

Commit cd3b27b

Browse files
The simplification sweep, the rule-set checker and the crash harness run in CI (#1652)
* The simplification sweep, the rule-set checker and the crash harness run in CI Three more harnesses move into Sources/Tests/Harnesses, each failing on a defect and on nothing else: - SimpSweep: a simplification that changes the value at a sampled real point. - RuleCheck: a rule set that does not settle, alone or composed with the normalisation, and a Sound declaration a value falsifies. A value change under SoundUnderAssumptions stays information, as it was. - CrashCheck: a crash or an exception that is not the library declining. A case that did not finish is reported and does not fail, as in the others. CrashCheck runs one child process per case, about four minutes, so it is a job of its own beside the others. On master 529403b: 10463/10463 agree; 30 sets, 17418 applications, 0 findings; 2212 cases, 0 crashed. Part of #1256. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * CrashCheck's README says what fails the run now A case that did not finish no longer fails it, and the reason for a process per case stands without the run that showed it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 529403b commit cd3b27b

13 files changed

Lines changed: 1568 additions & 5 deletions

File tree

‎.github/workflows/Harnesses.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
dotnet build -c Release Sources/Tests/Harnesses/RootCheck
4444
dotnet build -c Release Sources/Tests/Harnesses/CasBench
4545
dotnet build -c Release Sources/Tests/Harnesses/PropCheck
46+
dotnet build -c Release Sources/Tests/Harnesses/SimpSweep
47+
dotnet build -c Release Sources/Tests/Harnesses/RuleCheck
4648
4749
# One step each, every one run whatever the one before did, so a red run names the harness.
4850
- name: BoundCheck
@@ -60,9 +62,46 @@ jobs:
6062
if: success() || failure()
6163
run: dotnet Sources/Tests/Harnesses/PropCheck/bin/Release/net10.0/propcheck.dll
6264

65+
- name: SimpSweep
66+
if: success() || failure()
67+
run: dotnet Sources/Tests/Harnesses/SimpSweep/bin/Release/net10.0/simpsweep.dll
68+
69+
- name: RuleCheck
70+
if: success() || failure()
71+
run: dotnet Sources/Tests/Harnesses/RuleCheck/bin/Release/net10.0/rulecheck.dll
72+
6373
- name: Reports
6474
if: always()
6575
uses: actions/upload-artifact@v6
6676
with:
6777
name: harness-reports
6878
path: harness-reports
79+
80+
# A job of its own: one child process per case is minutes rather than seconds, and running it
81+
# beside the others keeps them quick.
82+
CrashCheck:
83+
runs-on: ubuntu-latest
84+
env:
85+
HARNESS_REPORTS: ${{ github.workspace }}/harness-reports
86+
87+
steps:
88+
- uses: actions/checkout@v6
89+
90+
- name: Setup .NET 10
91+
uses: actions/setup-dotnet@v5
92+
with:
93+
dotnet-version: '10.x'
94+
dotnet-quality: 'preview'
95+
96+
- name: Build
97+
run: dotnet build -c Release Sources/Tests/Harnesses/CrashCheck
98+
99+
- name: CrashCheck
100+
run: dotnet Sources/Tests/Harnesses/CrashCheck/bin/Release/net10.0/crashcheck.dll
101+
102+
- name: Report
103+
if: always()
104+
uses: actions/upload-artifact@v6
105+
with:
106+
name: crashcheck-report
107+
path: harness-reports

‎CLAUDE.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ nothing else is read:
1919
[`Contributing/SimplificationContract.md`](Sources/AngouriMath/Docs/Contributing/SimplificationContract.md).
2020
A rule states the assumptions under which it holds, or it is asserting there are none.
2121

22-
Four measurement harnesses live in `Sources/Tests/Harnesses` and run in CI on every change to the
23-
library: the boundary checker, root completeness, the self-verifying solver corpus and the property
24-
checker. Each fails on a defect; its README says which. The rest are still in the analysis workspace
25-
one directory up (`work/`): simplification sweeps, a crash harness that survives a stack overflow,
26-
and a checker for the documentation's code samples. Run them before claiming anything is
22+
Seven measurement harnesses live in `Sources/Tests/Harnesses` and run in CI on every change to the
23+
library: the boundary checker, root completeness, the self-verifying solver corpus, the property
24+
checker, the simplification sweep, the rule-set checker, and a crash harness that survives a stack
25+
overflow. Each fails on a defect; its README says which. The rest are still in the analysis workspace
26+
one directory up (`work/`), among them a checker for the documentation's code samples. Run them before claiming anything is
2727
fixed.
2828

2929
There is also a *gate*, which is not a harness:

‎Sources/Tests/Harnesses/.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ boundcheck.md
33
rootcheck.md
44
coverage.md
55
propcheck.md
6+
simpsweep.md
7+
rulecheck.md
8+
crashcheck.md
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Reflection;
12+
using AngouriMath;
13+
using AngouriMath.Extensions;
14+
15+
namespace CrashCheck;
16+
17+
/// <summary>What is run against what. A case is one expression put through one operation.</summary>
18+
sealed record Case(string Expression, string Operation)
19+
{
20+
public override string ToString() => $"{Operation}::{Expression}";
21+
}
22+
23+
/// <summary>
24+
/// The case list, built rather than written down.
25+
/// </summary>
26+
/// <remarks>
27+
/// The expressions come from the <see cref="Entity"/> node types found by reflection, so a node
28+
/// added later is covered without anyone having to remember this file -- which is the whole
29+
/// reason a node's first appearance in a release has twice been the thing that crashed. They are
30+
/// then composed to a small depth, because what kills the process is nearly always a
31+
/// composition rather than a leaf: the recorded stack overflow was integration by parts feeding
32+
/// itself, not any one node.
33+
/// </remarks>
34+
static class Cases
35+
{
36+
/// The operations a case can name. Each is a whole pipeline rather than a single rule.
37+
public static readonly string[] Operations =
38+
{
39+
"simplify", "expand", "factorize", "eval", "innersimplify",
40+
"differentiate", "integrate", "limit", "solve", "alternate",
41+
"stringize-roundtrip", "latexize", "compile", "domain",
42+
};
43+
44+
/// <summary>Every concrete <see cref="Entity"/> node the library has, one instance each,
45+
/// printed so that the child process can parse it back from its argument.</summary>
46+
public static List<string> NodeInstances(out List<string> uninstantiable)
47+
{
48+
var leaves = new Entity[] { "x", 2, "1/2", "-3", "y", MathS.pi, MathS.i };
49+
var printed = new List<string>();
50+
uninstantiable = new List<string>();
51+
52+
foreach (var type in ConcreteEntityTypes())
53+
{
54+
var built = false;
55+
// The shortest constructor first: a node wants as few arguments as it can take,
56+
// and the ones with extra flags -- an interval's open/closed pair, for instance --
57+
// are covered by the written shapes below instead.
58+
foreach (var constructor in type.GetConstructors()
59+
.OrderBy(c => c.GetParameters().Length))
60+
{
61+
var parameters = constructor.GetParameters();
62+
if (parameters.Length == 0 || parameters.Length > 3) continue;
63+
if (!parameters.All(p => p.ParameterType == typeof(Entity)
64+
|| typeof(Entity).IsAssignableFrom(p.ParameterType))) continue;
65+
try
66+
{
67+
var arguments = parameters
68+
.Select((p, i) => Convert(leaves[i % leaves.Length], p.ParameterType))
69+
.ToArray();
70+
if (arguments.Any(a => a is null)) continue;
71+
var node = (Entity)constructor.Invoke(arguments);
72+
var text = node.Stringize();
73+
// It has to survive the round trip through text, since that is how it
74+
// reaches the child. A node whose printed form does not parse is itself a
75+
// finding, and StringizeRoundTripTest in the library is where that belongs.
76+
_ = text.ToEntity();
77+
printed.Add(text);
78+
built = true;
79+
break;
80+
}
81+
catch
82+
{
83+
// Try the next constructor.
84+
}
85+
}
86+
if (!built) uninstantiable.Add(type.Name);
87+
}
88+
return printed.Distinct().ToList();
89+
}
90+
91+
static object Convert(Entity leaf, Type wanted)
92+
{
93+
if (wanted == typeof(Entity)) return leaf;
94+
if (wanted == typeof(Entity.Variable)) return (Entity.Variable)"x";
95+
try
96+
{
97+
return wanted.IsInstanceOfType(leaf) ? leaf : null;
98+
}
99+
catch
100+
{
101+
return null;
102+
}
103+
}
104+
105+
static IEnumerable<Type> ConcreteEntityTypes()
106+
{
107+
var pending = new Queue<Type>();
108+
pending.Enqueue(typeof(Entity));
109+
while (pending.Count > 0)
110+
{
111+
var current = pending.Dequeue();
112+
foreach (var nested in current.GetNestedTypes(BindingFlags.Public))
113+
{
114+
pending.Enqueue(nested);
115+
if (!nested.IsAbstract && typeof(Entity).IsAssignableFrom(nested))
116+
yield return nested;
117+
}
118+
}
119+
}
120+
121+
/// <summary>
122+
/// Shapes that a constructor cannot reach, or that are worth having because something has
123+
/// already died on their kind: recursion that feeds itself, a binder, a set builder, a
124+
/// condition, and the deep nesting that turns a linear pass into an exponential one.
125+
/// </summary>
126+
public static readonly string[] WrittenShapes =
127+
{
128+
// Integration by parts feeding itself is the recorded crash.
129+
"x * ln(x)", "x2 * ln(x)", "x3 * ln(x)", "x * e ^ x", "x2 * sin(x)",
130+
"x ^ 4 * ln(x) * sin(x)", "ln(ln(ln(x)))", "e ^ e ^ e ^ x",
131+
// A rewrite whose output re-matches its own pattern.
132+
"1 / (1 / (1 / x))", "sqrt(sqrt(sqrt(x)))", "((x ^ 2) ^ 2) ^ 2",
133+
"(x + 1) ^ 8", "(x + y + 1) ^ 5", "(a + b + c + d) ^ 4",
134+
// The mathematical constants, free and bound. A bound one is a variable and a free one is
135+
// not, which is what Entity.Constant is for -- and only the free one is reachable by
136+
// construction, so the node type is otherwise uncovered here. #984
137+
"pi", "e", "sin(pi) + ln(e)", "sum(pi, pi, 1, 3)", "derivative(e ^ 2, e)", "{ e : e > 0 }",
138+
// Binders and conditions, where #878 found a condition escaping its scope.
139+
"{ x : x > 0 }", "{ x : x = x }", "{ x : 1 = 1 }", "{ x : sin(x) > 0 and x in RR }",
140+
"x provided x > 0", "x provided false", "(x provided x > 0) + 1",
141+
"piecewise(1 provided x > 0, 2 provided x <= 0)",
142+
// Sets and intervals.
143+
"{ 1, 2, 3 }", "[0; 1]", "(0; 1)", "RR", "CC", "ZZ", "QQ", "BB", "{ 1, 2 } \\/ [0; 5]",
144+
"x in ZZ", "x in QQ", "x in BB", "[0; 1) \\/ (1; 2]",
145+
"{ 1, 2 } /\\ [0; 5]", "{ x : x in RR } \\ { 0 }",
146+
// Matrices, including the shapes that made Simplify stop descending.
147+
"[[1, 2], [3, 4]]", "[1, 2, 3]", "[[x, y], [y, x]]",
148+
// Lambdas and applications, added late and with no parser support for years.
149+
"x -> x + 1", "(x -> x + 1) applied to 2",
150+
// Nodes whose evaluation reaches for a limit, which reaches for evaluation.
151+
"limit(x!, x, +oo)", "limit(x ^ x, x, 0)", "limit(floor(x), x, 0)",
152+
"limit(sgn(x) / x, x, 0)", "derivative(abs(x), x)", "integral(1 / x, x)",
153+
"integral(integral(x, x), x)", "derivative(derivative(sin(x), x), x)",
154+
// The power form of the derivative, where a derivative that cannot be taken survives
155+
// every pass. Derivativef's simplification decides by asking for the derivative and
156+
// keeping the node when a Derivativef comes back -- so anything that simplifies on the
157+
// way to that test asks the same node again and never stops. Cost me a stack overflow
158+
// at 3214 frames. https://github.com/asc-community/AngouriMath/issues/1002
159+
"derivative(x!, x, 2)", "derivative(x!, x, 3)", "derivative(sin(x!) + x, x, 2)",
160+
"derivative(apply(f, x), x, -1)", "derivative(apply(f, x), x, -2)",
161+
"derivative(abs(x), x, 2)", "derivative(sgn(x), x, 2)",
162+
// The degenerate arithmetic that a rule's assumption is usually about.
163+
"0 ^ 0", "1 ^ (+oo)", "(+oo) - (+oo)", "0 * (+oo)", "log(1, 1)", "x / x", "x - x",
164+
"0 / 0", "(-8) ^ (1/3)", "(-1) ^ (1/2)", "abs(sgn(x))",
165+
// Factorials and gamma, which have their own recursion.
166+
"x!", "(x + 1)! / x!", "(x!)!", "gamma(gamma(x))",
167+
// Big and small numbers, where the decimal context saturates.
168+
"2 ^ 1000", "2 ^ (-1000)", "10 ^ 10000", "1 / 10 ^ 200",
169+
// Booleans, where excluded middle was decided wrongly.
170+
"x > 0 or x <= 0", "not (x > 0) or (x > 0)", "a and not a", "a xor a",
171+
};
172+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<!--
4+
Does anything take the process down: every case runs in a child process of its own, so a
5+
stack overflow is a result rather than the end of the run.
6+
A harness, not a test project: it is run by .github/workflows/Harnesses.yml and by hand,
7+
and `dotnet test` does not pick it up. See ../README.md.
8+
-->
9+
10+
<PropertyGroup>
11+
<OutputType>Exe</OutputType>
12+
<TargetFramework>net10.0</TargetFramework>
13+
<Nullable>disable</Nullable>
14+
<LangVersion>preview</LangVersion>
15+
<AssemblyName>crashcheck</AssemblyName>
16+
<RootNamespace>CrashCheck</RootNamespace>
17+
<InvariantGlobalization>true</InvariantGlobalization>
18+
<IsPackable>false</IsPackable>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<Compile Include="../Shared/*.cs" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<ProjectReference Include="../../../AngouriMath/AngouriMath.csproj" />
27+
</ItemGroup>
28+
</Project>

0 commit comments

Comments
 (0)