Binary files /tmp/tmp2eftb0e3/KeoT2Pno7K/r-cran-brobdingnag-1.2-6/build/partial.rdb and /tmp/tmp2eftb0e3/QOb2Ut5hxA/r-cran-brobdingnag-1.2-7/build/partial.rdb differ Binary files /tmp/tmp2eftb0e3/KeoT2Pno7K/r-cran-brobdingnag-1.2-6/build/vignette.rds and /tmp/tmp2eftb0e3/QOb2Ut5hxA/r-cran-brobdingnag-1.2-7/build/vignette.rds differ diff -Nru r-cran-brobdingnag-1.2-6/debian/changelog r-cran-brobdingnag-1.2-7/debian/changelog --- r-cran-brobdingnag-1.2-6/debian/changelog 2020-05-30 09:49:20.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/debian/changelog 2022-02-12 06:58:20.000000000 +0000 @@ -1,8 +1,10 @@ -r-cran-brobdingnag (1.2-6-2build1) groovy; urgency=medium +r-cran-brobdingnag (1.2-7-1) unstable; urgency=medium - * No-change rebuild against r-api-4.0 + * New upstream version + * Standards-Version: 4.6.0 (routine-update) + * debhelper-compat 13 (routine-update) - -- Graham Inggs Sat, 30 May 2020 09:49:20 +0000 + -- Andreas Tille Sat, 12 Feb 2022 07:58:20 +0100 r-cran-brobdingnag (1.2-6-2) unstable; urgency=medium diff -Nru r-cran-brobdingnag-1.2-6/debian/control r-cran-brobdingnag-1.2-7/debian/control --- r-cran-brobdingnag-1.2-6/debian/control 2020-05-15 14:07:56.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/debian/control 2022-02-12 06:58:20.000000000 +0000 @@ -4,10 +4,10 @@ Section: gnu-r Testsuite: autopkgtest-pkg-r Priority: optional -Build-Depends: debhelper-compat (= 12), +Build-Depends: debhelper-compat (= 13), dh-r, r-base-dev -Standards-Version: 4.5.0 +Standards-Version: 4.6.0 Vcs-Browser: https://salsa.debian.org/r-pkg-team/r-cran-brobdingnag Vcs-Git: https://salsa.debian.org/r-pkg-team/r-cran-brobdingnag.git Homepage: https://cran.r-project.org/package=Brobdingnag diff -Nru r-cran-brobdingnag-1.2-6/DESCRIPTION r-cran-brobdingnag-1.2-7/DESCRIPTION --- r-cran-brobdingnag-1.2-6/DESCRIPTION 2018-08-13 13:20:03.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/DESCRIPTION 2022-02-03 07:50:18.000000000 +0000 @@ -1,19 +1,20 @@ Package: Brobdingnag Type: Package Title: Very Large Numbers in R -Version: 1.2-6 -Date: 2018-08-08 -Author: Robin K. S. Hankin -Depends: R (>= 2.13.0), methods +Version: 1.2-7 +Authors@R: person(given=c("Robin", "K. S."), family="Hankin", role = c("aut","cre"), email="hankin.robin@gmail.com", comment = c(ORCID = "0000-0001-5982-0415")) Maintainer: Robin K. S. Hankin -Description: Handles very large numbers in R. Real numbers are held +Depends: R (>= 2.13.0), methods +Description: Very large numbers in R. Real numbers are held using their natural logarithms, plus a logical flag indicating - sign. The package includes a vignette that gives a - step-by-step introduction to using S4 methods. -LazyLoad: yes + sign. Functionality for complex numbers is also provided. The + package includes a vignette that gives a step-by-step + introduction to using S4 methods. +Suggests: cubature License: GPL Repository: CRAN -URL: https://github.com/RobinHankin/Brobdingnag.git +URL: https://github.com/RobinHankin/Brobdingnag NeedsCompilation: no -Packaged: 2018-08-10 01:21:37 UTC; rhankin -Date/Publication: 2018-08-13 13:20:03 UTC +Packaged: 2022-02-02 21:08:17 UTC; rhankin +Author: Robin K. S. Hankin [aut, cre] () +Date/Publication: 2022-02-03 07:50:18 UTC Binary files /tmp/tmp2eftb0e3/KeoT2Pno7K/r-cran-brobdingnag-1.2-6/inst/doc/Brobdingnag.pdf and /tmp/tmp2eftb0e3/QOb2Ut5hxA/r-cran-brobdingnag-1.2-7/inst/doc/Brobdingnag.pdf differ diff -Nru r-cran-brobdingnag-1.2-6/inst/doc/Brobdingnag.R r-cran-brobdingnag-1.2-7/inst/doc/Brobdingnag.R --- r-cran-brobdingnag-1.2-6/inst/doc/Brobdingnag.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/inst/doc/Brobdingnag.R 2022-02-02 21:08:12.000000000 +0000 @@ -0,0 +1,64 @@ +### R code from vignette source 'Brobdingnag.Rnw' + +################################################### +### code chunk number 1: googol_definition +################################################### + + + +################################################### +### code chunk number 2: Brobdingnag.Rnw:69-70 +################################################### +require(Brobdingnag) + + +################################################### +### code chunk number 3: Brobdingnag.Rnw:71-72 +################################################### +googol <- as.brob(10)^100 + + +################################################### +### code chunk number 4: define_f +################################################### +stirling <- function(n){n^n*exp(-n)*sqrt(2*pi*n)} + + +################################################### +### code chunk number 5: f_of_a_googol +################################################### +stirling(googol) + + +################################################### +### code chunk number 6: TwoToTheGoogolth +################################################### +2^(1/googol) + + +################################################### +### code chunk number 7: define_function_f +################################################### +f <- function(x){as.numeric( (pi*x -3*x -(pi-3)*x)/x)} + + +################################################### +### code chunk number 8: try.f.with.one.seventh +################################################### +f(1/7) +f(as.brob(1/7)) + + +################################################### +### code chunk number 9: try.f.with.a.googol +################################################### +f(1e100) +f(as.brob(1e100)) + + +################################################### +### code chunk number 10: try_f_with_bignumbers +################################################### +f(as.brob(10)^1000) + + diff -Nru r-cran-brobdingnag-1.2-6/inst/doc/Brobdingnag.Rnw r-cran-brobdingnag-1.2-7/inst/doc/Brobdingnag.Rnw --- r-cran-brobdingnag-1.2-6/inst/doc/Brobdingnag.Rnw 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/inst/doc/Brobdingnag.Rnw 2022-02-02 21:07:16.000000000 +0000 @@ -0,0 +1,231 @@ +\documentclass[nojss]{jss} + +\usepackage{dsfont} +\usepackage{bbm} +\usepackage{amsfonts} +\usepackage{wasysym} + +\author{Robin K. S. Hankin\\Auckland University of Technology} +\title{Very large numbers in \proglang{R}: Introducing package \pkg{Brobdingnag}} +%\VignetteIndexEntry{The Brobdingnag: package} + +\Plainauthor{Robin K. S. Hankin} +\Plaintitle{Very large numbers in R: Introducing package Brobdingnag} +\Plaintitle{Introducing package Brobdingnag} + + +\Abstract{ + + This vignette shows how to use the \pkg{Brobdingnag} package to + manipulate very large numbers; it is based on~\cite{Rnews:Hankin:2007}. + + The other vignette shows how to use \proglang{S4} methods in the + context of a simple package. + } + +\Keywords{\proglang{S4} methods, Brobdingnag, \proglang{R}} +\Plainkeywords{S4 methods, Brobdingnag, R} + +\Address{ + Robin K. S. Hankin\\ + Auckland University of Technology + E-mail: \email{hankin.robin@gmail.com}\hfill\includegraphics[width=1in]{\Sexpr{system.file("help/figures/brobdingnag.png",package="Brobdingnag")}} +} + +%% need no \usepackage{Sweave.sty} +\SweaveOpts{echo=TRUE} +\begin{document} + +\newsymbol\leqslant 1336 + + +\hfill\includegraphics[width=1in]{\Sexpr{system.file("help/figures/brobdingnag.png",package="Brobdingnag")}} + +\section{Introduction} + +The largest floating point number representable in standard double +precision arithmetic is a little under~$2^{1024}$, or +about~$1.79\times 10^{308}$. This is too small for some applications. + +The \proglang{R} package \pkg{Brobdingnag}~\citep{swift1726} overcomes this limit +by representing a real number~$x$ using a double precision variable +with value~$\log\left|x\right|$, and a logical corresponding to~$x\geq +0$; the \proglang{S4} class of such objects is \code{brob}. Complex numbers with +large absolute values (class \code{glub}) may be represented using a +pair of \code{brob}s to represent the real and imaginary components. + +The package allows user-transparent access to the large numbers +allowed by Brobdingnagian arithmetic. The package also includes a +vignette---\code{brob}---which documents the \proglang{S4} methods used and +includes a step-by-step tutorial. The vignette also functions as a +``Hello, World!'' example of \proglang{S4} methods as used in a simple package. +It also includes a full description of the \code{glub} class. + +\section[Package ``Brobdingnag'' in use]{Package \pkg{Brobdingnag} in use} + +Most readers will be aware of a googol which is equal to~$10^{100}$: + +<>= +<>= +require(Brobdingnag) +<>= +googol <- as.brob(10)^100 +@ + +Note the coercion of \code{double} value \code{10} to an object of +class \code{brob} using function \code{as.brob()}: raising this to the +power~100 (also double) results in another \code{brob}. The result is +printed using exponential notation, which is convenient for very large +numbers. + +A googol is well within the capabilities of standard double precision +arithmetic. Now, however, suppose we wish to compute its factorial. +Taking the first term of Stirling's series gives + +<>= +stirling <- function(n){n^n*exp(-n)*sqrt(2*pi*n)} +@ + +\noindent which then yields + +<>= +stirling(googol) +@ + +Note the transparent coercion to \code{brob} form within function +\code{stirling()}. + +It is also possible to represent numbers very close to~1. Thus + +<>= +2^(1/googol) +@ + +It is worth noting that if~$x$ has an exact representation in double +precision, then~$e^x$ is exactly representable using the system +described here. Thus~$e$ and~$e^{1000}$ may be represented exactly. + +\subsection{Accuracy} + +For small numbers (that is, representable using standard double +precision floating point arithmetic), \pkg{Brobdingnag} suffers a +slight loss of precision compared to normal representation. Consider +the following function, whose return value for nonzero arguments is +algebraically zero: + +<>= +f <- function(x){as.numeric( (pi*x -3*x -(pi-3)*x)/x)} +@ + +\begin{verbatim} +f <- function(x){ + as.numeric( (pi*x -3*x -(pi-3)*x)/x) +} +\end{verbatim} + +This function combines multiplication and addition; one might expect a +logarithmic system such as described here to have difficulty with it. + + +<>= +f(1/7) +f(as.brob(1/7)) +@ + +This typical example shows that Brobdingnagian numbers suffer a slight +loss of precision for numbers of moderate magnitude. This degradation +increases with the magnitude of the argument: + +<>= +f(1e100) +f(as.brob(1e100)) +@ + +Here, the brobs' accuracy is about two orders of magnitude worse than +double precision arithmetic: this would be expected, as the number of +bits required to specify the exponent goes as $\log\log x$. + +Compare + + +<>= +f(as.brob(10)^1000) +@ + +\noindent showing a further degradation of precision. However, +observe that conventional double precision arithmetic cannot deal with +numbers this big, and the package returns about 12 correct significant +figures. + +\section{A practical example} + +In the field of population dynamics, and especially the modelling of +biodiversity~\citep{hankin2007b,hubbell2001}, complicated +combinatorial formulae often arise. + +\citet{etienne2005}, for example, considers a sample of~$N$ +individual organisms taken from some natural population; the sample +includes~$S$ distinct species, and each individual is assigned a label +in the range~$1$ to~$S$. The sample comprises~$n_i$ members of +species~$i$, with~$1\leq i\leq S$ and~$\sum n_i=N$. For a given +sample~$D$ Etienne defines, amongst other terms, $K(D,A)$ for $1\leq +A\leq N-S+1$ as + +\begin{equation} +\sum_{ +\left\{ +a_1,\ldots,a_S\left| +\sum_{i=1}^S a_i=A\right. +\right\}} +\prod_{i=1}^S +\frac{ +\overline{s}(n_i,a_i) +\overline{s}(a_i,1)}{ +\overline{s}(n_i,1)} +\end{equation} + +\noindent +where~$\overline{s}(n,a)$ is the Stirling number of the second +kind~\citep{abramowitz1965}. The summation is over~$a_i=1,\ldots,n_i$ +with the restriction that the~$a_i$ sum to~$A$, as carried out by +\code{blockparts()} of the \pkg{partitions} +package~\citep{hankin2006,hankin2007}. + +Taking an intermediate-sized dataset due to Saunders\footnote{The +dataset comprises species counts on kelp holdfasts; +here \code{saunders.exposed.tot} of package +\pkg{untb}~\citep{hankin2007b}, is used.} of only~5903 individuals---a +relatively small dataset in this context---the maximal element +of~$K(D,A)$ is about~$1.435\times 10^{1165}$. The accuracy of package +\pkg{Brobdingnag} in this context may be assessed by comparing it with +that computed by \proglang{PARI/GP}~\citep{batut2000} with a working precision +of~100 decimal places; the natural logs of the two values +are~$2682.8725605988689$ and~$2682.87256059887$ respectively: +identical to 14 significant figures. + + +%Pari with 100 decimal places gives 2682.872560598868918515209515642292607616628612201118344882119616522539674163937533805390351760715777. + +% 2682.8725605988689 +%and with R: 2682.87256059887 + + + + +\section{Conclusions} + +The \pkg{Brobdingnag} package allows representation and manipulation +of numbers larger than those covered by standard double precision +arithmetic, although accuracy is eroded for very large numbers. This +facility is useful in several contexts, including combinatorial +computations such as encountered in theoretical modelling of +biodiversity. + +\subsubsection*{Acknowledgments} +I would like to acknowledge the many stimulating and helpful comments +made by the \proglang{R}-help list over the years. + + +\bibliography{brob} + +\end{document} Binary files /tmp/tmp2eftb0e3/KeoT2Pno7K/r-cran-brobdingnag-1.2-6/inst/doc/brobpaper.pdf and /tmp/tmp2eftb0e3/QOb2Ut5hxA/r-cran-brobdingnag-1.2-7/inst/doc/brobpaper.pdf differ diff -Nru r-cran-brobdingnag-1.2-6/inst/doc/brobpaper.R r-cran-brobdingnag-1.2-7/inst/doc/brobpaper.R --- r-cran-brobdingnag-1.2-6/inst/doc/brobpaper.R 2018-08-10 01:21:36.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/inst/doc/brobpaper.R 1970-01-01 00:00:00.000000000 +0000 @@ -1,64 +0,0 @@ -### R code from vignette source 'brobpaper.Rnw' - -################################################### -### code chunk number 1: googol_definition -################################################### - - - -################################################### -### code chunk number 2: brobpaper.Rnw:67-68 -################################################### -require(Brobdingnag) - - -################################################### -### code chunk number 3: brobpaper.Rnw:69-70 -################################################### -googol <- as.brob(10)^100 - - -################################################### -### code chunk number 4: define_f -################################################### -stirling <- function(n){n^n*exp(-n)*sqrt(2*pi*n)} - - -################################################### -### code chunk number 5: f_of_a_googol -################################################### -stirling(googol) - - -################################################### -### code chunk number 6: TwoToTheGoogolth -################################################### -2^(1/googol) - - -################################################### -### code chunk number 7: define_function_f -################################################### -f <- function(x){as.numeric( (pi*x -3*x -(pi-3)*x)/x)} - - -################################################### -### code chunk number 8: try.f.with.one.seventh -################################################### -f(1/7) -f(as.brob(1/7)) - - -################################################### -### code chunk number 9: try.f.with.a.googol -################################################### -f(1e100) -f(as.brob(1e100)) - - -################################################### -### code chunk number 10: try_f_with_bignumbers -################################################### -f(as.brob(10)^1000) - - diff -Nru r-cran-brobdingnag-1.2-6/inst/doc/brobpaper.Rnw r-cran-brobdingnag-1.2-7/inst/doc/brobpaper.Rnw --- r-cran-brobdingnag-1.2-6/inst/doc/brobpaper.Rnw 2018-08-06 21:27:39.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/inst/doc/brobpaper.Rnw 1970-01-01 00:00:00.000000000 +0000 @@ -1,229 +0,0 @@ -\documentclass[nojss]{jss} - -\usepackage{dsfont} -\usepackage{bbm} -\usepackage{amsfonts} -\usepackage{wasysym} - -\author{Robin K. S. Hankin\\Auckland University of Technology} -\title{Very large numbers in \proglang{R}: Introducing package \pkg{Brobdingnag}} -%\VignetteIndexEntry{The Brobdingnag: package} - -\Plainauthor{Robin K. S. Hankin} -\Plaintitle{Very large numbers in R: Introducing package Brobdingnag} -\Plaintitle{Introducing package Brobdingnag} - - -\Abstract{ - - This vignette shows how to use the \pkg{Brobdingnag} package to - manipulate very large numbers; it is based on~\cite{Rnews:Hankin:2007}. - - The other vignette shows how to use \proglang{S4} methods in the - context of a simple package. - } - -\Keywords{\proglang{S4} methods, Brobdingnag, \proglang{R}} -\Plainkeywords{S4 methods, Brobdingnag, R} - -\Address{ - Robin K. S. Hankin\\ - Auckland University of Technology - E-mail: \email{hankin.robin@gmail.com} -} - -%% need no \usepackage{Sweave.sty} -\SweaveOpts{echo=TRUE} -\begin{document} - -\newsymbol\leqslant 1336 - - -\section{Introduction} - -The largest floating point number representable in standard double -precision arithmetic is a little under~$2^{1024}$, or -about~$1.79\times 10^{308}$. This is too small for some applications. - -The \proglang{R} package \pkg{Brobdingnag}~\citep{swift1726} overcomes this limit -by representing a real number~$x$ using a double precision variable -with value~$\log\left|x\right|$, and a logical corresponding to~$x\geq -0$; the \proglang{S4} class of such objects is \code{brob}. Complex numbers with -large absolute values (class \code{glub}) may be represented using a -pair of \code{brob}s to represent the real and imaginary components. - -The package allows user-transparent access to the large numbers -allowed by Brobdingnagian arithmetic. The package also includes a -vignette---\code{brob}---which documents the \proglang{S4} methods used and -includes a step-by-step tutorial. The vignette also functions as a -``Hello, World!'' example of \proglang{S4} methods as used in a simple package. -It also includes a full description of the \code{glub} class. - -\section[Package ``Brobdingnag'' in use]{Package \pkg{Brobdingnag} in use} - -Most readers will be aware of a googol which is equal to~$10^{100}$: - -<>= -<>= -require(Brobdingnag) -<>= -googol <- as.brob(10)^100 -@ - -Note the coercion of \code{double} value \code{10} to an object of -class \code{brob} using function \code{as.brob()}: raising this to the -power~100 (also double) results in another \code{brob}. The result is -printed using exponential notation, which is convenient for very large -numbers. - -A googol is well within the capabilities of standard double precision -arithmetic. Now, however, suppose we wish to compute its factorial. -Taking the first term of Stirling's series gives - -<>= -stirling <- function(n){n^n*exp(-n)*sqrt(2*pi*n)} -@ - -\noindent which then yields - -<>= -stirling(googol) -@ - -Note the transparent coercion to \code{brob} form within function -\code{stirling()}. - -It is also possible to represent numbers very close to~1. Thus - -<>= -2^(1/googol) -@ - -It is worth noting that if~$x$ has an exact representation in double -precision, then~$e^x$ is exactly representable using the system -described here. Thus~$e$ and~$e^{1000}$ may be represented exactly. - -\subsection{Accuracy} - -For small numbers (that is, representable using standard double -precision floating point arithmetic), \pkg{Brobdingnag} suffers a -slight loss of precision compared to normal representation. Consider -the following function, whose return value for nonzero arguments is -algebraically zero: - -<>= -f <- function(x){as.numeric( (pi*x -3*x -(pi-3)*x)/x)} -@ - -\begin{verbatim} -f <- function(x){ - as.numeric( (pi*x -3*x -(pi-3)*x)/x) -} -\end{verbatim} - -This function combines multiplication and addition; one might expect a -logarithmic system such as described here to have difficulty with it. - - -<>= -f(1/7) -f(as.brob(1/7)) -@ - -This typical example shows that Brobdingnagian numbers suffer a slight -loss of precision for numbers of moderate magnitude. This degradation -increases with the magnitude of the argument: - -<>= -f(1e100) -f(as.brob(1e100)) -@ - -Here, the brobs' accuracy is about two orders of magnitude worse than -double precision arithmetic: this would be expected, as the number of -bits required to specify the exponent goes as $\log\log x$. - -Compare - - -<>= -f(as.brob(10)^1000) -@ - -\noindent showing a further degradation of precision. However, -observe that conventional double precision arithmetic cannot deal with -numbers this big, and the package returns about 12 correct significant -figures. - -\section{A practical example} - -In the field of population dynamics, and especially the modelling of -biodiversity~\citep{hankin2007b,hubbell2001}, complicated -combinatorial formulae often arise. - -\citet{etienne2005}, for example, considers a sample of~$N$ -individual organisms taken from some natural population; the sample -includes~$S$ distinct species, and each individual is assigned a label -in the range~$1$ to~$S$. The sample comprises~$n_i$ members of -species~$i$, with~$1\leq i\leq S$ and~$\sum n_i=N$. For a given -sample~$D$ Etienne defines, amongst other terms, $K(D,A)$ for $1\leq -A\leq N-S+1$ as - -\begin{equation} -\sum_{ -\left\{ -a_1,\ldots,a_S\left| -\sum_{i=1}^S a_i=A\right. -\right\}} -\prod_{i=1}^S -\frac{ -\overline{s}(n_i,a_i) -\overline{s}(a_i,1)}{ -\overline{s}(n_i,1)} -\end{equation} - -\noindent -where~$\overline{s}(n,a)$ is the Stirling number of the second -kind~\citep{abramowitz1965}. The summation is over~$a_i=1,\ldots,n_i$ -with the restriction that the~$a_i$ sum to~$A$, as carried out by -\code{blockparts()} of the \pkg{partitions} -package~\citep{hankin2006,hankin2007}. - -Taking an intermediate-sized dataset due to Saunders\footnote{The -dataset comprises species counts on kelp holdfasts; -here \code{saunders.exposed.tot} of package -\pkg{untb}~\citep{hankin2007b}, is used.} of only~5903 individuals---a -relatively small dataset in this context---the maximal element -of~$K(D,A)$ is about~$1.435\times 10^{1165}$. The accuracy of package -\pkg{Brobdingnag} in this context may be assessed by comparing it with -that computed by \proglang{PARI/GP}~\citep{batut2000} with a working precision -of~100 decimal places; the natural logs of the two values -are~$2682.8725605988689$ and~$2682.87256059887$ respectively: -identical to 14 significant figures. - - -%Pari with 100 decimal places gives 2682.872560598868918515209515642292607616628612201118344882119616522539674163937533805390351760715777. - -% 2682.8725605988689 -%and with R: 2682.87256059887 - - - - -\section{Conclusions} - -The \pkg{Brobdingnag} package allows representation and manipulation -of numbers larger than those covered by standard double precision -arithmetic, although accuracy is eroded for very large numbers. This -facility is useful in several contexts, including combinatorial -computations such as encountered in theoretical modelling of -biodiversity. - -\subsubsection*{Acknowledgments} -I would like to acknowledge the many stimulating and helpful comments -made by the \proglang{R}-help list over the years. - - -\bibliography{brob} - -\end{document} Binary files /tmp/tmp2eftb0e3/KeoT2Pno7K/r-cran-brobdingnag-1.2-6/inst/doc/S4_brob.pdf and /tmp/tmp2eftb0e3/QOb2Ut5hxA/r-cran-brobdingnag-1.2-7/inst/doc/S4_brob.pdf differ diff -Nru r-cran-brobdingnag-1.2-6/inst/doc/S4_brob.R r-cran-brobdingnag-1.2-7/inst/doc/S4_brob.R --- r-cran-brobdingnag-1.2-6/inst/doc/S4_brob.R 2018-08-10 01:21:33.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/inst/doc/S4_brob.R 2022-02-02 21:08:16.000000000 +0000 @@ -7,7 +7,7 @@ ################################################### -### code chunk number 2: S4_brob.Rnw:120-129 +### code chunk number 2: S4_brob.Rnw:122-131 ################################################### setClass("swift", representation = "VIRTUAL" @@ -27,9 +27,9 @@ ################################################### -### code chunk number 4: new_flaky_arguments +### code chunk number 4: new_flaky_arguments (eval = FALSE) ################################################### -new("brob",x=1:10,positive=c(TRUE,FALSE,FALSE)) +## new("brob",x=1:10,positive=c(TRUE,FALSE,FALSE)) ################################################### @@ -115,7 +115,7 @@ ################################################### -### code chunk number 14: S4_brob.Rnw:366-371 +### code chunk number 14: S4_brob.Rnw:368-373 ################################################### setAs("brob", "numeric", function(from){ out <- exp(from@x) @@ -185,7 +185,7 @@ ################################################### -### code chunk number 23: S4_brob.Rnw:465-469 +### code chunk number 23: S4_brob.Rnw:467-471 ################################################### setGeneric("getX",function(x){standardGeneric("getX")}) setGeneric("getP",function(x){standardGeneric("getP")}) @@ -200,7 +200,7 @@ ################################################### -### code chunk number 25: S4_brob.Rnw:481-482 +### code chunk number 25: S4_brob.Rnw:483-484 ################################################### setMethod("length","brob",function(x){length(x@x)}) @@ -212,7 +212,7 @@ ################################################### -### code chunk number 27: S4_brob.Rnw:492-499 +### code chunk number 27: S4_brob.Rnw:494-501 ################################################### setMethod("[", "brob", function(x, i, j, drop){ @@ -230,7 +230,7 @@ ################################################### -### code chunk number 29: S4_brob.Rnw:512-529 +### code chunk number 29: S4_brob.Rnw:514-531 ################################################### setReplaceMethod("[",signature(x="brob"), function(x,i,j,value){ @@ -268,7 +268,7 @@ ################################################### -### code chunk number 32: S4_brob.Rnw:568-569 +### code chunk number 32: S4_brob.Rnw:570-571 ################################################### setGeneric(".cPair", function(x,y){standardGeneric(".cPair")}) @@ -280,7 +280,7 @@ ################################################### -### code chunk number 34: S4_brob.Rnw:579-583 +### code chunk number 34: S4_brob.Rnw:581-585 ################################################### setMethod(".cPair", c("brob", "brob"), function(x,y){.Brob.cPair(x,y)}) setMethod(".cPair", c("brob", "ANY"), function(x,y){.Brob.cPair(x,as.brob(y))}) @@ -314,7 +314,7 @@ ################################################### -### code chunk number 38: S4_brob.Rnw:633-636 +### code chunk number 38: S4_brob.Rnw:635-638 ################################################### setMethod("sqrt","brob", function(x){ brob(ifelse(x@positive,x@x/2, NaN),TRUE) @@ -334,7 +334,7 @@ ################################################### -### code chunk number 41: S4_brob.Rnw:648-679 +### code chunk number 41: S4_brob.Rnw:650-681 ################################################### setMethod("Math", "brob", function(x){ @@ -438,7 +438,7 @@ ################################################### -### code chunk number 45: S4_brob.Rnw:771-780 +### code chunk number 45: S4_brob.Rnw:773-782 ################################################### setMethod("Arith",signature(e1 = "brob", e2="missing"), function(e1,e2){ @@ -531,7 +531,7 @@ ################################################### -### code chunk number 53: S4_brob.Rnw:876-879 +### code chunk number 53: S4_brob.Rnw:878-881 ################################################### setMethod("Compare", signature(e1="brob", e2="ANY" ), .Brob.compare) setMethod("Compare", signature(e1="ANY" , e2="brob"), .Brob.compare) @@ -560,7 +560,7 @@ ################################################### -### code chunk number 57: S4_brob.Rnw:910-913 +### code chunk number 57: S4_brob.Rnw:912-915 ################################################### setMethod("Logic",signature(e1="swift",e2="ANY"), .Brob.logic) setMethod("Logic",signature(e1="ANY",e2="swift"), .Brob.logic) @@ -582,7 +582,7 @@ ################################################### -### code chunk number 60: S4_brob.Rnw:958-1009 +### code chunk number 60: S4_brob.Rnw:960-1011 ################################################### if(!isGeneric("sum")){ setGeneric("max", function(x, ..., na.rm = FALSE) @@ -678,7 +678,7 @@ ################################################### -### code chunk number 63: S4_brob.Rnw:1055-1067 +### code chunk number 63: S4_brob.Rnw:1057-1069 ################################################### setMethod("Summary", "brob", function(x, ..., na.rm=FALSE){ diff -Nru r-cran-brobdingnag-1.2-6/inst/doc/S4_brob.Rnw r-cran-brobdingnag-1.2-7/inst/doc/S4_brob.Rnw --- r-cran-brobdingnag-1.2-6/inst/doc/S4_brob.Rnw 2018-08-06 23:50:14.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/inst/doc/S4_brob.Rnw 2022-02-02 21:07:16.000000000 +0000 @@ -29,7 +29,7 @@ \Address{ Robin K. S. Hankin\\ Auckland University of Technology\\ - E-mail: \email{hankin.robin@gmail.com} + E-mail: \email{hankin.robin@gmail.com}\hfill\includegraphics[width=1in]{\Sexpr{system.file("help/figures/brobdingnag.png",package="Brobdingnag")}} } %% need no \usepackage{Sweave.sty} @@ -39,6 +39,8 @@ \newsymbol\leqslant 1336 +\hfill\includegraphics[width=1in]{\Sexpr{system.file("help/figures/brobdingnag.png",package="Brobdingnag")}} + \section{Introduction} This vignette proves that it is possible for a `normal' @@ -181,7 +183,7 @@ Now, an optional step is to define a function that tests whether the arguments passed to {\tt new()} are acceptable. As it stands, the following code: -<>= +<>= new("brob",x=1:10,positive=c(TRUE,FALSE,FALSE)) @ diff -Nru r-cran-brobdingnag-1.2-6/man/brob-class.Rd r-cran-brobdingnag-1.2-7/man/brob-class.Rd --- r-cran-brobdingnag-1.2-6/man/brob-class.Rd 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/brob-class.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -11,7 +11,7 @@ \alias{getX,brob-method} \alias{sign<-,brob-method} -\title{Class "brob" } +\title{Class \dQuote{brob}} \description{ The formal S4 class for Brobdingnagian numbers } diff -Nru r-cran-brobdingnag-1.2-6/man/brobmat-arith.Rd r-cran-brobdingnag-1.2-7/man/brobmat-arith.Rd --- r-cran-brobdingnag-1.2-6/man/brobmat-arith.Rd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/brobmat-arith.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -0,0 +1,54 @@ +\name{brobmat.mult} +\alias{brobmat.mult} +\alias{brobmat.add} +\alias{brobmat.mult} +\alias{brobmat.power} +\alias{brobmat.inverse} +\alias{brobmat.greater} +\alias{brobmat.equal} +\alias{brobmat.compare} +\alias{brobmat.arith} +\alias{brobmat_matrixprod} +\alias{getat} +\title{ +Brobdingagian matrix arithmetic +} +\description{Basic arithmetic for Brobdingnagian matrices} +\usage{ +brobmat.mult(e1, e2) +brobmat.add(e1, e2) +brobmat.mult(e1, e2) +brobmat.power(e1, e2) +brobmat.inverse(e1) +brobmat.greater(e1, e2) +brobmat.equal(e1, e2) +getat(e1,e2) +} +\arguments{ + \item{e1,e2}{Arguments coerced to \code{brobmat} + } +} +\details{ + +These functions are helper functions used by the \code{brobmat} Arith +group and are not designed to be user-friendly. Function \code{getat()} +is a helper function that sets attributes such as dimnames of returned +values. + +} +\value{ +Return a \code{brobmat}, or logical for the comparison operators. +} +\author{Robin K. S. Hankin} +\examples{ +a <- brobmat(1:54,6,9) +rownames(a) <- letters[1:6] +a + 1e30 +a-a + +b <- as.brobmat(matrix(rnorm(27),9,3)) +colnames(b) <- month.abb[1:3] + +a \%*\% b + +} \ No newline at end of file diff -Nru r-cran-brobdingnag-1.2-6/man/brobmat-class.Rd r-cran-brobdingnag-1.2-7/man/brobmat-class.Rd --- r-cran-brobdingnag-1.2-6/man/brobmat-class.Rd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/brobmat-class.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -0,0 +1,126 @@ +\name{brobmat-class} +\Rdversion{1.1} +\docType{class} +\alias{brobmat-class} +\alias{[,brobmat,ANY,ANY-method} +\alias{[,brobmat,index,index-method} +\alias{[,brobmat,index,missing-method} +\alias{[,brobmat,missing,index-method} +\alias{[,brobmat,missing,missing-method} +\alias{[,brobmat,matrix,missing-method} +\alias{[<-,brobmat,index,index-method} +\alias{[<-,brobmat,index,missing-method} +\alias{[<-,brobmat,missing,index-method} +\alias{[<-,brobmat,matrix,missing-method} +\alias{[<-,brobmat,missing,missing-method} +\alias{\%*\%,ANY,brobmat-method} +\alias{\%*\%,brobmat,ANY-method} +\alias{\%*\%,brobmat,brobmat-method} +\alias{Arith,ANY,brobmat-method} +\alias{Arith,brob,brobmat-method} +\alias{Arith,brobmat,ANY-method} +\alias{Arith,brobmat,brob-method} +\alias{Arith,brobmat,brobmat-method} +\alias{Arith,brobmat,missing-method} +\alias{as.matrix,brobmat-method} +\alias{as.vector,brobmat-method} +\alias{coerce,brobmat,matrix-method} +\alias{colnames,brobmat-method} +\alias{colnames<-,brobmat-method} +\alias{Compare,ANY,brobmat-method} +\alias{Compare,brobmat,ANY-method} +\alias{Compare,brobmat,brobmat-method} +\alias{diag,brobmat-method} +\alias{diag,ANY-method} +\alias{dimnames,brobmat-method} +\alias{dimnames<-,brobmat-method} +\alias{getP,brobmat-method} +\alias{getP,ANY-method} +\alias{getP,numeric-method} +\alias{getX,brobmat-method} +\alias{getX,ANY-method} +\alias{getX,numeric-method} +\alias{length,brobmat-method} +\alias{Math,brobmat-method} +\alias{ncol,brobmat-method} +\alias{nrow,brobmat-method} +\alias{rownames,brobmat-method} +\alias{rownames<-,brobmat-method} +\alias{show,brobmat-method} +\alias{t,brobmat-method} +\alias{t,ANY-method} + +\title{Class \code{"brobmat"}} +\description{ + The \code{brobmat} class provides basic Brobdingnagian arithmetic for + matrices. +} +\section{Objects from the Class}{ +Objects can be created by calls of the form \code{new("brobmat", ...)}, +although functions \code{brobmat()}, \code{as.brobmat()} are more +user-friendly. +} +\section{Slots}{ + \describe{ + \item{\code{x}:}{Object of class \code{"matrix"} that specifes the + exponent} + \item{\code{positive}:}{Object of class \code{"logical"} that + specifies the sign} + } +} +\section{Methods}{ + \describe{ + \item{[}{\code{signature(x = "brobmat", i = "ANY", j = "ANY")}: ... } + \item{[}{\code{signature(x = "brobmat", i = "index", j = "index")}: ... } + \item{[}{\code{signature(x = "brobmat", i = "index", j = "missing")}: ... } + \item{[}{\code{signature(x = "brobmat", i = "missing", j = "index")}: ... } + \item{[}{\code{signature(x = "brobmat", i = "missing", j = "missing")}: ... } + \item{[}{\code{signature(x = "brobmat", i = "matrix", j = "missing")}: ... } + \item{[<-}{\code{signature(x = "brobmat", i = "index", j = "index")}: ... } + \item{[<-}{\code{signature(x = "brobmat", i = "index", j = "missing")}: ... } + \item{[<-}{\code{signature(x = "brobmat", i = "missing", j = "index")}: ... } + \item{[<-}{\code{signature(x = "brobmat", i = "matrix", j = "missing")}: ... } + \item{[<-}{\code{signature(x = "brobmat", i = "missing", j = "missing")}: ... } + \item{\%*\%}{\code{signature(x = "ANY", y = "brobmat")}: ... } + \item{\%*\%}{\code{signature(x = "brobmat", y = "ANY")}: ... } + \item{\%*\%}{\code{signature(x = "brobmat", y = "brobmat")}: ... } + \item{Arith}{\code{signature(e1 = "ANY", e2 = "brobmat")}: ... } + \item{Arith}{\code{signature(e1 = "brob", e2 = "brobmat")}: ... } + \item{Arith}{\code{signature(e1 = "brobmat", e2 = "ANY")}: ... } + \item{Arith}{\code{signature(e1 = "brobmat", e2 = "brob")}: ... } + \item{Arith}{\code{signature(e1 = "brobmat", e2 = "brobmat")}: ... } + \item{Arith}{\code{signature(e1 = "brobmat", e2 = "missing")}: ... } + \item{as.matrix}{\code{signature(x = "brobmat")}: ... } + \item{as.vector}{\code{signature(x = "brobmat")}: ... } + \item{coerce}{\code{signature(from = "brobmat", to = "matrix")}: ... } + \item{colnames}{\code{signature(x = "brobmat")}: ... } + \item{colnames<-}{\code{signature(x = "brobmat")}: ... } + \item{Compare}{\code{signature(e1 = "ANY", e2 = "brobmat")}: ... } + \item{Compare}{\code{signature(e1 = "brobmat", e2 = "ANY")}: ... } + \item{Compare}{\code{signature(e1 = "brobmat", e2 = "brobmat")}: ... } + \item{diag}{\code{signature(x = "brobmat")}: ... } + \item{dimnames}{\code{signature(x = "brobmat")}: ... } + \item{dimnames<-}{\code{signature(x = "brobmat")}: ... } + \item{getP}{\code{signature(x = "brobmat")}: ... } + \item{getX}{\code{signature(x = "brobmat")}: ... } + \item{length}{\code{signature(x = "brobmat")}: ... } + \item{Math}{\code{signature(x = "brobmat")}: ... } + \item{ncol}{\code{signature(x = "brobmat")}: ... } + \item{nrow}{\code{signature(x = "brobmat")}: ... } + \item{rownames}{\code{signature(x = "brobmat")}: ... } + \item{rownames<-}{\code{signature(x = "brobmat")}: ... } + \item{show}{\code{signature(object = "brobmat")}: ... } + \item{t}{\code{signature(x = "brobmat")}: ... } + } +} +\references{ +Brobdingnag R News paper +} +\author{Robin K. S. Hankin} +\seealso{ +\code{\link{as.brob}}, \code{\linkS4class{brob}} +} +\examples{ +showClass("brobmat") +} +\keyword{classes} diff -Nru r-cran-brobdingnag-1.2-6/man/brobmat.Rd r-cran-brobdingnag-1.2-7/man/brobmat.Rd --- r-cran-brobdingnag-1.2-6/man/brobmat.Rd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/brobmat.Rd 2021-08-09 10:03:41.000000000 +0000 @@ -0,0 +1,50 @@ +\name{brobmat} +\alias{brobmat} +\alias{brobmat_to_brob} +\alias{as.brobmat} +\alias{t} +\alias{t.brobmat} +\alias{newbrobmat} +\alias{as.brobmat} +\alias{is.brobmat} +\alias{print.brobmat} +\alias{diag} +\title{Brobdingnagian matrices} +\description{ +Basic matrix arithmetic for Brobdingnagian numbers. Matrix addition, +multiplication extraction and replacement implemented but not the +determinant or matrix inverse. +} +\usage{ +brobmat(..., positive) +newbrobmat(x,positive) +as.brobmat(x) +is.brobmat(x) +brobmat_to_brob(x) +diag(x,...) +\method{print}{brobmat}(x,...) +t(x,...) +} +\arguments{ + \item{x}{Argument} + \item{\dots}{Further arguments} + \item{positive}{Logical, indicating whether an element is positive} +} +\details{ + Basic arithmetic for Brobdingnagian matrices. + + Function \code{brobmat()} is like \code{brob()} in that it interprets + its first argument as the exponent (but creates a matrix). Function + \code{as.brobmat()} coerces a numeric matrix to a + \code{brobmat}. +} +\value{ +Generally return a \code{brobmat} or \code{brob}. +} +\author{Robin K. S. Hankin} +\examples{ + +brobmat(-10:19,5,6) +as.brobmat(matrix(-10:19,5,6)) + +} \ No newline at end of file diff -Nru r-cran-brobdingnag-1.2-6/man/brob.Rd r-cran-brobdingnag-1.2-7/man/brob.Rd --- r-cran-brobdingnag-1.2-6/man/brob.Rd 2018-08-06 21:29:26.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/brob.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -11,7 +11,6 @@ as.brob(x) is.brob(x) } -%- maybe also 'usage' for other objects documented here. \arguments{ \item{x}{Quantity to be tested, coerced in to Brobdingnagian form} \item{positive}{In function \code{brob()}, logical indicating whether diff -Nru r-cran-brobdingnag-1.2-6/man/cbrob.Rd r-cran-brobdingnag-1.2-7/man/cbrob.Rd --- r-cran-brobdingnag-1.2-6/man/cbrob.Rd 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/cbrob.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -3,7 +3,7 @@ \alias{cBrob} \title{Combine Brobdingnagian vectors} \description{ - Combine Brobdingnagian or Glubdubbdribian vectors through concatenation + Combine Brobdingnagian or Glubdubbdribian vectors through concatenation } \usage{ cbrob(x, ...) diff -Nru r-cran-brobdingnag-1.2-6/man/Extract.Rd r-cran-brobdingnag-1.2-7/man/Extract.Rd --- r-cran-brobdingnag-1.2-6/man/Extract.Rd 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/Extract.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -7,6 +7,10 @@ \alias{[<-,brob-method} \alias{[,glub-method} \alias{[<-,glub-method} +\alias{[,brob,ANY,ANY-method} +\alias{[,glub,ANY,ANY-method} +\alias{[<-,brob,ANY,ANY-method} +\alias{[<-,glub,ANY,ANY-method} \title{Extract or Replace Parts of brobs or glubs} \description{ Methods for \code{"["} and \code{"[<-"}, i.e., extraction or Binary files /tmp/tmp2eftb0e3/KeoT2Pno7K/r-cran-brobdingnag-1.2-6/man/figures/brobdingnag.png and /tmp/tmp2eftb0e3/QOb2Ut5hxA/r-cran-brobdingnag-1.2-7/man/figures/brobdingnag.png differ diff -Nru r-cran-brobdingnag-1.2-6/man/glub-class.Rd r-cran-brobdingnag-1.2-7/man/glub-class.Rd --- r-cran-brobdingnag-1.2-6/man/glub-class.Rd 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/glub-class.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -42,7 +42,9 @@ a <- as.brob(45) new("glub",real=a, imag=a) -as.brob(5+5i) # standard colloquial R idiom +as.brob(5+5i) # standard R idiom; imaginary component discarded +as.glub(5+5i) # returns a Glubbdubdribian object + } \keyword{classes} diff -Nru r-cran-brobdingnag-1.2-6/man/glub.Rd r-cran-brobdingnag-1.2-7/man/glub.Rd --- r-cran-brobdingnag-1.2-6/man/glub.Rd 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/glub.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -19,10 +19,13 @@ } \details{ +A \dfn{Glubbdubdribian} number is the Brobdingnagian equivalent of a +complex number. + Function \code{glub()} takes two arguments that are coerced to -Brobdingnagian numbers and returns a complex number. This function is -not really intended for the end user: it is confusing and includes no -argument checking. Use function \code{as.glub()} instead. +Brobdingnagian numbers and returns a Glubbdubdribian number. This +function is not really intended for the end user: it is confusing and +includes no argument checking. Use function \code{as.glub()} instead. Function \code{as.glub()} is the user's workhorse: use this to coerce numeric or complex vectors to Glubbdubdribian form. diff -Nru r-cran-brobdingnag-1.2-6/man/index-class.Rd r-cran-brobdingnag-1.2-7/man/index-class.Rd --- r-cran-brobdingnag-1.2-6/man/index-class.Rd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/index-class.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -0,0 +1,34 @@ +\name{index-class} +\Rdversion{1.1} +\docType{class} +\alias{index-class} + +\title{Class \code{"index"}} +\description{ +A virtual class for matrix extraction, copied from the \code{Matrix} +package. +} +\section{Objects from the Class}{A virtual Class: No objects may be created from it.} +\section{Methods}{ + \describe{ + \item{[}{\code{signature(x = "brobmat", i = "index", j = "index")}: ... } + \item{[}{\code{signature(x = "brobmat", i = "index", j = "missing")}: ... } + \item{[}{\code{signature(x = "brobmat", i = "missing", j = "index")}: ... } + \item{[<-}{\code{signature(x = "brobmat", i = "index", j = "index")}: ... } + \item{[<-}{\code{signature(x = "brobmat", i = "index", j = "missing")}: ... } + \item{[<-}{\code{signature(x = "brobmat", i = "missing", j = "index")}: ... } + } +} +\references{ + +Douglas Bates and Martin Maechler (2019). Matrix: Sparse and Dense +Matrix Classes and Methods. {R} package version 1.2-18. +\url{https://CRAN.R-project.org/package=Matrix} + +} +\author{Bates and Maechler, I guess} +\seealso{\code{\linkS4class{brobmat}}} +\examples{ +showClass("index") +} +\keyword{classes} diff -Nru r-cran-brobdingnag-1.2-6/man/infinite.Rd r-cran-brobdingnag-1.2-7/man/infinite.Rd --- r-cran-brobdingnag-1.2-6/man/infinite.Rd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/infinite.Rd 2020-12-05 21:38:10.000000000 +0000 @@ -0,0 +1,57 @@ +\name{infinite-methods} +\docType{methods} +\alias{infinite} +\alias{is.infinite} +\alias{is.infinite,brob-method} +\alias{is.infinite,glub-method} +\alias{is.infinite,brob-method} +\alias{is.infinite,glub-method} +\alias{finite} +\alias{is.finite} +\alias{is.finite,brob-method} +\alias{is.finite,glub-method} +\alias{is.finite,brob-method} +\alias{is.finite,glub-method} +\title{Infinite brobs and glubs} +\description{Brobdingnagian and Glubbdubdribian infinity} +\usage{ +\S4method{is.infinite}{brob}(x) +\S4method{is.infinite}{glub}(x) +\S4method{is.finite}{brob}(x) +\S4method{is.finite}{glub}(x) +} +\arguments{ + \item{x}{vector of class brob or glub} +} +\details{ + + +For a Brobdingnagian number, \code{is.infinite()} returns \code{TRUE} if +the exponent is infinite. + +A Glubbdubdribian number is infinite if either the real or imaginary +component is infinite. + +Function \code{is.finite()} is simply the logical negation of +\code{is.infinite()}. + +} + + +\author{Robin K. S. Hankin} +\examples{ + +is.infinite(brob(c(1,4,Inf))) + +is.infinite(glub(3,Inf)) +is.infinite(glub(Inf,3)) + + +is.infinite(exp(1e300)) +is.infinite(brob(1e300)) +# (Brobdingnagian infinity is bigger than regular infinity ;-) + + +} +\keyword{math} +\keyword{methods} diff -Nru r-cran-brobdingnag-1.2-6/man/swift-class.Rd r-cran-brobdingnag-1.2-7/man/swift-class.Rd --- r-cran-brobdingnag-1.2-6/man/swift-class.Rd 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/man/swift-class.Rd 2021-12-26 09:14:10.000000000 +0000 @@ -3,7 +3,7 @@ \alias{swift-class} \title{Class "swift" } -\description{ A (virtual) class that extends \code{brob} and +\description{A (virtual) class that extends \code{brob} and \code{glub} objects} \section{Objects from the Class}{A virtual Class: No objects may be created from it.} \section{Methods}{ diff -Nru r-cran-brobdingnag-1.2-6/MD5 r-cran-brobdingnag-1.2-7/MD5 --- r-cran-brobdingnag-1.2-6/MD5 2018-08-13 13:20:03.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/MD5 2022-02-03 07:50:18.000000000 +0000 @@ -1,35 +1,47 @@ -e109ba497a60c9d44cf4d829b1275a2a *DESCRIPTION -a76fb678cb89fd7f206a15374a7f648f *NAMESPACE -37f333dbec9307dfbaa3bd78de710c67 *R/brob.R -e0e26c2f87a0a9762fcfbaa9b98cb14b *R/glub.R -e731479c5c88f60b03422fe5cb305773 *build/partial.rdb -b62f86a3447b139c0bacb238e2b1e0a7 *build/vignette.rds +83c2e2bca1eb5fee0711cc59fdd0b79a *DESCRIPTION +bf2440f72d817d5a4c29b38897e0247e *NAMESPACE +c0b6feb0a734c0fdcc01e2b4515edebd *R/aaa_allclasses.R +27b718c81756fc77fc7ea3bf8c7d1d77 *R/brob.R +145939bb79e6c45436aa97a24212c79b *R/extract.R +3cf5bc7d6ab3f9396d234ed897d3e297 *R/glub.R +fd2fc6c9a7fe6d978655f84ab635521c *R/matrix.R +1bd953f4ebc0a611cab32113d3ddcb20 *R/replace.R +fce5390eea91004c9afad9891e8c1353 *README.md +6efb3280a9041198eda3a79f7db267c6 *build/partial.rdb +6525f06078d61dbb1ec3648f64ae5b4e *build/vignette.rds 5f9c8a3521284acab0ed92e3cf7dfb20 *inst/CITATION -eb936011697482b74b3f77affc0a18ce *inst/doc/S4_brob.R -0f4940ac121e509bb53c73370a40d5a0 *inst/doc/S4_brob.Rnw -a4c6aaef616c36d8bdc770006f791773 *inst/doc/S4_brob.pdf -233539c68bc55bf8d9057ff8afc20a63 *inst/doc/brobpaper.R -45c4ed62052c1b99976e5edad350c029 *inst/doc/brobpaper.Rnw -af5337cbd5ae10ee7466fcf15a593fe9 *inst/doc/brobpaper.pdf +111296f080ca695566ab1d0ae0842e4a *inst/doc/Brobdingnag.R +8d8bf483cd54f083df9234301e0f5013 *inst/doc/Brobdingnag.Rnw +4a7a7befc77f21c7e85a4f66892db78f *inst/doc/Brobdingnag.pdf +8e2065ab4f0631bfe581cb3b9abe06ea *inst/doc/S4_brob.R +9e8657d9868b035a24e1ef3e0df217bc *inst/doc/S4_brob.Rnw +f99eb853fc7077c9867e8371ad360137 *inst/doc/S4_brob.pdf 0d2def0996a161ecbc9a96ca9cd090d5 *man/Arith.Rd 85243eea5c0b8e74b1595f231bc62849 *man/Brobdingnag-package.Rd 302f297f098a7bbbddecc887df17de75 *man/Compare.Rd 7ca6539ccaee5c5094b0e6d20b09786c *man/Complex.Rd -7d8fbf72f254726fcdd44e18ab94127b *man/Extract.Rd +1014d342689d92dc02fe55ea6b2a6a38 *man/Extract.Rd 89303f2a4b86ddccd5d2932fa1750816 *man/Logic.Rd 0d7d612faf4826b5b6c0945ba2ae305f *man/Math.Rd e787c21aeaeab370f76de321b1067fcf *man/Print.Rd 99e360c829510efe42b9715461235d35 *man/Summary.Rd 5009aaafb2e2906b3abb375582e48aa7 *man/as.numeric.Rd -78335dae6bb7ca21ed9282f480702254 *man/brob-class.Rd -ce1513c857b9b2352080a3b75cffe302 *man/brob.Rd -381d0242161ab82eb2562d8c44c889d3 *man/cbrob.Rd +eff4e4d01ab9ddc1470197bf4a5bdb93 *man/brob-class.Rd +729c51856bf6ec30a84578109b732e3a *man/brob.Rd +39b6473e2d9fd1ce3af16b0600a5eda1 *man/brobmat-arith.Rd +9702abd1cea8402880a14da58bb6fd78 *man/brobmat-class.Rd +7ab6fa254d90051ab2ba88fc0189a9f2 *man/brobmat.Rd +aace3e63f8fbafd066356d5d14c2db3a *man/cbrob.Rd +8c5cabb210b66b4bfa021b558ee2bfc8 *man/figures/brobdingnag.png 8a9c550cd6383e2fbe98c93122914f93 *man/getP.Rd -abe744b5edc3d25cf8cbf3c2d40eb58d *man/glub-class.Rd -505378177b8b1de3768cb07e5d0e2068 *man/glub.Rd +5a19831a55dc9eff9431fdd669ab500e *man/glub-class.Rd +ad5494dd3a2c6a36b0c5a6d20f10aac4 *man/glub.Rd +f13a73382f54d0518ee34f22d8606464 *man/index-class.Rd +b5ea9051be1307aa715e50609dbc7e6f *man/infinite.Rd ea082304393290114fa77c7628715b1a *man/length.Rd 415843ee2c300b95e4b6462fd91684f8 *man/plot.Rd -79769d298b6ee1589415f4df95bbed78 *man/swift-class.Rd -0f4940ac121e509bb53c73370a40d5a0 *vignettes/S4_brob.Rnw +fc63023acdb227d91b55ad8fe4c31737 *man/swift-class.Rd +8d8bf483cd54f083df9234301e0f5013 *vignettes/Brobdingnag.Rnw +9e8657d9868b035a24e1ef3e0df217bc *vignettes/S4_brob.Rnw 5cf6c46a3f1dfc10d123edc61a930e23 *vignettes/brob.bib -45c4ed62052c1b99976e5edad350c029 *vignettes/brobpaper.Rnw +428a8158d30bad682c9cea7eedab404e *vignettes/brobmat.Rmd diff -Nru r-cran-brobdingnag-1.2-6/NAMESPACE r-cran-brobdingnag-1.2-7/NAMESPACE --- r-cran-brobdingnag-1.2-6/NAMESPACE 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/NAMESPACE 2020-12-05 21:38:10.000000000 +0000 @@ -5,4 +5,5 @@ S3method("print","brob") S3method("print","glub") +S3method("print","brobmat") diff -Nru r-cran-brobdingnag-1.2-6/R/aaa_allclasses.R r-cran-brobdingnag-1.2-7/R/aaa_allclasses.R --- r-cran-brobdingnag-1.2-6/R/aaa_allclasses.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/R/aaa_allclasses.R 2020-12-05 21:38:10.000000000 +0000 @@ -0,0 +1,18 @@ +setClass("brobmat", slots = c(x="matrix",positive="logical")) +setClass("swift", + representation = "VIRTUAL" + ) + +setClass("brob", + slots = c(x="numeric",positive="logical"), + contains = "swift" + ) + +setClass("glub", + slots = c(real="brob",imag="brob"), + contains = "swift" + ) + +## Following modified from the Matrix package: +setClassUnion("index", members = c("numeric", "logical", "character")) + diff -Nru r-cran-brobdingnag-1.2-6/R/brob.R r-cran-brobdingnag-1.2-7/R/brob.R --- r-cran-brobdingnag-1.2-6/R/brob.R 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/R/brob.R 2021-08-09 10:03:41.000000000 +0000 @@ -1,12 +1,3 @@ -setClass("swift", - representation = "VIRTUAL" - ) - -setClass("brob", - representation = representation(x="numeric",positive="logical"), - prototype = list(x=numeric(),positive=logical()), - contains = "swift" - ) ".Brob.valid" <- function(object){ len <- length(object@positive) @@ -41,8 +32,10 @@ } else if(is.glub(x)){ warning("imaginary parts discarded") return(Re(x)) + } else if(is.brobmat(x)){ + return(brobmat_to_brob(x)) } else { - return(brob(log(abs(x)), x>=0)) + return(brob(log(abs(c(x))), c(x)>=0)) } } @@ -78,6 +71,9 @@ setMethod("getP","brob",function(x){x@positive}) setMethod("length","brob",function(x){length(x@x)}) +setMethod("is.infinite","brob",function(x){x@x == +Inf}) +setMethod("is.finite" ,"brob",function(x){x@x != +Inf}) + setGeneric("sign<-",function(x,value){standardGeneric("sign<-")}) setMethod("sign<-","brob",function(x,value){ brob(x@x,value) @@ -371,7 +367,7 @@ ".Brob.prod" <- function(x){ p <- x@positive val <- x@x - return(brob(sum(val),(sum(p)%%2)==0)) + return(brob(sum(val),(sum(!p)%%2)==0)) } ".Brob.sum" <- function(x){ diff -Nru r-cran-brobdingnag-1.2-6/R/extract.R r-cran-brobdingnag-1.2-7/R/extract.R --- r-cran-brobdingnag-1.2-6/R/extract.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/R/extract.R 2020-12-05 21:38:10.000000000 +0000 @@ -0,0 +1,77 @@ + + +## "x[]": +setMethod("[", + signature(x = "brobmat", + i = "missing", j = "missing", + drop = "ANY"), + function(x, i, j, ..., drop){ + return(x) + } ) + + +## select rows, x[i,]: +setMethod("[", + signature(x = "brobmat", + i = "index", j = "missing", + drop = "ANY"), + function(x,i,j, ..., drop) { + if(missing(drop)){drop <- TRUE} + xv <- getX(x)[i,,drop=drop] + if(drop & (!is.matrix(xv))){ + return(brob(xv,getP(x)[i,])) + } else { + return(newbrobmat(xv, getP(x)[i,,drop=FALSE])) + } + } ) + +## select columns, x[,j]: +setMethod("[", + signature(x = "brobmat", + i = "missing", j = "index", + drop = "ANY"), + function(x,i,j, ..., drop) { + if(missing(drop)){drop <- TRUE} + xv <- getX(x)[,j,drop=drop] + if(drop & (!is.matrix(xv))){ + return(brob(xv,getP(x)[,j])) + } else { + return(newbrobmat(xv, getP(x)[,j,drop=FALSE])) + } + } ) + +## matrix indexing +setMethod("[", + signature(x = "brobmat", + i = "matrix", j = "missing", + drop = "ANY"), + function(x,i,j, ..., drop) { + xv <- getX(x)[i] + return(brobmat(getX(x)[i], getP(x)[i])) + } ) + +## select both rows *and* columns +setMethod("[", + signature(x = "brobmat", + i = "index", j = "index", + drop = "ANY"), + function(x,i,j, ..., drop) { + if(missing(drop)){drop <- TRUE} + xv <- getX(x)[i,j,drop=drop] + if(drop & (!is.matrix(xv))){ + return(brob(xv,getP(x)[i,j])) + } else { + return(newbrobmat(xv, getP(x)[i,j,drop=FALSE])) + } + + } ) + +## bail out if any of (i,j,drop) is "non-sense" +setMethod("[", + signature(x = "brobmat", + i = "ANY", j = "ANY", + drop = "ANY"), + function(x,i,j, ..., drop){ + stop("invalid or not-yet-implemented brobmat subsetting") + } ) + diff -Nru r-cran-brobdingnag-1.2-6/R/glub.R r-cran-brobdingnag-1.2-7/R/glub.R --- r-cran-brobdingnag-1.2-6/R/glub.R 2018-05-16 23:47:13.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/R/glub.R 2020-12-05 21:38:10.000000000 +0000 @@ -1,8 +1,3 @@ -setClass("glub", - representation = representation(real="brob",imag="brob"), - prototype = list(real=new("brob"), imag=new("brob")), - contains = "swift" - ) ".Glub.valid" <- function(object){ if(length(object@real) == length(object@imag)){ @@ -26,7 +21,8 @@ } ) setMethod("as.numeric",signature(x="glub"),function(x){as(x,"numeric")}) - +setMethod("is.infinite",signature(x="glub"),function(x){is.infinite(Re(x)) | is.infinite(Im(x))}) +setMethod("is.finite",signature(x="glub"),function(x){is.finite(Re(x)) & is.finite(Im(x))}) "glub" <- function(real=double(), imag=double()){ if(missing(imag)){ diff -Nru r-cran-brobdingnag-1.2-6/R/matrix.R r-cran-brobdingnag-1.2-7/R/matrix.R --- r-cran-brobdingnag-1.2-6/R/matrix.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/R/matrix.R 2020-12-05 21:38:10.000000000 +0000 @@ -0,0 +1,298 @@ + + +`.brobmat.valid` <- function(object){ + + if(length(object@x) != length(object@positive)){ + return("length mismatch") + } else { + return(TRUE) + } +} + +setValidity("brobmat", .Brob.valid) + +`newbrobmat` <- function(x,positive){ + new("brobmat", x=x, positive=c(positive)) # this is the only use of new() here +} + +`brobmat` <- function(..., positive){ + data <- list(...)[[1]] + if(is.matrix(data)){ + M <- data + } else if(is.brob(data)){ + jj <- list(...) + jj[[1]] <- getX(data) + M <- do.call(matrix,jj) # signs not accounted for + return(newbrobmat(M,positive=getP(data))) + } else { + M <- matrix(...) + } + if(missing(positive)){positive <- rep(TRUE,length(M))} + positive <- cbind(c(M),positive)[,2]>0 + return(newbrobmat(M,positive=positive)) +} + +`is.brobmat` <- function(x){is(x,"brobmat")} + +setMethod("getX","brobmat",function(x){x@x}) +setMethod("getX","numeric",function(x){x}) +setMethod("getP","brobmat",function(x){ + out <- getX(x) + storage.mode(out) <- "logical" + out[] <- x@positive + ## No occurrences of '@' after this line + return(out) +}) +setMethod("getP","numeric",function(x){x>0}) +setMethod("length","brobmat",function(x){length(getX(x))}) + +`as.brobmat` <- function(x){ + if(is.brob(x)){ + return(newbrobmat(matrix(getX(x)),matrix(getP(x)))) # n-by-1 + } else if(is.numeric(x)){ + x <- as.matrix(x) + return(newbrobmat(log(abs(x)), c(x>=0))) + } +} + +`is.brobmat` <- function(x){is(x,"brobmat")} + +setAs("brobmat", "matrix", function(from){ + out <- exp(getX(from)) + negs <- !getP(from) + out[negs] <- -out[negs] + return(out) +} ) + +`brobmat_to_brob` <- function(x){ brob(c(getX(x)),c(getP(x))) } + + +setMethod("as.matrix",signature(x="brobmat"),function(x){as(x,"matrix")}) +setGeneric("nrow") +setGeneric("ncol") +setMethod("nrow",signature(x="brobmat"),function(x){nrow(getX(x))}) +setMethod("ncol",signature(x="brobmat"),function(x){ncol(getX(x))}) + + +`.brobmat.print` <- function(x, digits=5){ + out <- getX(x) + out[] <- paste(c("-","+")[1+getP(x)],"exp(",signif(out,digits),")",sep="") + noquote(out) +} + +`print.brobmat` <- function(x, ...){ + jj <- .brobmat.print(x, ...) + print(jj) + return(invisible(jj)) +} + +setMethod("show", "brobmat", function(object){print.brobmat(object)}) + + + +setMethod("Math", "brobmat", + function(x){ + switch(.Generic, + abs = brobmat(getX(x)), + log = { + out <- getX(x) + out[!getP(x)] <- NaN + out # numeric matrix + }, + log10 = { + out <- getX(x) + out[!getP(x)] <- NaN + out/log(10) # numeric matrix + + }, + log2 = { + out <- getX(x) + out[!getP(x)] <- NaN + out/log(2) # numeric matrix + }, + exp =, + cosh =, + sinh =, + acos =, + acosh =, + asin =, + asinh =, + atan =, + atanh =, + cos =, + sin =, + tan =, + tanh =, + trunc =, + lgamma =, + cumsum =, + gamma =, + ceiling=, + floor =, + stop(paste(.Generic, "not implemented on brobmats")) + ) + } ) + +setMethod("Arith",signature(e1 = "brobmat", e2="missing"), + function(e1,e2){ + switch(.Generic, + "+" = e1, + "-" = newbrobmat(getX(e1),positive=!getP(e1)), + stop(paste("Unary operator", .Generic, + "not allowed on brobmats")) + ) + } ) + + +"brobmat.arith" <- function(e1,e2){ + switch(.Generic, + "+" = brobmat.add (e1, e2), + "-" = brobmat.add (e1, -e2), + "*" = brobmat.mult (e1, e2), + "/" = brobmat.mult (e1, brobmat.inverse(e2)), + "^" = brobmat.power(e1, e2), + stop(paste("binary operator \"", .Generic, "\" not defined for Brobdingnagian numbers")) + ) } + +setMethod("Arith", signature(e1 = "brobmat", e2="brob" ), brobmat.arith) +setMethod("Arith", signature(e1 = "brob" , e2="brobmat"), brobmat.arith) +setMethod("Arith", signature(e1 = "brobmat", e2="ANY" ), brobmat.arith) +setMethod("Arith", signature(e1 = "ANY" , e2="brobmat"), brobmat.arith) +setMethod("Arith", signature(e1 = "brobmat", e2="brobmat"), brobmat.arith) + +`getat` <- function(e1,e2=e1){ + if(length(e1)>=length(e2)){ + return(attributes(getX(e1))) + } else { + return(attributes(getX(e2))) + } +} + +`brobmat.add` <- function(e1,e2){ + out <- as.brob(e1) + as.brob(e2) + jj <- getX(out) + attributes(jj) <- getat(e1,e2) + return(newbrobmat(jj,getP(out))) +} + +`brobmat.mult` <- function(e1,e2){ + out <- as.brob(e1) * as.brob(e2) + jj <- getX(out) + attributes(jj) <- getat(e1,e2) + return(newbrobmat(jj,getP(out))) +} + +`brobmat.inverse` <- function(e1){ + if(is.brobmat(e1)){ + out <- 1/as.brob(e1) + jj <- getX(out) + attributes(jj) <- getat(e1) + return(newbrobmat(jj,getP(out))) + } else { + return(1/e1) + } +} + +`brobmat.power` <- function(e1,e2){ + out <- as.brob(e1) ^ as.brob(e2) + jj <- getX(out) + attributes(jj) <- getat(e1,e2) + return(newbrobmat(jj,getP(out))) +} + +"brobmat.equal" <- function(e1,e2){ + out <- as.brob(e1) == as.brob(e2) + attributes(out) <- getat(e1,e2) + return(out) +} + +"brobmat.greater" <- function(e1,e2){ + out <- as.brob(e1) > as.brob(e2) + attributes(out) <- getat(e1,e2) + return(out) +} + +"brobmat.compare" <- function(e1,e2){ + if( (length(e1) == 0) | (length(e2)==0)) { + return(logical(0)) + } + + switch(.Generic, + "==" = brobmat.equal(e1,e2), + "!=" = !brobmat.equal(e1,e2), + ">" = brobmat.greater(e1,e2), + "<" = !brobmat.greater(e1,e2) & !brobmat.equal(e1,e2), + ">=" = brobmat.greater(e1,e2) | brobmat.equal(e1,e2), + "<=" = !brobmat.greater(e1,e2) | brobmat.equal(e1,e2), + stop(paste(.Generic, "not supported for brobmats numbers")) + ) +} + +setMethod("Compare", signature(e1="brobmat", e2="ANY" ), brobmat.compare) +setMethod("Compare", signature(e1="ANY" , e2="brobmat"), brobmat.compare) +setMethod("Compare", signature(e1="brobmat", e2="brobmat"), brobmat.compare) + + +`brobmat_matrixprod` <- function(x,y){ + stopifnot(ncol(x)==nrow(y)) + out <- brobmat(NA,nrow(x),ncol(y)) + for(i in seq_len(nrow(x))){ + for(j in seq_len(ncol(y))){ + out[i,j] <- sum(x[i,,drop=TRUE]*y[,j,drop=TRUE]) + } # j loop closes + } # i loop closes + if(!is.null(rownames(x))){rownames(out) <- rownames(x)} + if(!is.null(colnames(x))){colnames(out) <- colnames(y)} + return(out) +} + +setMethod("%*%", signature(x="brobmat", y="ANY" ), brobmat_matrixprod) +setMethod("%*%", signature(x="ANY" , y="brobmat"), brobmat_matrixprod) +setMethod("%*%", signature(x="brobmat", y="brobmat"), brobmat_matrixprod) + +setGeneric("as.vector") +setMethod("as.vector", signature(x="brobmat"), function(x){as.brob(x)}) +setMethod("as.vector", signature(x="brob"), function(x){x}) + +setGeneric("rownames") +setMethod("rownames", signature(x="brobmat"), function(x){rownames(getX(x))}) + +setGeneric("colnames") +setMethod("colnames", signature(x="brobmat"), function(x){colnames(getX(x))}) + +setGeneric("dimnames") +setMethod("dimnames", signature(x="brobmat"), function(x){dimnames(getX(x))}) + +setGeneric("rownames<-") +setMethod("rownames<-", signature(x="brobmat"), + function(x,value){ + jj <- getX(x) + rownames(jj) <- value + return(brobmat(jj,getP(x))) + } ) + +setGeneric("colnames<-") +setMethod("colnames<-", signature(x="brobmat"), + function(x,value){ + jj <- getX(x) + colnames(jj) <- value + return(brobmat(jj,getP(x))) + } ) + +setGeneric("dimnames<-") +setMethod("dimnames<-", signature(x="brobmat"), + function(x,value){ + jj <- getX(x) + dimnames(jj) <- value + return(brobmat(jj,getP(x))) + } ) + +setGeneric("diag", function(x, ...){standardGeneric("diag")}) +setMethod("diag", signature(x="brobmat"),function(x,...){brob(diag(getX(x)),diag(getP(x)))}) +setMethod("diag", signature(x="ANY"), function(x,...){base::diag(x)}) + +setGeneric("t", function(x, ...) standardGeneric("t")) +setMethod("t", signature(x="brobmat"),function(x,...){brob(t(getX(x)),t(getP(x)))}) +setMethod("t", signature(x="ANY"),function(x,...){base::t(x)}) + + diff -Nru r-cran-brobdingnag-1.2-6/R/replace.R r-cran-brobdingnag-1.2-7/R/replace.R --- r-cran-brobdingnag-1.2-6/R/replace.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/R/replace.R 2020-12-05 21:38:10.000000000 +0000 @@ -0,0 +1,70 @@ +## x[] <- value +setReplaceMethod("[", + signature(x = "brobmat", + i = "missing", j = "missing", + value = "ANY"), + function (x, i, j, ..., value){ + value <- as.brob(value) + jj.x <- getX(x) + jj.pos <- getP(x) + jj.x[] <- getX(value) # matrix or vector + jj.pos[] <- getP(value) + return(newbrobmat(x=jj.x,positive=jj.pos)) + } ) + +## x[i,] <- value +setReplaceMethod("[", + signature(x = "brobmat", + i = "index", j = "missing", + value = "ANY"), + function (x, i, j, ..., value){ + value <- as.brob(value) + jj.x <- getX(x) + jj.pos <- getP(x) + jj.x[i,] <- getX(value) # matrix or vector + jj.pos[i,] <- getP(value) + return(newbrobmat(x=jj.x,positive=jj.pos)) + } ) + +## x[,j] <- value +setReplaceMethod("[", + signature(x = "brobmat", + i = "missing", j = "index", + value = "ANY"), + function (x, i, j, ..., value){ + value <- as.brob(value) + jj.x <- getX(x) + jj.pos <- getP(x) + jj.x[,j] <- getX(value) # matrix or vector + jj.pos[,j] <- getP(value) + return(newbrobmat(x=jj.x,positive=jj.pos)) + } ) + +## x[cbind(1:3,2:4)] <- value +setReplaceMethod("[", + signature(x = "brobmat", + i = "matrix", j = "missing", + value = "ANY"), + function (x, i, j, ..., value){ + value <- as.brob(value) + jj.x <- getX(x) + jj.pos <- getP(x) + jj.x[i] <- getX(value) # matrix or vector + jj.pos[i] <- getP(value) + return(newbrobmat(x=jj.x,positive=jj.pos)) + } ) + +## x[i,j] <- value +setReplaceMethod("[", + signature(x = "brobmat", + i = "index", j = "index", + value = "ANY"), + function (x, i, j, ..., value){ + value <- as.brob(value) + jj.x <- getX(x) + jj.pos <- getP(x) + jj.x[i,j] <- getX(value) # matrix or vector + jj.pos[i,j] <- getP(value) + return(newbrobmat(x=jj.x,positive=jj.pos)) + } ) + diff -Nru r-cran-brobdingnag-1.2-6/README.md r-cran-brobdingnag-1.2-7/README.md --- r-cran-brobdingnag-1.2-6/README.md 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/README.md 2022-02-01 20:52:48.000000000 +0000 @@ -0,0 +1,162 @@ +Very large numbers in R: the Brobdingnag package +================ + + + + + + + +# Overview + +The Brobdingnag package provides R-centric functionality for working +with very large numbers. It represents a number +![x](https://latex.codecogs.com/png.latex?x "x") as its logarithm +![\\log\\left\|x\\right\|](https://latex.codecogs.com/png.latex?%5Clog%5Cleft%7Cx%5Cright%7C "\log\left|x\right|") +together with a logical that indicates whether +![x](https://latex.codecogs.com/png.latex?x "x") is positive. The +vignette functions as a “hello world” for S4 methods. + +The package has functionality to represent Brobdingnagian matrices, and +complex numbers. + +# Installation + +You can install the released version of Brobdingnag from +[CRAN](https://CRAN.R-project.org) with: + +``` r +# install.packages("Brobdingnag") # uncomment this to use the package +library("Brobdingnag") +#> +#> Attaching package: 'Brobdingnag' +#> The following objects are masked from 'package:base': +#> +#> diag, max, min, prod, range, sum, t +``` + +The package is maintained on +[github](https://github.com/RobinHankin/Brobdingnag). + +# The `Brobdingnag` package in use + +Consider a googol, conventionally defined as +![10^{100}](https://latex.codecogs.com/png.latex?10%5E%7B100%7D "10^{100}"). +In standard arithmetic we may evaluate this as follows: + +``` r +10^100 +#> [1] 1e+100 +``` + +But a googolplex, +![10^{10^{100}}](https://latex.codecogs.com/png.latex?10%5E%7B10%5E%7B100%7D%7D "10^{10^{100}}"), +is beyond floating-point representation: + +``` r +10^(10^100) +#> [1] Inf +``` + +We may represent a googol straightforwardly using Brobdingnagian +arithmetic, specifically by working with `brob` objects. + +``` r +as.brob(10) +#> [1] +exp(2.3026) +googol <- as.brob(10)^100 +googol +#> [1] +exp(230.26) +10^googol +#> [1] +exp(2.3026e+100) +``` + +In the above, we coerce `10` to Brobdingnagian form (that is, an object +of class `brob`) using `as.brob()`. Most arithmetic methods work +transparently with Brobdingnagian numbers: + +``` r +googol +#> [1] +exp(230.26) +googol + googol +#> [1] +exp(230.95) +googol/10 +#> [1] +exp(227.96) +1/googol +#> [1] +exp(-230.26) +sqrt(googol) +#> [1] +exp(115.13) +exp(googol) +#> [1] +exp(1e+100) +``` + +Note that precision may be adversely affected for very large numbers: + +``` r +gplex <- 10^googol +gplex +#> [1] +exp(2.3026e+100) +gplex - gplex/10 +#> [1] -exp(-Inf) +``` + +The last line looks odd \[the return value is package idiom for zero\] +but symbolically we have +![10^{10^{100}}/10=10^{10^{100}-1}\\simeq 10^{10^{100}}](https://latex.codecogs.com/png.latex?10%5E%7B10%5E%7B100%7D%7D%2F10%3D10%5E%7B10%5E%7B100%7D-1%7D%5Csimeq%2010%5E%7B10%5E%7B100%7D%7D "10^{10^{100}}/10=10^{10^{100}-1}\simeq 10^{10^{100}}"). +The package is vectorised and allows Brobdingnagian arithmetic: + +``` r +googol/(1:20) +#> [1] +exp(230.26) +exp(229.57) +exp(229.16) +exp(228.87) +exp(228.65) +#> [6] +exp(228.47) +exp(228.31) +exp(228.18) +exp(228.06) +exp(227.96) +#> [11] +exp(227.86) +exp(227.77) +exp(227.69) +exp(227.62) +exp(227.55) +#> [16] +exp(227.49) +exp(227.43) +exp(227.37) +exp(227.31) +exp(227.26) +``` + +Signed quantities operate as expected: + +``` r +as.brob(5) - 1:10 +#> [1] +exp(1.3863) +exp(1.0986) +exp(0.69315) +exp(-2.2204e-16) +#> [5] -exp(-Inf) -exp(4.4409e-16) -exp(0.69315) -exp(1.0986) +#> [9] -exp(1.3863) -exp(1.6094) +``` + +It is a semi-nonobvious fact that, in addition to large numbers (that +is, +![x\\colon\\left\|x\\right\|\\gg 1](https://latex.codecogs.com/png.latex?x%5Ccolon%5Cleft%7Cx%5Cright%7C%5Cgg%201 "x\colon\left|x\right|\gg 1") +and small numbers +(![x\\colon\\left\|x\\right\|\\ll 1](https://latex.codecogs.com/png.latex?x%5Ccolon%5Cleft%7Cx%5Cright%7C%5Cll%201 "x\colon\left|x\right|\ll 1")), +the package can deal with numbers very close to 1 (that is, +![x\\colon\\left\|x-1\\right\|\\ll 1](https://latex.codecogs.com/png.latex?x%5Ccolon%5Cleft%7Cx-1%5Cright%7C%5Cll%201 "x\colon\left|x-1\right|\ll 1")). +Suppose we wish to deal with +![e^{10^{-100}}\\simeq 1+10^{-100}](https://latex.codecogs.com/png.latex?e%5E%7B10%5E%7B-100%7D%7D%5Csimeq%201%2B10%5E%7B-100%7D "e^{10^{-100}}\simeq 1+10^{-100}"). +In the package: + +``` r +a <- brob(1e-100) +a +#> [1] +exp(1e-100) +a^googol +#> [1] +exp(1) +``` + +The last line being numerical verification of the fact that +![\\left(1+10^{-100}\\right)^{10^{100}}\\simeq e=2.718+](https://latex.codecogs.com/png.latex?%5Cleft%281%2B10%5E%7B-100%7D%5Cright%29%5E%7B10%5E%7B100%7D%7D%5Csimeq%20e%3D2.718%2B "\left(1+10^{-100}\right)^{10^{100}}\simeq e=2.718+"). +The package also includes some functionality for Brobdingnagian +matrices: + +``` r +brobmat(1:9,3,3) +#> [,1] [,2] [,3] +#> [1,] +exp(1) +exp(4) +exp(7) +#> [2,] +exp(2) +exp(5) +exp(8) +#> [3,] +exp(3) +exp(6) +exp(9) +brobmat(1:9,3,3) %*% 10^brobmat(9:1,3,3) +#> [,1] [,2] [,3] +#> [1,] +exp(18659) +exp(929.93) +exp(47.249) +#> [2,] +exp(18660) +exp(930.93) +exp(48.249) +#> [3,] +exp(18661) +exp(931.93) +exp(49.249) +``` diff -Nru r-cran-brobdingnag-1.2-6/vignettes/Brobdingnag.Rnw r-cran-brobdingnag-1.2-7/vignettes/Brobdingnag.Rnw --- r-cran-brobdingnag-1.2-6/vignettes/Brobdingnag.Rnw 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/vignettes/Brobdingnag.Rnw 2022-02-02 21:07:16.000000000 +0000 @@ -0,0 +1,231 @@ +\documentclass[nojss]{jss} + +\usepackage{dsfont} +\usepackage{bbm} +\usepackage{amsfonts} +\usepackage{wasysym} + +\author{Robin K. S. Hankin\\Auckland University of Technology} +\title{Very large numbers in \proglang{R}: Introducing package \pkg{Brobdingnag}} +%\VignetteIndexEntry{The Brobdingnag: package} + +\Plainauthor{Robin K. S. Hankin} +\Plaintitle{Very large numbers in R: Introducing package Brobdingnag} +\Plaintitle{Introducing package Brobdingnag} + + +\Abstract{ + + This vignette shows how to use the \pkg{Brobdingnag} package to + manipulate very large numbers; it is based on~\cite{Rnews:Hankin:2007}. + + The other vignette shows how to use \proglang{S4} methods in the + context of a simple package. + } + +\Keywords{\proglang{S4} methods, Brobdingnag, \proglang{R}} +\Plainkeywords{S4 methods, Brobdingnag, R} + +\Address{ + Robin K. S. Hankin\\ + Auckland University of Technology + E-mail: \email{hankin.robin@gmail.com}\hfill\includegraphics[width=1in]{\Sexpr{system.file("help/figures/brobdingnag.png",package="Brobdingnag")}} +} + +%% need no \usepackage{Sweave.sty} +\SweaveOpts{echo=TRUE} +\begin{document} + +\newsymbol\leqslant 1336 + + +\hfill\includegraphics[width=1in]{\Sexpr{system.file("help/figures/brobdingnag.png",package="Brobdingnag")}} + +\section{Introduction} + +The largest floating point number representable in standard double +precision arithmetic is a little under~$2^{1024}$, or +about~$1.79\times 10^{308}$. This is too small for some applications. + +The \proglang{R} package \pkg{Brobdingnag}~\citep{swift1726} overcomes this limit +by representing a real number~$x$ using a double precision variable +with value~$\log\left|x\right|$, and a logical corresponding to~$x\geq +0$; the \proglang{S4} class of such objects is \code{brob}. Complex numbers with +large absolute values (class \code{glub}) may be represented using a +pair of \code{brob}s to represent the real and imaginary components. + +The package allows user-transparent access to the large numbers +allowed by Brobdingnagian arithmetic. The package also includes a +vignette---\code{brob}---which documents the \proglang{S4} methods used and +includes a step-by-step tutorial. The vignette also functions as a +``Hello, World!'' example of \proglang{S4} methods as used in a simple package. +It also includes a full description of the \code{glub} class. + +\section[Package ``Brobdingnag'' in use]{Package \pkg{Brobdingnag} in use} + +Most readers will be aware of a googol which is equal to~$10^{100}$: + +<>= +<>= +require(Brobdingnag) +<>= +googol <- as.brob(10)^100 +@ + +Note the coercion of \code{double} value \code{10} to an object of +class \code{brob} using function \code{as.brob()}: raising this to the +power~100 (also double) results in another \code{brob}. The result is +printed using exponential notation, which is convenient for very large +numbers. + +A googol is well within the capabilities of standard double precision +arithmetic. Now, however, suppose we wish to compute its factorial. +Taking the first term of Stirling's series gives + +<>= +stirling <- function(n){n^n*exp(-n)*sqrt(2*pi*n)} +@ + +\noindent which then yields + +<>= +stirling(googol) +@ + +Note the transparent coercion to \code{brob} form within function +\code{stirling()}. + +It is also possible to represent numbers very close to~1. Thus + +<>= +2^(1/googol) +@ + +It is worth noting that if~$x$ has an exact representation in double +precision, then~$e^x$ is exactly representable using the system +described here. Thus~$e$ and~$e^{1000}$ may be represented exactly. + +\subsection{Accuracy} + +For small numbers (that is, representable using standard double +precision floating point arithmetic), \pkg{Brobdingnag} suffers a +slight loss of precision compared to normal representation. Consider +the following function, whose return value for nonzero arguments is +algebraically zero: + +<>= +f <- function(x){as.numeric( (pi*x -3*x -(pi-3)*x)/x)} +@ + +\begin{verbatim} +f <- function(x){ + as.numeric( (pi*x -3*x -(pi-3)*x)/x) +} +\end{verbatim} + +This function combines multiplication and addition; one might expect a +logarithmic system such as described here to have difficulty with it. + + +<>= +f(1/7) +f(as.brob(1/7)) +@ + +This typical example shows that Brobdingnagian numbers suffer a slight +loss of precision for numbers of moderate magnitude. This degradation +increases with the magnitude of the argument: + +<>= +f(1e100) +f(as.brob(1e100)) +@ + +Here, the brobs' accuracy is about two orders of magnitude worse than +double precision arithmetic: this would be expected, as the number of +bits required to specify the exponent goes as $\log\log x$. + +Compare + + +<>= +f(as.brob(10)^1000) +@ + +\noindent showing a further degradation of precision. However, +observe that conventional double precision arithmetic cannot deal with +numbers this big, and the package returns about 12 correct significant +figures. + +\section{A practical example} + +In the field of population dynamics, and especially the modelling of +biodiversity~\citep{hankin2007b,hubbell2001}, complicated +combinatorial formulae often arise. + +\citet{etienne2005}, for example, considers a sample of~$N$ +individual organisms taken from some natural population; the sample +includes~$S$ distinct species, and each individual is assigned a label +in the range~$1$ to~$S$. The sample comprises~$n_i$ members of +species~$i$, with~$1\leq i\leq S$ and~$\sum n_i=N$. For a given +sample~$D$ Etienne defines, amongst other terms, $K(D,A)$ for $1\leq +A\leq N-S+1$ as + +\begin{equation} +\sum_{ +\left\{ +a_1,\ldots,a_S\left| +\sum_{i=1}^S a_i=A\right. +\right\}} +\prod_{i=1}^S +\frac{ +\overline{s}(n_i,a_i) +\overline{s}(a_i,1)}{ +\overline{s}(n_i,1)} +\end{equation} + +\noindent +where~$\overline{s}(n,a)$ is the Stirling number of the second +kind~\citep{abramowitz1965}. The summation is over~$a_i=1,\ldots,n_i$ +with the restriction that the~$a_i$ sum to~$A$, as carried out by +\code{blockparts()} of the \pkg{partitions} +package~\citep{hankin2006,hankin2007}. + +Taking an intermediate-sized dataset due to Saunders\footnote{The +dataset comprises species counts on kelp holdfasts; +here \code{saunders.exposed.tot} of package +\pkg{untb}~\citep{hankin2007b}, is used.} of only~5903 individuals---a +relatively small dataset in this context---the maximal element +of~$K(D,A)$ is about~$1.435\times 10^{1165}$. The accuracy of package +\pkg{Brobdingnag} in this context may be assessed by comparing it with +that computed by \proglang{PARI/GP}~\citep{batut2000} with a working precision +of~100 decimal places; the natural logs of the two values +are~$2682.8725605988689$ and~$2682.87256059887$ respectively: +identical to 14 significant figures. + + +%Pari with 100 decimal places gives 2682.872560598868918515209515642292607616628612201118344882119616522539674163937533805390351760715777. + +% 2682.8725605988689 +%and with R: 2682.87256059887 + + + + +\section{Conclusions} + +The \pkg{Brobdingnag} package allows representation and manipulation +of numbers larger than those covered by standard double precision +arithmetic, although accuracy is eroded for very large numbers. This +facility is useful in several contexts, including combinatorial +computations such as encountered in theoretical modelling of +biodiversity. + +\subsubsection*{Acknowledgments} +I would like to acknowledge the many stimulating and helpful comments +made by the \proglang{R}-help list over the years. + + +\bibliography{brob} + +\end{document} diff -Nru r-cran-brobdingnag-1.2-6/vignettes/brobmat.Rmd r-cran-brobdingnag-1.2-7/vignettes/brobmat.Rmd --- r-cran-brobdingnag-1.2-6/vignettes/brobmat.Rmd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/vignettes/brobmat.Rmd 2022-02-02 21:07:16.000000000 +0000 @@ -0,0 +1,151 @@ +--- +title: "Brobdingnagian matrices" +author: "Robin K. S. Hankin" +date: "`r Sys.Date()`" +vignette: > + %\VignetteIndexEntry{brobmat} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r set-options, echo = FALSE} +knitr::opts_chunk$set(collapse = TRUE, comment = "#>", dev = "png", fig.width = 7, fig.height = 3.5, message = FALSE, warning = FALSE) +options(width = 80, tibble.width = Inf) +``` + +# Brobdgingnagian matrices + +R package `Brobdingnag` has basic functionality for matrices. It +includes matrix multiplication and addition, but determinants and +matrix inverses are not implemented. First load the package: + +```{r} +library("Brobdingnag") +``` + +The standard way to create a Brobdgingnagian matrix (a `brobmat`) is +to use function `brobmat()` which takes arguments similar to +`matrix()` and returns a matrix of entries created with `brob()`: + +```{r} +M1 <- brobmat(-10:13,4,6) +colnames(M1) <- state.abb[1:6] +M1 +``` + +Function `brobmat()` takes an argument `positive` which specifies the sign: + +```{r} +M2 <- brobmat( +c(1,104,-66,45,1e40,-2e40,1e-200,232.2),2,4, +positive=c(T,F,T,T,T,F,T,T)) +M2 +``` + +Standard matrix arithmetic is implemented, thus: + +```{r} +rownames(M2) <- c("a","b") +colnames(M2) <- month.abb[1:4] +M2 +M2[2,3] <- 0 +M2 +M2+1000 +``` + +We can also do matrix multiplication, although it is slow: + + +```{r} +M2 %*% M1 +``` + + +## Numerical verification: matrix multiplication + +We will verify matrix multiplication by carrying out the same +operation in two different ways. First, create two largish +Brobdingnagian matrices: + +```{r} +nrows <- 11 +ncols <- 18 +M3 <- brobmat(rnorm(nrows*ncols),nrows,ncols,positive=sample(c(T,F),nrows*ncols,replace=T)) +M4 <- brobmat(rnorm(nrows*ncols),ncols,nrows,positive=sample(c(T,F),nrows*ncols,replace=T)) +M3[1:3,1:3] +``` + +Now calculate the matrix product by coercing to numeric matrices and +multiplying:q + + +```{r} +p1 <- as.matrix(M3) %*% as.matrix(M4) +``` + +and then by using Brobdingnagian matrix multiplying, and then coercing +to numeric: + +```{r} +p2 <- as.matrix(M3 %*% M4) +``` + +The difference: + +```{r} +max(abs(p1-p2)) +``` + +is small. Now the other way: + +```{r} +q1 <- M3 %*% M4 +q2 <- as.brobmat(as.matrix(M3) %*% as.matrix(M4)) +max(abs(as.brob(q1-q2))) +``` + + +## Numerical verification: integration with the `cubature` package + +The matrix functionality of the `Brobdingnag` package was originally +written to leverage the functionality of the `cubature` package. Here +I give some numerical verification for this. + +Suppose we wish to evaluate + +\[ +\int_{x=0}^{x=4}(x^2-4)\,dx +\] + +using numerical methods. See how the integrand includes positive and +negative values; the theoretical value is $\frac{16}{3}=5.33\ldots$. +The `cubature` idiom for this would be + +```{r,label = numericalintegration} +library("cubature") + +f.numeric <- function(x){x^2 - 4} + +out.num <- cubature::hcubature(f = f.numeric, lowerLimit = 0, upperLimit = 4, vectorInterface = TRUE) +out.num +``` + +and the Brobdingnagian equivalent would be + + +```{r,label = numericalintegrationbrob} + +f.brob <- function(x) { + x <- as.brob(x[1, ]) + as.matrix( brobmat(x^2 - 4, ncol = length(x))) +} + +out.brob <- cubature::hcubature(f = f.brob, lowerLimit = 0, upperLimit = 4, vectorInterface = TRUE) +out.brob +``` + +We may compare the two methods: + +```{r,label=comparebrobandnumeric} +out.brob$integral - out.num$integral +``` diff -Nru r-cran-brobdingnag-1.2-6/vignettes/brobpaper.Rnw r-cran-brobdingnag-1.2-7/vignettes/brobpaper.Rnw --- r-cran-brobdingnag-1.2-6/vignettes/brobpaper.Rnw 2018-08-06 21:27:39.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/vignettes/brobpaper.Rnw 1970-01-01 00:00:00.000000000 +0000 @@ -1,229 +0,0 @@ -\documentclass[nojss]{jss} - -\usepackage{dsfont} -\usepackage{bbm} -\usepackage{amsfonts} -\usepackage{wasysym} - -\author{Robin K. S. Hankin\\Auckland University of Technology} -\title{Very large numbers in \proglang{R}: Introducing package \pkg{Brobdingnag}} -%\VignetteIndexEntry{The Brobdingnag: package} - -\Plainauthor{Robin K. S. Hankin} -\Plaintitle{Very large numbers in R: Introducing package Brobdingnag} -\Plaintitle{Introducing package Brobdingnag} - - -\Abstract{ - - This vignette shows how to use the \pkg{Brobdingnag} package to - manipulate very large numbers; it is based on~\cite{Rnews:Hankin:2007}. - - The other vignette shows how to use \proglang{S4} methods in the - context of a simple package. - } - -\Keywords{\proglang{S4} methods, Brobdingnag, \proglang{R}} -\Plainkeywords{S4 methods, Brobdingnag, R} - -\Address{ - Robin K. S. Hankin\\ - Auckland University of Technology - E-mail: \email{hankin.robin@gmail.com} -} - -%% need no \usepackage{Sweave.sty} -\SweaveOpts{echo=TRUE} -\begin{document} - -\newsymbol\leqslant 1336 - - -\section{Introduction} - -The largest floating point number representable in standard double -precision arithmetic is a little under~$2^{1024}$, or -about~$1.79\times 10^{308}$. This is too small for some applications. - -The \proglang{R} package \pkg{Brobdingnag}~\citep{swift1726} overcomes this limit -by representing a real number~$x$ using a double precision variable -with value~$\log\left|x\right|$, and a logical corresponding to~$x\geq -0$; the \proglang{S4} class of such objects is \code{brob}. Complex numbers with -large absolute values (class \code{glub}) may be represented using a -pair of \code{brob}s to represent the real and imaginary components. - -The package allows user-transparent access to the large numbers -allowed by Brobdingnagian arithmetic. The package also includes a -vignette---\code{brob}---which documents the \proglang{S4} methods used and -includes a step-by-step tutorial. The vignette also functions as a -``Hello, World!'' example of \proglang{S4} methods as used in a simple package. -It also includes a full description of the \code{glub} class. - -\section[Package ``Brobdingnag'' in use]{Package \pkg{Brobdingnag} in use} - -Most readers will be aware of a googol which is equal to~$10^{100}$: - -<>= -<>= -require(Brobdingnag) -<>= -googol <- as.brob(10)^100 -@ - -Note the coercion of \code{double} value \code{10} to an object of -class \code{brob} using function \code{as.brob()}: raising this to the -power~100 (also double) results in another \code{brob}. The result is -printed using exponential notation, which is convenient for very large -numbers. - -A googol is well within the capabilities of standard double precision -arithmetic. Now, however, suppose we wish to compute its factorial. -Taking the first term of Stirling's series gives - -<>= -stirling <- function(n){n^n*exp(-n)*sqrt(2*pi*n)} -@ - -\noindent which then yields - -<>= -stirling(googol) -@ - -Note the transparent coercion to \code{brob} form within function -\code{stirling()}. - -It is also possible to represent numbers very close to~1. Thus - -<>= -2^(1/googol) -@ - -It is worth noting that if~$x$ has an exact representation in double -precision, then~$e^x$ is exactly representable using the system -described here. Thus~$e$ and~$e^{1000}$ may be represented exactly. - -\subsection{Accuracy} - -For small numbers (that is, representable using standard double -precision floating point arithmetic), \pkg{Brobdingnag} suffers a -slight loss of precision compared to normal representation. Consider -the following function, whose return value for nonzero arguments is -algebraically zero: - -<>= -f <- function(x){as.numeric( (pi*x -3*x -(pi-3)*x)/x)} -@ - -\begin{verbatim} -f <- function(x){ - as.numeric( (pi*x -3*x -(pi-3)*x)/x) -} -\end{verbatim} - -This function combines multiplication and addition; one might expect a -logarithmic system such as described here to have difficulty with it. - - -<>= -f(1/7) -f(as.brob(1/7)) -@ - -This typical example shows that Brobdingnagian numbers suffer a slight -loss of precision for numbers of moderate magnitude. This degradation -increases with the magnitude of the argument: - -<>= -f(1e100) -f(as.brob(1e100)) -@ - -Here, the brobs' accuracy is about two orders of magnitude worse than -double precision arithmetic: this would be expected, as the number of -bits required to specify the exponent goes as $\log\log x$. - -Compare - - -<>= -f(as.brob(10)^1000) -@ - -\noindent showing a further degradation of precision. However, -observe that conventional double precision arithmetic cannot deal with -numbers this big, and the package returns about 12 correct significant -figures. - -\section{A practical example} - -In the field of population dynamics, and especially the modelling of -biodiversity~\citep{hankin2007b,hubbell2001}, complicated -combinatorial formulae often arise. - -\citet{etienne2005}, for example, considers a sample of~$N$ -individual organisms taken from some natural population; the sample -includes~$S$ distinct species, and each individual is assigned a label -in the range~$1$ to~$S$. The sample comprises~$n_i$ members of -species~$i$, with~$1\leq i\leq S$ and~$\sum n_i=N$. For a given -sample~$D$ Etienne defines, amongst other terms, $K(D,A)$ for $1\leq -A\leq N-S+1$ as - -\begin{equation} -\sum_{ -\left\{ -a_1,\ldots,a_S\left| -\sum_{i=1}^S a_i=A\right. -\right\}} -\prod_{i=1}^S -\frac{ -\overline{s}(n_i,a_i) -\overline{s}(a_i,1)}{ -\overline{s}(n_i,1)} -\end{equation} - -\noindent -where~$\overline{s}(n,a)$ is the Stirling number of the second -kind~\citep{abramowitz1965}. The summation is over~$a_i=1,\ldots,n_i$ -with the restriction that the~$a_i$ sum to~$A$, as carried out by -\code{blockparts()} of the \pkg{partitions} -package~\citep{hankin2006,hankin2007}. - -Taking an intermediate-sized dataset due to Saunders\footnote{The -dataset comprises species counts on kelp holdfasts; -here \code{saunders.exposed.tot} of package -\pkg{untb}~\citep{hankin2007b}, is used.} of only~5903 individuals---a -relatively small dataset in this context---the maximal element -of~$K(D,A)$ is about~$1.435\times 10^{1165}$. The accuracy of package -\pkg{Brobdingnag} in this context may be assessed by comparing it with -that computed by \proglang{PARI/GP}~\citep{batut2000} with a working precision -of~100 decimal places; the natural logs of the two values -are~$2682.8725605988689$ and~$2682.87256059887$ respectively: -identical to 14 significant figures. - - -%Pari with 100 decimal places gives 2682.872560598868918515209515642292607616628612201118344882119616522539674163937533805390351760715777. - -% 2682.8725605988689 -%and with R: 2682.87256059887 - - - - -\section{Conclusions} - -The \pkg{Brobdingnag} package allows representation and manipulation -of numbers larger than those covered by standard double precision -arithmetic, although accuracy is eroded for very large numbers. This -facility is useful in several contexts, including combinatorial -computations such as encountered in theoretical modelling of -biodiversity. - -\subsubsection*{Acknowledgments} -I would like to acknowledge the many stimulating and helpful comments -made by the \proglang{R}-help list over the years. - - -\bibliography{brob} - -\end{document} diff -Nru r-cran-brobdingnag-1.2-6/vignettes/S4_brob.Rnw r-cran-brobdingnag-1.2-7/vignettes/S4_brob.Rnw --- r-cran-brobdingnag-1.2-6/vignettes/S4_brob.Rnw 2018-08-06 23:50:14.000000000 +0000 +++ r-cran-brobdingnag-1.2-7/vignettes/S4_brob.Rnw 2022-02-02 21:07:16.000000000 +0000 @@ -29,7 +29,7 @@ \Address{ Robin K. S. Hankin\\ Auckland University of Technology\\ - E-mail: \email{hankin.robin@gmail.com} + E-mail: \email{hankin.robin@gmail.com}\hfill\includegraphics[width=1in]{\Sexpr{system.file("help/figures/brobdingnag.png",package="Brobdingnag")}} } %% need no \usepackage{Sweave.sty} @@ -39,6 +39,8 @@ \newsymbol\leqslant 1336 +\hfill\includegraphics[width=1in]{\Sexpr{system.file("help/figures/brobdingnag.png",package="Brobdingnag")}} + \section{Introduction} This vignette proves that it is possible for a `normal' @@ -181,7 +183,7 @@ Now, an optional step is to define a function that tests whether the arguments passed to {\tt new()} are acceptable. As it stands, the following code: -<>= +<>= new("brob",x=1:10,positive=c(TRUE,FALSE,FALSE)) @