DIFFT(1) OpenBSD Reference Manual DIFFT(1)

NAME

difftsymbolic differentiator

SYNOPSIS

difft [-nv] [-d variables] [-f function] [-o order] [-x variables] [file]

DESCRIPTION

The difft utility computes the derivative f′ of a function f. By default, it reads a function from standard input and differentiates with respect to x. The derived function is printed as a standalone LaTeX file (see LaTeX Output for details).

The arguments to difft are as follows:

-d variables
Domain of function. Multiple comma-separated variables may be listed. The domain is used only when printing the function. If not supplied, defaults to the value of -x.
-f function
The name of the function. Should be entirely alphanumeric.
-n
Print out the reduced, formatted input function then exit.
-o order
Number of times to differentiate. In the case of multivariate differentiation (see -x), this specifies how many times the multivariate derivative is sequentially recomputed with respect to all variables. This is ignored if -n is specified.
-T output
Output mode: -Tlatex for LaTeX (see LaTeX Output), -Tc for C (see C Output), -Tmathml for MathML (see MathML Output), or -Tgnuplot for gnuplot (see Gnuplot Output).
-x variables
Derive with respect to variables. The function is partially differentiated with respect to each comma-separated variable may be listed (in order). The variable symbol e is reserved (Euler's number). Variables should have no spaces.
-v
Print out derivation and reduction rules as they're computed. See Derivative Rules and Reduction Rules. Some output modes ignore this flag.
file
An input file consisting of a function to derive.

The difft utility accepts a simple mathematical language for specifying functions. It accepts binary and unary relations along with several functions. A formal grammar for the language follows, with comments in parentheses:

exp    <- - exp        (negate) 
          sin exp      (sine) 
          cos exp      (cosine) 
          tan exp      (tangent) 
          arcsin exp   (inverse sine) 
          arccos exp   (inverse cosine) 
          arctan exp   (inverse tangent) 
          ln exp       (natural log) 
          erf exp      (error function) 
          integral exp exp exp exp (integral) 
          (binary)     (binary) 
          (exp)        (sub-expression) 
          value        (value) 
binary <- exp + exp    (sum) 
          exp - exp    (subtract) 
          exp * exp    (product) 
          exp / exp    (quotient) 
          exp ^ exp    (exponent) 
value  <- num 
          ident 
ident  <- [[:alpha:]][[:alnum:]]* 
num    <- [[:digit:]]*[.[[:digit:]]*]?[eE][[:digit:]]+

All white-space is discarded (including newlines).

The following mathematical functions are understood by difft:

arccos, arcsin, arctan, cos, sin, tan
Trigonometric functions defined in the usual way, accepting a single-variable domain.
erf
The Gauss error function.
ln
The natural logarithm accepting a single-variable domain.
integral
A definite integral. The first parameter is the minimum, the second is the maximum, the third is the integrated function, and the last is the integrated function domain.

The following Greek letters are recognised and as a single Greek symbol (in applicable output modes): alpha, theta, omicron, tau, beta, pi, upsilon, gamma, phi, delta, kappa, rho, epsilon, lambda, chi, mu, sigma, psi, zeta, nu, omega, eta, xi, Gamma, Delta, Theta, Pi, Phi, Lambda, Sigma, Psi, Xi, Upsilon, and Omega.

C Output

Print C output with -Tc. This prints an ANSI C89 function consisting of <math.h> functions over double-precision variables. Optional arguments provided to -Ooptions are as follows:
fragment
Emit only the function and not a full C source file.

The -v flag is ignored in this mode.

LaTeX Output

The output specified by -Tlatex is LaTeX. Output is formatted within an align environment. Optional arguments provided to -Ooptions are as follows:
fragment
Emit only the derived or normalised function, and not a full LaTeX document.

If -v is specified, The display is broken into three columns: the equation being differentiated (only printed on the first row of output), the current stage of differentiation, and the rule of reduction or differentiation. Possible reduction and differentiation rules are noted in Differentiation Rules and Reduction Rules. Differentiated sub-expressions are highlighted in red, while reductions are highlighted in blue. Differentiated sub-expressions are also parenthesised and noted with the Lagrange derivative mark.

If -v is not specified, the function is printed as an assignment on a single line of output.

Greek letters are formatted as the LaTeX Greek symbol corresponding to the input name.

MathML Output

The output for -Tmathml conforms to the MathML2 “presentation” specification. Optional arguments provided to -Ooptions are as follows:
style=style.css
The file style.css is used for an external style-sheet. This must be a valid absolute or relative URI. See example.style.css for available CSS1 classes.

Expressions are enclosed within a well-formed XHTML document body. Output is broken into rows consisting of a series of expressions.

Printing of expressions follows as specified in LaTeX Output.

Greek letters are formatted as the HTML Greek symbol corresponding to the input name.

Gnuplot Output

The output for -Tgnuplot may be passed directly into gnuplot(1) for printing. Optional arguments provided to -Ooptions are as follows:
output=file
Use file as the PNG file to create. This is ignored if fragment is specified.
fragment
Emit only the derived or normalised function, not a full Gnuplot document.

By default, the output is formatted as a standalone Gnuplot document creating a colour PNG file difft.png. One-variable functions use plot, while two-variable functions use splot.

The -v flag is ignored with Gnuplot output; only the fully derived (or initial, if -n is specified) equation is printed. Furthermore, if the function has more than two arguments, -Ofragment is implied.

Greek letter symbols are ignored and printed verbatim.

IMPLEMENTATION NOTES

In this section, I describe the rules and behaviour of difft in accepting equations to differentiate.

Differentiation Rules

The following differentiation rules are applied to all functions. Assume differentiable functions f and g with respect to x, and c as a constant value.

Reduction Rules

The following reduction rules are applied following each step of differentiation.

EXIT STATUS

The difft utility exits 0 on success, and >0 if an error occurs.

EXAMPLES

To differentiation the Gumbel distribution function as a DVI file (usually called texput.dvi):

echo "(e^-(e^-x))" | difft | latex

To produce an XHTML/MathML file with CSS stylesheet style.css of a differentiation with all rules:

echo "(e^-(e^-x))" | difft -v -Tmathml -Ostyle=style.css

SEE ALSO

gnuplot(1), latex(1)

AUTHORS

The difft utility was written by Kristaps Dzonsons, kristaps@bsd.lv.

CAVEATS

The difft utility can differentiate integrals, but cannot compute direct integrals given outputs -Tgnuplot or -Tc. In place of an integral operator, the string “???” is printed.
January 28, 2012 OpenBSD 5.0