Repository navigation
Factorize refuses 0 and negative numbers rather than answering them as 1 - #2468
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 throwsInvalidNumberExceptionfor an integer that is not positive, which is the typeDocs/Usage/Exceptions.mdnames for "a numeric argument … this operation cannot use", and whatTaylorExpansionthrows for a negative term count. The return type is unchanged:nullwould 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 inInteger.Factorize(), whichMathS.NumberTheory.Factorizeand the catalogue'sprime_factorizationboth call.Factorize(360)[(2,3), (3,2), (5,1)]Factorize(1)[]Factorize(0),(-1),(-12)[]InvalidNumberExceptionphi(0),phi(-12)0,0divisorsigma(1, -12),divisorsigma(1, 0)NaN,NaNvaluation(-12, 2),valuation(0, 2)2,+ooCountDivisors(0),CountDivisors(-12)0,0The only internal caller that goes through
Factorizeis the divisor list inPolynomialFactoring, which passes the absolute value of a non-zero coefficient;phi,divisorsigma,mobius,primenu,primeomega,valuationandCountDivisorscheck the sign first and use their own factorisation, and the parser and MCP server refusefactorizeby name (#2453). The XML docs state the domain with an<exception>tag, and the entry is inBREAKING-CHANGES.md.Tests:
Issue2466_*, 16 cases inAFactorisationPastTheLongsTest.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