| NEWS | R Documentation |
News for Package mathr
Version 0.1.5 (2026-10-10)
0.1.4 was tagged but never sent to CRAN. Its changes, listed below, reach CRAN with this release.
The check that 0.1.4 put in front of the functions that work a value at a time missed some arguments:
pinQf,TolinVMmin,Plotinmlr,addinellipse,GradTol,StepTol,FnTolandItnLimitinOptim0, andninRnorm, and so inRmvn, which hands it toRnorm. Given a vector, each still stopped with one of R's own errors. Every argument that drives anifor awhileis now checked, andninRmvnbesides: 142 argument positions across 70 functions, among themnintrapez1andNinromb, which gained anifwith the fixes below. The help pages of the nine functions name the arguments added. SincePlot,add,DoubleinDec2BinandDecFlaginLOGare TRUE or FALSE, the error, and their help pages, now ask for "a single value" rather than "a single number".At a size of one, several functions failed.
runifLC()at its defaultn = 1,SymInv,LDLTandevJacobion a 1 x 1 matrix, andrombwithN = 1stopped with an error;trapez0on a single point returned NA;trapez1withn = 1returned three times the trapezoidal value, andNashSVDon a one-column matrix returned 0 as its singular value. In most, a2:nor1:(n-1)that should be empty at n = 1 counted down instead (intrapez1it added both end points a second time);NashSVDhas no pair of columns to rotate then, and so never set the singular value. Each now handles the case, asGradandDeriv2already did, and therombpage no longer asks for N above 2.At n = 0,
Rnormreturned FALSE, andRgamma,Rgamma0andRbetareturned one deviate for most shapes, wherernorm(0)givesnumeric(0). They all givenumeric(0)now.SQRT(Inf)never returned: it handed Inf toNORM, whose halving loop cannot end on Inf, andNORMlooped forever on a negative x as well.SQRT(Inf)is now Inf, with the warningEXPandLOGgive;NORMstops with a message on a non-finite x and gives a negative fraction for a negative x.evJacobistopped with "object 's' not found" on some symmetric matrices,diag(c(2, 1))among them: a test on the rotation sine ran on a pair that needed no rotation, before any sine had been set. The test now runs only when a rotation is made.VMminnever returned when its search direction right after resetting the Hessian estimate was not downhill, as at a starting point where the gradient is zero: a misspeltSmallXCountkept its loop alive.Optim0stopped with "object 'RelStep' not found" whenever it ended on its first iteration;RelStepandDelFare NA then.MachEps3andMachEps4withMaxIter = 0stopped with "object 'CurEps' not found"; they return their first trial value, 0.5 and -0.5, with iteration 0.Dec2Bin(0)took the logarithm of 0 and returned NaN bits; it returns all zeros, the pattern of +0, and for -0 the same with the sign bit set.Run.testreturned a p-value of 2 when no nonzero value was left; it returns NA.Given NA,
EXP,LOGandSQRTstopped with R's "missing value where TRUE/FALSE needed", andSQRTdid the same for NaN. They now return NA for NA, asexp,logandsqrtdo, andSQRTreturns NaN for NaN with the warningEXPandLOGalready give.mlrno longer callsanyNA, which first appeared in R 3.1.0, above the R (>= 3.0.0) that DESCRIPTION declares.Source comments that described methods the code does not use are corrected.
erfccheb,betaiapproxandgammpapproxforward toerfc,betaiandgammporgammq;erfcgoes throughgammq, not a Cephes rational approximation; and what theEXPguards keep from overflowing isg*P(y)andQ(y), noty = g*g.The Ref line on the
betacf,betai,erf,erfc,gammln,gammp,gammq,gcf,gser,inverfc,invbetaiandinvgammphelp pages lacked a full stop and ran into the sentence after it.GAMMAandLGAMMAhold the Lanczos coefficients the GNU Scientific Library uses, which only thegammlnpage said; their own pages now say it too.gammpapproxandbetaiapproxare no longer titled as quadrature approximations, which in this package they never were.The 0.1.4 entries below are corrected where they were wrong. The
EXPerror figures were relative errors in units of.Machine$double.eps, not ulp, and the shortcut was taken on every call whose result is finite and nonzero, not on every call. The oldEXPalso returned Inf atlog(.Machine$double.xmax)itself. Its NaN began near 2e78 rather than 1e78, came back instead of 0 for very large negative arguments as well, and was nearly but not quite total past 1e82. The overflow warning below0.9 * .Machine$double.xmaxis new in 0.1.4, not kept from before, and the 0.1.4 argument check did not reach every argument it said it did. Smaller corrections fix the list of bare titles and, under 0.1.0, which functions carry an attribution.
Version 0.1.4 (2026-09-20)
EXPwas not running its own algorithm. The range reduction leftxexp = x/ln2unrounded, so the reduced argumentgnever grew past about 1e-13, theabs(g) < sqrt(eps)shortcut was taken on every call whose result is finite and nonzero, and the rational approximation under it was dead code there. What came back was2^(x/ln2)and nothing else, up to 223 eps off in relative terms (about 444 ulp) at the ends of the range, and Inf atlog(.Machine$double.xmax)itself, wherex/ln2rounds to 1024.xexpis now rounded to the nearest integer, which is what putsgin the intervalabs(g) <= ln2/2the coefficients were fitted on. The shortcut is gone with it: oncegcan be nonzero, takingexp(g)as 1 throws away eight digits, and the rational form is exact atg = 0anyway. The final scaling is done in two halves, because2^xexpon its own overflows to Inf, and underflows to 0, at exponents where the result is still a finite nonzero number. Worst relative error over the whole range is now about 1.5 eps rather than 223, about 2 ulp.EXPreturned NaN instead of Inf for very large arguments, and NaN instead of 0 for very large negative ones, from about 2e78 in magnitude and for nearly every argument past about 1e82. The overflow guard sat at0.9 * .Machine$double.xmax, which is nowhere near where exp overflows, so such an argument reached a range reduction that could not reduce it:ggrew with x until the numerator and the denominator of the rational form both overflowed, and their quotient was NaN. The guard is now atlog(.Machine$double.xmax)going up and at-1075*ln2going down, the latter being where exp falls under half the least subnormal. Overflow now warns and returns Inf for every argument past the upper limit, where it used to warn only past0.9 * .Machine$double.xmax; underflow returns 0 quietly. Both limits agree withexpto the last double.EXP(-Inf)returned-Inf. The branch for it had been the+Infbranch with the sign flipped, so it handed the argument back instead of the limit. It returns 0, which is whatexpdoes.Given a vector, the functions here that work a value at a time failed with "the condition has length > 1", the message R raises for an
ifwhose condition is not a single value. It names neither the function nor the reason. 130 argument positions across 64 functions,EXP,LOG,SQRTand the distribution functions among them, are now checked up front, and the error names the function and the argument and points atsapply. Arguments that do accept a vector and return the right answer for one, such asmuinQnormorxinDnorm, are untouched. Each of the 64 help pages now names the arguments its own function constrains, so the ones that are scalar throughout and the ones that merely have a scalar control argument, such asstandardizeinmlr, can be told apart without reading the source.The
CholandLDLTexamples lost their last line in the rendered help page. A percent sign starts a comment in Rd, soL %*% t(L)was cut back toL. Both are now escaped and the round trip back to M shows.Help page titles:
invbetaiwas titled as the inverse of gammp,NORM,DENORMandellipRangecarried their bare names, and seven pairs of pages shared one title (convandconv0,deconvanddeconv0,gammpandgammq,trapez0andtrapez1,Run.testandrun.p,PbinomandPpois,QnormandQlnorm). Each title now says what its page is about.LOG,EXPandSQRTsay that current CPUs provide them at the instruction level, so the R versions are there to be read. DESCRIPTION says the same of the package as a whole: it is best studied with its source open.Help pages brought back in line with the code.
erfanderfccallgammpandgammq, noterfccheb;gammpandgammqcallgserorgcf;betaicallsbetacfandgammln;inverfcgoes through the normal quantile;GetPreturnssolve(H, g); the attribute set byMachEps3andMachEps4is "iteration"; themlrcolumns are R-Student, COV-Ratio and DFFITS;NORMreturns c(f, n);NashSVDtakes any real matrix;GAMMAreturns Inf at zero as well as at the negative integers; therunifLCrecurrence adds k.Distribution parameters are named for what they are: mean and standard deviation for the normal and log-normal, location and scale for t, degrees of freedom for chi-square and F, rate for the gamma density, distribution and quantile functions, scale for
RgammaandRgamma0, mean lambda for Poisson and rate alpha forRexp.Spelling and wording fixed across the help pages, among them Decomposition, Meticulous, Numerical, commutative, array, lengths, chi-square and distribution, together with argument names and function names left over from copied pages.
Version 0.1.3 (2026-08-31)
Every help page now carries a runnable example. Where a base R equivalent exists the example shows both, so the agreement can be seen at a glance.
Rbetawas wrong for every case except Beta(1, 1). It built the two gamma deviates with the shape and the scale arguments the other way round, so Rbeta(n, 2, 5) had mean 0.65 where the distribution has 2/7 = 0.286.Rgammadivided by bet in its alph == 1 branch where the other two branches multiply, so that one shape came out with mean 1/bet instead of bet.Rgamma0never scaled the accepted deviate by alph, so every shape returned the same Exp(1) times bet: mean 1 rather than 3 for Rgamma0(n, 3, 1). It also now requires alph >= 1, which is the range its rejection step is valid over. UseRgammabelow that.simps13had the Simpson weights 4 and 2 on the wrong points, which left it converging to the wrong value: 21.099 against a true 21.337 even at n = 60. It is now accurate to 1e-12 there.Both Simpson rules failed at their smallest legal n, 2 and 3, on a seq() with the wrong sign of step.
The
simps38example asked for n = 10, which is not a multiple of 3, so the help page showed NULL.The
deconv0example divided by a spectrum containing a zero and printed Inf and NaN.The
erfcchebtitle no longer claims a Chebyshev approximation, which it stopped using in 0.1.0.
Version 0.1.2 (2026-08-31)
ChkFxleftshow.error.messageholding a list instead of restoring it.options()returns the previous settings as a list, and that list was being passed back as the value. The restore now passes the list whole and runs fromon.exit, so early returns are covered too.mlr(Plot = TRUE)no longer opens a device of its own and no longer leavespar()changed. It draws on the current device and restores the previous settings on exit.Diagnostics in
mlranddeconvgo throughmessage()rather thancat(), so they can be suppressed and do not write to stdout.The
ellipseexamples no longer calldev.new().Packaging for CRAN:
Authors@Rreplaces the free text author fields, the obsoleteLazyLoadfield is gone, and the reference manual is no longer shipped under inst/doc, since CRAN builds its own and the copy was 86 percent of the tarball.
Version 0.1.1 (2026-08-31)
QpoisandQbinomnow follow the quantile convention of base R, the smallest k whose cumulative probability reaches p. They previously returned the largest k whose cumulative probability did not exceed p, one belowstats::qpoisandstats::qbinomfor every p. The two now agree exactly over a wide parameter grid; see tests/.Qbinom(p, n, pe)returns n for p = 1, and both functions compare against a tolerance sized to the accuracy ofPpoisandPbinom, about 1e-12. Feeding a cumulative probability straight back in as p can still land on the other side of a tie, because those two are built from the incomplete gamma and beta rather than the saddle point algorithms base R uses.
Version 0.1.0 (2026-08-31)
First release.
Calculus, distribution functions, random variate generation, linear algebra, differential equations and optimization, sized for one semester.
The special functions follow freely licensed reference implementations, each attributed in its own help page, and the distribution and quantile functions are built on them.
gammlnuses the Lanczos g=7 coefficients of the GNU Scientific Library.gser,gcf,gammpandgammqfollow the Cephes series and continued fraction as redistributed in ALGLIB.betacfandbetaifollow the continued fraction and symmetry transform of the GNU Scientific Library.inverfcuses the Cephes normal quantile ndtri.erfanderfccome from the incomplete gamma function through erf(x) = P(1/2, x^2) and erfc(x) = Q(1/2, x^2). That needs no coefficient table of its own and stays accurate far into the tail: erfc holds to 1e-13 relative down to erfc(26) = 5.7e-296, where a rational fit in x alone has long since lost its significant digits.invgammpandinvbetaiare bracketed Newton iterations on the forward functions, following the strategy of gsl_cdf_gamma_Pinv and gsl_cdf_beta_Pinv. Above the median the residual is formed in the upper tail, which avoids the loss of about eight digits that a lower-tail residual suffers for p near 1.gammpapprox,betaiapproxanderfcchebare thin wrappers overgammp,betaianderfc.Every distribution function is checked against the base R equivalent over a wide parameter grid. See tests/.