Skip to content

Use Newton iteration for fmpq_poly_(sin|cos|sin_cos)_series#2664

Open
fredrik-johansson wants to merge 1 commit intoflintlib:mainfrom
fredrik-johansson:series
Open

Use Newton iteration for fmpq_poly_(sin|cos|sin_cos)_series#2664
fredrik-johansson wants to merge 1 commit intoflintlib:mainfrom
fredrik-johansson:series

Conversation

@fredrik-johansson
Copy link
Copy Markdown
Collaborator

Following #2663, implement Newton iteration for fmpq_poly sine and cosine and use this instead of the tangent formula. Straightforward translation from the gr_poly code done with the help of Claude. Also slightly improve the basecase code, move out a helper function, and do some light refactoring.

Example timings for fmpq_poly_sin_series, input series $f = \log(1+x)$:

      n           old         new  speedup
      2      5.75e-08     6.3e-08  (0.913)   
      4      1.59e-07    1.61e-07  (0.988)   
      8      1.79e-06    1.39e-06  (1.288)   
     16      6.66e-06    4.79e-06  (1.390)   
     32       5.8e-05    1.63e-05  (3.558)   
     64      0.000252    7.86e-05  (3.206)   
    128       0.00122    0.000354  (3.446)   
    256       0.00517     0.00162  (3.191)   
    512        0.0245      0.0069  (3.551)   
   1024         0.176      0.0327  (5.382)   
   2048         0.943       0.173  (5.451)   
   4096         5.572       0.938  (5.940)   
   8192        31.597       5.636  (5.606)   

Same input for fmpq_poly_sin_cos_series:

      n           old         new  speedup
      2      5.03e-08    5.84e-08  (0.861)   
      4      1.84e-07    1.86e-07  (0.989)   
      8      2.21e-06    1.85e-06  (1.195)   
     16      8.29e-06    6.54e-06  (1.268)   
     32      6.41e-05    2.04e-05  (3.142)   
     64      0.000287    9.03e-05  (3.178)   
    128       0.00139    0.000427  (3.255)   
    256       0.00591     0.00196  (3.015)   
    512        0.0282     0.00822  (3.431)   
   1024         0.198      0.0396  (5.000)   
   2048         1.072       0.214  (5.009)   
   4096         6.358       1.209  (5.259)   
   8192        36.188       7.237  (5.000)   

This can potentially be optimized a bit more by avoiding some of the intermediate GCDs (in the Karatsuba steps, for example), but that would need closer profiling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant