diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md
index 22bbeb165..a7530b85b 100644
--- a/BREAKING-CHANGES.md
+++ b/BREAKING-CHANGES.md
@@ -573,6 +573,20 @@ Every spelling but `lcm` was a parse error in 2.5.0, the congruence node being n
| `forall n in ZZ : 6 divides n^3 + 5 n` | `UnhandledParseException` | `True` |
| `exists x, y in ZZ : 3 x^2 - 5 y^2 = 1` | `UnhandledParseException` | `False` |
+### Floors and ceilings of `n` over a whole number are decided over its residues
+
+A comparison between floors and ceilings of linear functions of `n` and a linear part in `n`
+repeats with the least common multiple of their denominators where the drifts cancel: over a
+period, a floor of `(p/q) n + b` rises by as much as the linear terms do. The residues then decide
+it, as they decide a divisibility. `forall n in ZZ : floor(n/2) + ceil(n/2) = n` and Hermite's
+`floor(n/3) + floor((n + 1)/3) + floor((n + 2)/3) = n` are `True`, where they were left as written
+([#1409](https://github.com/asc-community/AngouriMath/issues/1409)).
+
+| Input | Was (2.5.0) | Now |
+|---|---|---|
+| `forall n in ZZ : floor(n/2) + ceil(n/2) = n` | `UnhandledParseException` (left as written when quantifiers arrived) | `True` |
+| `exists n in ZZ : floor(n/2) + ceil(n/2) = n + 1` | `UnhandledParseException` (left as written when quantifiers arrived) | `False` |
+
### An antiderivative built through an even root says where the root is real
The linear-radical substitution, `u = (a x + b)^(1/q)`, and the general substitution for an even
diff --git a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs
index 3cebc869f..249eeaf08 100644
--- a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs
+++ b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs
@@ -773,6 +773,10 @@ internal static bool IsIntegerSet(SpecialSet set)
case Equalsf or Greaterf or GreaterOrEqualf or Lessf or LessOrEqualf:
if (body is not IBinaryNode { NodeFirstChild: var lhs, NodeSecondChild: var rhs })
return null;
+ // Floors and ceilings of linear functions beside a linear part, where the
+ // drifts cancel: floor(n/2) + ceil(n/2) - n repeats with 2.
+ if (DriftlessPeriod(lhs - rhs, x) is { } rounding)
+ return rounding;
if (ResiduePeriod(lhs, x, set) is not { } l || ResiduePeriod(rhs, x, set) is not { } r)
return null;
return l * r / l.Gcd(r);
@@ -846,6 +850,50 @@ private static bool OnlyAbout(Entity condition, Variable x)
}
}
+ ///
+ /// The period of a sum of floors and ceilings of linear functions of
+ /// and of a linear part, where the drifts cancel, or . A floor of
+ /// (p/q) x + b rises by p when x rises by q, and a linear
+ /// term by its slope times q, so where these sum to nothing the difference repeats
+ /// with the least common multiple of the q: floor(n/2) + ceil(n/2) - n with
+ /// 2, and Hermite's floor(n/3) + floor((n + 1)/3) + floor((n + 2)/3) - n with 3.
+ /// https://github.com/asc-community/AngouriMath/issues/1409
+ ///
+ private static EInteger? DriftlessPeriod(Entity difference, Variable x)
+ {
+ var period = EInteger.One;
+ var drift = ERational.Zero;
+ var rounded = false;
+ foreach (var term in Sumf.LinearChildren(difference))
+ {
+ if (!term.ContainsNode(x))
+ continue;
+ var (coefficient, core) = term is Mulf(Rational factor, var rest) ? (factor.ERational, rest) : (ERational.One, term);
+ var argument = core switch
+ {
+ Floorf floor => floor.Argument,
+ Ceilf ceiling => ceiling.Argument,
+ _ => null,
+ };
+ if (Slope(argument ?? core, x) is not { } slope)
+ return null;
+ if (argument is not null)
+ {
+ rounded = true;
+ var q = slope.Denominator.Abs();
+ period = period * q / period.Gcd(q);
+ }
+ drift = drift.Add(coefficient.Multiply(slope));
+ }
+ return rounded && drift.IsZero ? period : null;
+ }
+
+ /// The slope of an expression linear in with a rational one, or .
+ private static ERational? Slope(Entity expression, Variable x)
+ => TreeAnalyzer.TryGetPolyLinear(expression, x, out var a, out var b) && !b.ContainsNode(x) && a.Evaled is Rational rate
+ ? rate.ERational
+ : null;
+
///
/// The period, in , of an expression's residue modulo
/// : the modulus for a polynomial with whole coefficients,
diff --git a/Sources/Tests/UnitTests/Core/QuantifierTest.cs b/Sources/Tests/UnitTests/Core/QuantifierTest.cs
index 21a18dca7..edc589120 100644
--- a/Sources/Tests/UnitTests/Core/QuantifierTest.cs
+++ b/Sources/Tests/UnitTests/Core/QuantifierTest.cs
@@ -91,6 +91,14 @@ public void DecidedOverAFiniteSet(string statement, string expected)
[InlineData("exists! k in ZZ : (0 < k and k < 7) and 3 divides k and 2 divides k", "True")]
[InlineData("forall k in ZZ : (0 < k and k < 7 and 2 divides k) implies 3 divides binomial(7, k) - 1", "False")]
[InlineData("forall n in ZZ : n >= 5 implies 2^n > n^2", "True")]
+ // Floors and ceilings of n over a whole number beside n itself repeat where the drifts
+ // cancel, and the residues decide them: floor(n/2) + ceil(n/2) = n, and Hermite's
+ // identity for thirds.
+ [InlineData("forall n in ZZ : floor(n/2) + ceil(n/2) = n", "True")]
+ [InlineData("forall n in ZZ : floor(n/3) + floor((n + 1)/3) + floor((n + 2)/3) = n", "True")]
+ [InlineData("forall n in ZZ : floor(n/2) = n/2", "False")]
+ [InlineData("forall n in ZZ+ : ceil(n/2) - floor(n/2) <= 1", "True")]
+ [InlineData("exists n in ZZ : floor(n/2) + ceil(n/2) = n + 1", "False")]
// Prob 8.9.24 for every prime: that p is prime and 0 < k < p is established by the
// quantifiers around the claim, in either order and with the hypothesis curried, and the
// rule for p divides binomial(p, k) reads it. Without the primality, or without either