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
   c)  M-th Roots ( more general )
 

-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.
 

     c)  M-th Roots  ( More general )
 

-More general nested roots may be computed with a small modification of the previous programs.

     "INRM+"  evaluates

      R(m) =  mroot( a1 + b1 mroot( a2 + b2 mroot( ......... mroot( an + bn mroot( an+1 + bn+1 mroot.... ) ) ) ) )

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

                                         R01 to R05: temp  ( R02 = R03 = R(m) )  at the end
Flags: /
Subroutine:  A program that takes n in X-register and R01 and returns  an & bn in registers  Y & X  respectively.
 
 

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

 
    ( 50 bytes / SIZE 006 )
 
 

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

 
Example:       an = 2 n - 1  ,  bn = 2 n  ,   m = 3   and if you choose  n0 = 10

-Load this short subroutine in main memory:
 
 

 01  LBL "T"
 02  ST+ X
 03  ENTER^
 04  DSE Y
 05  RTN

 
    T  ASTO 00

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

         R(m)  = ( 1 + 2 Cbrt( 3 + 4 Cbrt( 5 + 6 Cbrt( ....... Cbrt( 2n-1 + 2n Cbrt( .... ) ) ) )   ~  1.806579801              ---Execution time = 130s---
 
 
 

Reference:

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