Skip to content

Factorize refuses 0 and negative numbers rather than answering them as 1 - #2468

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
fix/factorize-zero-and-negatives
Nov 16, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
fix/factorize-zero-and-negatives

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

MathS.NumberTheory.Factorize(n) returned [] for 0, −1 and −12. An empty list is the factorisation of 1, so each answer claimed the number was 1. It now throws InvalidNumberException for an integer that is not positive, which is the type Docs/Usage/Exceptions.md names for "a numeric argument … this operation cannot use", and what TaylorExpansion throws for a negative term count. The return type is unchanged: null would have needed a nullable return, and a negative number as −1 times the factorisation of |n| would need a slot for the sign that a list of (prime, power) does not have. The guard is in Integer.Factorize(), which MathS.NumberTheory.Factorize and the catalogue's prime_factorization both call.

input was (2.7.0, and master) now
Factorize(360) [(2,3), (3,2), (5,1)] unchanged
Factorize(1) [] unchanged
Factorize(0), (-1), (-12) [] InvalidNumberException
phi(0), phi(-12) 0, 0 unchanged
divisorsigma(1, -12), divisorsigma(1, 0) NaN, NaN unchanged
valuation(-12, 2), valuation(0, 2) 2, +oo unchanged
CountDivisors(0), CountDivisors(-12) 0, 0 unchanged

The only internal caller that goes through Factorize is the divisor list in PolynomialFactoring, which passes the absolute value of a non-zero coefficient; phi, divisorsigma, mobius, primenu, primeomega, valuation and CountDivisors check the sign first and use their own factorisation, and the parser and MCP server refuse factorize by name (#2453). The XML docs state the domain with an <exception> tag, and the entry is in BREAKING-CHANGES.md.

Tests: Issue2466_*, 16 cases in AFactorisationPastTheLongsTest.cs. Full check: 20,135 unit tests, 0 failed; MCP 444, Terminal 69, F# 134, Interactive 19; AOT OK; BoundCheck 0 disagreements, RootCheck 596/596, CasBench 120/121 with 0 wrong, SimpSweep 10463/10463, RuleCheck clean, CanonCheck and Confluence at their baselines.

Closes #2466.

🤖 Generated with Claude Code

Part of #2466

Factorize answered 0, -1 and -12 with the empty list, the factorisation
of 1. 0 has no factorisation into primes, and a negative integer is -1
times the factorisation of its absolute value, which a list of primes
cannot write. Each now throws InvalidNumberException, the type
Exceptions.md gives for a numeric argument an operation cannot use (as
TaylorExpansion does for a negative term count); 1 is still the empty
product. The return type is unchanged.

phi, divisorsigma, mobius, primenu, primeomega, valuation and
CountDivisors do not go through Integer.Factorize and answer as before
at 0 and below, pinned by tests; the rational-root divisors take the
absolute value of a non-zero coefficient.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.95%. Comparing base (3abd4d9) to head (7ff4495).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2468   +/-   ##
=======================================
  Coverage   86.95%   86.95%           
=======================================
  Files         320      320           
  Lines       71457    71460    +3     
  Branches    20864    20865    +1     
=======================================
+ Hits        62132    62135    +3     
  Misses       5005     5005           
  Partials     4320     4320           
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.48% <100.00%> (+<0.01%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 39.81% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/AngouriMath/Convenience/MathS.cs 90.74% <ø> (ø)
...Continuous/Entity.Continuous.Integer.Definition.cs 85.18% <100.00%> (+0.87%) ⬆️
Sources/AngouriMath/Core/Operations/Catalogue.cs 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 8c0ec60 into master Nov 16, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 16, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fix/factorize-zero-and-negatives branch November 16, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

MathS.NumberTheory.Factorize answers 0 and negative numbers as if they were 1

1 participant