Math: Math group generic functions in the 'vfunc' package: trig,...

MathR Documentation

Math group generic functions in the vfunc package: trig, exponential, log, etc.

Description

The S4 Math group contains 35 functions including sin(), log(), etc. The vfunc equivalents are capitalized, as in Sin(), Log(), etc.

Usage

Abs(x)
Sign(x)
Sqrt(x)
Ceiling(x)
Floor(x)
Trunc(x)
Cummax(x)
Cummin(x)
Cumprod(x)
Cumsum(x)
Log(x)
Log10(x)
Log2(x)
Log1p(x)
Acos(x)
Acosh(x)
Asin(x)
Asinh(x)
Atan(x)
Atanh(x)
Exp(x)
Expm1(x)
Cos(x)
Cosh(x)
Cospi(x)
Sin(x)
Sinh(x)
Sinpi(x)
Tan(x)
Tanh(x)
Tanpi(x)
Gamma(x)
Lgamma(x)
Digamma(x)
Trigamma(x)

Arguments

x

Generally take a single argument of class numeric, function, or vf

Details

The reason for this rather untransparent device is that primitive functions such as sin() behave somewhat differently from other functions. We have:

Sin <- as.vf(function(x){sin(x)})
setMethod("sin", "vf", function(x){as.vf(function(o){Sin(x(o))})})

We define Sin() to be an object of class vf; the call to setMethod() ensures that Sin(f) operates as intended.

Value

Given a numeric, return a numeric; given a vf, return a vf

Note

Note that “sin <- as.vf(sin)” does not work as desired, giving a runtime error; trying to get round this with things like “sin <- as.vf(function(x)sin)” and similar means that “sin(3)” does not work.

There is no way to inform all vf objects that, if used as a function with an argument of a primitive such as sin, to return another vf object—and not to try and evaluate “f(sin)”, which fails:

f <- as.vf(function(x){x^2 + 1})
f(Sin)
#> An object of class "vf"
#> function (...) 
#> {
#>     e1(...) + e2
#> }
#> <bytecode: 0x6065e7c8a900>
#> <environment: 0x6065e7c8a548>
f(sin)
#> Error in x^2: non-numeric argument to binary operator

Above, we see f(sin) returning an error (it tries to evaluate “sin^2 + 1”). Observe that “Sin^2 + 1” is perfectly OK, for Sin is a virtual function.

Author(s)

Robin K. S. Hankin

Examples


Sin + Exp

c((Sin + Exp)(.02232) ,sin(0.02232) +  exp(0.02232))

vfunc documentation built on Aug. 8, 2025, 6:20 p.m.