

   SSyymmbboolliicc aanndd AAllggoorriitthhmmiicc DDeerriivvaattiivveess ooff SSiimmppllee EExxpprreessssiioonnss

        D(expr, namevec)
        deriv(expr, namevec, function.arg = NULL, tag = ".expr")

   AArrgguummeennttss::

       expr: expression which should be derivated

    namevec: character vector, giving the variable names with
             respect to which derivatives will be computed.

   function.arg: ... ?? ...

        tag: ... ?? ...

   DDeessccrriippttiioonn::

        `D' is modelled after its S pendant for taking simple
        symbolic derivatives.

        `deriv' is a generic function with a default and a
        `formula' method.  It returns a `call' for computing
        the `expr' and its (partial) derivatives, simultane-
        ously.  It uses so-called ``algorithmic derivatives''.

        Currently, `deriv.formula' just calls `deriv.default'
        after extracting the expression to the right of `~'.

   VVaalluuee::

        `D' returns an expression and therefore can easily be
        iterated for higher derivatives.

        `deriv' returns a `call' object which becomes an
        `expression' when evaluated once.  Evaluation of the
        latter expression returns the function values with a
        `".gradient"' attribute containing the gradient matrix.

   NNoottee::

        This help page should be fixed up by one of RR or some-
        one else who fluently speaks the language in
        `RHOME/src/main/deriv.c'.

        It's author, MM, has only got a vague idea and thinks
        that a help page is better than none.

   RReeffeerreenncceess::

        A. Griewank, G. F. Corliss (1991).  Automatic Differen-
        tiation of Algorithms: Theory, Implementation, and
        Application.  SIAM proceedings, Philadelphia.

   SSeeee AAllssoo::

        `nlm' for numeric minimization which should make use of
        derivatives.

   EExxaammpplleess::

        ## formula argument :
        dx2x <- deriv(~ x^2, "x") ; dx2x
        ##- expression({
        ##-         .value <- x^2
        ##-         .grad <- array(0, c(length(.value), 1), list(NULL, c("x")))
        ##-         .grad[, "x"] <- 2 * x
        ##-         attr(.value, "gradient") <- .grad
        ##-         .value
        ##- })
        mode(dx2x)
        e.dx2x <- eval(dx2x); mode(e.dx2x)
        x <- -1:2
        eval(e.dx2x)

        ## Something `tougher':
        trig.exp <- expression(sin(cos(x + y^2)))
        D(trig.exp, c("x", "y"))

        dxy <- deriv(trig.exp, c("x", "y"))
        dxy
        y <- 1
        eval(eval(dxy))

