Introduction
An .MTH file is a utility file for
Derive, the
computer algebra system for DOS made by Soft Warehouse of Honolulu. It is a plain text
file of definitions and expressions, such as the functions
ELLIPTIC_F and FIBONACCI, written in Derive’s own expression
syntax. Derive’s Transfer Load and Merge commands read one, and Transfer Save writes
one, so it is how a set of definitions is kept between sessions and handed to others.
Derive came with a library of them (VECTOR.MTH, ODE1.MTH,
BESSEL.MTH and about twenty more, each described in the
DERIVE.HLP help file), and users made their own. A file that sets out a
walk through some mathematics, to be played rather than loaded, uses the
.DMO extension instead.
Structure
A file is lines of ASCII text, each ending in a carriage return and line feed, and the
last line is followed by a single 1A byte (Ctrl-Z, the old DOS end-of-file
mark). All 34 different files found for this page end that way. There is no signature
and no header block.
"File ELLIPTIC.MTH, (c) 1990 by Soft Warehouse Inc."
ELLIPTIC_F(phi,m):=INT(1/SQRT(1-m*SIN(t_)^2),t_,0,phi)
ELLIPTIC_E(phi,m):=INT(SQRT(1-m*SIN(t_)^2),t_,0,phi)
ELLIPTIC.MTH, the Derive 2 library file for elliptic integralsLines
Each line holds one expression of one of three kinds, and a blank line separates it from the next (the library files have one after every expression).
| Kind | Looks like | Meaning |
|---|---|---|
| Text | "File MISC.MTH, copyright …" | A line in double quotes is a text expression, a note that is kept with the file. Most library files open with one naming the file and its copyright |
| Function definition | CATALAN(n):=COMB(2*n,n)/(n+1) | A name, its parameters in brackets, := and the body |
| Variable definition | mile:=5280*foot | A name, := and its value. The value may be missing: foot:= in ENGLISH.MTH leaves the base unit undefined |
| Expression | INT(SIN(5*x-pi/4),x) | Anything else: an expression to work with. MATHS.MTH and TFT.MTH hold only these, the saved steps of a working session |
Line continuation
A line that does not fit is broken after 78 characters of text, and a ~ is
put at the end of the physical line, which makes it 79 long. The next physical line
carries on from the next character, so the break can fall anywhere, even inside a name or
a number. To read the line, remove each ~ and its line break and join the
pieces. In the .MTH files on this Mac every physical line that ends in ~ is 76
to 79 characters long, and no line is longer than 79. (A .DMO
demo is not wrapped.)
CATALAN(n):=COMB(2*n,n)/(n+1)
FIBONACCI(n):=IF(n>=0 AND FLOOR(n)=n,ELEMENT(ITERATE([ELEMENT(v,2),ELEMENT(v,1~
)+ELEMENT(v,2)],v,[0,1],n),1),1/SQRT(5)*(((1+SQRT(5))/2)^n-((SQRT(5)-1)/2)^n*C~
OS(pi*n)))
MISC.MTH: the second definition is wrapped twice, and the second break falls inside COSExpression syntax in the files
Derive’s syntax is not specified on this page. These are the forms met in the library files.
- Function and variable names are letters, digits and underscores. Functions built into
Derive (
SIN,INT,VECTOR,ELEMENT,LIMand so on) are written in capitals in the library files. - The library files end the names of dummy variables in an underscore, such as
t_,k_andm_, so they do not clash with a name the user already has. This is a habit of the files, not a rule of the syntax. - Constants:
piandinfby name,#e(the base of natural logarithms) and#i(the imaginary unit) with a hash. A leading@and a number, as in@1inLIM2, stands for an arbitrary integer. - Operators:
+ - * / ^,=and the comparisons,ANDandOR,!for factorial,.for the dot product of vectors and matrices, and a back quote after a matrix for its transpose. Vectors and matrices are written in square brackets, a matrix being a vector of vectors:[[1,0],[0,1]]. - A line may carry bytes above 127:
GRAPHICS.MTHhas a parameter named with byteE9, the capital theta of the DOS character set (code page 437). The viewer shows it as the same byte in Windows-1252.
A worked example
The first 0x70 bytes of ELLIPTIC.MTH. The first line is a text expression,
then a blank line, then the start of the first definition. Every line break is
0D 0A.
00000000: 2246 696c 6520 454c 4c49 5054 4943 2e4d "File ELLIPTIC.M
00000010: 5448 2c20 2863 2920 3139 3930 2062 7920 TH, (c) 1990 by
00000020: 536f 6674 2057 6172 6568 6f75 7365 2049 Soft Warehouse I
00000030: 6e63 2e22 0d0a 0d0a 454c 4c49 5054 4943 nc."....ELLIPTIC
00000040: 5f46 2870 6869 2c6d 293a 3d49 4e54 2831 _F(phi,m):=INT(1
00000050: 2f53 5152 5428 312d 6d2a 5349 4e28 745f /SQRT(1-m*SIN(t_
00000060: 295e 3229 2c74 5f2c 302c 7068 6929 0d0a )^2),t_,0,phi)..
The last bytes of the file are 29 0d 0a 1a: the final bracket, the line
break and the Ctrl-Z.
In the file viewer
The viewer shows the text coloured: names the file defines, Derive’s built-in functions,
operators, constants, numbers and text lines each have their own colour, and a word
broken by a ~ is coloured as one word. The Overview tab lists every
definition in a table: its name, whether it is a function or a variable, its parameters,
its body (shortened) and its line; a click goes to that line. Only text that reads as
Derive is taken, so another format using the extension is left to the viewer that
knows it.
Later versions
Derive for Windows (Derive 5 and 6, last version 6.1, discontinued in 2007) still writes
.mth. Its online help (Derive 6.1 help, SaveAs and Save
pages, read 2026-11-18 through a copy at waluigibsod.github.io) says: expressions and the
Derive state variable settings are saved as ASCII text in an mth file, which any text editor can
read and change; long expressions are written over several lines with a tilde (~) as
the continuation character, as in the DOS files above; opening an mth file restores only the
mathematical expressions and their annotations; and the state variables go into the file only
when the Save State Variables box of Save As is ticked (they are always saved in a .dfw
worksheet). Derive 6.01 (March 2004) changed Derive to allow ASCII character 26, the Ctrl-Z
that ends the DOS files, inside an mth file. How the state variables are written in the text
is not shown in that help and no Derive 6 file was examined, so it is unverified here.
The .dfw worksheet of Derive for Windows holds all the worksheet objects:
expressions, plots, text and OLE objects. The help says they cannot be edited with a text
editor, and no layout of the file was found, so .dfw is not described and the
explorer does not read it.
Related files
- .DMO: a Derive demonstration, the same text syntax with ; comment lines.
DERIVE.HLP: Derive’s help file, which lists each utility file and the functions it defines.
Not described
This is a partial reference and a partial viewer, built from the Derive 2 library files (28 different .MTH files, each found in five copies on this Mac) and nothing else.
Known, not yet covered
- Reference: Derive’s full expression grammar, operator precedence and complete list of built-in functions. They are documented in the Derive user manual, which was not available here; only the forms met in the library files are listed, and
DERIVE.HLPnames the functions of each utility file. - Reference: files from later Derive versions, such as Derive 6 for Windows (the help’s statements about .mth are above under “Later versions”; the state-variable lines and the .dfw layout are unverified). The versions are published products and their files could be examined; they were not, and may differ.
- Reference and viewer: non-ASCII bytes. Code page 437, the DOS character set, is documented;
E9inGRAPHICS.MTHis its capital theta, but the viewer shows it as Windows-1252 (é) instead. - Viewer: loading, simplifying or running the definitions. The file is shown as coloured text only.
- Viewer: syntax checking, and built-in functions beyond a fixed list of about 80 names. Others are left plain and nothing is flagged as wrong.
- Viewer: definitions that do not start a line, or whose parameters contain brackets. The definitions table lists only lines that start with
name:=orname(parameters):=, and the rest are shown only in the text.
Unknown
- Reference: what Derive’s Transfer Save writes (spacing, brackets, wrapping, and whether it always breaks after 78 characters). No public description was found, and it was not checked against a running Derive.
- Reference: quoted text lines. That they are text expressions is inferred from the library files, and the escaping of a quote inside one is not documented anywhere found.
Links
Software
- Derive – the computer algebra system that reads and writes these files (DOS, later Windows)
- Any text editor – the files are plain ASCII text with DOS line endings
Reference
- Derive (computer algebra system) – Wikipedia’s account of the program and its history