Repository navigation
Shader source from expressions: MathS.Shaders.Hlsl and Glsl, with a page - #2470
Merged
Merged
Conversation
Prints expressions as straight-line HLSL or GLSL: one assignment per output, every repeated subexpression computed once into a local, and in HLSL one sincos for a sin and cos of the same argument. The use is an exact gradient or a closed-form physical law derived on the CPU and run on the GPU. The code computes the real-valued reading that Compile<double, ...> computes, and the tests hold the printed text to it: the same printer writes C# against helpers named as HLSL's intrinsics, Roslyn compiles that text, and it is compared with Compile<double, double, double> at 200 points per case, each case required to have at least 50 points with a real value. What has no faithful form is declined with the node named rather than printed approximately: complex constants, Providedf, a piecewise without a final always-true case, names that are not identifiers, and nodes such as factorial and round. Integer powers above the fourth go through pow(abs(x), n) with the sign restored for odd n, since pow of a negative base is undefined in both languages, and mod is printed floored, as Modf is. No clause of Packaging.md section 4 fires: pure managed code and no new referenced assembly (KernelDependenciesTest), beside IntoLinq. No existing answer changes. Measured: UnitTests 18256 passed, 13 skipped, 0 failed (net10.0); FSharpWrapperUnitTests 134 passed; kernel builds warning-free on netstandard2.0, net8.0 and net10.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AGENTS.md: an operation the library offers by name is an entry of the catalogue. The two queries answer what MathS.Shaders.Hlsl and Glsl answer, which CatalogueTest checks on sin(x) * cos(x), where HLSL's sincos makes the two differ. No surface offers them yet: the MCP server's Tools.NotOffered and the terminal's OneShot.notOffered list them, pointing at #2298, which proposes am_shader_source. Part of #2293. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The printer now checks an expression before printing anything and returns the refusal, rather than throwing and catching inside the printer. What Compile refuses, a binder (now including a product over a set) or a statement where a number is expected, is declined with Compile's own message, through Binders.Refusal and StatementPositions.Refusal, which Check now throws from. It makes the rewrites Compile makes: a matrix operation on matrices written out is the number it gives, a membership in an interval or a finite set is its comparisons, and the exponential quotient tanh is spelled as is rescaled so it does not divide an overflow by an overflow. Printed, as Compile compiles them: a rational power with an odd denominator below ten as the real root of a negative base (x^(1/3) was pow(x, 1/3), NaN at a negative x where Compile has a value); cotan, sec, csc and their inverses; conjugate, re, im and arg of a real; iverson, xor and implies. Declined with a reason: gcd and lcm (a loop), matrices and the matrix operations of a variable, membership in a set of numbers. The XML docs and Docs/Usage/Shaders.md name where the shader and Compile<double> differ: +-inf at a zero divisor and at zero to a negative power, 1.0 for an unsimplified x^0, and pow of a negative base. The page works the exact normal of a smooth union of two spheres through, in HLSL and GLSL; docsamples runs its six samples. Part of #2293 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…says The printer writes numbers with double's round-trip format and names as the caller maps them; Stringize appears only in the reason a node is declined. This pins that: four expressions printed as HLSL and GLSL with the flag off and on give the same code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2470 +/- ##
==========================================
+ Coverage 86.96% 86.98% +0.02%
==========================================
Files 321 324 +3
Lines 71603 71849 +246
Branches 20895 20955 +60
==========================================
+ Hits 62269 62501 +232
- Misses 5011 5017 +6
- Partials 4323 4331 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MathS.Shaders.HlslandMathS.Shaders.Glslprint expressions as straight-line shader source: one assignment per output, each repeated subexpression computed once into a local,sincosfor a sin/cos pair in HLSL. The contract is the issue's: the code computes the real readingCompile<double, …>computes, and the tests hold it to that — the same printer writes C# against helpers named as HLSL's intrinsics, Roslyn compiles that text, and its values are compared withCompile<double, …>at 200 points per case.Four commits, meant to be merged as they are (rebase, not squash):
MathS.Shaders.HlslandGlsl— fromfeat/shader-source, rebased onto master.hlslandglsl.GeneratedSource(null, At, Reason)when it declines.Binders.Refusal,StatementPositions.Refusal); five tests assert the two messages are equal.tanhis rescaled (tanh(400)is 1, not inf/inf).x^(1/3)printedpow(x, 1/3),NaNat negativex, where Compile takes the real root; it now printssign(x) * pow(abs(x), p).Docs/Usage/Shaders.md: a sphere's normal, the exact gradient of an exponential smooth union of two spheres in HLSL and GLSL with the generated code, mapping variables to shader names, and the contract. Its 6 samples passdocsamples. Linked from the README's Compilation section, AGENTS.md andPackaging.md§5.MathS.Settings.UnicodeOutputsays (Unicode output: MathS.Settings.UnicodeOutput, and the parser reads the glyphs it prints #2469 merged after this was written): four expressions in HLSL and GLSL, flag off and on.Compile<double>lambda,productover a setdot,cross,det,trace,transpose, an entry, of a variableconjugate,re,im,argcotan,sec,cscand their inverses;iverson,xor,impliessin(x > 0)gcd,lcmRR,ZZand the other number sets;provided,round, factorial, special functionsAt a zero divisor the shader and Compile differ, as decided on the issue: since #2288
Compile<double>givesNaNata / 0and at zero to a non-positive power, where the printed code gives ±inf under IEEE 754 (and1.0for an unsimplifiedx^0). Guarding every quotient would cost a branch each; the difference is documented onMathS.Shadersand on the page instead.Packaging: none of AGENTS.md's clauses fires —
KernelDependenciesTestpasses (no new referenced assembly), and the printer composes the kernel's own refusals and rewrites. Offering the shaders from the MCP server and the terminal is #2298. Happypig375's suggestion that the same printer could speed up compiled functions is for later.ShadersTest: 70 cases. Full check on commit 3 before the rebase onto c530e40: 20,185 unit tests, 0 failed; MCP 444, Terminal 69, F# 134, Interactive 19; AOT OK; BoundCheck 0 disagreements, RootCheck 596/596, CasBench 120/121 with 0 wrong, PropCheck clean, SimpSweep 10463/10463, RuleCheck clean, CanonCheck and Confluence at their baselines. After the rebase: Shaders, PublicApi, KernelDependencies, Catalogue and StringizeRoundTrip, 799 passed.Closes #2293.
🤖 Generated with Claude Code