Skip to content

A Taylor expansion simplifies each derivative before taking the next - #2302

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-taylor-expansion-simplifies-each-derivative
Oct 31, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-taylor-expansion-simplifies-each-derivative

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Each derivative is simplified before the next is taken, and each coefficient once it is evaluated at the point.

master and 2.6.0 now
Taylor("sin(x) / x", 11, ("x", 1)) OutOfMemoryException (32 s at a 2 GB heap) 529 characters, 0.9 s
Taylor("sin(x) / x", 7, ("x", 1)) 36,421 characters 333 characters
Taylor("sin(x) / x", 4, ("x", 0)) NaN + NaN + NaN / 2! + NaN / 3! NaN
Taylor("sin(x)", 0, ("x", 1)) throws AngouriBugException 0
Taylor("sin(x) + cos(y)", 6, ("x", 1)), third term cos(1) * (-1) * (x - 1) ^ 3 / 3! -cos(1) * (x - 1) ^ 3 / 3!
  • The ninth derivative of sin(x) / x has 7,797,110 nodes as differentiated and 87 simplified.
  • The sum stops asking for terms once it has them. It used to take one derivative more and drop it.
  • A function with no value at the point has no derivatives there, so the expansion is NaN once.
  • The Series examples in MathS now print what they say, so they come off DocumentationExamplesRunTest's failing list.
  • e^x / (1 + x^2) still grows about threefold a step, through Simplify not cancelling a shared factor. That's Simplify does not cancel a factor when a numerator's term holds a power of it #2301.
  • Seven of the new and changed tests fail on master. The suite, the trio, F#, AOT and the eight harnesses pass.

Fixes #2291.

🤖 Generated with Claude Code

SingleTaylorExpansionTerms took each derivative from the one before it
as it stood, and only the term built from it was simplified. A
quotient's derivatives grew about eightfold a step: the ninth of
sin(x) / x had 7,797,110 nodes, and 87 simplified, so 7 terms around 1
printed in 36,421 characters and 11 ran out of memory. Each derivative
is now simplified before the next is taken, and each coefficient once
it is evaluated at the point, so 11 terms are 529 characters in 0.9 s.
The partial derivatives of the multivariable expansion are simplified
the same way.

The sum stops asking for terms once it has them, where it took one
derivative more and dropped it. No terms are 0, where the empty sum
threw AngouriBugException. A function with no value at the point has
no derivatives there either, so its expansion is NaN once, where it
was a NaN for each term after as many derivatives.

The documented examples of Maclaurin, Taylor and TaylorTerms print the
simplified coefficients, cos(1) * (-1) is -cos(1), so they now say what
they print and leave DocumentationExamplesRunTest's failing list. The
cotan(1 - t) pins in SeriesTest take the simplified coefficients,
csc(1)^2 and 2 cot(1) csc(1)^2.

e^x / (1 + x^2) still grows about threefold a step: the quotient rule
squares the denominator and Simplify does not cancel the factor the
numerator's terms share with it. That is Simplify's, #2301.

Seven of the new and changed tests fail on master. The suite, the
trio, F#, AOT and the eight harnesses pass.

Fixes #2291.

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

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.77%. Comparing base (c633c41) to head (5f514dc).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
Sources/AngouriMath/Functions/Series.cs 93.33% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2302      +/-   ##
==========================================
+ Coverage   86.74%   86.77%   +0.03%     
==========================================
  Files         310      310              
  Lines       67973    67974       +1     
  Branches    19744    19736       -8     
==========================================
+ Hits        58961    58984      +23     
+ Misses       4880     4869      -11     
+ Partials     4132     4121      -11     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.32% <93.33%> (+0.03%) ⬆️
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 Δ
Sources/AngouriMath/Convenience/MathS.cs 90.51% <ø> (ø)
Sources/AngouriMath/Functions/Series.cs 93.67% <93.33%> (+3.79%) ⬆️

... 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 2c62523 into master Oct 31, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 31, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-taylor-expansion-simplifies-each-derivative branch October 31, 2026 19:47
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 Taylor expansion differentiates without simplifying, so sin(x)/x to 11 terms runs out of memory

1 participant