Skip to content

FastExpression compiles statements, provided and piecewise - #2209

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
fastexpression-compiles-statements-and-branches
Oct 29, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
fastexpression-compiles-statements-and-branches

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Part of #2195: item 1, statements and branches in FastExpression.

Entity.Compile(...) refused every comparison, connective and Boolean, and with them every provided, piecewise and Iverson bracket.

  • A statement compiles to its truth value on the stack: 1 where it holds, 0 where it does not, and NaN where it has none. NaN is what evaluation leaves for one, as for i > 1. The comparisons and the connectives are the LINQ compiler's ThreeValuedLogic from A compiled statement with no truth value has none #2208, so the two compilers agree, Kleene's tables included.
  • provided and piecewise need no jump. A provided is NaN where its predicate does not hold. A piecewise is the first case whose predicate holds, or NaN, and passes over a case with no truth value as evaluation does. Every case is computed and the one that holds is kept, so the instructions still run in one pass over a foreach. The cost is computing the cases not taken.
  • An Iverson bracket is the truth value of its statement.
Compile("x").Call(…) 2.6.0 now
x > 1 at 2, at i UncompilableNodeException 1, NaN
x provided x > 0 at -1 UncompilableNodeException NaN
piecewise(x provided x > 0, -x) at -3 UncompilableNodeException 3
iverson(x > 0) at 2 UncompilableNodeException 1

Tests: FastExpressionStatementTest compiles 20 expressions, comparisons, connectives, provided, piecewise and Iverson brackets inside arithmetic. Each is compared with evaluation at 2, 1, 1/2, -3, i, 1 + i and NaN, and the cases of a piecewise are checked to be taken in order. The AOT smoke test checks a piecewise and a statement in a native build. Full suite 17919/0, interactive trio, AOT smoke 67/0, all frameworks build.

Still open on #2195: mod over Complex in LINQ, the numerical nodes of item 3 and the calculus nodes of item 4.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Compile refused every comparison, connective and Boolean, and so every
provided, piecewise and Iverson bracket. A statement now compiles to
its truth value on the stack: 1 where it holds, 0 where it does not,
and NaN where it has none, which is what evaluation leaves for one. The
comparisons and the connectives are the LINQ compiler's, with Kleene's
tables. A provided is NaN where its predicate does not hold, and a
piecewise is the first case whose predicate holds, or NaN: every case
is computed and the one that holds is kept, so the instructions still
run in one pass with no jump. Each is checked against evaluation over a
grid of expressions and points.

Part of #2195

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 29, 2026
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.17021% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.57%. Comparing base (4f20451) to head (9c48c29).

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2209      +/-   ##
==========================================
- Coverage   86.57%   86.57%   -0.01%     
==========================================
  Files         302      302              
  Lines       66950    67045      +95     
  Branches    19464    19469       +5     
==========================================
+ Hits        57965    58044      +79     
- Misses       4883     4896      +13     
- Partials     4102     4105       +3     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.12% <86.17%> (-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 Δ
...ath/Functions/Compilation/Compile.FE.Definition.cs 100.00% <ø> (ø)
...ath/Functions/Compilation/IntoFE/FastExpression.cs 95.97% <100.00%> (+1.01%) ⬆️
...gouriMath/Functions/Compilation/IntoFE/Compiler.cs 87.37% <80.00%> (-1.67%) ⬇️

... and 8 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 4db6c18 into master Oct 29, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 29, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fastexpression-compiles-statements-and-branches branch October 29, 2026 20:37
Rafael-SOWNet added a commit that referenced this pull request Oct 30, 2026
…2229)

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>
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