A Taylor expansion differentiates without simplifying, so sin(x)/x to 11 terms runs out of memory
I maintainer di solito rispondono entro 1 giorno
Una pull request collegata è già stata integrata.
- #2302 di @Rafael-SOWNet — integrata
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- csharp
- Ambito
- performance
Direzione di ricerca
Start with Sources/AngouriMath/Functions/Series.cs, especially SingleTaylorExpansionTerms and MultivariableTaylorExpansionTerms. Reproduce the reported Taylor(sin(x) / x, 11, ("x", 1)) case and compare the derivative growth and runtime. Done means the requested expansion completes efficiently without computing and discarding an extra term; the expected behavior at x = 0 needs triage.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
MathS.Series.Taylor on master (87a0eff), with the heap capped at 4 GB:
| Answered | |
|---|---|
Taylor(sin(x) / x, 7, ("x", 1)) |
36 421 characters, 1.4 s |
Taylor(sin(x) / x, 9, ("x", 1)) |
2 039 500 characters, 87 s |
Taylor(sin(x) / x, 11, ("x", 1)) |
OutOfMemoryException in SingleTaylorExpansion after 89 s |
Taylor(sin(x) / x, 11, ("x", 0)) |
OutOfMemoryException after 42 s; without the cap, on an earlier build, the process passed 35 GB before it was killed |
Taylor(sin(x) / x, 4, ("x", 0)) |
NaN + NaN + NaN / 2! + NaN / 3! |
The cause is in SingleTaylorExpansionTerms: each derivative is taken from the previous one as it stands (currExpr = currExpr.Differentiate(exprVariable)), and only the term built from it is simplified. For a quotient the tree grows about eightfold per step:
| k | nodes of the k-th derivative, as differentiated | simplified before the next step |
|---|---|---|
| 1 | 11 | 11 |
| 3 | 122 | 33 |
| 5 | 2 647 | 47 |
| 7 | 110 799 | 69 |
| 9 | 7 797 110 | 87 |
Simplifying each derivative before taking the next gives the 11 terms at x = 1 in 0.85 s. Two smaller points in the same place:
SingleTaylorExpansionchecksterms.Count >= termCountonly after the iterator has produced the next term, so one derivative more than is kept (the largest) is taken, substituted and simplified, then dropped.MultivariableTaylorExpansionhas the same order.MultivariableTaylorExpansionTermsdifferentiates the partial derivatives unsimplified in the same way.
What it should have done: answer Taylor(sin(x) / x, 11, ("x", 1)) in about a second. At x = 0, sin(x) / x has no value, so every coefficient is NaN; the expansion should say that once (the step-simplified loop above answers NaN), or expand the continuous extension 1 - x^2/6 + x^4/120 - ..., which is a choice for triage, instead of differentiating ten times to print a sum of NaNs.
Found while building a Taylor-polynomial view for browser demos of the library.
- Lingua principale
- C#
- Stelle
- 831
- Fork
- 79
- Merge medio
- 1h 12m
- PR unite (30g)
- 518
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ASC-Community/AngouriMath
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ASC-Community/AngouriMath#2220 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Opinions wanted
Difficoltà 4/5 Più di una settimana Idoneità per principianti 15/100
ASC-Community/AngouriMath#2319 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
ASC-Community/AngouriMath#2298 ·
I maintainer di solito rispondono entro 1 giorno
-
The kernel under WebAssembly: 1.26 MB Brotli over the bare runtime, and 0.2 s to the first SimplifyAperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 48/100
ASC-Community/AngouriMath#2296 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
ASC-Community/AngouriMath#2293 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ASC-Community/AngouriMath
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 3 giorni
-
enhancement P3 performance
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
thomhurst/TUnit#7380 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
documentation trivial
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
PCL-Community/PCL-CE#3767 ·
I maintainer di solito rispondono entro 1 giorno