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.
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 page is a partial reference, read from the Derive 2 library files (28 different .MTH files, each found in five copies on this Mac) and nothing else.
| Item | Reference | Viewer |
|---|---|---|
| Expression grammar | Only the forms met in the library files are listed. The full grammar, operator precedence and the complete list of built-in functions are not given | Colours a fixed list of about 80 built-in function names. A built-in that is not on it is left plain, and nothing is checked for correct syntax |
| What Derive writes | Not checked against a running Derive: how Transfer Save spaces, brackets and wraps an expression, and whether it always writes 78 characters before the ~ | Reads the files as text only. It does not simplify, run or load the definitions |
| Text lines | That a line in double quotes is a text expression is inferred from the library files; escaping of a quote inside one is unknown | Colours a text line up to the next quote or the end of the line, and counts them |
| Later Derive versions | Files written by later versions (such as Derive 6 for Windows) were not examined and may differ | Takes any text that reads as Derive, so such a file shows as the same coloured text |
| Non-ASCII bytes | Only the single case of E9 in GRAPHICS.MTH was seen, and it is taken to be CP437 theta | Shows the byte as Windows-1252 (é), not as theta |
| Definition table | Not applicable | Finds a definition only when the line starts with name:= or name(parameters):=. Parameters containing brackets, and definitions that do not start a line, are not listed |
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