Skip to content

gcd and lcm compile at whole arguments; the binders are refused alike, saying to evaluate first - #2443

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
compile-gcd-and-binder-refusal
Nov 14, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
compile-gcd-and-binder-refusal

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Part of #2195: the two decisions left open in the last note there.

gcd and lcm compile at whole arguments, NaN at any other, in FastExpression and the LINQ compiler, over Complex and over double, the way #2217 compiles mobius and prime. Evaluation takes them over the rationals, but a compiled argument is a double, and the double nearest 0.1 is not 1/10. A whole double past 2^53 is read as the integer it is, and the result is rounded once by EFloat (not by (double)BigInteger, #2218). The signs follow evaluation, measured on 2.7.0: gcd(-4, 6) = 2, gcd(0, 5) = 5, gcd(0, 0) = 0, lcm(-4, 6) = 12, lcm(0, 3) = 0.

The calculus nodes and the binders stay refused: derivative, integral, limit, sum, product, a sum or extremum over a set, apply and lambda. Both compilers now refuse them by one check, with UncompilableNodeException as before, and the message names the node and says to call .Evaled or Simplify() first and compile the result. The LINQ compiler said the bound variable was not among the arguments, and FastExpression asked for a bug report. For a maximum, minimum, argmax or argmin over a set, .Evaled currently leaves the node as written, so the advice does not yet help there.

Measured: unit tests 19776 passed, MCP/Terminal/Interactive/F# green, AOT smoke 78/78; boundcheck 0 disagreements, rootcheck 596/596, casbench 0 wrong, propcheck 0 failures of 1355, simpsweep 10463/10463, rulecheck 0, canoncheck and confluence on baseline. work/compilecheck on this branch: FastExpression 68 of 75 numeric nodes, LINQ 68 over Complex and 67 over double, statements 16 of 16, 0 disagreements; gcd and lcm now compile in all three.

🤖 Generated with Claude Code

…, saying to evaluate first

gcd and lcm compile in FastExpression and in the LINQ compiler, over Complex
and over double: exactly at whole arguments, rounded once by EFloat, and NaN
at any other. Evaluation takes them over the rationals too, but a compiled
argument is a double, and the double nearest 0.1 is not 1/10. A whole double
past 2^53 is read as the integer it is. Both are non-negative, as evaluation
gives them: gcd(-4, 6) = 2, gcd(0, 5) = 5, gcd(0, 0) = 0, lcm(-4, 6) = 12,
lcm(0, 3) = 0. gcd(12, 18, 8) is gcd(gcd(12, 18), 8) and compiles nested.

The calculus nodes and the binders -- derivative, integral, limit, sum,
product, a sum, a maximum, a minimum, argmax and argmin over a set, apply and
lambda -- stay refused with UncompilableNodeException, by one check both
compilers run, whose message names the node and says to call .Evaled or
Simplify() first and compile the result. The LINQ compiler said the bound
variable was not among the arguments, and FastExpression asked for a bug
report for a sum, a product or a lambda.

The tests compare all three compiled forms with evaluation exactly, as
doubles, at every pair of 14 whole arguments, among them -12, 0, 2^60,
3 * 2^58 and two numbers near 10^15 whose lcm is past 2^53; check NaN at
1/2, 5/2, -3/2, i, 1 + i, NaN and infinity beside 0, 1 and 6; and assert the
refusal and its message for each binder in both compilers, and that the
evaluated expression compiles.

gcd(x, 6) at 4, by Compile: UncompilableNodeException (2.7.0), (2, 0) now.

Part of #2195.

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

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.93%. Comparing base (eec3588) to head (93d0fa2).

Files with missing lines Patch % Lines
...urces/AngouriMath/Functions/Compilation/Binders.cs 92.30% 1 Missing and 1 partial ⚠️
...gouriMath/Functions/Compilation/IntoFE/Compiler.cs 81.81% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2443      +/-   ##
==========================================
- Coverage   86.93%   86.93%   -0.01%     
==========================================
  Files         315      316       +1     
  Lines       70509    70574      +65     
  Branches    20606    20613       +7     
==========================================
+ Hits        61297    61353      +56     
- Misses       4941     4948       +7     
- Partials     4271     4273       +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.47% <94.11%> (-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 Δ
...ath/Functions/Compilation/IntoFE/FastExpression.cs 96.84% <100.00%> (+0.06%) ⬆️
...ctions/Compilation/IntoLinq/CompilationProtocol.cs 94.31% <100.00%> (+0.06%) ⬆️
...Functions/Compilation/IntoLinq/IntoLinqCompiler.cs 97.76% <100.00%> (+0.01%) ⬆️
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 75.24% <100.00%> (+0.50%) ⬆️
...s/AngouriMath/Numerics/NumberTheoreticFunctions.cs 96.61% <100.00%> (+0.95%) ⬆️
...urces/AngouriMath/Functions/Compilation/Binders.cs 92.30% <92.30%> (ø)
...gouriMath/Functions/Compilation/IntoFE/Compiler.cs 86.46% <81.81%> (-0.23%) ⬇️

... 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 2d5b90a into master Nov 14, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 14, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the compile-gcd-and-binder-refusal branch November 14, 2026 17:58
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.

1 participant