Evaluating Expressions

Expressions can be evaluated simply by entering them into the Command line.  Expressions consist of numbers, variables (a-z, A-Z), operators (+, -, /), parentheses, and underscores (_) for the last result.  Multiplication is implied for two adjacent operands.

e.g.    -9.8(y-Y)/(x-X)+2b

Entering an expression causes it to be evaluated immediately.  If the expression contains any undefined variables, an error message is displayed.

The program can be used simply as a four-function calculator.  Entering an arithmetic expression causes it to be evaluated and have its result displayed immediately.

Simple expressions consist of integers, floating-point numbers, and arithmetic operators (+, -, /).  For readability, large numbers may be input using commas (,) as group separators.  Decimal fractions between -1 and 1 (e.g. 0.396, -0.125) MUST have a leading zero.  Numbers must NOT be entered using scientific notation of any kind (e.g. "1x10^5", "3.215e-9").  There are some special rules for multiplication that require further explanation...

> 2+2

  Answer = 4


> 17-5

  Answer = 12


> -2+5.015+11/3

  Answer = 6.68166666666667


> 1,234+27,342,953

  Answer = 27,344,187

Expressions are automatically grouped and evaluated according to standard mathematical conventions.  Parentheses may be used to group subexpressions and override operator precedence and the normal order of evaluation.

> (2.75+9.99)/643

  Answer = 0.0198133748055988


> -418/(1018+3)

  Answer = -0.409402546523017


> 54+9.11/(-32)

  Answer = 53.7153125

Keeping with standard algebraic notation, there is no explicit symbol for multiplication.  Multiplication is implied for two adjacent operands or expressions.  When multiplying two numbers together, they must be separated by enclosing at least one of them in parentheses.

> 3(4)

  Answer = 12


> 12(12)3

  Answer = 432


> (12)12(3)

  Answer = 432


> 12((12)3)

  Answer = 432


> 5(2.31-175)

  Answer = -863.45

If a floating-point answer can be represented as a convenient fraction, both the floating-point result and an equivalent fraction (reduced to lowest terms) will be displayed.

> 512/384

  Answer = 1.33333333333333 (or 4 / 3, or 1 & 1 / 3)


> (1.675+3.4)/2

  Answer = 2.5375 (or 203 / 80, or 2 & 43 / 80)

An underscore (_) character can be used in an expression to refer to the most recent answer...  AutoMathic fills in the blanks with the last result and evaluates the expression:

> 5_+2

  Answer = 14.6875 (or 235 / 16, or 14 & 11 / 16)


> _-2

  Answer = 12.6875 (or 203 / 16, or 12 & 11 / 16)


> _/5+_

  Answer = 15.225 (or 609 / 40, or 15 & 9 / 40)

Using "_" to refer to the last result allows calculations to be done piecemeal, building-up results bit-by-bit to see and use intermediate values.

Variables

Variables are symbols used to represent unknown or changeable quantities.  In this program, any uppercase or lowercase letter (A-Z, a-z) can be used as a variable name.  Variable names are case-sensitive, so "G" and "g" for example represent two distinct variables.  Variables may be defined as follows:

> x=11
                          
x = 11



       x = 11


> y=3

                          
y = 3

       y = 3


> e=2.71828

                          
e = 2.71828

       e = 2.71828

Once defined, variables can be used in place of numbers in calculations:

> 5+x

  Answer = 16

Unlike numbers, variables do not require surrounding parentheses when multiplying them by numbers or other variables.  This allows the input to resemble standard algebraic expressions and equations...

> 3y-(2x-1)

  Answer = -12


> 7xy/(-e)


  Answer = -84.9802080727519

Since a variable might not always have a value assigned to it, trying to evaluate an expression with one or more undefined variables leads to an error message:

> 2w
 * ERROR: Variable 'w' is undefined.
  Answer = 0

To show the definition (if any) of a variable, use the "list" command or enter an expression consisting of the variable itself.

> list w
> list x
       x = 11
> list x y
       x = 11
       y = 3
> e
  Answer = 2.71828

Note that no output or error message was generated when "list"ing the undefined variable "w".

To show the definitions of all variables, use the "list variables" command:

> list variables

     x = 11
       y = 3
       e = 2.71828

Variable definitions persist until redefined or explicitly erased.  To redefine a variable, simply assign it a new value.

> list x

       x = 11

> x=7

x = 7
       x = 7
> list x

       x = 7

To erase the value of one or more variables, use the "clear" command.  This is discussed fully in the "Erasing Variables" section.