# Mathomatic User's Manual

### Table of Contents

1. Introduction
2. History
3. Developer Information
4. Startup
5. Equations and Expressions
   1. Constants
   2. Variables
   3. Operators
      1. Order of Operations example
   4. Complex Numbers
6. Commands
7. Documentation License

Mathomatic Command Reference
Unix/Linux man page for Mathomatic

## Introduction

Mathomatic is an easy to use and colorful algebra calculator that can symbolically:

- combine and solve equations containing many variables,
- completely simplify and compare mathematical expressions and equations,
- do simple calculus transformations and series,
- perform quick real number, imaginary number, and polynomial arithmetic and GCD computations,
- generate efficient C, Java, or Python language code from simplified equations,
- plot expressions with Gnuplot in two or three dimensions,
- … and much more.

The name "Mathomatic" is a portmanteau of "math" and "automatic". It is a unique computer algebra system (CAS), in that all constants are one or more floating point values. All numeric arithmetic is IEEE standard floating point arithmetic, which most computers do very quickly. Mathomatic is written entirely in C, which is like a CAS written in assembly language, running as fast as the computer allows without any high-level language overhead.

Mathomatic is exceptionally good at solving, differentiating, simplifying, and calculating elementary algebra. It is designed with a simple command-line interface (CLI) that tries to be helpful. All input and output is line at a time ASCII text. By default, input is standard input and output is standard output.

## History

Mathomatic development started in the year 1986, originally using the Microsoft C compiler for MS-DOS. Versions 1 and 2 were published by Dynacomp of Rochester, New York in 1987 and 1988 as a scientific software product for DOS. Afterwards it was released as shareware and emailware with a 2D equation graphing program written in Microsoft C for DOS. At the turn of the century, Mathomatic was ported to the GNU C Compiler (GCC) under Linux and became free and open source software by publishing under the GNU Lesser General Public License. The graphing program was discontinued; 2D/3D graphing of equations is now accomplished with Gnuplot.

Mathomatic is currently developed and maintained on a Ubuntu Linux x86-64-bit computer.

## Developer Information

Building Mathomatic from source requires a C compiler with the standard C libraries. If compiled with the GCC C compiler for a Unix-like operating system, no changes need to be made to the source code. See the file README.txt for compilation instructions.

Mathomatic can easily be ported to any computer with at least 1 megabyte of free RAM. In the standard distribution, found on the Mathomatic home page, the maximum memory usage defaults to 400 megabytes (the version command tells this). Maximum memory usage is not reached unless all equation spaces are filled. The default maximum memory usage should be less than the amount of free RAM, and is adjusted by changing the `DEFAULT_N_TOKENS` define in the C include file am.h and recompiling. Memory usage can also be adjusted at startup with the -m option.

The Mathomatic source code can also be compiled as a symbolic math library that is callable from any C compatible program. See the file lib/README.txt for more developer information and how to include Mathomatic in your program.

Very little disk space (a few megabytes) is required to compile, install, and run the Mathomatic application. A readline library must be installed to use readline, which allows editing and history recall of all Mathomatic line input by pressing the arrow keys.

## Startup

SYNOPSIS
  mathomatic [ options ] [ input_files or input ]
  rmath [ input_files ]

To start the compiled, interactive Mathomatic application, run a terminal emulator which opens a shell window, and type "mathomatic" at the shell prompt (without double quotes). If m4 (macro) Mathomatic was installed, you may type "rmath" instead, to use Mathomatic with input of functions like `sin(x)` and `sqrt(x)` allowed and automatically expanded to equivalent algebraic expressions. Logarithm function input is currently not available, because the logarithm function has not yet been implemented in the Mathomatic symbolic math engine.

Color mode is toggled by the -c option on the shell command line, like this:

    $ mathomatic -c

ANSI color mode outputs ANSI terminal escape sequences to make each level of parentheses a different color, improving readability. If ANSI color mode is on, an ANSI compatible terminal emulator is required. If the colors are hard to see, use the -b option (bold colors) instead, to enable color mode and increase the brightness.

The other options are described in the Unix/Linux man page for Mathomatic. After any options, text files may be specified on the shell command line that will be automatically read in with the read command, unless the -e option is specified, in which case mathematical expressions and Mathomatic commands are expected, separated by unquoted space characters.

It is recommended that the name mathomatic be shortened to am and e for quicker and easier access from the shell command line. This can be done in the Bash shell by adding the following two lines to your ~/.bashrc file:

    alias am=mathomatic
    alias e="mathomatic -e --"

Then just typing "am" at the shell prompt will run Mathomatic as an interactive application. Typing "e" followed by a quoted mathematical expression at the shell prompt will quickly and silently bring up Mathomatic and calculate and display the result. "am" stands for "algebraic manipulator", and "e" stands for "evaluate".

## Equations and Expressions

Mathematical equations and expressions are entered into equation spaces by typing, pasting, or reading them in. The maximum 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.

Each equation space is successively numbered with an equation number (starting at 1). The main prompt "`1—>` " contains the equation number of the current equation space. The current equation can be changed by typing a valid equation number at the main prompt, or by entering another equation or expression, which becomes the current equation.

To enter an equation into the first available equation space and make it the current equation, simply type it in at the main prompt. Each equation space consists of two equation sides, called the Left-Hand Side (LHS) and the Right-Hand Side (RHS), separated by an equals sign (=). Each equation side consists of a 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 {}.

Note that the equals sign does not make an assignment to any variables, it only signifies equality (sameness) between the results of evaluating the LHS and RHS. Shown here 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 independent variables b and c. In Mathomatic, any variable can be made the dependent variable by simply typing the variable name in at the prompt. This will solve the current equation for that variable and, if successful, make that variable the LHS.

Here is the above equation entered into Mathomatic and solved for b, then calculated for the values a=1 and c=1:

    1—> a=b-(c+2)

    #1: a = b − c − 2

    1—> b

    #1: b = 2 + c + a

    1—> calculate
    Enter a: 1
    Enter c: 1

     b = 4

    1—>

The "`#1:`" listed in front of each displayed equation always indicates the equation space number it is stored in.

Mathomatic automatically does both symbolic and numeric mathematics computations during any manipulations. This means that it can handle algebraic formulas, as well as numbers. What follows is an example of the result of both types of computations working together during equation simplification and solving:

    1—> 3*(x-1) + 1 = 2x + 1

    #1: (3·(x − 1)) + 1 = (2·x) + 1

    1—> simplify

    #1: (3·x) − 2 = (2·x) + 1

    1—> solve verify x

    #1: x = 3

    Solution verified.
    1—>

The "solve verify" command, used above, solves the current equation and then verifies the result by plugging the result into the original equation and simplifying. If an identity results (the LHS is identical to the RHS), a "Solution verified" message is displayed, otherwise "Solution might be incorrect" is displayed.

Non-equations, that is any mathematical expression without an equals sign, may be entered into equation spaces too. However, if the expression entered at the main prompt contains no variables, it will only be calculated and displayed without storing, unless the autocalc or auto option is turned off. Non-equations cannot be solved.

### Constants

In Mathomatic, numeric arithmetic is double precision floating point with about 14 decimal digits accuracy. Many results will be exact, because multiple floating point numbers can be combined for a single mathematical value; for example: 2^(1/3), which is the cubed root of 2 exactly.

Constants are approximated real numbers stored internally as IEEE 754 standard 64-bit (8 bytes) double precision floating point values. They may be entered as decimal (base 10) numbers in normal notation or in scientific notation (also called exponential notation). Constants may also be entered in hexadecimal (base 16) by prepending them with "0x".

Constants are displayed in decimal (base 10, rounded to 14 digits) using either normal or scientific notation, whichever is shortest. Results are usually accurate from 12 to 14 digits, due to accumulated round-off error, because all constants are stored internally as double precision (rounded to 15 decimal digits) floats. And the amount of round-off error is not tracked, making Mathomatic unsuitable for applications requiring high precision, like astronomical calculations.

Excepting constants with a name (like "inf" for the infinity constant), constants always start with a decimal digit (0..9) or a period.

Examples of equivalent constants follow:

Normal Notation (base 10) | Scientific Notation (base 10) | Hexadecimal Notation (base 16)
--- | --- | ---
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 exact syntax to enter constants as above may be found by looking up the C library function `strtod(3)`. In the Unix shell, `"man strtod"` will do that.

- The largest valid constant is ±1.797693e+308 (slightly less than 2^1024).
- The smallest valid constant is ±2.225074e-308 or 0.

The infinity constant is entered by typing "inf". Positive and negative infinity are distinct and understood, however division by zero produces one infinity value, not the two-valued ±infinity which would be more correct. Also, floating point overflow produces either positive or negative infinity.

    1—> 1/0
    Warning: Division by zero.

     answer = inf

    1—> 0/0
    Warning: Division by zero.

     answer = nan

    1—>

nan or NaN stands for Not a Number and it means an invalid or indeterminate floating point arithmetic result. NaN cannot be directly entered into Mathomatic. The appearance of NaN in an expression means the expression is unusable.

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 the irreducible fraction 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 may convert it back to a fraction for display after all floating point arithmetic has been done, if the result is equal to a fraction.

Irrational numbers, such as the square root of two (2^(1/2)) and pi, are preserved and simplified for exactness, unless explicitly approximated.

Denominators of fractions are usually rationalized in Mathomatic; for example, 1/(2^(1/2)) becomes the equivalent (2^(1/2))/2 upon simplification. This can be turned off with the command "set no rationalize_denominators".

### Variables

Variables are what Mathomatic is all about. That is where the term "symbolic" comes from, because variables are symbolic in nature. They are symbols that can represent known or unknown values, or any expression. Variables need not be defined in Mathomatic, just entering the variable name is enough.

Variable names consist of any combination of letters (a..z), digits (0..9), and underscores (_). They never start with a digit. By using the "set special_variable_characters" command, you can add to the allowed variable name characters. By default, letters in variable names are case sensitive, meaning the alphabetic case of each letter in the variable name is important. For example, variables named "A1" and "a1" represent two different variables, unless "set no case_sensitive" is entered beforehand.

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 unit (square root of -1)
sign, sign1, sign2, … - may only be +1 or -1
integer, integer1, … - may be any integer value

The above can be used anywhere variables are required.

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

### Operators

Mathomatic implements the standard rules of algebra for addition (+), subtraction (−), multiplication (*), division (/), modulo division (%), and all forms of exponentiation (^ or **). An example of a rule of algebra is 2*x + 3*x being simplified to 5*x.

All available operators are at least numerically capable and have precedence decreasing as indicated:

    ! factorial (gamma function)
    ** or ^ power (exponentiation)
    * multiply      / divide        % modulus       // integral divide
    + add           − subtract
    = equate (lowest precedence)

Higher precedence operators are grouped (or evaluated) first, then multiple operators of the same precedence level are grouped left to right. This is called the "order of operations".

The default operator is multiply (*). If an expression (operand) is entered when an operator is expected, a multiply operator is automatically inserted. For example, entering 2x, 2(x), and (2)(x) all result in the expression 2*x.

The modulo operator a % b (spoken as "a modulo b") gives the remainder of the division a / b. The sign of the result depends on the "set modulus_mode" option. Using "integer" variables allows further simplification here. An integer variable is specified by using a variable name that starts with "integer", like "integer1", "integer_x", etc.

The integral divide operator a // b divides a by b and then truncates by zeroing the fractional part to make the result an integer. For example, 8 // 3 results in 2, which is useful when doing integer arithmetic.

Factorials x! use the gamma function gamma(x+1), so that the factorial operator works with any real number, not just the positive integers.

Currently no rules of algebra are implemented for the integral divide operator (//) and factorials (!), and these two operators will not evaluate if an operand is a complex number.

Absolute value notation is allowed, |x| is converted to (x^2)^.5. This is not the same as standard absolute value where the real and imaginary parts of complex numbers are separated and then squared, but it works the same when given real number values with no imaginary units. The absolute value operation |x| results in a positive value for any x value; that is, if -1 is a factor, it is removed.

#### Order of Operations example

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

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

Mathomatic will parenthesize the highest precedence operators first (negate, then power, then times and divide; from left to right, but that doesn't matter in this case). 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 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, division, and exponentiation. It can also approximate roots of real and complex numbers, giving a single result; when multiple results are possible, the first real number result is chosen.

Complex numbers are in the form:

    a + b*i#

where a is the real part (a real number) and b is the imaginary part (an imaginary number). 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 unit 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 and .5^i#, will be approximated, and only a single root will be produced, even though there may be many roots (see the roots command). That single root is called the "principal value", which may be unexpected and will often be inexact.

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

    replace i with -i

## Commands

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

Copyright © 1987-2010 George Gesslein II

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included here in the Mathomatic documentation directory.

Up to the documentation index www.mathomatic.org