This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nirinA
Recipients mark.dickinson, nirinA, rhettinger, stutzbach, terry.reedy
Date 2008-07-28.17:04:18
SpamBayes Score 0.21821478
Marked as misclassified No
Message-id <1217264660.12.0.780048947724.issue3366@psf.upfronthosting.co.za>
In-reply-to
Content
i wrote pure Python equivalent of the patch and will
post it to the ASPN cookbook as suggested. i'm wondering
if i have to upload the code here too, or just the link
will suffice?

Raymond Hettinger:
> Can you also implement blending of approximations:
> (1-t)*f1(x) + t*f2(x)

i do this with the Python code for now, and my question is:
how to choose the values for the borders?

with erf, for example, one has typically 5 domains
of approximation and one can write something like:

    def erf(x):
        f = float(x)
        if (f == inf):
            return 1.0
        elif (f == -inf):
            return -1.0
        elif (f == nan):
            return nan
        else:
            if (abs(x)<0.84375):
                return erf1(x)
            elif (0.84375<=abs(x)<1.25):
                return erf2(x)
            elif (1.25<=abs(x)<2.857142):
                return erf3(x)
            elif (2.857142<=abs(x)<6):
                return erf4(x)
            elif (abs(x)>=6):
                return erf5(x)

implementing the blending of approximations,
one may write:

    def blend(x, a, b, f1, f2):
        if x < a:
            return f1(x)
        if x > b:
            return f2(x)
        return (((b-x)*f1(x))-((a-x)*f2(x)))/(b-a)

and the definition becomes:

    def erf(x):
	f=float(x)
	if (abs(x)<0.83):
		return erf1(x)
	elif (0.83<=abs(x)<0.85):
		return blend(x,0.83,0.85,erf1,erf2)
	elif (0.85<=abs(x)<1.24):
		return erf2(x)
	elif (1.24<=abs(x)<1.26):
		return blend(x,1.24,1.26,erf2,erf3)
	elif (1.26<=abs(x)<2.84):
		return erf3(x)
	elif (2.84<=abs(x)<2.86):
		return blend(x,2.84,2.86,erf3,erf4)
	elif (2.86<=abs(x)<5.99):
		return erf4(x)
	elif (5.99<=abs(x)<6.01):
		return blend(x,5.99,6.01,erf4,erf5)
	elif (abs(x)>=6.01):
		return erf5(x)

but the choice of these values is somewhat arbitrary.
or i completely misunderstood what you mean by "blending of approximations"!

for erf functions, blending of approximations, as i understand it,
may be implemented easily as the functions are monotonics.
for gammas, this will be a bit complicated, especially for
negative values, where there are extremums for half integers and
discontinuities for integers.
in the other hand, i'm wondering if these coefficients had been chosen
with optimization of discontinuities already taken into account.
History
Date User Action Args
2008-07-28 17:04:20nirinAsetrecipients: + nirinA, rhettinger, terry.reedy, mark.dickinson, stutzbach
2008-07-28 17:04:20nirinAsetmessageid: <1217264660.12.0.780048947724.issue3366@psf.upfronthosting.co.za>
2008-07-28 17:04:19nirinAlinkissue3366 messages
2008-07-28 17:04:18nirinAcreate