The code below creates a function that produces a graph to show the convergence of the Bloch-Beilinson Conjecture to the value of pi/4. This conjecture involves the summation of the following:

= 1/1 - 1/3 + 1/5 - 1/7 + …

Loading the appropriate packages

library("ggplot2")
## Warning: package 'ggplot2' was built under R version 3.5.3

The code

The following code creates the summation using the example number of iterations of 20, and produces the graph of the results:

vector <- c()
value <- 0
for (i in 1:10){
  value <- value + 1/(4*i - 3)
  vector <- c(vector, value)
  value <- value - (1/(4*i - 1))
  vector <- c(vector, value)
}
vector2 <- c(1:(20))
dataset <- data.frame(vector2, vector)
graph20 <- ggplot(data <- dataset, aes(x <- vector2, y <- vector)) + geom_point() + geom_line(col = "black") + geom_segment(aes(x = 0, y = pi/4, xend = 20, yend = pi/4), size = 1, col = "red") + labs(y = "Summed of n values", x = "nth value")
print(graph20)

The function

The previous code can be embedded into a function, with the input ā€˜n’ representing the number of iterations you want to represent:

BlochFunction <- function(n){
  vector <- c()
  value <- 0
  for (i in 1:(n/2)){
    value <- value + 1/(4*i - 3)
    vector <- c(vector, value)
    value <- value - (1/(4*i - 1))
    vector <- c(vector, value)
  }
  vector2 <- c(1:(n))
  dataset <- data.frame(vector2, vector)
  a <- ggplot(data <- dataset, aes(x <- vector2, y <- vector)) + geom_point() + geom_line(col = "black") + geom_segment(aes(x = 0, y = pi/4, xend = n, yend = pi/4), size = 1, col = "red") + labs(y = "Summed of n values", x = "nth value")
  a
}

Example output plot

The following example provides the plot for the first 100 values

BlochFunction(n = 100)