How to resolve the algorithm Check Machin-like formulas step by step in the R programming language

Published on 12 May 2024 09:40 PM
#R

How to resolve the algorithm Check Machin-like formulas step by step in the R programming language

Table of Contents

Problem Statement

Machin-like formulas   are useful for efficiently computing numerical approximations for

π

{\displaystyle \pi }

Verify the following Machin-like formulas are correct by calculating the value of tan   (right hand side) for each equation using exact arithmetic and showing they equal 1: and confirm that the following formula is incorrect by showing   tan   (right hand side)   is not   1: These identities are useful in calculating the values:

You can store the equations in any convenient data structure, but for extra credit parse them from human-readable text input. Note: to formally prove the formula correct, it would have to be shown that

− 3 p i

4

{\displaystyle {-3pi \over 4}}

< right hand side <

5 p i

4

{\displaystyle {5pi \over 4}}

due to

tan ⁡ ( )

{\displaystyle \tan()}

periodicity.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Check Machin-like formulas step by step in the R programming language

Source code in the r programming language

#lang R
library(Rmpfr)
prec <- 1000 # precision in bits
`%:%` <- function(e1, e2) '/'(mpfr(e1, prec), mpfr(e2, prec)) # operator %:% for high precision division
# function for checking identity of tan of expression and 1, making use of high precision division operator %:%
tanident_1 <- function(x) identical(round(tan(eval(parse(text = gsub("/", "%:%", deparse(substitute(x)))))), (prec/10)), mpfr(1, prec))

tanident_1( 1*atan(1/2)    +  1*atan(1/3) )
## [1] TRUE
tanident_1( 2*atan(1/3)    +  1*atan(1/7))
## [1] TRUE
tanident_1( 4*atan(1/5)    + -1*atan(1/239))
## [1] TRUE
tanident_1( 5*atan(1/7)    +  2*atan(3/79))
## [1] TRUE
tanident_1( 5*atan(29/278) +  7*atan(3/79))
## [1] TRUE
tanident_1( 1*atan(1/2)    +  1*atan(1/5)   +   1*atan(1/8) )
## [1] TRUE
tanident_1( 4*atan(1/5)    + -1*atan(1/70)  +   1*atan(1/99) )
## [1] TRUE
tanident_1( 5*atan(1/7)    +  4*atan(1/53)  +   2*atan(1/4443))
## [1] TRUE
tanident_1( 6*atan(1/8)    +  2*atan(1/57)  +   1*atan(1/239))
## [1] TRUE
tanident_1( 8*atan(1/10)   + -1*atan(1/239) +  -4*atan(1/515))
## [1] TRUE
tanident_1(12*atan(1/18)   +  8*atan(1/57)  +  -5*atan(1/239))
## [1] TRUE
tanident_1(16*atan(1/21)   +  3*atan(1/239) +   4*atan(3/1042))
## [1] TRUE
tanident_1(22*atan(1/28)   +  2*atan(1/443) +  -5*atan(1/1393) + -10*atan(1/11018))
## [1] TRUE
tanident_1(22*atan(1/38)   + 17*atan(7/601) +  10*atan(7/8149))
## [1] TRUE
tanident_1(44*atan(1/57)   +  7*atan(1/239) + -12*atan(1/682)  +  24*atan(1/12943))
## [1] TRUE
tanident_1(88*atan(1/172)  + 51*atan(1/239) +  32*atan(1/682)  +  44*atan(1/5357) + 68*atan(1/12943))
## [1] TRUE
tanident_1(88*atan(1/172)  + 51*atan(1/239) +  32*atan(1/682)  +  44*atan(1/5357) + 68*atan(1/12944))
## [1] FALSE


  

You may also check:How to resolve the algorithm Soloway's recurring rainfall step by step in the Ruby programming language
You may also check:How to resolve the algorithm Angle difference between two bearings step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm XML/Input step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Magic 8-ball step by step in the Commodore BASIC programming language
You may also check:How to resolve the algorithm Gapful numbers step by step in the Julia programming language