www.delorie.com/gnu/docs/calc/calc_155.html   search  
Buy the book!

GNU Emacs Calc 2.02 Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.5 Simplification Modes

The current simplification mode controls how numbers and formulas are "normalized" when being taken from or pushed onto the stack. Some normalizations are unavoidable, such as rounding floating-point results to the current precision, and reducing fractions to simplest form. Others, such as simplifying a formula like a+a (or 2+3), are done by default but can be turned off when necessary.

When you press a key like + when 2 and 3 are on the stack, Calc pops these numbers, normalizes them, creates the formula 2+3, normalizes it, and pushes the result. Of course the standard rules for normalizing 2+3 will produce the result 5.

Simplification mode commands consist of the lower-case m prefix key followed by a shifted letter.

The m O (calc-no-simplify-mode) command turns off all optional simplifications. These would leave a formula like 2+3 alone. In fact, nothing except simple numbers are ever affected by normalization in this mode.

The m N (calc-num-simplify-mode) command turns off simplification of any formulas except those for which all arguments are constants. For example, 1+2 is simplified to 3, and a+(2-2) is simplified to a+0 but no further, since one argument of the sum is not a constant. Unfortunately, (a+2)-2 is not simplified because the top-level `-' operator's arguments are not both constant numbers (one of them is the formula a+2). A constant is a number or other numeric object (such as a constant error form or modulo form), or a vector all of whose elements are constant.

The m D (calc-default-simplify-mode) command restores the default simplifications for all formulas. This includes many easy and fast algebraic simplifications such as a+0 to a, and a + 2 a to 3 a, as well as evaluating functions like deriv(x^2, x) to 2 x.

The m B (calc-bin-simplify-mode) mode applies the default simplifications to a result and then, if the result is an integer, uses the b c (calc-clip) command to clip the integer according to the current binary word size. See section 8.7 Binary Number Functions. Real numbers are rounded to the nearest integer and then clipped; other kinds of results (after the default simplifications) are left alone.

The m A (calc-alg-simplify-mode) mode does algebraic simplification; it applies all the default simplifications, and also the more powerful (and slower) simplifications made by a s (calc-simplify). See section 11.3.2 Algebraic Simplifications.

The m E (calc-ext-simplify-mode) mode does "extended" algebraic simplification, as by the a e (calc-simplify-extended) command. See section 11.3.3 "Unsafe" Simplifications.

The m U (calc-units-simplify-mode) mode does units simplification; it applies the command u s (calc-simplify-units), which in turn is a superset of a s. In this mode, variable names which are identifiable as unit names (like `mm' for "millimeters") are simplified with their unit definitions in mind.

A common technique is to set the simplification mode down to the lowest amount of simplification you will allow to be applied automatically, then use manual commands like a s and c c (calc-clean) to perform higher types of simplifications on demand. See section 18.4 Programming with Formulas, for another sample use of no-simplification mode.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003