Author: George Gesslein II

# Mathomatic User Manual

## Introduction

Mathomatic is a symbolic math command line interpreter that can:

- combine and solve algebraic equations,
- completely simplify and compare expressions,
- perform calculus transformations,
- help with series analysis,
- perform standard, complex number, and polynomial arithmetic,
- generate efficient C, Java, or Python language code from equations,
- do quick calculations, etc.

Mathomatic development was started in 1986 and it was originally written in Microsoft C for MS-DOS and released as shareware. It was made a better product under the GNU/Linux operating system, using only the GCC C compiler. The C source code is highly portable and will compile and run correctly under any operating system.

## Requirements

Building from source requires a C compiler with the standard C libraries. If compiled with the GCC C compiler, no changes need to be made to the source code.

Mathomatic can be ported to any computer with at least 1 megabyte of free RAM, by changing some parameters in the C source file "am.h". The Mathomatic standard distribution (found on the Mathomatic home page) maximum memory usage defaults to 50 megabytes. Very little disk space is required.

## Startup

SYNOPSIS
  mathomatic [ options ] [ input_files ]

To start the Mathomatic interpreter, type "mathomatic" at the shell prompt. Mathomatic uses the GNU readline library to handle reading and editing line input and history. By default, the line editing commands are similar to the cursor movement commands used by GNU Emacs, and a vi-style line editing interface is also available.

Color mode is toggled by the "-c" option. ANSI color mode outputs ANSI escape sequences to make each level of parentheses a different color, to improve readability. Color mode is on by default. If the colors are too hard to see, try typing "set bold" at the Mathomatic prompt to increase the brightness. Set options can be made permanent, see the set command.

The other options are described in the man page. After any options, file names may be specified that will be read in with the read command.

It is recommended that the name "mathomatic" be shortened to "am" for quicker access. This can be done in the Bash shell by adding the following line to your "~/.bashrc" file:

    alias am=mathomatic

Then just typing "am" at the shell prompt will bring up Mathomatic. If color mode doesn't work right, use this instead:

    alias am="mathomatic -c"

to turn off color. "am" stands for algebraic manipulator.

## Equations and Expressions

Mathematical equations and expressions are entered into equation spaces. The number and size of available equation spaces is displayed every time Mathomatic starts up. When an expression grows larger than half the equation space size, processing stops and the "Expression too large" message is displayed, returning you to the main prompt.

The main prompt contains the number of the current equation space (origin 1).

To enter an equation or expression into the first available equation space, simply type it in at the main prompt. Equations consist of a Left Hand Side (LHS) and a Right Hand Side (RHS). The equation sides are separated by one, and only one, equal sign (=). An equation side consists of an algebraic mathematical expression, which is a mix of constants, variables, and operators, mostly in standard infix notation. Parentheses are used to override operator precedence and group things together. Valid parentheses characters are (), [], and {}.

Shown below is a valid equation with its parts labeled:

            equation
    -----------------------
    | variables   constant|
    |--------------     | |
    ||     |      |     | |
     a  =  b  -  (c  +  2)
    | |   |   |      |    |
    | |   |   --------    |
    | |   |   operators   |
    ---   -----------------
    LHS          RHS

In the above equation, the variable a is called the dependent variable because its value depends on the variables b and c. b and c are called independent variables. In Mathomatic, any variable can be made the dependent variable by simply typing the variable name in at the prompt. This will solve the equation for that variable and, if successful, make that variable the LHS.

Here is the above equation entered into Mathomatic and solved for b:

    Mathomatic version 12.7.3 (www.mathomatic.org)
    Copyright (C) 1987-2008 George Gesslein II.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    50 equation spaces available, 960 kilobytes per equation space.
    1—> a=b-(c+2)

    #1: a = b - c - 2

    1—> b

    #1: b = 2 + c + a

    1—>

### Constants

All constants are stored internally as IEEE 754 standard 64-bit (8 bytes) double precision floating point numbers. They may be entered in normal, scientific, or hexadecimal notation. They are displayed in decimal (up to 14 digits) in normal or scientific notation, whichever is shortest. Results exceeding 14 digits are always rounded to 14 digits and are usually accurate from 12 to 14 digits, due to accumulated round-off error.

Excepting constants with a name (like "inf" for the infinity constant), constants always start with a decimal digit (0..9) or a period. To enter a constant in hexadecimal, prepend it with "0x".

Examples of equivalent constants follow:

Normal Notation | Scientific Notation | Hexadecimal Notation
--- | --- | ---
10 | 1e1 (1.0 times 101) | 0xa
.125 | 1.25e-1 (1.25 times 10-1) | 0x.2
255 | 2.55e2 (2.55 times 102) | 0xff

- The largest value of a constant is ±1.7e+308.
- The smallest value of a constant is ±2.3e-308.

The infinity constant is entered by typing "inf". Positive and negative infinity are distinct and understood, however division by zero produces infinity, not ±infinity which would be more correct.

    1—> 1/0

     answer = inf

    1—> 0/0

     answer = nan

    1—>

"nan" stands for Not a Number and usually means an invalid floating point arithmetic result.

Fractions (such as 100/101) are preserved if the numerator and denominator are not large. Fractions are always presented in fully reduced form (for example, 6/9 is converted to 2/3). Constants which are exactly equal to a fraction are converted and displayed as fully reduced fractions (for example, 0.5 converts to 1/2). Mathomatic internally converts a fraction to a single floating point value, then converts it back to a fraction for display, after all floating point arithmetic has been done.

Irrational numbers, such as 2^(1/2), are preserved and simplified, if possible. This can be turned off with the command "set no preserve_roots", 2^(1/2) will then always be approximated as 1.4142135623731.

### Variables

Variables are what Mathomatic is all about. That is where the term "symbolic" comes from, because variables are symbolic in nature. They can represent known or unknown values, or any expression.

Variables consist of any combination of letters, digits, and underscores (_). They never start with a digit.

The following variables are predefined and are not normal variables:

    e or e# - the universal constant e (2.718281828...).
    pi or pi# - the universal constant pi (3.1415926...).
    i or i# - the imaginary number (square root of -1).
    sign, sign1, sign2, sign3, ... - may only be +1 or -1.
    integer - may be any integer.

By default, letters in variable names are case sensitive (see the "set case" option), meaning the alphabetic case of each letter in the variable name is important. For example, variables named "ABC" and "abc" represent two different variables, unless "set no case" is entered beforehand.

To automatically enter multiplication by a unique sign variable, precede any expression with "+/−".

### Operators

Operators have precedence decreasing as indicated:

    - negate                               (unary prefix operator)
    ! factorial (gamma function)           (unary postfix operator)
    ** or ^ power (exponentiation)         (binary infix operator)
    * multiply    / divide      % modulus  (binary infix operators)
    + add         - subtract               (binary infix operators)
    = equate                               (signifies equivalence)

Operators in the same precedence level are evaluated left to right.

All operators can be symbolically simplified by Mathomatic, except for factorial.

The negate operator (-) may precede any expression and has the highest precedence of all operators. This is different from many other math programs, where negate has been given the same precedence as times/divide. So in Mathomatic -2^x will give the expected -2 to the power of x, and not -1*(2^x), which are completely different.

The default operator for variables and constants is multiply (*). If a variable or constant is entered when an operator is expected, a multiply operator is automatically inserted.

The modulo operator a % b gives the remainder of the division a / b. Whether the result is always positive or has the same sign as the dividend depends on the "set true_modulus" option.

Factorials (x!) use the gamma function (gamma(x+1)), so that they work with any real number, not just the positive integers. Complex number gamma calculation is currently unavailable. On overflow, the factorial remains unevaluated:

    1—> 170!

     answer = 7.2574156153081e+306

    1—> 171!

     answer = 171!

    1—>

Standard absolute value notation is allowed, |x| is converted to (x^2)^.5. This doesn't always work as expected, but works enough to be useful.

The following example shows why operator precedence is important. Given the expression:

    64/-2^4 + 6*(3+1)

Mathomatic will parenthesize the highest precedence operators first (negate, then power, then times and divide). Addition and subtraction are the lowest precedence, so no need to parenthesize them. The result will be:

    (64/((-2)^4)) + (6*(3+1))

This is evaluated by combining constants from left to right on the same level of parentheses, deepest levels first. So the calculations are performed in the following order:

    (64/16) + (6*4)   Combine deepest level parentheses first.
    4 + 24            Divided 64 by 16 and then multiplied 6 by 4.
    28                Added 24 to 4.

If the calculations were performed in a different order, the result would be different.

### Complex Numbers

Mathomatic automatically performs complex number addition, subtraction, multiplication, and division. It will also approximate roots and powers of complex numbers.

Complex numbers are in the form:

    a + b*i#

where a is the real part and b is the imaginary part. i# represents the square root of -1 ("-1^.5" in Mathomatic notation), and may be entered into Mathomatic as "i", it will be displayed as "i#".

The imaginary number i# may appear anywhere within an expression, as many times as you want, Mathomatic will handle and simplify it properly.

As an example of imaginary numbers being produced, -2^.5 will be converted to (2^.5)*i#.

Roots of complex numbers, such as i#^.5, will be approximated, and only a single root will be produced, even though there may be many roots. This may produce inaccurate, unexpected, or even incorrect results, therefore a warning is displayed when this is done.

Conjugation of all complex numbers in the current equation is accomplished by typing the following command:

    replace i with -i

## Commands

Mathomatic has about 40 simple English commands that may be typed at the main prompt. Please consult the Mathomatic Command Reference, for detailed information on commands.

Copyright © 1987-2008 George Gesslein II

Mathomatic Home Page