[Edu-sig] Halley's Method for nth root of P

Kirby Urner pdx4d@teleport.com
Fri, 12 May 2000 15:28:19 -0700


Here's an interesting function that returns the nth root of P.

Usage:

>>> halley(2,2)     # 2nd root of 2
1.41421356237
>>> 2.0**0.5        # check
1.41421356237

>>> halley(7,3)     # 3rd root of 7
1.91293118277
>>> 7.0**(1./3.)    # check
1.91293118277

>>> halley(1000,4)  # 4th root of 1000 (duh)
10.0

Maybe the math module is even using something similar
(or C internally)?

Kirby


# thanks to Domingo G=F3mez Mor=EDn
# http://www.etheron.net/usuarios/dgomez/Roots.htm

def halley(P,n,d=3D10,x=3D1.0):
       # P -- find nth root of this number
       # n -- whole number root
       # d -- level of depth for recursion (default 10)
       # x -- initial value of x (default 1)
	if d>1:	=09
	   newx =3D ((n+1.0)*P*x + (n-1)*(x**(n+1)))/((n-1)*P + (n+1)*x**n)
   	   return halley(P,n,d-1,newx)	  =20
	else:
	   return x




Return-Path: <siegel@eico.com>
Delivered-To: edu-sig@python.org
Received: from mail.eico.com (unknown [216.216.41.149])
	by dinsdale.python.org (Postfix) with SMTP id A4C461CD1F
	for <edu-sig@python.org>; Fri, 12 May 2000 19:12:00 -0400 (EDT)
Received: from siegel ([209.109.224.69]) by mail.eico.com (Lotus SMTP MTA v4.6.4  (830.2 3-23-1999)) with SMTP id 852568DD.007E3246; Fri, 12 May 2000 18:58:24 -0400
From: "Arthur Siegel" <siegel@eico.com>
To: "Jeffrey Elkner" <jelkner@yorktown.arlington.k12.va.us>,
	"PythonEd" <edu-sig@python.org>
Date: Fri, 12 May 2000 19:07:54 -0400
Message-ID: <NDBBIAEANKEFIFOFMJHPAEKHCBAA.siegel@eico.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
Importance: Normal
In-Reply-To: <BCD0C7B9B8B650B6852568DD0069B8B1.0069B9C0852568DD@eico.com>
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
Subject: [Edu-sig] Unsubscribe
Sender: edu-sig-admin@python.org
Errors-To: edu-sig-admin@python.org
X-BeenThere: edu-sig@python.org
X-Mailman-Version: 2.0beta3
Precedence: bulk
List-Id: Python in education <edu-sig.python.org>

I was going to wait until Monday, but now prefer to face the week-end with a
clearer
head.

I had written -

>>Fair enough?

I certainly thought so.

But I will take silence as a no in this case.

So I guess I've seen this through to the end. I am proud of at least that.

Guido:

Please remove the EDU-SIG link to PyGeo.  It's busted anyway

David Ascher:

Thanks for listening.

To Starship:

Please consider my February something (my e-mail archives don't go back far
enough to pinpoint)
request for a crew account, delivered according to instructions, in good
order with receipt acknowledged
- withdrawn.

To Stephen:

I'll settle for the consolation prize.  $300, I believe. You have the
address.

To Kirby:

Love to hear Urner on the Transcendentalists.  Will be checking your site.