Repository navigation
The number-theoretic functions compile - #2217
Merged
Merged
Conversation
mobius, divisorsigma, primenu, primeomega, valuation, prime and primepi compile in FastExpression and in the LINQ compiler, over Complex and over double. prime and valuation were refused with UncompilableNodeException; the other five are new since 2.6.0. Each is computed by the routines the interpreter uses: Primes.Factorization for the functions of a factorisation, IsPrime for the valuation's prime, GetPrime for the n-th prime and CountUpTo for the prime count. So a compiled value is exact at a whole argument and NaN at any other, as evaluation gives, and a number too large to factorise or a prime past the millionth is NaN where the interpreter leaves it as written. The test compares both compilers with evaluation at 68 arguments for each function of a factorisation, including 1099511627776 = 2^40, 600851475143 and the non-whole 5/2 and 1 + i; the divisor sigma at six orders, among them -1, 1/2 and i; the valuation at seven numbers and six bases, two of them not prime; the n-th prime up to the 10000th; and the prime count up to 100000. prime(x) at 10: UncompilableNodeException (2.6.0), 29 now. valuation(x, 2) at 12: UncompilableNodeException (2.6.0), 2 now. Part of #2195. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2217 +/- ##
==========================================
+ Coverage 86.62% 86.64% +0.01%
==========================================
Files 305 306 +1
Lines 67365 67494 +129
Branches 19550 19566 +16
==========================================
+ Hits 58357 58480 +123
- Misses 4897 4901 +4
- Partials 4111 4113 +2
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.
Part of #2195, item 3.
mobius,divisorsigma,primenu,primeomega,valuation,primeandprimepicompile in FastExpression and in the LINQ compiler, overComplexand overdouble.primeandvaluationwere refused withUncompilableNodeException. The other five are new since 2.6.0.Each uses the routine the interpreter uses:
mobius,primenu,primeomega,divisorsigmaPrimes.Factorizationvaluation(to check that the base is prime)IsPrimeprimeGetPrimeprimepiCountUpToSo a compiled value is exact at a whole argument and
NaNat any other, as evaluation gives. Two inputs the interpreter leaves as written areNaNwhen compiled: a number too large to factorise, and a prime past the millionth."prime(x)".ToEntity().Compile("x").Call(10)UncompilableNodeException(29, 0)"valuation(x, 2)".ToEntity().Compile("x").Call(12)UncompilableNodeException(2, 0)NumberTheoreticCompilationTestcompares both compilers with evaluation:2^40,600851475143,5/2and1 + i;-1,1/2andi;gcdandlcmare not in this PR. Evaluation takes them over the rationals, and every finite double is a rational, so a compiledgcdat0.1would be exact for the double nearest0.1and meaningless for0.1. Whether they should compile only at whole numbers, or stay refused, is a separate decision.🤖 Generated with Claude Code