Skip to content

A congruence compiles - #2233

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-congruence-compiles
Oct 30, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-congruence-compiles

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Part of #2195, item 3.

a = b (mod n) was refused by both compilers, the last statement about whole numbers that was. It now compiles to the truth value evaluation gives:

  • between whole numbers, whether n divides a - b;
  • a modulus of 0 meaning equality;
  • no truth value for a fraction, a complex number, NaN or an infinity.

NumberStatements.Congruent takes the difference in whole numbers. At 2^60 + 256, the double difference x - 1 rounds back to x, which 4 divides, so x = 1 (mod 4) would have been True. The exact difference is 3 modulo 4, and evaluation says False.

FastExpression has a three-argument instruction, CALL_CONGRUENT. The LINQ compiler calls the kernel over Complex where any of the three numbers is one, and over double otherwise. A chain such as x = 1 = 11 (mod 5) is a conjunction of congruences, and compiles as one.

2.6.0 now
"x = 1 (mod 5)".ToEntity().Compile("x").Call(6) UncompilableNodeException (1, 0)
"x = 1 (mod 5)".ToEntity().Compile<double, bool>("x")(6) UncompilableNodeException True

Tests: CongruenceCompilationTest compares both compilers with evaluation on 10 numbers by 10 numbers by 7 moduli, among them -5, 0, 5/2, i, +oo and 10^20. It also checks the case past 2^53 and a chain. Full suite 18093/0, interactive trio, AOT smoke 73/0, all frameworks build.

🤖 Generated with Claude Code

a = b (mod n) was refused by both compilers, the last statement about
whole numbers that was. It now compiles to the truth value evaluation
gives:
- between whole numbers, whether n divides a - b;
- a modulus of 0 meaning equality;
- no truth value for a fraction, a complex number, NaN or an infinity.

NumberStatements.Congruent takes the difference in whole numbers. At
2^60 + 256, the double difference x - 1 rounds back to x, which 4
divides, so x = 1 (mod 4) would have been True. The exact difference is
3 modulo 4, and evaluation says False.

FastExpression has a three-argument instruction, CALL_CONGRUENT. The LINQ
compiler calls the kernel over Complex where any of the three numbers is
one, and over double otherwise. A chain such as x = 1 = 11 (mod 5) is a
conjunction of congruences, and compiles as one.

CongruenceCompilationTest compares both compilers with evaluation on 10
numbers by 10 numbers by 7 moduli, among them -5, 0, 5/2, i, +oo and
10^20. It also checks the case past 2^53 and a chain.

Part of #2195.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.68%. Comparing base (56e0946) to head (7403535).

Files with missing lines Patch % Lines
...gouriMath/Functions/Compilation/IntoFE/Compiler.cs 83.33% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2233      +/-   ##
==========================================
- Coverage   86.69%   86.68%   -0.02%     
==========================================
  Files         310      310              
  Lines       67717    67738      +21     
  Branches    19644    19649       +5     
==========================================
+ Hits        58707    58716       +9     
- Misses       4895     4907      +12     
  Partials     4115     4115              
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.23% <95.23%> (-0.02%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

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.75% <100.00%> (+0.03%) ⬆️
...ctions/Compilation/IntoLinq/CompilationProtocol.cs 91.37% <100.00%> (+0.17%) ⬆️
Sources/AngouriMath/Numerics/NumberStatements.cs 94.28% <100.00%> (+0.95%) ⬆️
...gouriMath/Functions/Compilation/IntoFE/Compiler.cs 85.30% <83.33%> (+0.23%) ⬆️

... and 5 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 fba9096 into master Oct 30, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 30, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-congruence-compiles branch October 30, 2026 09: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.

1 participant