[Cfp-interest 2872] example for scaled reductions
David Hough CFP
pcfp at oakapple.net
Mon Aug 28 16:22:47 PDT 2023
I'm not happy with my choice of Clebsch-Gordan coefficients as an example
for scaled product, even though it was part of the lore of justification
of trapped overflows with scaled exponents.
The example fragment computes a term n1! * n2! / n3! , by explicitly computing
each factorial each time.
Anybody who was actually programming Clebsch-Gordan would build up
or use a precomputed
table of scaled factorials and multiply and divide those -
term_scaled = scaledfactorial[n1]*scaled_factorial[n2]/scaledfactorial[n3] ;
term_scale = sf_logb[n1}+sf_logb[n2}-sf_logb[n3}
And unlike the example fragment, one would not compute
scalb(term_scaled, term_scale)
until the end of the whole computation; the example fragment
computes just one piece of a much larger formula, involving sqrts
and alternating-sign sums of inverses of products of factorials.
Even if the table of scaled factorials were built up dynamically as needed,
new members would probably be built up by induction -
t = double(n+1) * scaled_factorial[n] ;
t_logb = logb(t) ;
scaledfactorial[n+1] = scalb(t, -t_logb) ;
sf_logb[n+1] = t_logb + sf_logb[n] ;
So scaled_prod wouldn't be used at all.
A better example would have variable factors that can't be tabulated in
advance and can't benefit from such cacheing.
Maybe the WG members won't care. The Clebsch-Gordan
fragment example is correct, just not very efficient programming for that
specific problem.
More information about the Cfp-interest
mailing list