Skip to content

A statement where a number is expected is refused by both compilers - #2229

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-statement-where-a-number-is-expected-is-refused
Oct 30, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-statement-where-a-number-is-expected-is-refused

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2227.

A statement in a numeric position, such as the argument of sin or a summand, has no value: evaluation leaves sin(True) and True + 2 as written. Each compiler disagreed with that, in its own way:

  • FastExpression carries a statement as its truth value, so it took True as 1. sin(x > 1) at 2 was 0.8414709848078965, and max(x > 1, 0) was 1. This came with FastExpression compiles statements, provided and piecewise #2209 and is unreleased.
  • The LINQ compiler threw KeyNotFoundException for sin(x > 1) and (x > 1)^2, from widening a bool to double. For max(x > 1, 0) it threw AngouriBugException, which asks for a bug report. Both are on 2.6.0.

StatementPositions.Check now runs in both compilers, after the membership rewrite and before anything is compiled. A statement-valued node is a statement, or a provided or piecewise over one. It may stand:

  • at the root;
  • as an operand of a connective;
  • on both sides of an equality of statements;
  • in an Iverson bracket;
  • as a provided's or a piecewise's value or predicate;
  • in a set or a quantifier.

Anywhere else it is refused with UncompilableNodeException, whose message points to iverson, the way to take a statement as a number.

2.6.0 master now
"sin(x > 1)".ToEntity().Compile("x").Call(2) refused (0.8414709848078965, 0) refused
"sin(x > 1)".ToEntity().Compile<double, double>("x") throws KeyNotFoundException throws KeyNotFoundException refused
"max(x > 1, 0)".ToEntity().Compile<double, double>("x") throws AngouriBugException throws AngouriBugException refused

Tests: StatementInANumericPositionTest has 10 statements in numeric positions, refused by FastExpression and by LINQ over double and over Complex; all 10 fail without the check. It also has 8 places where a statement is taken, which compile as before. Full suite 18060/0, interactive trio, AOT smoke 73/0, all frameworks build.

🤖 Generated with Claude Code

A statement in a numeric position, such as the argument of sin or a
summand, has no value: evaluation leaves sin(True) and True + 2 as
written. The compilers each disagreed with that, differently:
- FastExpression, which carries a statement as its truth value, took
  True as 1. So sin(x > 1) at 2 was 0.8414709848078965 and
  max(x > 1, 0) was 1. This came with #2209 and is unreleased.
- The LINQ compiler threw KeyNotFoundException for sin(x > 1) and
  (x > 1)^2, from widening a bool to double. For max(x > 1, 0) it threw
  AngouriBugException, which asks for a bug report. Both are on 2.6.0.

StatementPositions.Check now runs in both compilers, after the
membership rewrite and before anything is compiled. A statement-valued
node is a statement, or a provided or piecewise over one. It may stand
at the root, as an operand of a connective, on both sides of an equality
of statements, in an Iverson bracket, as a provided's or a piecewise's
value or predicate, and in a set or a quantifier. Anywhere else it is
refused with UncompilableNodeException, whose message points to iverson,
the way to take a statement as a number.

StatementInANumericPositionTest: 10 statements in numeric positions,
refused by FastExpression and by LINQ over double and over Complex. All
10 fail without the check. Also 8 places where a statement is taken,
which compile as before.

Fixes #2227.

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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.68%. Comparing base (595f523) to head (fbc2d11).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2229   +/-   ##
=======================================
  Coverage   86.68%   86.68%           
=======================================
  Files         309      310    +1     
  Lines       67660    67679   +19     
  Branches    19621    19627    +6     
=======================================
+ Hits        58648    58665   +17     
  Misses       4895     4895           
- Partials     4117     4119    +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.23% <100.00%> (+<0.01%) ⬆️
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 Δ
...gouriMath/Functions/Compilation/IntoFE/Compiler.cs 85.33% <100.00%> (+0.30%) ⬆️
...Functions/Compilation/IntoLinq/IntoLinqCompiler.cs 96.87% <100.00%> (+0.04%) ⬆️
...riMath/Functions/Compilation/StatementPositions.cs 100.00% <100.00%> (ø)

... 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 1c9dbce 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-statement-where-a-number-is-expected-is-refused branch October 30, 2026 07:05
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.

A statement where a number is expected: FastExpression answers, LINQ throws outside the library

1 participant