Skip to content

A compiled statement asked for as a number is its truth value - #2228

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-statement-compiles-to-its-truth-value
Oct 30, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-statement-compiles-to-its-truth-value

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2224.

In the LINQ compiler, a statement compiled to a number, as Compile<double, double> or Compile<Complex, Complex>, threw InvalidProtocolProvided: NaN conversion not implemented for System.Boolean. That exception says the caller's protocol is wrong, and none had been given. A provided statement threw the same. A piecewise of statements threw KeyNotFoundException, from MaxType's table of numeric types.

The root is that ConvertNaN had no case for a statement. In three-valued logic a statement with no truth value is null, so ConvertNaN(bool) is now a null bool?. On top of that:

  • ConvertType takes a statement to a number by its Iverson value: 1, 0, or NaN where it has none. That is what FastExpression and an Iverson bracket give.
  • A provided statement is a bool?, with no truth value where its predicate fails.
  • A piecewise whose cases are all statements is a bool?. One that mixes statements and numbers is refused with UncompilableNodeException.
  • A statement that may have no truth value, asked for as long or int, which have no NaN, is refused the same way.
2.6.0 and master now
"x > 1".ToEntity().Compile<double, double>("x")(2) throws InvalidProtocolProvided 1
"x > 1 provided x > 0".ToEntity().Compile<double, bool?>("x")(-1) throws InvalidProtocolProvided null
"piecewise(x > 1 provided x > 0, x < -1)".ToEntity().Compile<double, bool?>("x")(-2) throws KeyNotFoundException true

Tests. StatementAsANumberCompilationTest has 17 cases, and all fail on master:

  • eight statements, among them a provided and a piecewise one, compiled as Complex and as double and compared with FastExpression at 12 points, including i, NaN and +oo;
  • provided and piecewise statements compiled as bool?;
  • the two refusals.

Full suite 18042/0, interactive trio, AOT smoke 73/0, all frameworks build.

A statement in a numeric position, as in sin(x > 1), is a different defect, filed as #2227.

🤖 Generated with Claude Code

In the LINQ compiler, a statement compiled to a number, as
Compile<double, double> or Compile<Complex, Complex>, threw
InvalidProtocolProvided: "NaN conversion not implemented for
System.Boolean". That exception says the caller's protocol is wrong, and
no protocol had been given. A provided statement threw the same, and a
piecewise of statements threw KeyNotFoundException, from MaxType's table
of numeric types. All three are on 2.6.0 as well.

The root is that ConvertNaN had no case for a statement. In three-valued
logic a statement with no truth value is null, so ConvertNaN(bool) is now
a null bool?. On top of that:
- ConvertType takes a statement to a number by its Iverson value: 1, 0,
  or NaN where it has none. That is what FastExpression and an Iverson
  bracket give.
- A provided statement is a bool?, with no truth value where its
  predicate fails.
- A piecewise whose cases are all statements is a bool?. One that mixes
  statements and numbers is refused with UncompilableNodeException.
- A statement that may have no truth value, asked for as long or int,
  which have no NaN, is refused the same way.

StatementAsANumberCompilationTest compares eight statements, among them a
provided and a piecewise one, as Complex and as double against
FastExpression, at 12 points that include i, NaN and +oo. It also checks
provided and piecewise statements as bool?, and the two refusals. All 17
fail on master.

A statement in a numeric position, such as sin(x > 1), is a different
defect, #2227.

Fixes #2224.

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 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.66%. Comparing base (c50b9ff) to head (834fe1e).

Files with missing lines Patch % Lines
...ctions/Compilation/IntoLinq/CompilationProtocol.cs 88.88% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2228      +/-   ##
==========================================
- Coverage   86.67%   86.66%   -0.02%     
==========================================
  Files         309      309              
  Lines       67644    67660      +16     
  Branches    19612    19621       +9     
==========================================
+ Hits        58629    58635       +6     
- Misses       4896     4907      +11     
+ Partials     4119     4118       -1     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.21% <88.88%> (-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 Δ
...ctions/Compilation/IntoLinq/CompilationProtocol.cs 91.20% <88.88%> (-0.16%) ⬇️

... and 6 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 595f523 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-compiles-to-its-truth-value branch October 30, 2026 06:26
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 compiled to a number throws InvalidProtocolProvided

1 participant