/* mpn_sqrlo -- squares an n-limb number and returns the low n limbs of the result.
Contributed to the GNU project by Torbjorn Granlund and Marco Bodrato.
THIS IS (FOR NOW) AN INTERNAL FUNCTION. IT IS ONLY SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED THAT IT'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
The GNU MP Library is free software; you can redistribute it and/or modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
or
* the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
or both in parallel, as here.
The GNU MP Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received copies of the GNU General Public License and the GNU Lesser General Public License along with the GNU MP Library. If not,
see https://www.gnu.org/licenses/. */
/* THINK: The DC strategy uses different constants in different Toom's ranges. Something smoother?
*/
/* Compute the least significant half of the product {xy,n}*{yp,n}, or formally {rp,n} = {xy,n}*{yp,n} Mod (B^n).
Above the given threshold, the Divide and Conquer strategy is used. The operand is split in two, and a full square plus a mullo is used to obtain the final result. The more natural strategy is to split in two halves, but this is far from optimal when a sub-quadratic multiplication is used.
Mulders suggests an unbalanced split in favour of the full product, split n = n1 + n2, where an = n1 <= n2 = (1-a)n; i.e. 0 < a <= 1/2.
To compute the value of a, we assume that the cost of mullo for a given size ML(n) is a fraction of the cost of a full product with same size M(n), and the cost M(n)=n^e for some exponent 1 < e <= 2; then we can write:
Given a value for e, want to minimise the value of k, i.e. the function k=(1-a)^e/(1-2*a^e).
With e=2, the exponent for schoolbook multiplication, the minimum is given by the values a=1-a=1/2.
With e=log(3)/log(2), the exponent for Karatsuba (aka toom22), Mulders compute (1-a) = 0.694... and we approximate a with 11/36.
Other possible approximations follow: e=log(5)/log(3) [Toom-3] -> a ~= 9/40 e=log(7)/log(4) [Toom-4] -> a ~= 7/39 e=log(11)/log(6) [Toom-6] -> a ~= 1/8 e=log(15)/log(8) [Toom-8] -> a ~= 1/10
The values above where obtained with the following trivial commands in the gp-pari shell:
For an actual implementation, the assumption that M(n)=n^e is incorrect, as a consequence also the assumption that ML(n)=k*M(n) with a constant k is wrong.
But theory suggest us two things: - the best the multiplication product is (lower e), the more k approaches 1, and a approaches 0.
- A value for a smaller than optimal is probably less bad than a bigger one: e.g. let e=log(3)/log(2), a=0.3058_ the optimal value, and k(a)=0.808_ the mul/mullo speed ratio. We get k(a+1/6)=0.929_ but k(a-1/6)=0.865_.
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.