A Taylor expansion differentiates without simplifying, so sin(x)/x to 11 terms runs out of memory

Đã đóng
#2,291 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #2302 của @Rafael-SOWNet — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
performance

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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:

  • SingleTaylorExpansion checks terms.Count >= termCount only after the iterator has produced the next term, so one derivative more than is kept (the largest) is taken, substituted and simplified, then dropped. MultivariableTaylorExpansion has the same order.
  • MultivariableTaylorExpansionTerms differentiates 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.

Ngôn ngữ chính
C#
Star
832
Fork
79
Merge trung bình
1 giờ 12 phút
Pull request đã merge (30 ngày)
518

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ASC-Community/AngouriMath

Tất cả issue của ASC-Community/AngouriMath

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.