hp41programs

Nested Radicals

Nested Radicals for the HP-41


Overview
 

 1°)  Finite Nested Radicals

   a)  Square Roots
   b)  M-th Roots

 2°)  Infinite Nested Radicals

   a)  Square Roots
   b)  M-th Roots
 

-Just a few elementary programs to calculate a few continued roots.
 
 

1°)  Finite Nested Radicals
 

     a)  Square Roots
 

 "FNR2"  evaluates   Rn =  sqrt( u1 + sqrt( u2 + sqrt ( ......... + sqrt( un ) ) ) )

    where  n is a positive integer  and  un = f(n)
 

Data Registers:           •  R00 = f name                 ( Register R00 is to be initialized before executing "FNR2" )

                                         R01 = n , n-1 , ..... , 0
                                         R02 = partial sums , then  Rn
Flags: /
Subroutine:  A program that takes n in X-register and R01 and returns  f(n) =  un
 
 
 

 01  LBL "FNR2"
 02  STO 01
 03  CLX
 04  STO 02
 05  LBL 01
 06  RCL 01
 07  XEQ IND 00
 08  RCL 02
 09  +
 10  SQRT
 11  STO 02
 12  DSE 01
 13  GTO 01
 14  END

 
( 26 bytes / SIZE 003 )
 
 

      STACK        INPUTS      OUTPUTS
           X             n            Rn 

 
Example:    un = f(n) = n3  ,   n = 9

-Load this short subroutine in main memory:
 
 

 01  LBL "T"
 02  3
 03  Y^X
 04  RTN

 
    T  ASTO 00
 
    9  XEQ "FNR2"  >>>>   Rn = 2.176788597                                           ---Execution time = 7s---
 
 

     b)  M-th Roots
 

-Just minor modifications for n-th roots:    R(m)n =  mroot( u1 + mroot( u2 + mroot ( ......... + mroot( un ) ) ) )
 

Data Registers:           •  R00 = f name                                  ( Register R00 is to be initialized before executing "FNRM" )

                                         R01 = n , n-1 , ..... , 0
                                         R02 = partial sums , then  Rn
                                         R03 = 1/m
Flags: /
Subroutine:  A program that takes n in X-register and R01 and returns  f(n) =  un
 
 

 01  LBL "FNRM"
 02  STO 01
 03  X<>Y
 04  1/X
 05  STO 03
 06  CLX
 07  STO 02
 08  LBL 01
 09  RCL 01
 10  XEQ IND 00
 11  RCL 02
 12  +
 13  RCL 03
 14  Y^X
 15  STO 02
 16  DSE 01
 17  GTO 01
 18  END

 
( 30 bytes / SIZE 004 )
 
 

      STACK        INPUTS      OUTPUTS
           Y             m            /
           X             n          R(m)n 

 
Example:       un = f(n) = n4  ,   n = 7  ,  m = 3

-Load this short subroutine in main memory:
 
 

 01  LBL "T"
 02  X^2
 03  X^2
 04  RTN

 
    T  ASTO 00
 
    3   ENTER^
    7   XEQ "FNRM"  >>>>   R(m)n  = 1.551416993                                           ---Execution time = 6s---
 

2°)  Infinite Nested Radicals
 

     a)  Square Roots
 

-We want to evaluate:  R =  sqrt( u1 + sqrt( u2 + sqrt ( ......... + sqrt( un + sqrt ( un+1.... ) ) ) ) )
 

-Here, you give a positive integer n0 and the HP41 calculates   Rn0 ,  Rn0+1 , ......   until 2 consecutive nested roots are equal.
 
 

Data Registers:           •  R00 = f name                                        ( Register R00 is to be initialized before executing "INR2" )

                                         R01 = n , n-1 , ..... , 0
                                         R02 = partial sums , then  Rn
                                         R03 = n0 , n0 + 1 , n0 +2 , .......
                                         R04 = Sums
Flags: /
Subroutine:  A program that takes n in X-register and R01 and returns  f(n) =  un
 
 

 01  LBL "INR2"
 02  STO 03
 03  SIGN
 04  ST- 03
 05  CHS
 06  STO 02
 07  LBL 01
 08  ISG 03
 09  CLX
 10  RCL 03
 11  STO 01
 12  CLX
 13  STO 04
 14  LBL 02
 15  RCL 01
 16  XEQ IND 00
 17  RCL 04
 18  +
 19  SQRT
 20  STO 04
 21  DSE 01
 22  GTO 02
 23  ENTER^
 24  VIEW X
 25  X<> 02
 26  X#Y?
 27  GTO 01
 28  END

 
( 45 bytes / SIZE 005 )
 
 

      STACK        INPUTS      OUTPUTS
           X             n0            R 

 
Example:    un = f(n) = n3  and if you choose   n0 = 6

-Load this short subroutine in main memory:
 
 

 01  LBL "T"
 02  3
 03  Y^X
 04  RTN

 
    T  ASTO 00
 
    6  XEQ "INR2"  >>>>   The HP41 displays the successive approximations and finally:

                                          R = 2.176788597                                                                                                 ---Execution time = 34s---
 

-Thus,      sqrt ( 1 + sqrt ( 8 + sqrt ( 27 + sqrt ( 64 + sqrt ( ............... ) ) ) ) ) = 2.176788597

Note:

-With n0 = 9 we get the same result in 16 seconds only
 

     b)  M-th Roots
 

-The same method is used with m-th roots to estimate

      R(m) =  mroot( u1 + mroot( u2 + mroot( ......... + mroot( un + mroot( un+1.... ) ) ) ) )
 
 

Data Registers:           •  R00 = f name                                         ( Register R00 is to be initialized before executing "INRM" )

                                         R01 = n , n-1 , ..... , 0
                                         R02 = partial sums , then  Rn
                                         R03 = n0 , n0 + 1 , n0 +2 , .......
                                         R04 = Sums   ,   R05 = 1/m
Flags: /
Subroutine:  A program that takes n in X-register and R01 and returns  f(n) =  un
 
 

 01  LBL "INRM"
 02  STO 03
 03  SIGN
 04  ST- 03
 05  CHS
 06  STO 02
 07  X<>Y
 08  1/X
 09  STO 05
 10  LBL 01
 11  ISG 03
 12  CLX
 13  RCL 03
 14  STO 01
 15  CLX
 16  STO 04
 17  LBL 02
 18  RCL 01
 19  XEQ IND 00
 20  RCL 04
 21  +
 22  RCL 05
 23  Y^X
 24  STO 04
 25  DSE 01
 26  GTO 02
 27  ENTER^
 28  VIEW X
 29  X<> 02
 30  X#Y?
 31  GTO 01
 32  END

 
( 49 bytes / SIZE 006 )
 
 

      STACK        INPUTS      OUTPUTS
           Y             m            R(m)
           X             n0            R(m)

 
Example:       un = f(n) = n4  ,  m = 3   and if you choose  n0 = 4

-Load this short subroutine in main memory:
 
 

 01  LBL "T"
 02  X^2
 03  X^2
 04  RTN

 
    T  ASTO 00
 
    3   ENTER^
    4   XEQ "INRM"  >>>>   The HP41 displays the successive approximations and finally:

                                             R(m)  = 1.551416993                                                                                     ---Execution time = 20s---

-So,      cbrt ( 1 + cbrt ( 16 + cbrt ( 81 + cbrt ( 256 + cbrt ( ............... ) ) ) ) ) = 1.551416993 
 

Notes:

-With n0 = 6 you get the same result in 12 seconds only
-Execution time will be much larger if the continued root converges slowly...

-The subroutine may be inserted in the program itself - after line 18 - to avoid XEQ IND 00  and this will reduce execution time.
 
 

Reference:

[1]  http://www.wolframalpha.com/entities/mathworld/nested_radical/eb/vf/zu/