Skip to content

Commit fa6fed4

Browse files
The arm for a quadratic off the real line excludes the arms on the sign of its discriminant (#1799)
An antiderivative over a quadratic with i among its coefficients has an arm off the real line, `not D in RR or D > 0`, beside `D = 0` and `D < 0`. A sum of two such answers drops a pair of arms whose conditions contradict each other, and that arm was read against neither: `D = 0` asks D to be real, and `D < 0` is NaN off the real line, so neither pairing is ever true. The contradiction now reads `not q in RR` as a test of q, and a disjunction as contradicted where each of its arms is. x^2/(x^2 + a + i b)^3 had 7 arms and has 3. Part of #1788. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 15aae3d commit fa6fed4

3 files changed

Lines changed: 127 additions & 9 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,20 @@ whatever `a` is ([#718](https://github.com/asc-community/AngouriMath/issues/718)
480480
| `"sqrt(a + i*a*sinh(g + f*x))/x".ToEntity().Integrate("x")` | `integral(...)` | `Shi` and `Chi` of half of `f x` |
481481
| `"1/sqrt(a + i*a*sinh(g + f*x))".ToEntity().Integrate("x")` | `integral(...)` | arctangents and logarithms of `e^((g + f x)/2)` |
482482

483+
### The arm for a quadratic off the real line excludes the arms on the sign of its discriminant
484+
485+
**Shorter answers.** An antiderivative over a quadratic with `i` among its coefficients has an arm
486+
off the real line, `not D in RR or D > 0`, beside the arms `D = 0` and `D < 0`. A sum of two such
487+
answers pairs their arms and drops a pair whose conditions contradict each other, and that arm was
488+
read against neither, though `D = 0` asks `D` to be real and `D < 0` is NaN off the real line. Those
489+
pairs are dropped now
490+
([#1788](https://github.com/asc-community/AngouriMath/issues/1788)).
491+
492+
| Input | Was (2.5.0) | Now |
493+
|---|---|---|
494+
| `"x^2/(x^2 + a + i*b)^3".ToEntity().Integrate("x")` | 10 arms, and no value at a real `x`; 7 arms and 2,722 characters on the unreleased master | 3 arms, 1,069 characters |
495+
| `"1/(x^2 + i*a)^2 + 1/(x^2 + i*a)^3".ToEntity().Integrate("x")` | 9 arms, and no value at a real `x`; 7 arms and 1,994 characters on the unreleased master | 3 arms, 779 characters |
496+
483497
### The hyperbolic functions have antiderivatives, and so does anything rational in `e^(k x)`
484498

485499
An integrand rational in `e^(k x)` becomes a rational function of one variable under

‎Sources/AngouriMath/Functions/Evaluation/Evaluation.Classes.cs‎

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,28 +241,103 @@ private Entity CombinedCaseByCase(Piecewise a, Piecewise b,
241241
private static (bool Always, Entity? Undecided) Contradiction(Entity predicate)
242242
{
243243
var tests = new List<(Entity Quantity, int Relation)>();
244+
var choices = new List<Entity>();
244245
foreach (var conjunct in Conjuncts(predicate))
245246
if (SignTest(conjunct) is { } test)
246247
tests.Add(test);
248+
else if (conjunct is Orf)
249+
choices.Add(conjunct);
247250
Entity? undecided = null;
248251
for (var i = 0; i < tests.Count; i++)
249252
for (var j = i + 1; j < tests.Count; j++)
253+
switch (Against(tests[i], tests[j]))
254+
{
255+
case (true, _):
256+
return (true, null);
257+
case (false, { } quantity):
258+
undecided = quantity;
259+
break;
260+
}
261+
// A disjunction beside them contradicts them where each of its arms does: the arm a
262+
// quadratic off the real line owes, `not D in RR or D > 0`, against `D = 0` is false
263+
// for every value, and against `D < 0` false for a real one and NaN off the real
264+
// line. Read as neither, the sum of the antiderivatives over three powers of one
265+
// quadratic kept every pairing of their arms, 45 for
266+
// `2 d^3 t^2/((t^2 - c - i d)^3 (t^2 - c + i d))` where 9 hold every case.
267+
// https://github.com/asc-community/AngouriMath/issues/1788
268+
foreach (var choice in choices)
269+
{
270+
var (always, quantity, read) = (true, (Entity?)null, true);
271+
foreach (var arm in Disjuncts(choice))
250272
{
251-
if (tests[i].Quantity != tests[j].Quantity)
273+
if (SignTest(arm) is not { } armTest)
274+
{
275+
read = false;
276+
break;
277+
}
278+
var (armAlways, armQuantity) = (false, (Entity?)null);
279+
foreach (var test in tests)
280+
switch (Against(armTest, test))
281+
{
282+
case (true, _):
283+
armAlways = true;
284+
break;
285+
case (false, { } q):
286+
armQuantity ??= q;
287+
break;
288+
}
289+
if (armAlways)
252290
continue;
253-
var (r1, r2) = (tests[i].Relation, tests[j].Relation);
254-
// 0 is "= 0", 2 is "not = 0", 1 and -1 the signs.
255-
if (r1 == 0 && r2 != 0 || r2 == 0 && r1 != 0)
256-
return (true, null);
257-
if (r1 * r2 == -1)
258-
undecided = tests[i].Quantity;
291+
if (armQuantity is null || quantity is not null && quantity != armQuantity)
292+
{
293+
read = false;
294+
break;
295+
}
296+
(always, quantity) = (false, armQuantity);
259297
}
298+
if (!read)
299+
continue;
300+
if (always)
301+
return (true, null);
302+
undecided = quantity;
303+
}
260304
return (false, undecided);
261305
}
262306

307+
/// <summary>
308+
/// Two tests of one quantity <c>q</c>: in <c>Always</c> where no value satisfies both,
309+
/// and otherwise the quantity where a real one satisfies neither together and one off the
310+
/// real line makes a sign NaN; null where they do not test one quantity or agree.
311+
/// </summary>
312+
private static (bool Always, Entity? Undecided) Against((Entity Quantity, int Relation) first, (Entity Quantity, int Relation) second)
313+
{
314+
if (first.Quantity != second.Quantity)
315+
return (false, null);
316+
var (r1, r2) = (first.Relation, second.Relation);
317+
// 0 is "= 0", 2 is "not = 0", 1 and -1 the signs, 3 "not in RR": zero is real.
318+
if (r1 == 0 && r2 != 0 || r2 == 0 && r1 != 0)
319+
return (true, null);
320+
if (r1 * r2 == -1 || r1 == 3 && r2 is 1 or -1 || r2 == 3 && r1 is 1 or -1)
321+
return (false, first.Quantity);
322+
return (false, null);
323+
}
324+
325+
private static IEnumerable<Entity> Disjuncts(Entity condition)
326+
{
327+
if (condition is Orf(var left, var right))
328+
{
329+
foreach (var disjunct in Disjuncts(left))
330+
yield return disjunct;
331+
foreach (var disjunct in Disjuncts(right))
332+
yield return disjunct;
333+
}
334+
else
335+
yield return condition;
336+
}
337+
263338
/// <summary>Whether <paramref name="predicate"/> has a conjunct testing <paramref name="quantity"/> against zero.</summary>
264339
private static bool TestsTheSignOf(Entity predicate, Entity quantity)
265-
=> Conjuncts(predicate).Any(conjunct => SignTest(conjunct) is var (q, relation) && q == quantity && relation != 2);
340+
=> Conjuncts(predicate).Any(conjunct => SignTest(conjunct) is var (q, relation) && q == quantity && relation is 0 or 1 or -1);
266341

267342
/// <summary>
268343
/// A comparison of a quantity with zero as the quantity, with any constant factor taken
@@ -281,11 +356,13 @@ private static (Entity Quantity, int Relation)? SignTest(Entity conjunct)
281356
Lessf(var zero, var q) when zero == Integer.Zero => (q, 1),
282357
Lessf(var q, var zero) when zero == Integer.Zero => (q, -1),
283358
Greaterf(var zero, var q) when zero == Integer.Zero => (q, -1),
359+
Notf(Inf(var q, SpecialSet.Reals)) => (q, 3),
284360
_ => null,
285361
};
286362
if (read is not var (quantity, relation))
287363
return null;
288-
// The constant factor out: `4 f (-d)` is `f (-d)`, and `2 f` is `f`.
364+
// The constant factor out: `4 f (-d)` is `f (-d)`, and `2 f` is `f`. A real one, which
365+
// leaves `not in RR` as it is.
289366
if (quantity is Mulf(Real factor, var rest) && !factor.IsZero)
290367
(quantity, relation) = (rest, relation is 1 or -1 && factor.IsNegative ? -relation : relation);
291368
return (quantity, relation);

‎Sources/Tests/UnitTests/Core/ContradictoryConjunctionTest.cs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,33 @@ public void TwoPiecewisesOnTheSameSplitCombineCaseByCase()
9999
Assert.Equal(Number.Integer.Create(11 + 6), chain.Substitute("q", 0).Evaled);
100100
}
101101

102+
/// <summary>
103+
/// The arm an antiderivative owes a quadratic off the real line, <c>not q in RR or q &gt; 0</c>,
104+
/// against the arms on the sign of <c>q</c>: an equality asks <c>q</c> to be real, and a
105+
/// strict sign is NaN off the real line, so neither pairing is ever true, and a sum of
106+
/// such piecewises stays at three cases. The antiderivative of
107+
/// <c>2 d^3 t^2/((t^2 - c - i d)^3 (t^2 - c + i d))</c> kept 45.
108+
/// https://github.com/asc-community/AngouriMath/issues/1788
109+
/// </summary>
110+
[Fact]
111+
public void TheArmOffTheRealLineExcludesTheSignArms()
112+
{
113+
const string arms = "piecewise(1 provided not q in RR or q > 0, 2 provided q = 0, 3 provided q < 0)";
114+
var sum = (arms.ToEntity() + arms.ToEntity()).InnerSimplified;
115+
Assert.Equal(3, CaseCount(sum));
116+
Assert.Equal(Number.Integer.Create(2), sum.Substitute("q", 1).Evaled);
117+
Assert.Equal(Number.Integer.Create(4), sum.Substitute("q", 0).Evaled);
118+
Assert.Equal(Number.Integer.Create(6), sum.Substitute("q", -1).Evaled);
119+
Assert.Equal(Number.Integer.Create(2), sum.Substitute("q", "i").Evaled);
120+
121+
var chain = sum;
122+
for (var i = 0; i < 4; i++)
123+
chain = (chain + arms.ToEntity()).InnerSimplified;
124+
Assert.Equal(3, CaseCount(chain));
125+
Assert.Equal(Number.Integer.Create(6), chain.Substitute("q", "1 + i").Evaled);
126+
Assert.Equal(Number.Integer.Create(18), chain.Substitute("q", -2).Evaled);
127+
}
128+
102129
/// <summary>
103130
/// A quantity is read up to a constant factor: <c>f = 0</c> and <c>not 2 f = 0</c>
104131
/// contradict each other, which is how the integrator's case for a vanishing leading

0 commit comments

Comments
 (0)