Skip to content

Updates to the fixed module#2779

Open
fredrik-johansson wants to merge 3 commits into
flintlib:mainfrom
fredrik-johansson:fixed4
Open

Updates to the fixed module#2779
fredrik-johansson wants to merge 3 commits into
flintlib:mainfrom
fredrik-johansson:fixed4

Conversation

@fredrik-johansson

Copy link
Copy Markdown
Collaborator

Follow up #2778 with some major improvements:

  • New functions fixed_inv_newton, fixed_div_newton, fixed_rsqrt_ui_newton, fixed_rsqrt_newton, fixed_sqrt_newton - Newton-based division and square root code, ported from radix, asymptotically faster than the GMP functions, used internally at high precision
  • Faster code for precomputing $\log(1+2^{-i})$ and $\mathrm{atan}(2^{-i})$ values. Also, static precomputed tables for very small n
  • Bit-burst and hybrid bit-burst / RS algorithms for the exponential
  • Sin/cos/tan were missing the square root trick for their series

New timings for exp and sin_cos (both got up to 50% or so faster at high precision):

fredrik@mordor:~/src/flint$ build/fixed/profile/p-fixed exp 30000
     n     bits   digits     r     arb (ns)   fixed (ns)    ratio
     1       64       19    12        145.0         21.9    6.609
     2      128       39    16        198.4         42.0    4.727
     3      192       58    16        251.8         78.2    3.220
     4      256       77    16        331.9        125.9    2.636
     5      320       96    16        427.2        164.0    2.605
     6      384      116    24        518.8        206.0    2.519
     7      448      135    32        671.4        248.0    2.708
     8      512      154    32        732.4        396.7    1.846
     9      576      173    32        915.5        408.2    2.243
    10      640      193    32       1083.4        438.7    2.470
    11      704      212    32       1266.5        503.5    2.515
    12      768      231    64       1525.9        717.2    2.128
    16     1024      308    64       2624.5       1007.1    2.606
    21     1344      405    64       4272.5       1220.7    3.500
    28     1792      539    64       7141.1       2136.2    3.343
    37     2368      713    64      12451.2       3295.9    3.778
    49     3136      944   128      16845.7       5188.0    3.247
    65     4160     1252   128      23925.8       8056.6    2.970
    86     5504     1657   192      34179.7      12939.5    2.642
   114     7296     2196   256      51757.8      21484.4    2.409
   152     9728     2928   256      81054.7      36132.8    2.243
   202    12928     3892   320     132812.5      61523.4    2.159
   269    17216     5183   384     222656.2     100585.9    2.214
   358    22912     6897   512     375000.0     167968.8    2.233
   477    30528     9190   576     625000.0     265625.0    2.353
   636    40704    12253   768    1062500.0     453125.0    2.345
   848    54272    16338   768    2062500.0     703125.0    2.933
  1130    72320    21770   768    2843750.0    1078125.0    2.638
  1506    96384    29014   768    4187500.0    1625000.0    2.577
  2008   128512    38686   768    6187500.0    2359375.0    2.623
  2677   171328    51575   768    9000000.0    3468750.0    2.595
  3569   228416    68760   768   13031250.0    4843750.0    2.690
  4758   304512    91667   768   18796875.0    7343750.0    2.560
  6344   406016   122223   768   27656250.0   11265625.0    2.455
  8458   541312   162951   768   39281250.0   16375000.0    2.399
 11277   721728   217262   768   56718750.0   24531250.0    2.312
 15036   962304   289682   768   83671875.0   38421875.0    2.178
 20048  1283072   386243   768  118203125.0   56218750.0    2.103
 26730  1710720   514978   768  170015625.0   86875000.0    1.957
fredrik@mordor:~/src/flint$ build/fixed/profile/p-fixed sin_cos 30000
     n     bits   digits     r     arb (ns)   fixed (ns)    ratio
     1       64       19     4        160.2         35.3    4.541
     2      128       39     5        217.4         76.3    2.850
     3      192       58     9        286.1        160.2    1.786
     4      256       77    14        389.1        221.3    1.759
     5      320       96    15        534.1        305.2    1.750
     6      384      116    18        625.6        377.7    1.657
     7      448      135    16        793.5        457.8    1.733
     8      512      154    16       1068.1        610.4    1.750
     9      576      173    16       1251.2        747.7    1.673
    10      640      193    19       1434.3        869.8    1.649
    11      704      212    23       1647.9       1022.3    1.612
    12      768      231    25       1953.1       1190.2    1.641
    16     1024      308    64       3173.8       2441.4    1.300
    21     1344      405    64       5065.9       3234.9    1.566
    28     1792      539    64       8544.9       5065.9    1.687
    37     2368      713    64      14648.4       7812.5    1.875
    49     3136      944   128      22705.1      12451.2    1.824
    65     4160     1252   192      33203.1      20996.1    1.581
    86     5504     1657   192      49804.7      32226.6    1.545
   114     7296     2196   192      78125.0      48828.1    1.600
   152     9728     2928   192     121093.8      77148.4    1.570
   202    12928     3892   192     183593.8     121093.8    1.516
   269    17216     5183   256     285156.2     199218.8    1.431
   358    22912     6897   384     453125.0     335937.5    1.349
   477    30528     9190   384     718750.0     531250.0    1.353
   636    40704    12253   384    1171875.0     843750.0    1.389
   848    54272    16338   384    2281250.0    1250000.0    1.825
  1130    72320    21770   512    3328125.0    1750000.0    1.902
  1506    96384    29014   768    5500000.0    2593750.0    2.120
  2008   128512    38686   768    7765625.0    3406250.0    2.280
  2677   171328    51575   768   12062500.0    4859375.0    2.482
  3569   228416    68760   768   17640625.0    6609375.0    2.669
  4758   304512    91667   768   28390625.0    9703125.0    2.926
  6344   406016   122223   768   44140625.0   13968750.0    3.160
  8458   541312   162951   768   68953125.0   20296875.0    3.397
 11277   721728   217262   768   94046875.0   30921875.0    3.041
 15036   962304   289682   768  132062500.0   46593750.0    2.834
 20048  1283072   386243   768  192531250.0   72187500.0    2.667
 26730  1710720   514978   768  268203125.0  110078125.0    2.436

Comment thread doc/source/fixed.rst
Comment on lines +31 to +32
`a \in [1/B, 1)` with `an` fraction limbs, sets `(q, n+2)` to an
approximation of `1/a \in (1, B]` with `n` fraction limbs and two

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is B? And isn't it supposed to be a \in [1 / 2, 1)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

B = 2^FLINT_BITS.

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.

2 participants