We need to start with Christoffel symbols of second kind.
require(Deriv)
## Loading required package: Deriv
## Warning: package 'Deriv' was built under R version 4.0.5
dot_prod<-function(a,b){
Simplify(paste(paste(a,b,sep="*"),collapse="+") )
}
g=matrix(c("1","0","0","sin(theta)^2"),nrow=2)
inv_g=matrix(c("1","0","0","1/sin(theta)^2"),nrow=2)
Gamma2nd<-function(k,i,j){
para=c("theta","phi")
g1=inv_g[k,]
g2=sapply(g[i,],function(m) Deriv(m,para[j]))
g3=sapply(g[,j],function(m) Deriv(m,para[i]))
g4=sapply(para,function(m) Deriv(g[i,j],m))
g5=sapply(paste(paste(g2,g3,sep="+"),g4,sep="-"),Simplify)
res=Simplify(paste0(dot_prod(g1,g5),"/2"))
return(res)
}
data=expand.grid(1:2,1:2,1:2)
Gamma <- array(apply(data,1,function(x) Gamma2nd(x[3],x[2],x[1])),dim = c(2, 2, 2))
Gamma
## , , 1
##
## [,1] [,2]
## [1,] "0" "0"
## [2,] "0" "-(cos(theta) * sin(theta))"
##
## , , 2
##
## [,1] [,2]
## [1,] "0" "cos(theta)/sin(theta)"
## [2,] "cos(theta)/sin(theta)" "0"
Contractions can produce \(+/-\) Ricci tensors due to symmetry. \[ R_{ij} = \frac{\partial}{\partial x^{j}} \Gamma^{k}_{ik} - \frac{\partial}{\partial x^{k}} \Gamma^{k}_{ij} + \Gamma^{m}_{ik} \Gamma^{k}_{mj} - \Gamma^{m}_{ij}\Gamma^{k}_{mk} \]
Ricci<-function(i,j){
para=c("theta","phi")
term1=paste(Deriv(Gamma[i,1,1],para[j]),Deriv(Gamma[i,2,2],para[j]),sep="+")
term1=Simplify(term1)
term2=paste(Deriv(Gamma[i,j,1],para[1]),Deriv(Gamma[i,j,2],para[2]),sep="+")
term2=Simplify(paste0("-(",term2,")"))
m=c(1,2,1,2)
k=c(1,1,2,2)
mydata=cbind(m,k)
g3=apply(mydata,1,function(x) Gamma[i,x[1],x[2]] )
g4=apply(mydata,1,function(x) Gamma[x[2],j,x[1]] )
term3=Simplify(dot_prod(g3,g4))
g5=apply(mydata,1,function(x) Gamma[i,j,x[1]] )
g6=apply(mydata,1,function(x) Gamma[x[1],x[2],x[2]] )
term4=dot_prod(g5,g6)
term4=paste0("-(",term4,")")
res=paste(term1,term2,term3,term4,sep="+")
return(Simplify(res))
}
data=expand.grid(1:2,1:2)
array(apply(data,1,function(x) Ricci(x[1],x[2])),dim = c(2, 2))
## [,1] [,2]
## [1,] "-1" "0"
## [2,] "0" "-sin(theta)^2"
GENERAL RELATIVITY IRREDUCIBLE MINIMUM, ALAN L. MYERS