Arbitrary precision arithmetic

library(caracas)

An example

n_2 <- as_sym("2")
n_pi <- as_sym("pi", declare_symbols = FALSE) # pi is a constant in SymPy
x <- sqrt(n_2) * n_pi
x
#> [caracas]: √2⋅π
N(x)
#> [caracas]: 4.44288293815837
N(x, 5)
#> [caracas]: 4.4429
N(x, 50)
#> [caracas]: 4.4428829381583662470158809900606936986146216893757
as.character(N(x, 50))
#> [1] "4.4428829381583662470158809900606936986146216893757"

Another example

As SymPy requires mpmath this can be used directly, for example like this (example due to Hans W Borchers, thanks!):

mpmath <- reticulate::import('mpmath')
mpmath$mp$dps <- 30
z <- mpmath$mpc(real = '1.0', imag = '63.453')
zeta_z <- mpmath$zeta(z)
zeta_z
#> (2.3454640626800434588582100226 - 0.641476965582898402371607967236j)
as.character(zeta_z$real)
#> [1] "2.3454640626800434588582100226"
as.character(zeta_z$imag)
#> [1] "-0.641476965582898402371607967236"